def compile_values(self, scope, builder): if not (self.left.infer_type(scope), self.right.infer_type(scope)) == (TupleType(1), TupleType(1)): raise SemanticError( "Arithmetic can only be performed on single integers.") [l_value], [r_value] = (e.compile_values(scope, builder) for e in (self.left, self.right)) result = getattr(builder, self.instruction_name)(l_value, r_value) return [result]
def compile_predicate(self, scope, builder): """Returns an LLVM i1 value representing the result of the comparison.""" if not (self.left.infer_type(scope), self.right.infer_type(scope)) == (TupleType(1), TupleType(1)): raise SemanticError( "Comparisons can only be made between single integers.") [l_value], [r_value] = (e.compile_values(scope, builder) for e in (self.left, self.right)) return builder.icmp_signed(self.cmpop, l_value, r_value)
def compile(self, scope, builder, logger): begin_type = self.range.begin_expression.infer_type(scope) end_type = self.range.end_expression.infer_type(scope) if begin_type != TupleType(1) or end_type != TupleType(1): raise SemanticError( "Indices in array declaration must be single integers.") [begin] = self.range.begin_expression.compile_values(scope, builder) [end] = self.range.end_expression.compile_values(scope, builder) length = builder.add(builder.sub(end, begin), i32_t(1)) data_slot = builder.alloca(i32_t, length) structure_slot = builder.alloca(array_t) builder.store(array_t([begin, end, data_slot]), structure_slot) # TODO: Add new array variable to scope. raise SemanticError("Arrays are not supported.", self.identifier)
def infer_type(self, scope): return TupleType(1)
def infer_type(self, scope): return TupleType(sum( e.infer_type(scope).length for e in self.elements))