aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormryouse2022-05-13 22:50:15 +0000
committermryouse2022-05-13 22:50:15 +0000
commit47a483d875e9bd0fb0575f9450790eb962e0d799 (patch)
tree29b4b4857ad177bbc4b584dd1858e78447f242cf
parent9ac2c37464ae95d78e9d410fa8ec71543fe46d8e (diff)
return nil (empty list) if there's nothing else to return
-rw-r--r--std.py26
-rw-r--r--tokens.py7
2 files changed, 20 insertions, 13 deletions
diff --git a/std.py b/std.py
index 7d69345..9496a95 100644
--- a/std.py
+++ b/std.py
@@ -16,12 +16,11 @@ def _get_debug():
def std_exit(status=None):
out = 0 if status is None else status.value
sys.exit(out)
- return NebBool(True) # this should never be reached
+ return NebNil()
def std_print(arg):
print(arg.value)
- #return [] # TODO this should return empty list
- return NebBool(True)
+ return NebNil()
def std_print_all(arg):
for idx, item in enumerate(arg.items):
@@ -31,17 +30,17 @@ def std_print_all(arg):
raise exception("print-all needs all strings!")
for x in arg.items:
std_print(x)
- return NebBool(True)
+ return NebNil()
def std_debug_on():
global DEBUG
DEBUG = True
- return NebBool(True)
+ return NebNil()
def std_debug_off():
global DEBUG
DEBUG = False
- return NebBool(True)
+ return NebNil()
# math
def std_add(arg, rest):
@@ -109,7 +108,8 @@ def std_if(cond, t_branch, f_branch=None):
return evaluate_expression(f_branch)
else:
return f_branch
- return NebBool(True)
+ #return NebBool(True)
+ return NebNil()
# type validation
def std_is_string(arg):
@@ -242,19 +242,19 @@ def evaluate_expression(expr):
raise Exception(f"'{expr.symbol.name}' called with unknown signature: '{expr.in_sig()}'")
def build_std():
- print_string = FuncImpl(NebFunction("print", [NebString], NebString), std_print)
+ print_string = FuncImpl(NebFunction("print", [NebString], NebNil), std_print)
STD["print"] = [print_string]
- print_all = FuncImpl(NebFunction("print-all", [NebList], NebBool), std_print_all)
+ print_all = FuncImpl(NebFunction("print-all", [NebList], NebNil), std_print_all)
STD["print-all"] = [print_all]
- exit_ = FuncImpl(NebFunction("exit", [], NebBool), std_exit)
- exit_int = FuncImpl(NebFunction("exit", [NebInt], NebBool), std_exit)
+ exit_ = FuncImpl(NebFunction("exit", [], NebNil), std_exit)
+ exit_int = FuncImpl(NebFunction("exit", [NebInt], NebNil), std_exit)
STD["exit"] = [exit_, exit_int]
- debug_on = FuncImpl(NebFunction("debug-on", [], NebBool), std_debug_on)
+ debug_on = FuncImpl(NebFunction("debug-on", [], NebNil), std_debug_on)
STD["debug-on"] = [debug_on]
- debug_off = FuncImpl(NebFunction("debug-off", [], NebBool), std_debug_off)
+ debug_off = FuncImpl(NebFunction("debug-off", [], NebNil), std_debug_off)
STD["debug-off"] = [debug_off]
# arithmetic
diff --git a/tokens.py b/tokens.py
index 1f1fe1b..6e4ba86 100644
--- a/tokens.py
+++ b/tokens.py
@@ -140,3 +140,10 @@ class NebList(NebAny):
out += f"{item} "
return f"{out}]"
+class NebNil(NebList):
+ def __init__(self):
+ super().__init__([])
+
+ def __str__(self):
+ return "()"
+