From e2b105629164a6df98c8b1ca63c5304ef697b2d1 Mon Sep 17 00:00:00 2001 From: mryouse Date: Sat, 18 Jun 2022 01:34:42 +0000 Subject: cleanup outdated comments and dead code --- interpreter.py | 39 --------------------------------------- 1 file changed, 39 deletions(-) diff --git a/interpreter.py b/interpreter.py index f5a8562..c675930 100644 --- a/interpreter.py +++ b/interpreter.py @@ -5,8 +5,6 @@ from parser import parse from typeclass import TypeEnum, is_subtype_of from pathlib import Path from glob import glob -from collections import namedtuple -from dataclasses import dataclass import subprocess import shlex import random @@ -14,7 +12,6 @@ import sys import math -@dataclass class Arg: def __init__(self, name, type_, *, optional=False, lazy=False): @@ -101,7 +98,6 @@ class Builtin(Function): class UserFunction(Function): def __init__(self, name, params, body): - # TODO this doesn't do type checking, or optional, or lazy newparams, args, many = self.process_params(name, params) super().__init__(name, newparams, body, args, many) @@ -195,7 +191,6 @@ def interpret(exprs, *, env=GLOBALS, ns=None): def evaluate(expr, env, ns=None): if isinstance(expr, Literal) or isinstance(expr, Function) or isinstance(expr, Type): - #return expr.value return expr elif isinstance(expr, Symbol): if env.contains(expr.name): @@ -205,15 +200,6 @@ def evaluate(expr, env, ns=None): else: raise NebPanic(f"no such symbol: {expr}") - ''' - if not env.contains(expr.name): - raise NebPanic(f"no such symbol: {expr}") - if ns is None: - return evaluate(env.get(expr.name), env, ns) - else: - return evaluate(env.get(f"{ns}/{expr.name}"), env, ns) - ''' - # if it's a literal list, return it if expr.data: return expr @@ -224,8 +210,6 @@ def evaluate(expr, env, ns=None): if not isinstance(expr.args[0], Symbol): raise NebPanic("can't evaluate without a symbol") name = expr.args[0].name - #if ns is not None: - # name = f"{ns}/{name}" if env.contains(name): return env.get(name).call(expr, env, ns) elif ns is not None and env.contains(f"{ns}/{name}"): @@ -243,7 +227,6 @@ def interpretOr(symbol, args, env, ns): return ev return Bool(False) -#GLOBALS.register("or", Builtin(interpretOr, 2)) or_arg = Arg("arg", TypeEnum.BOOL, lazy=True) GLOBALS.register("or", Builtin(interpretOr, [or_arg, or_arg], or_arg)) @@ -345,7 +328,6 @@ not_arg = Arg("not", TypeEnum.BOOL) GLOBALS.register("not", Builtin(interpretNot, [not_arg])) def interpretIf(symbol, args, env, ns): - # if cond t-branch [f-branch] if args[0].value: return evaluate(args[1], env, ns) elif len(args) == 3: @@ -414,7 +396,6 @@ def interpretToString(symbol, args, env, ns): GLOBALS.register("->string", Builtin(interpretToString, [Arg("arg", TypeEnum.ANY)])) def interpretConcat(symbol, args, env, ns): - # concat str1 str2...strN out = "" for arg in args: out += arg.value @@ -424,7 +405,6 @@ string_arg = Arg("arg", TypeEnum.STRING) GLOBALS.register("concat", Builtin(interpretConcat, [string_arg, string_arg], string_arg)) def interpretForCount(symbol, args, env, ns): - # for-count int exprs new_env = Environment(env) ret = None for idx in range(0, args[0].value): @@ -440,7 +420,6 @@ for_body_arg = Arg("body", TypeEnum.ANY, lazy=True) GLOBALS.register("for-count", Builtin(interpretForCount, [for_count_arg, for_body_arg], for_body_arg)) def interpretForEach(symbol, args, env, ns): - # for-each list exprs new_env = Environment(env) ret = None for item in args[0].args: @@ -482,12 +461,6 @@ def interpretBranch(symbol, args, env, ns): GLOBALS.register("branch", Builtin(interpretBranch, [for_body_arg], for_body_arg)) def interpretFunc(symbol, args, env, ns): - # func (args) (exprs) - - # maybe: - # arg [:type] -> type is optional - # ?arg default -> 'arg' is optional, defaulted - # *arg [:type] -> 'arg' is a list containing the remaining args if not isinstance(args[0], Symbol): raise InterpretPanic(symbol, "requires a :string name") name = args[0].name # NOTE: we are not evaluating the name!! @@ -503,8 +476,6 @@ def interpretFunc(symbol, args, env, ns): GLOBALS.register("func", Builtin(interpretFunc, [def_name_arg, lambda_args_arg, lambda_body_arg], lambda_body_arg)) -# THINGS NEEDED FOR AOC -# - read the contents of a file def interpretReadLines(symbol, args, env, ns): target_file_name = args[0].value target_file = Path(target_file_name).resolve() @@ -517,7 +488,6 @@ def interpretReadLines(symbol, args, env, ns): GLOBALS.register("read-lines", Builtin(interpretReadLines, [Arg("filename", TypeEnum.STRING)])) -# - strip whitespace from string def interpretStrip(symbol, args, env, ns): return String(args[0].value.strip()) @@ -533,7 +503,6 @@ def interpretStringToInt(symbol, args, env, ns): GLOBALS.register("string->int", Builtin(interpretStringToInt, [Arg("arg", TypeEnum.STRING)])) -# - split a string by a given field def interpretSplit(symbol, args, env, ns): target = args[0] if len(args) == 1: @@ -544,13 +513,11 @@ def interpretSplit(symbol, args, env, ns): GLOBALS.register("split", Builtin(interpretSplit, [Arg("target", TypeEnum.STRING)], Arg("splitter", TypeEnum.STRING, optional=True))) -# - get the length of a list def interpretListLength(symbol, args, env, ns): return Int(len(args[0].args)) GLOBALS.register("list-length", Builtin(interpretListLength, [Arg("arg", TypeEnum.LIST)])) -# - first/rest of list def interpretFirst(symbol, args, env, ns): if len(args[0].args) == 0: raise InterpretPanic(symbol, "list is empty") @@ -564,10 +531,7 @@ def interpretRest(symbol, args, env, ns): GLOBALS.register("rest", Builtin(interpretRest, [Arg("arg", TypeEnum.LIST)])) -# - iterate over list -# - map def interpretMap(symbol, args, env, ns): - # TODO: to support lambdas, we can't assume the func is defined func = args[0] if not isinstance(func, Function): raise InterpretPanic(symbol, "requires a :func as its first argument", func) @@ -626,7 +590,6 @@ def interpretGlob(symbol, args, env, ns): GLOBALS.register("glob", Builtin(interpretGlob, [Arg("regex", TypeEnum.STRING)])) def interpretShell(symbol, args, env, ns): - # TODO either fail or throw exception (?) on error ret = subprocess.run(shlex.split(args[0].value), capture_output=True) return List([String(r) for r in ret.stdout.decode("utf-8").split("\n")], True) @@ -884,7 +847,6 @@ def interpretUseAs(symbol, args, env, ns): interpret(parse(lex(data)), ns=args[1].name) return List([]) -# TODO takes a symbol as its second, that may be wrong GLOBALS.register("use-as", Builtin(interpretUseAs, [Arg("filename", TypeEnum.STRING), Arg("namespace", TypeEnum.ANY, lazy=True)])) def interpretFloor(symbol, args, env, ns): @@ -893,7 +855,6 @@ def interpretFloor(symbol, args, env, ns): GLOBALS.register("floor", Builtin(interpretFloor, [Arg("floor", TypeEnum.NUMBER)])) def interpretFilter(symbol, args, env, ns): - # TODO: to support lambdas, we can't assume the func is defined func = args[0] if not isinstance(func, Function): raise InterpretPanic(symbol, "requires a :func as its first argument", func) -- cgit v1.2.3