aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--repl.py8
-rw-r--r--std.py19
2 files changed, 25 insertions, 2 deletions
diff --git a/repl.py b/repl.py
index af84c82..8b4622e 100644
--- a/repl.py
+++ b/repl.py
@@ -1,6 +1,8 @@
from lexer import lex
from parser import parse
from runner import evaluate
+from std import _get_debug
+
def main():
idx = 1
@@ -10,9 +12,11 @@ def main():
continue
try:
lexed = lex(inp, [])
- print(f" - LEX: {lexed}")
+ if _get_debug():
+ print(f" - LEX: {lexed}")
parsed = parse(lexed, [])
- print(f" - PARSE: {parsed}")
+ if _get_debug():
+ print(f" - PARSE: {parsed}")
ev = evaluate(parsed, [])
print(f"=> {ev}")
idx += 1
diff --git a/std.py b/std.py
index f957b53..6f591fc 100644
--- a/std.py
+++ b/std.py
@@ -5,6 +5,10 @@ from collections import namedtuple
FuncImpl = namedtuple("FuncImpl", ("func", "impl"))
STD = {}
+DEBUG = True
+
+def _get_debug():
+ return DEBUG
def std_exit(status=0):
sys.exit(status)
@@ -15,6 +19,16 @@ def std_print(arg):
#return [] # TODO this should return empty list
return NebLiteral(NebType.BOOL, True)
+def std_debug_on():
+ global DEBUG
+ DEBUG = True
+ return NebLiteral(NebType.BOOL, True)
+
+def std_debug_off():
+ global DEBUG
+ DEBUG = False
+ return NebLiteral(NebType.BOOL, True)
+
# math
def std_add(arg1, arg2):
typ = NebType.INT
@@ -45,6 +59,11 @@ def build_std():
exit_int = FuncImpl(NebFunction("exit", [NebType.INT], NebType.BOOL), std_exit)
STD["exit"] = build_sig_dict(exit_, exit_int)
+ debug_on = FuncImpl(NebFunction("debug-on", [], NebType.BOOL), std_debug_on)
+ STD["debug-on"] = build_sig_dict(debug_on)
+ debug_off = FuncImpl(NebFunction("debug-off", [], NebType.BOOL), std_debug_off)
+ STD["debug-off"] = build_sig_dict(debug_off)
+
# arithmetic
add_int_int = FuncImpl(NebFunction("+", [NebType.INT, NebType.INT], NebType.INT), std_add)
add_int_float = FuncImpl(NebFunction("+", [NebType.INT, NebType.FLOAT], NebType.FLOAT), std_add)