diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2023-11-19 18:41:55 +0200 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2023-11-19 18:41:55 +0200 |
| commit | 8f754f8b13e55e4bb92d72f105c5aaaba1754b7d (patch) | |
| tree | b70b813c091691d6645f8cb82295f41f24f3be93 /src/scope.c | |
| parent | 5304dbcf4df1fc211b5099f4d6eb7f23dfa8c454 (diff) | |
| download | ek-8f754f8b13e55e4bb92d72f105c5aaaba1754b7d.tar.gz ek-8f754f8b13e55e4bb92d72f105c5aaaba1754b7d.zip | |
start working on instruction lowering
Diffstat (limited to 'src/scope.c')
| -rw-r--r-- | src/scope.c | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/src/scope.c b/src/scope.c index 369a89b..6c94aec 100644 --- a/src/scope.c +++ b/src/scope.c @@ -40,14 +40,9 @@ static struct param_node *find_matching_param(struct resolve_node *node, static int traits_resolve(struct ast_node *arg_type, struct ast_node *param_type) { - /** @todo are more checks required? */ - return AST_TYPE(arg_type).as == AST_TRAIT_TYPE(param_type).def; -} - -static int typeofs_resolve(struct ast_node *arg_type, struct ast_node *param_type) -{ - internal_error("typeof resolve unimplemented"); - return 0; + /** @todo are more checks required? arg_type should already be in + * `as`-form*/ + return AST_TRAIT_TYPE(arg_type).def == AST_TRAIT_TYPE(param_type).def; } static int types_resolve(struct ast_node *arg_type, struct ast_node *param_type) @@ -56,11 +51,16 @@ static int types_resolve(struct ast_node *arg_type, struct ast_node *param_type) if (!param_type) return 1; + /* if arg is specifying to be matches as `as`, then do it */ + if (AST_TYPE(arg_type).as) + return types_resolve(AST_TYPE(arg_type).as, param_type); + if (AST_TYPE(param_type).kind == AST_TYPE_TRAIT) return traits_resolve(arg_type, param_type); + /* typeof is matched later */ if (AST_TYPE(param_type).kind == AST_TYPE_TYPEOF) - return typeofs_resolve(arg_type, param_type); + return 1; return types_match(arg_type, param_type); } @@ -110,8 +110,6 @@ static int add_next_resolve(struct scope *scope, struct ast_node *resolve, struct resolve_node *node, struct ast_node *params) { assert(node); - if (params && actualize_temp_type(scope, params)) - return -1; /* TODO: variadics in macros? */ /* we've run out of params, check if this is a suitable node */ @@ -855,7 +853,13 @@ void scope_add_scope(struct scope *parent, struct scope *child) static int add_actual(struct actual *actuals, struct ast_node *node) { - /* TODO: check that there isn't already an actual like ours */ + if (!actuals->node) { + /* fill empty first element */ + actuals->node = node; + return 0; + } + + /* TODO: check that there isn't already an actual like ours? */ struct actual *actual = calloc(1, sizeof(struct actual)); if (!actual) return -1; @@ -876,13 +880,15 @@ static struct ast_node *find_actual(struct actual *actuals, { assert(node->node_type == AST_ID); - if (actuals) - do { - struct ast_node *actual = actuals->node; - if (identical_ast_nodes(0, actual->_proc.id, node)) - return actual; + if (!actuals) + return NULL; + + do { + struct ast_node *actual = actuals->node; + if (identical_ast_nodes(0, actual->_proc.id, node)) + return actual; - } while ((actuals = actuals->next)); + } while ((actuals = actuals->next)); return NULL; } |
