From 3d23b45a0ab381f34a2dae327e22cfa862af46ea Mon Sep 17 00:00:00 2001 From: mryouse Date: Fri, 13 May 2022 02:35:25 +0000 Subject: lists? not sure if they fully work, but somewhat --- std.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'std.py') diff --git a/std.py b/std.py index fe0ede1..0cd5aee 100644 --- a/std.py +++ b/std.py @@ -1,6 +1,7 @@ from tokens import * import sys from collections import namedtuple +import subprocess FuncImpl = namedtuple("FuncImpl", ("func", "impl")) @@ -22,6 +23,16 @@ def std_print(arg): #return [] # TODO this should return empty list return NebBool(True) +def std_print_all(arg): + for idx, item in enumerate(arg.items): + if isinstance(item, NebExpression): + arg.items[idx] = evaluate_expression(item) + elif not isinstance(item, NebString): + raise exception("print-all needs all strings!") + for x in arg.items: + std_print(x) + return NebBool(True) + def std_debug_on(): global DEBUG DEBUG = True @@ -103,6 +114,12 @@ def std_is_bool(arg): else: return NebBool(False) +# shell +def std_shell(arg): + assert isinstance(arg, NebString) + subprocess.run(arg.value) + return NebBool(True) + def evaluate_expression(expr): if not expr.symbol.name in STD: raise Exception(f"no such symbol: {expr.symbol.name}") @@ -135,6 +152,9 @@ def build_std(): print_string = FuncImpl(NebFunction("print", [NebString], NebString), std_print) STD["print"] = [print_string] + print_all = FuncImpl(NebFunction("print-all", [NebList], NebBool), std_print_all) + STD["print-all"] = [print_all] + exit_ = FuncImpl(NebFunction("exit", [], NebBool), std_exit) exit_int = FuncImpl(NebFunction("exit", [NebInt], NebBool), std_exit) STD["exit"] = [exit_, exit_int] @@ -175,4 +195,8 @@ def build_std(): is_bool = FuncImpl(NebFunction("string?", [NebAny], NebBool), std_is_bool) STD["bool?"] = [is_bool] + # shell + shell_string = FuncImpl(NebFunction("$", [NebString], NebBool), std_shell) + STD["$"] = [shell_string] + build_std() -- cgit v1.2.3