forked from M-Labs/artiq
1
0
Fork 0

compiler: add None type support

This commit is contained in:
Sebastien Bourdeauducq 2014-08-17 23:46:29 +08:00
parent 9e21ea5658
commit 4b0788d92c
3 changed files with 26 additions and 1 deletions

View File

@ -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

View File

@ -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)):

View File

@ -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: