Skip to content

Commit 0b6af24

Browse files
committed
fix a typo in type_to_tag
1 parent ae03506 commit 0b6af24

File tree

5 files changed

+31
-5
lines changed

5 files changed

+31
-5
lines changed

interp_Ctup.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44

55
class InterpCtup(InterpCif):
66

7+
def interp_cmp(self, cmp):
8+
match cmp:
9+
case Is():
10+
return lambda x, y: x is y
11+
case _:
12+
return super().interp_cmp(cmp)
13+
714
def interp_exp(self, e, env):
815
match e:
916
case Tuple(es, Load()):

interp_Lany.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def type_to_tag(self, typ):
2121
case IntType():
2222
return 'int'
2323
case BoolType():
24-
return 'int'
24+
return 'bool'
2525
case _:
2626
raise Exception('type_to_tag unexpected ' + repr(typ))
2727

interp_Lvar.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ def interp_exp(self, e, env):
1212

1313
def interp_stmt(self, s, env, cont):
1414
match s:
15-
case Assign([lhs], value):
16-
env[lhs.id] = self.interp_exp(value, env)
15+
case Assign([Name(id)], value):
16+
env[id] = self.interp_exp(value, env)
1717
return self.interp_stmts(cont, env)
1818
case _:
1919
return super().interp_stmt(s, env, cont)

type_check_Ctup.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ def check_type_equal(self, t1, t2, e):
2222

2323
def type_check_exp(self, e, env):
2424
match e:
25+
case Compare(left, [cmp], [right]) if isinstance(cmp, Is):
26+
l = self.type_check_exp(left, env)
27+
r = self.type_check_exp(right, env)
28+
self.check_type_equal(l, r, e)
29+
return BoolType()
2530
case Allocate(length, typ):
2631
return typ
2732
case GlobalValue(name):

utils.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def repr_Not(self):
289289

290290

291291
def str_UnaryOp(self):
292-
return str(self.op) + str(self.operand)
292+
return str(self.op) + ' ' + str(self.operand)
293293

294294

295295
UnaryOp.__str__ = str_UnaryOp
@@ -469,6 +469,20 @@ def repr_GtE(self):
469469
GtE.__repr__ = repr_GtE
470470

471471

472+
def str_Is(self):
473+
return 'is'
474+
475+
476+
Is.__str__ = str_Is
477+
478+
479+
def repr_Is(self):
480+
return 'Is()'
481+
482+
483+
Is.__repr__ = repr_Is
484+
485+
472486
def str_Tuple(self):
473487
return '(' + ', '.join([str(e) for e in self.elts]) + ',)'
474488

@@ -863,7 +877,7 @@ class Closure(expr):
863877
__match_args__ = ("arity", "args")
864878

865879
def __str__(self):
866-
return 'closure[' + repr(self.arity) + '](' + ', '.join([str(e) for e in self.args]) + ')'
880+
return 'closure{' + repr(self.arity) + '}(' + ', '.join([str(e) for e in self.args]) + ')'
867881

868882

869883
@dataclass

0 commit comments

Comments
 (0)