Skip to content

Commit

Permalink
fix: Prevent more-than-6 args and prevent struct args
Browse files Browse the repository at this point in the history
  • Loading branch information
keyvank committed Oct 21, 2024
1 parent 2547788 commit 3cc7ce0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions codegen/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ general_type *new_primitive_type(char *type_name)
general_type *ret = (general_type *)malloc(sizeof(general_type));
primitive_type *data = (primitive_type *)malloc(sizeof(primitive_type));
data->type_name = type_name;
ret->kind = TYPE_PRIMITIVE;
ret->data = data;
ret->debug = primitive_type_debug;
ret->size = primitive_type_size;
Expand All @@ -250,6 +251,7 @@ general_type *new_pointer_type(general_type *of)
general_type *ret = (general_type *)malloc(sizeof(general_type));
pointer_type *data = (pointer_type *)malloc(sizeof(pointer_type));
data->of = of;
ret->kind = TYPE_POINTER;
ret->data = data;
ret->debug = pointer_type_debug;
ret->size = pointer_type_size;
Expand All @@ -262,6 +264,7 @@ general_type *new_func_pointer_type(general_type *return_type)
general_type *ret = (general_type *)malloc(sizeof(general_type));
func_pointer_type *data = (func_pointer_type *)malloc(sizeof(func_pointer_type));
data->return_type = return_type;
ret->kind = TYPE_FUNC_POINTER;
ret->data = data;
ret->debug = func_pointer_type_debug;
ret->size = func_pointer_type_size;
Expand All @@ -274,6 +277,7 @@ general_type *new_struct_type(char *struct_name)
general_type *ret = (general_type *)malloc(sizeof(general_type));
struct_type *data = (struct_type *)malloc(sizeof(struct_type));
data->struct_name = struct_name;
ret->kind = TYPE_STRUCT;
ret->data = data;
ret->debug = struct_type_debug;
ret->size = struct_type_size;
Expand Down
6 changes: 6 additions & 0 deletions codegen/codegen.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ typedef struct

typedef struct general_type_
{
int kind;
void *data;
void (*debug)(struct general_type_ *self, context *ctx, int depth);
int (*size)(struct general_type_ *self, context *ctx);
Expand All @@ -30,6 +31,11 @@ typedef struct
general_type **fields;
} context_struct;

#define TYPE_PRIMITIVE 0
#define TYPE_POINTER 1
#define TYPE_FUNC_POINTER 2
#define TYPE_STRUCT 3

typedef struct
{
char *type_name;
Expand Down
5 changes: 5 additions & 0 deletions parser/expr/func_call.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ apply_result *func_call_apply(parser_node *node, context *ctx)
for (int i = 0; i < call->num_args; i++)
{
apply_result *regval = call->args[i]->apply(call->args[i], ctx);
if (regval->type->kind == TYPE_STRUCT)
{
fprintf(stderr, "Passing structs to functions is unsupported!\n");
exit(1);
}

symbol *tmp = new_temp_symbol(ctx, regval->type);
add_text(ctx, "mov rax, %s", regval->code);
Expand Down

0 comments on commit 3cc7ce0

Please sign in to comment.