aboutsummaryrefslogtreecommitdiff
path: root/std.py
diff options
context:
space:
mode:
authormryouse2022-05-10 02:46:42 +0000
committermryouse2022-05-10 02:46:42 +0000
commit3e70f2ce47ee954640df9ee3b432964c1111b5ed (patch)
tree0ed1155e401b1768adc0fd537721b5a75749e1c0 /std.py
parent7bed8de9b493ca2a2b13d6293db6bd81b73325ce (diff)
refactor: std to own file, implement 'exit', multiple sigs
Diffstat (limited to 'std.py')
-rw-r--r--std.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/std.py b/std.py
new file mode 100644
index 0000000..dfa1cef
--- /dev/null
+++ b/std.py
@@ -0,0 +1,32 @@
+from tokens import *
+import sys
+from collections import namedtuple
+
+FuncImpl = namedtuple("FuncImpl", ("func", "impl"))
+
+STD = {}
+
+def std_exit(status=0):
+ sys.exit(status)
+ return NebLiteral(NebType.BOOL, True)
+
+def std_print(arg):
+ print(arg.value)
+ #return [] # TODO this should return empty list
+ return NebLiteral(NebType.BOOL, True)
+
+def build_std():
+ print_string = FuncImpl(NebFunction("print", [NebType.STRING], NebType.BOOL), std_print)
+ STD["print"] = {
+ print_string.func.in_sig(): print_string
+ }
+
+ exit_ = FuncImpl(NebFunction("exit", [], NebType.BOOL), std_exit)
+ exit_int = FuncImpl(NebFunction("exit", [NebType.INT], NebType.BOOL), std_exit)
+
+ STD["exit"] = {
+ exit_.func.in_sig(): exit_,
+ exit_int.func.in_sig(): exit_int
+ }
+
+build_std()