diff --git a/compiler/build_cf_graph.jou b/compiler/build_cf_graph.jou index e54e39b5..0ab88bc4 100644 --- a/compiler/build_cf_graph.jou +++ b/compiler/build_cf_graph.jou @@ -316,7 +316,7 @@ def build_class_field_pointer( for f = class_type->classdata.fields; f < &class_type->classdata.fields[class_type->classdata.nfields]; f++: if strcmp(f->name, fieldname) == 0: - result = add_local_var(st, f->type->pointer()) + result = add_local_var(st, f->type->pointer_type()) ins = CfInstruction{ location = location, @@ -340,7 +340,7 @@ def build_class_field( fieldname: byte*, location: Location, ) -> LocalVariable*: - ptr = add_local_var(st, instance->type->pointer()) + ptr = add_local_var(st, instance->type->pointer_type()) add_unary_op(st, location, CfInstructionKind::AddressOfLocalVar, instance, ptr) field_ptr = build_class_field_pointer(st, ptr, fieldname, location) field = add_local_var(st, field_ptr->type->value_type) @@ -464,7 +464,7 @@ def build_and_or( def build_address_of_expression(st: State*, address_of_what: AstExpression*) -> LocalVariable*: if address_of_what->kind == AstExpressionKind::GetVariable: - ptrtype = get_expr_types(st, address_of_what)->type->pointer() + ptrtype = get_expr_types(st, address_of_what)->type->pointer_type() addr = add_local_var(st, ptrtype) local_var = find_local_var_cf(st, address_of_what->varname) @@ -483,7 +483,7 @@ def build_address_of_expression(st: State*, address_of_what: AstExpression*) -> return addr if address_of_what->kind == AstExpressionKind::Self: - ptrtype = get_expr_types(st, address_of_what)->type->pointer() + ptrtype = get_expr_types(st, address_of_what)->type->pointer_type() addr = add_local_var(st, ptrtype) local_var = find_local_var_cf(st, "self") @@ -586,7 +586,7 @@ def build_function_or_method_call( def build_instantiation(st: State*, type: Type*, inst: AstInstantiation*, location: Location) -> LocalVariable*: instance = add_local_var(st, type) - instanceptr = add_local_var(st, type->pointer()) + instanceptr = add_local_var(st, type->pointer_type()) add_unary_op(st, location, CfInstructionKind::AddressOfLocalVar, instance, instanceptr) add_unary_op(st, location, CfInstructionKind::PtrMemsetToZero, instanceptr, NULL) @@ -603,9 +603,9 @@ def build_array(st: State*, type: Type*, items: AstExpression*, location: Locati assert type->kind == TypeKind::Array arr = add_local_var(st, type) - arrptr = add_local_var(st, type->pointer()) + arrptr = add_local_var(st, type->pointer_type()) add_unary_op(st, location, CfInstructionKind::AddressOfLocalVar, arr, arrptr) - first_item_ptr = add_local_var(st, type->array.item_type->pointer()) + first_item_ptr = add_local_var(st, type->array.item_type->pointer_type()) add_unary_op(st, location, CfInstructionKind::PtrCast, arrptr, first_item_ptr) for i = 0; i < type->array.len; i++: @@ -896,8 +896,8 @@ def build_assert(st: State*, assert_location: Location, assertion: AstAssertion* strcpy(argnames[2], "lineno") argtypes: Type** = malloc(3 * sizeof(argtypes[0])) - argtypes[0] = byteType->pointer() - argtypes[1] = byteType->pointer() + argtypes[0] = byteType->pointer_type() + argtypes[1] = byteType->pointer_type() argtypes[2] = intType ins = CfInstruction{ diff --git a/compiler/structs.jou b/compiler/structs.jou index 6dc9810c..b7845501 100644 --- a/compiler/structs.jou +++ b/compiler/structs.jou @@ -63,7 +63,7 @@ class Constant: if self->kind == ConstantKind::Bool: return boolType if self->kind == ConstantKind::String: - return byteType->pointer() + return byteType->pointer_type() if self->kind == ConstantKind::Integer: return get_integer_type(self->integer.size_in_bits, self->integer.is_signed) assert False diff --git a/compiler/typecheck.jou b/compiler/typecheck.jou index bc394a64..b14c2554 100644 --- a/compiler/typecheck.jou +++ b/compiler/typecheck.jou @@ -164,7 +164,7 @@ def type_from_ast(ft: FileTypes*, asttype: AstType*) -> Type*: if asttype->kind == AstTypeKind::Pointer: if asttype->value_type->is_void(): return voidPtrType - return type_from_ast(ft, asttype->value_type)->pointer() + return type_from_ast(ft, asttype->value_type)->pointer_type() if asttype->kind == AstTypeKind::Array: tmp = type_from_ast(ft, asttype->value_type) @@ -228,11 +228,11 @@ def handle_signature(ft: FileTypes*, astsig: AstSignature*, self_class: Type*) - and astsig->args[i].type.name[0] == '\0' ): # just "self" without a type after it --> default to "self: Foo*" in class Foo - argtype = self_class->pointer() + argtype = self_class->pointer_type() else: argtype = type_from_ast(ft, &astsig->args[i].type) - if strcmp(sig.argnames[i], "self") == 0 and argtype != self_class and argtype != self_class->pointer(): + if strcmp(sig.argnames[i], "self") == 0 and argtype != self_class and argtype != self_class->pointer_type(): snprintf(msg, sizeof(msg), "type of self must be %s* (default) or %s", self_class->name, self_class->name) fail(astsig->args[i].type.location, msg) @@ -255,7 +255,7 @@ def handle_signature(ft: FileTypes*, astsig: AstSignature*, self_class: Type*) - and not ( sig.nargs == 2 and sig.argtypes[0] == intType - and sig.argtypes[1] == byteType->pointer()->pointer() + and sig.argtypes[1] == byteType->pointer_type()->pointer_type() ) ): fail( @@ -614,7 +614,7 @@ def do_implicit_cast( if ( types->expr->kind == AstExpressionKind::String - and from == byteType->pointer() + and from == byteType->pointer_type() and to->kind == TypeKind::Array and to->array.item_type == byteType ): @@ -640,7 +640,7 @@ def do_implicit_cast( def cast_array_to_pointer(fom: FunctionOrMethodTypes*, types: ExpressionTypes*) -> None: assert types->type->kind == TypeKind::Array - do_implicit_cast(fom, types, types->type->array.item_type->pointer(), Location{}, NULL) + do_implicit_cast(fom, types, types->type->array.item_type->pointer_type(), Location{}, NULL) def do_explicit_cast(fom: FunctionOrMethodTypes*, types: ExpressionTypes*, to: Type*, location: Location) -> None: assert types->implicit_cast_type == NULL @@ -1120,7 +1120,7 @@ def typecheck_expression(ft: FileTypes*, expr: AstExpression*) -> ExpressionType elif expr->kind == AstExpressionKind::Null: result = voidPtrType elif expr->kind == AstExpressionKind::String: - result = byteType->pointer() + result = byteType->pointer_type() elif expr->kind == AstExpressionKind::GetEnumMember: result = find_type(ft, expr->enum_member.enum_name) @@ -1224,7 +1224,7 @@ def typecheck_expression(ft: FileTypes*, expr: AstExpression*) -> ExpressionType elif expr->kind == AstExpressionKind::AddressOf: ensure_can_take_address(ft->current_fom_types, &expr->operands[0], "the '&' operator cannot be used with %s") temptype = typecheck_expression_not_void(ft, &expr->operands[0])->type - result = temptype->pointer() + result = temptype->pointer_type() elif expr->kind == AstExpressionKind::GetVariable: result = find_any_var(ft, expr->varname) diff --git a/compiler/types.jou b/compiler/types.jou index bc9bb28f..4daff9ab 100644 --- a/compiler/types.jou +++ b/compiler/types.jou @@ -58,7 +58,7 @@ class Type: # Returns a type that represents pointer to the original type. # Result is cached. Don't worry about freeing it. - def pointer(self) -> Type*: + def pointer_type(self) -> Type*: info = self as TypeInfo* assert self == &info->type # the 'type' field is first member and has 0 bytes offset