1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
from .. import TypeEnum, Environment, Arg, Builtin, evaluate, InterpretPanic, TypeWrap, MultiFunction
from ..structs import *
BOOLEAN = Environment()
def interpretEq(symbol, args, env, ns):
# 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 f"{args[0]}" == f"{args[1]}":
return Bool(True)
else:
return Bool(False)
elif 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.ANY)
eq_func = Builtin("eq?", interpretEq, [eq_arg, eq_arg], return_type=Type(":bool"))
eq_multi = MultiFunction("eq?")
eq_multi.register(eq_func)
BOOLEAN.register("eq?", eq_multi)
def interpretNot(symbol, args, env, ns):
return Bool(not args[0].value)
not_arg = Arg("not", TypeEnum.BOOL)
not_func = Builtin("not", interpretNot, [not_arg], return_type=Type(":bool"))
not_multi = MultiFunction("not")
not_multi.register(not_func)
BOOLEAN.register("not", not_multi)
|