Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
rpkak committed Jan 13, 2024
1 parent 2b63eb8 commit 84083b2
Show file tree
Hide file tree
Showing 11 changed files with 170 additions and 79 deletions.
5 changes: 3 additions & 2 deletions src/ptlang_ast/ptlang_ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,7 @@ ptlang_ast_exp ptlang_ast_exp_copy(ptlang_ast_exp exp)
}
case PTLANG_AST_EXP_FUNCTION_CALL:
{
copy->content.function_call.function = ptlang_ast_exp_copy(copy->content.function_call.function);
copy->content.function_call.function = ptlang_ast_exp_copy(exp->content.function_call.function);
copy->content.function_call.parameters = NULL;
for (size_t i = 0; i < arrlenu(exp->content.function_call.parameters); i++)
{
Expand Down Expand Up @@ -1087,7 +1087,7 @@ ptlang_ast_exp ptlang_ast_exp_copy(ptlang_ast_exp exp)
}
case PTLANG_AST_EXP_TERNARY:
copy->content.ternary_operator.condition =
ptlang_ast_exp_copy(copy->content.ternary_operator.condition);
ptlang_ast_exp_copy(exp->content.ternary_operator.condition);
copy->content.ternary_operator.if_value = ptlang_ast_exp_copy(exp->content.ternary_operator.if_value);
copy->content.ternary_operator.else_value =
ptlang_ast_exp_copy(exp->content.ternary_operator.else_value);
Expand Down Expand Up @@ -1115,6 +1115,7 @@ ptlang_ast_exp ptlang_ast_exp_copy(ptlang_ast_exp exp)
? exp->ast_type->content.integer.size
: exp->ast_type->content.float_size;
uint32_t byte_size = (bit_size - 1) / 8 + 1;
copy->content.binary = ptlang_malloc(byte_size);
memcpy(copy->content.binary, exp->content.binary, byte_size);
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/ptlang_ast/ptlang_ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ ptlang_ast_exp ptlang_ast_exp_array_element_new(ptlang_ast_exp array, ptlang_ast
ptlang_ast_exp ptlang_ast_exp_reference_new(bool writable, ptlang_ast_exp value,
ptlang_ast_code_position pos);
ptlang_ast_exp ptlang_ast_exp_dereference_new(ptlang_ast_exp value, ptlang_ast_code_position pos);
ptlang_ast_exp ptlang_ast_exp_binary_new(uint8_t* binary, ptlang_ast_exp prev);
ptlang_ast_exp ptlang_ast_exp_binary_new(uint8_t *binary, ptlang_ast_exp prev);

ptlang_ast_stmt ptlang_ast_stmt_block_new(ptlang_ast_code_position pos);
void ptlang_ast_stmt_block_add_stmt(ptlang_ast_stmt block_stmt, ptlang_ast_stmt stmt);
Expand Down Expand Up @@ -199,5 +199,4 @@ ptlang_ast_exp ptlang_ast_exp_copy(ptlang_ast_exp exp);

ptlang_ast_ident ptlang_ast_ident_copy(ptlang_ast_ident ident);


#endif
2 changes: 1 addition & 1 deletion src/ptlang_eval/ptlang_eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ptlang_ast_exp ptlang_eval_const_exp(ptlang_ast_exp exp)
LLVMContextRef C = LLVMContextCreate();
LLVMModuleRef M = LLVMModuleCreateWithNameInContext("ptlang_eval", C);

LLVMTypeRef type = ptlang_ir_builder_type(exp->ast_type, NULL, C);
// LLVMTypeRef type = ptlang_ir_builder_type(exp->ast_type, NULL, C);

LLVMTypeRef func_type =
LLVMFunctionType(LLVMVoidTypeInContext(C), (LLVMTypeRef[]){LLVMPointerTypeInContext(C, 0)}, 1, false);
Expand Down
6 changes: 4 additions & 2 deletions src/ptlang_ir_builder/ptlang_ir_builder.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ LLVMTypeRef ptlang_ir_builder_type(ptlang_ast_type type, ptlang_ir_builder_build
{
param_types[i] = ptlang_ir_builder_type(type->content.function.parameters[i], ctx, C);
}
function_type = LLVMFunctionType(ptlang_ir_builder_type(type->content.function.return_type, ctx, C),
param_types, arrlenu(type->content.function.parameters), false);
// function_type = LLVMFunctionType(ptlang_ir_builder_type(type->content.function.return_type, ctx, C),
// param_types, arrlenu(type->content.function.parameters), false);
ptlang_free(param_types);
function_type = LLVMPointerTypeInContext(C, 0);
return function_type;
Expand Down Expand Up @@ -1695,6 +1695,8 @@ LLVMValueRef ptlang_ir_builder_exp(ptlang_ast_exp exp, ptlang_ir_builder_build_c

LLVMValueRef as_array = LLVMConstArray(LLVMArrayType(byte, byte_size), bytes, byte_size);

ptlang_free(bytes);

LLVMValueRef as_int = LLVMConstBitCast(as_array, LLVMIntType(byte_size * 8));
if (bit_size != byte_size * 8)
{
Expand Down
4 changes: 1 addition & 3 deletions src/ptlang_ir_builder/ptlang_ir_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ typedef struct ptlang_ir_builder_scope_s ptlang_ir_builder_scope;

typedef struct ptlang_ir_builder_struct_def_s ptlang_ir_builder_struct_def;


typedef struct ptlang_ir_builder_build_context_s
{
LLVMBuilderRef builder;
Expand All @@ -34,5 +33,4 @@ typedef struct ptlang_ir_builder_build_context_s
LLVMTypeRef ptlang_ir_builder_type(ptlang_ast_type type, ptlang_ir_builder_build_context *ctx,
LLVMContextRef C);

LLVMValueRef ptlang_ir_builder_exp(ptlang_ast_exp exp, ptlang_ir_builder_build_context *ctx);

LLVMValueRef ptlang_ir_builder_exp(ptlang_ast_exp exp, ptlang_ir_builder_build_context *ctx);
2 changes: 1 addition & 1 deletion src/ptlang_main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ int main(void)
exit(1);
}

pltang_context_destory(&ctx);
ptlang_context_destory(&ctx);

LLVMModuleRef llvmmod = ptlang_ir_builder_module(mod, target_data_layout);
LLVMDumpModule(llvmmod);
Expand Down
4 changes: 3 additions & 1 deletion src/ptlang_main/ptlang_context.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "ptlang_context.h"

void pltang_context_destory(ptlang_context *ctx) { shfree(ctx->type_scope); }
void ptlang_context_destory(ptlang_context *ctx) { shfree(ctx->type_scope); }

ptlang_ast_type ptlang_context_unname_type(ptlang_ast_type type, ptlang_context_type_scope *type_scope)
{
Expand Down Expand Up @@ -82,6 +82,8 @@ size_t ptlang_context_type_to_string(ptlang_ast_type type, char *out, ptlang_con
{
memcpy(out, "Error Type", size);
}

return size;
}
switch (type->type)
{
Expand Down
2 changes: 1 addition & 1 deletion src/ptlang_main/ptlang_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ typedef struct ptlang_context_s
LLVMTargetDataRef target_data_layout;
} ptlang_context;

void pltang_context_destory(ptlang_context *ctx);
void ptlang_context_destory(ptlang_context *ctx);

ptlang_ast_type ptlang_context_unname_type(ptlang_ast_type type, ptlang_context_type_scope *type_scope);

Expand Down
1 change: 1 addition & 0 deletions src/ptlang_utils/ptlang_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct node_s
size_t index;
size_t lowlink;
bool on_stack;
void* data;
};

typedef struct ptlang_utils_str
Expand Down
Loading

0 comments on commit 84083b2

Please sign in to comment.