Skip to content

Commit

Permalink
Rename pointer() to pointer_type()
Browse files Browse the repository at this point in the history
  • Loading branch information
Akuli committed Jan 10, 2025
1 parent e961498 commit 2cc2b4e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
18 changes: 9 additions & 9 deletions compiler/build_cf_graph.jou
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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")
Expand Down Expand Up @@ -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)
Expand All @@ -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++:
Expand Down Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion compiler/structs.jou
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions compiler/typecheck.jou
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand All @@ -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(
Expand Down Expand Up @@ -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
):
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion compiler/types.jou
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 2cc2b4e

Please sign in to comment.