summaryrefslogtreecommitdiff
path: root/src/runner/runner.c
diff options
context:
space:
mode:
authorA404M <ahmadmahmoudiprogrammer@gmail.com>2025-04-07 16:53:53 +0330
committerA404M <ahmadmahmoudiprogrammer@gmail.com>2025-04-07 16:53:53 +0330
commit92bf7bf5de203eac51befc914dfddbc29d49351b (patch)
tree645448cbedf2d0cc9b3b39651daf1d069c80015a /src/runner/runner.c
parent62b7af496f2c694ff5361cf21042bbe14f969c64 (diff)
add a way to make generic structs
Diffstat (limited to 'src/runner/runner.c')
-rw-r--r--src/runner/runner.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/runner/runner.c b/src/runner/runner.c
index 984af3f..a407204 100644
--- a/src/runner/runner.c
+++ b/src/runner/runner.c
@@ -787,9 +787,7 @@ AstTree *runExpression(AstTree *expr, bool *shouldRet, bool isLeft) {
case AST_TREE_TOKEN_VALUE_BOOL:
case AST_TREE_TOKEN_VALUE_FLOAT:
case AST_TREE_TOKEN_VALUE_OBJECT:
- case AST_TREE_TOKEN_OPERATOR_POINTER:
case AST_TREE_TOKEN_FUNCTION:
- case AST_TREE_TOKEN_KEYWORD_STRUCT:
return copyAstTree(expr);
case AST_TREE_TOKEN_OPERATOR_ADDRESS: {
AstTreeSingleChild *metadata = expr->metadata;
@@ -820,6 +818,9 @@ AstTree *runExpression(AstTree *expr, bool *shouldRet, bool isLeft) {
if (isLeft) {
return copyAstTree(expr);
} else {
+ if (variable->value == NULL) {
+ UNREACHABLE;
+ }
return copyAstTree(variable->value);
}
}
@@ -862,6 +863,27 @@ AstTree *runExpression(AstTree *expr, bool *shouldRet, bool isLeft) {
return copyAstTree(var->value);
}
}
+ case AST_TREE_TOKEN_KEYWORD_STRUCT: {
+ expr = copyAstTree(expr);
+ AstTreeStruct *metadata = expr->metadata;
+ for (size_t i = 0; i < metadata->variables.size; ++i) {
+ AstTreeVariable *member = metadata->variables.data[i];
+ AstTree *type = member->type;
+ member->type = runExpression(member->type, shouldRet, isLeft);
+ if (type != member->type) {
+ astTreeDelete(type);
+ }
+ }
+ return expr;
+ }
+ case AST_TREE_TOKEN_OPERATOR_POINTER: {
+ AstTreeSingleChild *metadata = expr->metadata;
+ AstTreeSingleChild *newMetadata =
+ runExpression(metadata, shouldRet, isLeft);
+
+ return newAstTree(AST_TREE_TOKEN_OPERATOR_POINTER, newMetadata,
+ copyAstTree(expr->type), expr->str_begin, expr->str_end);
+ }
case AST_TREE_TOKEN_NONE:
}
UNREACHABLE;