py2llvm/VNone: bugfixes

This commit is contained in:
Sebastien Bourdeauducq 2014-12-19 12:43:13 +08:00
parent f31386d15d
commit 44e7b99792
2 changed files with 15 additions and 5 deletions

View File

@ -10,6 +10,13 @@ class VNone(VGeneric):
def alloca(self, builder, name):
pass
def set_const_value(self, builder, v):
assert v is None
def set_value(self, builder, other):
if not isinstance(other, VNone):
raise TypeError
def o_bool(self, builder):
r = VBool()
if builder is not None:

View File

@ -1,7 +1,7 @@
import llvmlite.ir as ll
from artiq.py2llvm.values import VGeneric
from artiq.py2llvm.base_types import VInt
from artiq.py2llvm.base_types import VInt, VNone
class VList(VGeneric):
@ -12,9 +12,12 @@ class VList(VGeneric):
def get_llvm_type(self):
count = 0 if self.alloc_count is None else self.alloc_count
return ll.LiteralStructType([ll.IntType(32),
ll.ArrayType(self.el_type.get_llvm_type(),
count)])
if isinstance(self.el_type, VNone):
return ll.LiteralStructType([ll.IntType(32)])
else:
return ll.LiteralStructType([
ll.IntType(32), ll.ArrayType(self.el_type.get_llvm_type(),
count)])
def __repr__(self):
return "<VList:{} x{}>".format(
@ -52,7 +55,7 @@ class VList(VGeneric):
def o_subscript(self, index, builder):
r = self.el_type.new()
if builder is not None:
if builder is not None and not isinstance(r, VNone):
index = index.o_int(builder).auto_load(builder)
ssa_r = builder.gep(self.llvm_value, [
ll.Constant(ll.IntType(32), 0),