From 4b0788d92c5bc8576a93293acfc8a11e1da030e0 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sun, 17 Aug 2014 23:46:29 +0800 Subject: [PATCH] compiler: add None type support --- artiq/compiler/ir_ast_body.py | 4 +++- artiq/compiler/ir_infer_types.py | 1 + artiq/compiler/ir_values.py | 22 ++++++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/artiq/compiler/ir_ast_body.py b/artiq/compiler/ir_ast_body.py index ced70968a..8e8fb270e 100644 --- a/artiq/compiler/ir_ast_body.py +++ b/artiq/compiler/ir_ast_body.py @@ -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 diff --git a/artiq/compiler/ir_infer_types.py b/artiq/compiler/ir_infer_types.py index 62f2e3c44..2a9d6f60c 100644 --- a/artiq/compiler/ir_infer_types.py +++ b/artiq/compiler/ir_infer_types.py @@ -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)): diff --git a/artiq/compiler/ir_values.py b/artiq/compiler/ir_values.py index ad6c0d1bb..7d7ed5793 100644 --- a/artiq/compiler/ir_values.py +++ b/artiq/compiler/ir_values.py @@ -2,6 +2,28 @@ from types import SimpleNamespace from llvm import core as lc +# None type + +class VNone: + def __repr__(self): + return "" + + 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: