|
2 | 2 |
|
3 | 3 | import java.io.PrintStream; |
4 | 4 | import java.util.ArrayList; |
| 5 | +import java.util.HashMap; |
5 | 6 | import java.util.List; |
6 | 7 | import org.antlr.v4.runtime.BaseErrorListener; |
7 | 8 | import org.antlr.v4.runtime.CharStreams; |
@@ -50,8 +51,9 @@ public class Compiler { |
50 | 51 | public static PrintStream out = System.out; |
51 | 52 | public static ErrorAsciiKind errorKind = ErrorAsciiKind.GLEAM_STYLE; |
52 | 53 | public static boolean exitOnError = true; |
53 | | - private static List<Runnable> nativeFunctions = new ArrayList<>(); |
54 | | - |
| 54 | + private final static List<Runnable> nativeFunctions = new ArrayList<>(); |
| 55 | + private final static HashMap<String, PiccodeValue> symbols = new HashMap<>(); |
| 56 | + |
55 | 57 | public static PiccodeValue compile(String file, String code) { |
56 | 58 | return compile(file, code, List.of()); |
57 | 59 | } |
@@ -194,9 +196,20 @@ public static void prepareGlobalScope(String file, String globalScopeName) { |
194 | 196 | Context.top.pushStackFrame(scope_id); |
195 | 197 | Context.top.putLocal("true", new PiccodeBoolean("true")); |
196 | 198 | Context.top.putLocal("false", new PiccodeBoolean("false")); |
| 199 | + |
| 200 | + for (var kv: symbols.entrySet()) { |
| 201 | + var key = kv.getKey(); |
| 202 | + var value = kv.getValue(); |
| 203 | + Context.top.putLocal(key, value); |
| 204 | + } |
| 205 | + |
197 | 206 | addSystemFunctions(); |
198 | 207 | } |
199 | 208 |
|
| 209 | + public static void addSymbol(String name, PiccodeValue value) { |
| 210 | + symbols.put(name, value); |
| 211 | + } |
| 212 | + |
200 | 213 | public static void addNativeFunctions(Runnable funcs) { |
201 | 214 | funcs.run(); |
202 | 215 | } |
|
0 commit comments