diff options
| author | mryouse | 2022-05-10 05:05:39 +0000 |
|---|---|---|
| committer | mryouse | 2022-05-10 05:05:39 +0000 |
| commit | fcff78ad45953c2473270c928e0256917f30d5c2 (patch) | |
| tree | fcbac87029def35873453208082b2e806b6093a5 | |
| parent | b9db8d7c741ca81e71a56e84b030c67659597735 (diff) | |
add debug toggle
| -rw-r--r-- | repl.py | 8 | ||||
| -rw-r--r-- | std.py | 19 |
2 files changed, 25 insertions, 2 deletions
@@ -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 @@ -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) |
