Skip to content

Commit 0295508

Browse files
committed
backend: Code improvements and the addition of system annotations
1 parent 53ebb8e commit 0295508

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

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

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,13 @@
2424
import org.piccode.rt.PiccodeString;
2525
import org.piccode.rt.PiccodeUnit;
2626
import org.piccode.rt.PiccodeValue;
27+
import org.piccode.rt.PiccodeWarning;
2728
import org.piccode.rt.modules.PiccodeArrayModule;
2829
import org.piccode.rt.modules.PiccodeFileModule;
30+
import org.piccode.rt.modules.PiccodeFsModule;
2931
import org.piccode.rt.modules.PiccodeIOModule;
3032
import org.piccode.rt.modules.PiccodeMathModule;
33+
import org.piccode.rt.modules.PiccodeObjectModule;
3134
import org.piccode.rt.modules.PiccodeStringModule;
3235
import org.piccode.rt.modules.PiccodeSystemModule;
3336
import org.piccode.rt.modules.PiccodeTimeModule;
@@ -75,7 +78,7 @@ public static PiccodeValue compile(String file, String code, List<PiccodeValue>
7578
var _result = new CallAst(new IdentifierAst("main"), List.of()).execute(null);
7679
return _result;
7780
}
78-
81+
7982
Context.top.dropStackFrame();
8083
return res;
8184
} catch (PiccodeReturnException ret) {
@@ -105,18 +108,17 @@ public static List<Ast> parse(String file, String code) {
105108
}
106109

107110
public static StatementList program(String file, String code) {
108-
111+
109112
if (code.startsWith("#!/")) {
110113
code = sanitizeSourceFile(code);
111114
}
112-
115+
113116
var err = new SyntaxError(file);
114-
117+
115118
var lexer = new PiccodeScriptLexer(CharStreams.fromString(code));
116119
lexer.removeErrorListeners();
117120
lexer.addErrorListener(err);
118-
119-
121+
120122
var parser = new PiccodeScriptParser(new CommonTokenStream(lexer));
121123
parser.removeErrorListeners();
122124
parser.addErrorListener(err);
@@ -144,11 +146,10 @@ public static void prepareGlobalScope(String file, String globalScopeName) {
144146
scope_id.file = file;
145147
Context.top.pushStackFrame(scope_id);
146148
Context.top.putLocal("true", new PiccodeBoolean("true"));
147-
Context.top.putLocal("false", new PiccodeBoolean("false"));
149+
Context.top.putLocal("false", new PiccodeBoolean("false"));
148150
addSystemFunctions();
149151
}
150152

151-
152153
private static void addSystemFunctions() {
153154
PiccodeIOModule.addFunctions();
154155
PiccodeArrayModule.addFunctions();
@@ -160,18 +161,24 @@ private static void addSystemFunctions() {
160161
PiccodeTypesModule.addFunctions();
161162
PiccodeVirtualModule.addFunctions();
162163
PiccodeFileModule.addFunctions();
164+
PiccodeFsModule.addFunctions();
165+
PiccodeObjectModule.addFunctions();
166+
167+
Context.addAnnotation("Deprecated", (frame, node) -> {
168+
var warning = new PiccodeWarning(node.file, node.line, node.column, "Invocation of a deprecated function");
169+
warning.report();
170+
return node.execute(frame);
171+
});
163172
}
164173

165-
166174
private static class SyntaxError extends BaseErrorListener {
167175

168176
public String file;
169177

170178
public SyntaxError(String file) {
171179
this.file = file;
172180
}
173-
174-
181+
175182
@Override
176183
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) {
177184
throw new PiccodeException(file, line, charPositionInLine, msg);

0 commit comments

Comments
 (0)