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):
|
def _visit_expr_NameConstant(self, node):
|
||||||
v = node.value
|
v = node.value
|
||||||
if isinstance(v, bool):
|
if v is None:
|
||||||
|
r = ir_values.VNone()
|
||||||
|
elif isinstance(v, bool):
|
||||||
r = ir_values.VBool()
|
r = ir_values.VBool()
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
|
@ -51,6 +51,7 @@ d = 4 # stays int32
|
||||||
x = int64(7)
|
x = int64(7)
|
||||||
a += x # promotes a to int64
|
a += x # promotes a to int64
|
||||||
foo = True
|
foo = True
|
||||||
|
bar = None
|
||||||
"""
|
"""
|
||||||
ns = infer_types(ast.parse(testcode))
|
ns = infer_types(ast.parse(testcode))
|
||||||
for k, v in sorted(ns.items(), key=itemgetter(0)):
|
for k, v in sorted(ns.items(), key=itemgetter(0)):
|
||||||
|
|
|
@ -2,6 +2,28 @@ from types import SimpleNamespace
|
||||||
|
|
||||||
from llvm import core as lc
|
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
|
# Integer type
|
||||||
|
|
||||||
class VInt:
|
class VInt:
|
||||||
|
|
Loading…
Reference in New Issue