diff options
| author | mryouse | 2022-05-13 02:35:25 +0000 | 
|---|---|---|
| committer | mryouse | 2022-05-13 02:35:25 +0000 | 
| commit | 3d23b45a0ab381f34a2dae327e22cfa862af46ea (patch) | |
| tree | 104bd1949d60947058b1208169b0372092b0f14c /std.py | |
| parent | e18bdec21683adfb2658359568a54a2f3f21d703 (diff) | |
lists? not sure if they fully work, but somewhat
Diffstat (limited to 'std.py')
| -rw-r--r-- | std.py | 24 | 
1 files changed, 24 insertions, 0 deletions
| @@ -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() | 
