some utility methods
This commit is contained in:
parent
05bafc7317
commit
b2f5068e12
@ -86,4 +86,7 @@ public class Reading {
|
||||
public static String resourceToString(String name) {
|
||||
return streamToString(resourceToStream(name));
|
||||
}
|
||||
public static byte[] resourceToBytes(String name) {
|
||||
return streamToBytes(resourceToStream(name));
|
||||
}
|
||||
}
|
||||
|
@ -30,12 +30,15 @@ public abstract class Location implements Comparable<Location> {
|
||||
};
|
||||
}
|
||||
public final Location nextLine() {
|
||||
return changeLine(1);
|
||||
}
|
||||
public final Location changeLine(int offset) {
|
||||
var self = this;
|
||||
|
||||
return new Location() {
|
||||
@Override public Filename filename() { return self.filename(); }
|
||||
@Override public int start() { return 0; }
|
||||
@Override public int line() { return self.line() + 1; }
|
||||
@Override public int line() { return self.line() + offset; }
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ package me.topchetoeu.jscript.compilation;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import java.util.function.Function;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
@ -78,8 +78,11 @@ public final class CompileResult {
|
||||
return instructions.toArray(new Instruction[0]);
|
||||
}
|
||||
|
||||
public FunctionMap map(Function<Location, Location> mapper) {
|
||||
return map.map(mapper).build(scope.localNames(), scope.capturableNames(), scope.captureNames());
|
||||
}
|
||||
public FunctionMap map() {
|
||||
return map.build(scope.localNames(), scope.captureNames());
|
||||
return map.build(scope.localNames(), scope.capturableNames(), scope.captureNames());
|
||||
}
|
||||
public FunctionBody body() {
|
||||
var builtChildren = new FunctionBody[children.size()];
|
||||
|
Loading…
Reference in New Issue
Block a user