some utility methods

This commit is contained in:
TopchetoEU 2024-12-25 02:50:37 +02:00
parent 05bafc7317
commit b2f5068e12
Signed by: topchetoeu
GPG Key ID: 6531B8583E5F6ED4
3 changed files with 12 additions and 3 deletions

View File

@ -86,4 +86,7 @@ public class Reading {
public static String resourceToString(String name) { public static String resourceToString(String name) {
return streamToString(resourceToStream(name)); return streamToString(resourceToStream(name));
} }
public static byte[] resourceToBytes(String name) {
return streamToBytes(resourceToStream(name));
}
} }

View File

@ -30,12 +30,15 @@ public abstract class Location implements Comparable<Location> {
}; };
} }
public final Location nextLine() { public final Location nextLine() {
return changeLine(1);
}
public final Location changeLine(int offset) {
var self = this; var self = this;
return new Location() { return new Location() {
@Override public Filename filename() { return self.filename(); } @Override public Filename filename() { return self.filename(); }
@Override public int start() { return 0; } @Override public int start() { return 0; }
@Override public int line() { return self.line() + 1; } @Override public int line() { return self.line() + offset; }
}; };
} }

View File

@ -2,7 +2,7 @@ package me.topchetoeu.jscript.compilation;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Function;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
@ -78,8 +78,11 @@ public final class CompileResult {
return instructions.toArray(new Instruction[0]); 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() { public FunctionMap map() {
return map.build(scope.localNames(), scope.captureNames()); return map.build(scope.localNames(), scope.capturableNames(), scope.captureNames());
} }
public FunctionBody body() { public FunctionBody body() {
var builtChildren = new FunctionBody[children.size()]; var builtChildren = new FunctionBody[children.size()];