Skip to content

Commit 8b03242

Browse files
committed
Compiler: Defer native function initialization
1 parent 36b4707 commit 8b03242

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/main/java/org/piccode/backend/Compiler.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,23 +196,28 @@ public static void prepareGlobalScope(String file, String globalScopeName) {
196196
Context.top.pushStackFrame(scope_id);
197197
Context.top.putLocal("true", new PiccodeBoolean("true"));
198198
Context.top.putLocal("false", new PiccodeBoolean("false"));
199+
addSystemFunctions();
200+
201+
for (var func: nativeFunctions) {
202+
func.run();
203+
}
199204

200205
for (var kv: symbols.entrySet()) {
201206
var key = kv.getKey();
202207
var value = kv.getValue();
203208
Context.top.putLocal(key, value);
204209
}
205-
206-
addSystemFunctions();
210+
207211
}
208212

209213
public static void addSymbol(String name, PiccodeValue value) {
210214
symbols.put(name, value);
211215
}
212216

213217
public static void addNativeFunctions(Runnable funcs) {
214-
funcs.run();
218+
nativeFunctions.add(funcs);
215219
}
220+
216221
private static void addSystemFunctions() {
217222
addNativeFunctions(PiccodeIOModule::addFunctions);
218223
addNativeFunctions(PiccodeArrayModule::addFunctions);

0 commit comments

Comments
 (0)