def test_types01(): frame = State() frame.set_variable(1345, Integer(20)) frame.set_variable(15, String("something else")) frame.set_variable(667, Float(2.78)) assert isinstance(frame.get_variable(1345), Integer) assert isinstance(frame.get_variable(1345), Type) assert isinstance(frame.get_variable(15), String) assert isinstance(frame.get_variable(15), Type) assert isinstance(frame.get_variable(667), Float) assert isinstance(frame.get_variable(667), Type)
def _get_variable_wrapper(l_val): ''' Returns the correct variable wrapper for a given LLVMValueRef. ''' value = Variable(l_val) if llwrap.LLVMIsConstant(l_val): val_type = llwrap.LLVMGetTypeKind(llwrap.LLVMTypeOf(l_val)) if val_type == llwrap.LLVMIntegerTypeKind: if llwrap.LLVMIsUndef(l_val): value = Constant(Integer(0), l_val) else: value = Constant(Integer(llwrap.LLVMConstIntGetSExtValue(l_val)), l_val) elif val_type == llwrap.LLVMDoubleTypeKind or val_type == llwrap.LLVMFloatTypeKind: if llwrap.LLVMIsUndef(l_val): value = Constant(Float(0.0), l_val) else: with lltype.scoped_alloc(rffi.SIGNEDP.TO, 1) as signed_ptr: fl_var = Float(llwrap.LLVMConstRealGetDouble(l_val, signed_ptr)) value = Constant(fl_var, l_val) return value
def test_set_var01(): frame = State() frame.set_variable(1345, Integer(20)) assert frame.has_key(1345) assert frame.get_variable(1345).value == 20 frame.set_variable(1345, String("something else")) assert frame.has_key(1345) assert frame.get_variable(1345).value == "something else" frame.set_variable(667, Float(2.78)) assert frame.has_key(667) assert frame.get_variable(667).value == 2.78 assert isinstance(frame.get_variable(667), Float) assert isinstance(frame.get_variable(667), Type)
def execute(self, args): # convert Signed to Floating Point x = args[0] assert isinstance(x, Integer) return Float(float(x.value))
def execute(self, args): # truncate a floating point value (double -> float) x = args[0] assert isinstance(x, Float) return Float(x.value)
def execute(self, args): # extend a floating point value (eg float -> double) x = args[0] assert isinstance(x, Float) return Float(x.value)
def execute(self, args): x, y = args assert isinstance(x, Float) and isinstance(y, Float) return Float(x.value / y.value)