From 666179df6d54ec5413f44c7002982ccb6c2c4732 Mon Sep 17 00:00:00 2001 From: mryouse Date: Sun, 10 Jul 2022 20:34:19 +0000 Subject: bugfix: definitions weren't registering (falling out of env) --- repl.neb | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/repl.neb b/repl.neb index e8cb9b5..c661716 100644 --- a/repl.neb +++ b/repl.neb @@ -26,18 +26,22 @@ (print "version: < 0") (def next-cmd-num 1) - (func evaluate-cmd (cmd) - (def evaluated (parse-neb cmd)) - (print (concat "=> " (->string evaluated))) - (redef next-cmd-num (+ 1 next-cmd-num)) - (redef _history_ (append _history_ cmd))) + + (func get-non-empty-input () + (def tmp "") + (while (eq? "" tmp) + (redef tmp (strip (read-line (prompt next-cmd-num))))) + tmp) ; this is the actual loop part (while #true - (def this-cmd (strip (read-line (prompt next-cmd-num)))) - (if (not (eq? "" this-cmd)) + (def this-cmd (get-non-empty-input)) + (def evaluated (try - (evaluate-cmd this-cmd) - (print (concat "panic! " _panic_)))))) + (eval (parse-neb this-cmd)) + _panic_)) + (print (concat "=> " (->string evaluated))) + (redef next-cmd-num (+ 1 next-cmd-num)) + (redef _history_ (append _history_ this-cmd)))) (repl) -- cgit v1.2.3 From a876130d9a0819f13998b2eb591df7e0726dba25 Mon Sep 17 00:00:00 2001 From: mryouse Date: Sun, 10 Jul 2022 20:41:54 +0000 Subject: bugfix: panics shouldn't increment or be included in history --- repl.neb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/repl.neb b/repl.neb index c661716..77faed6 100644 --- a/repl.neb +++ b/repl.neb @@ -36,12 +36,18 @@ ; this is the actual loop part (while #true (def this-cmd (get-non-empty-input)) + (def panicked #false) ; we may not need this two-step if there's a :panic type (def evaluated (try (eval (parse-neb this-cmd)) - _panic_)) - (print (concat "=> " (->string evaluated))) - (redef next-cmd-num (+ 1 next-cmd-num)) - (redef _history_ (append _history_ this-cmd)))) + (block + (redef panicked #true) + _panic_))) + (if panicked + (print (concat "panic! " evaluated)) + (block + (print (concat "=> " (->string evaluated))) + (redef next-cmd-num (+ 1 next-cmd-num)) + (redef _history_ (append _history_ this-cmd)))))) (repl) -- cgit v1.2.3 From 5194669bd08d7cabefe1e22e72de75df5443af38 Mon Sep 17 00:00:00 2001 From: mryouse Date: Sun, 10 Jul 2022 21:11:52 +0000 Subject: eq? now supports types --- neb/std/boolean.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/neb/std/boolean.py b/neb/std/boolean.py index e716a87..b37eaed 100644 --- a/neb/std/boolean.py +++ b/neb/std/boolean.py @@ -1,17 +1,28 @@ -from .. import TypeEnum, Environment, Arg, Builtin, evaluate, InterpretPanic +from .. import TypeEnum, Environment, Arg, Builtin, evaluate, InterpretPanic, TypeWrap from ..structs import * BOOLEAN = Environment() def interpretEq(symbol, args, env, ns): - # NOTE this currently only works for literals - # compare types because 0 != #false in neb - if type(args[0]) == type(args[1]) and args[0].value == args[1].value: - return Bool(True) - else: + # TODO this is a bit hacky + if (isinstance(args[0], Type) or isinstance(args[0], TypeWrap)) and \ + (isinstance(args[1], Type) or isinstance(args[1], TypeWrap)): + if args[0].name == args[1].name: + return Bool(True) + else: + return Bool(False) + elif type(args[0]) != type(args[1]): + print(f"not the same {type(args[0])} {type(args[1])}") return Bool(False) + elif isinstance(args[0], Literal): + if args[0].value == args[1].value: + return Bool(True) + else: + return Bool(False) + else: + raise InterpretPanic(symbol, "unknown comparison type", args[0]) -eq_arg = Arg("value", TypeEnum.LITERAL) +eq_arg = Arg("value", TypeEnum.ANY) BOOLEAN.register("eq?", Builtin("eq?", interpretEq, [eq_arg, eq_arg], return_type=Type(":bool"))) -- cgit v1.2.3 From 9226c0221e603668346676fffa8dc49e934882d3 Mon Sep 17 00:00:00 2001 From: mryouse Date: Sun, 10 Jul 2022 21:13:41 +0000 Subject: strings should be printed with surrounding quotes --- repl.neb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/repl.neb b/repl.neb index 77faed6..cc8ae06 100644 --- a/repl.neb +++ b/repl.neb @@ -33,6 +33,12 @@ (redef tmp (strip (read-line (prompt next-cmd-num))))) tmp) + (func print-result (res) + (print (concat "=> " + (if (eq? :string (typeof res)) + (concat "\"" res "\"") + (->string res))))) + ; this is the actual loop part (while #true (def this-cmd (get-non-empty-input)) @@ -43,10 +49,11 @@ (block (redef panicked #true) _panic_))) + (if panicked (print (concat "panic! " evaluated)) (block - (print (concat "=> " (->string evaluated))) + (print-result evaluated) (redef next-cmd-num (+ 1 next-cmd-num)) (redef _history_ (append _history_ this-cmd)))))) -- cgit v1.2.3 From 2006ac2b87d8af1c9df93cacdd1cb8c7b9307779 Mon Sep 17 00:00:00 2001 From: mryouse Date: Mon, 11 Jul 2022 01:55:21 +0000 Subject: implement tab completion --- neb.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/neb.py b/neb.py index 7e3380f..86c96b1 100644 --- a/neb.py +++ b/neb.py @@ -4,6 +4,16 @@ import sys import readline +class NebCompleter: + + def __init__(self, syntax): + self.syntax = syntax + + def complete(self, text, state): + results = [x for x in self.syntax if x.startswith(text)] + [None] + return results[state] + + def build_std(repl=False): GLOBALS = Environment() global_dict = { **BOOLEAN.environment, @@ -34,6 +44,11 @@ def debug(prev_lexed, prev_parsed): def repl(): env = build_std(True) + + readline.parse_and_bind("tab: complete") + cmp = NebCompleter(env.environment.keys()) + readline.set_completer(cmp.complete) + print("### neb :)(:") print("version: < 0") idx = 1 @@ -65,6 +80,11 @@ def repl(): def run_file(filename): env = build_std(True) + + readline.parse_and_bind("tab: complete") + cmp = NebCompleter(env.environment.keys()) + readline.set_completer(cmp.complete) + with open(filename, "r") as fil: data = fil.read() -- cgit v1.2.3 From 0ed39a708e332399b871a88bf6c7a777630f9247 Mon Sep 17 00:00:00 2001 From: mryouse Date: Mon, 11 Jul 2022 01:57:33 +0000 Subject: bugfix: remove extra print statements --- neb/std/boolean.py | 1 - 1 file changed, 1 deletion(-) diff --git a/neb/std/boolean.py b/neb/std/boolean.py index b37eaed..e480656 100644 --- a/neb/std/boolean.py +++ b/neb/std/boolean.py @@ -12,7 +12,6 @@ def interpretEq(symbol, args, env, ns): else: return Bool(False) elif type(args[0]) != type(args[1]): - print(f"not the same {type(args[0])} {type(args[1])}") return Bool(False) elif isinstance(args[0], Literal): if args[0].value == args[1].value: -- cgit v1.2.3