diff options
Diffstat (limited to 'neb/std/boolean.py')
| -rw-r--r-- | neb/std/boolean.py | 25 | 
1 files 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"))) | 
