forked from M-Labs/artiq
compiler: add None type support
This commit is contained in:
parent
9e21ea5658
commit
4b0788d92c
|
@ -34,7 +34,9 @@ class Visitor:
|
|||
|
||||
def _visit_expr_NameConstant(self, node):
|
||||
v = node.value
|
||||
if isinstance(v, bool):
|
||||
if v is None:
|
||||
r = ir_values.VNone()
|
||||
elif isinstance(v, bool):
|
||||
r = ir_values.VBool()
|
||||
else:
|
||||
raise NotImplementedError
|
||||
|
|
|
@ -51,6 +51,7 @@ d = 4 # stays int32
|
|||
x = int64(7)
|
||||
a += x # promotes a to int64
|
||||
foo = True
|
||||
bar = None
|
||||
"""
|
||||
ns = infer_types(ast.parse(testcode))
|
||||
for k, v in sorted(ns.items(), key=itemgetter(0)):
|
||||
|
|
|
@ -2,6 +2,28 @@ from types import SimpleNamespace
|
|||
|
||||
from llvm import core as lc
|
||||
|
||||
# None type
|
||||
|
||||
class VNone:
|
||||
def __repr__(self):
|
||||
return "<VNone>"
|
||||
|
||||
def same_type(self, other):
|
||||
return isinstance(other, VNone)
|
||||
|
||||
def merge(self, other):
|
||||
if not isinstance(other, VNone):
|
||||
raise TypeError
|
||||
|
||||
def create_alloca(self, builder, name):
|
||||
pass
|
||||
|
||||
def o_bool(self, builder):
|
||||
r = VBool()
|
||||
if builder is not None:
|
||||
r.create_constant(False)
|
||||
return r
|
||||
|
||||
# Integer type
|
||||
|
||||
class VInt:
|
||||
|
|
Loading…
Reference in New Issue