List of known bugs:
-[ ] macros are not allowed at the expression level. This is not necessarily a bug, but does
+[X] macros are not allowed at the expression level. This is not necessarily a bug, but does
bring many complications to the table about how resolve this. Current solution is to
turn expression macros (macros that specify a return value) into a `do` expression.
}
if (callee->kind == Ast_Kind_Macro) {
- if (current_checking_level == EXPRESSION_LEVEL) {
- ERROR(call->token->pos, "Macros calls are not allowed at the expression level yet.");
- }
-
calling_a_macro = 1;
call->callee = callee;
SYMRES(expression, &(*mcall)->left);
if ((*mcall)->left == NULL) return Symres_Error;
- AstFieldAccess* implicit_field_access = make_field_access(context.ast_alloc, (*mcall)->left, NULL);
- implicit_field_access->token = call_node->callee->token;
- call_node->callee = (AstTyped *) implicit_field_access;
+ if (((*mcall)->flags & Ast_Flag_Has_Been_Symres) == 0) {
+ AstFieldAccess* implicit_field_access = make_field_access(context.ast_alloc, (*mcall)->left, NULL);
+ implicit_field_access->token = call_node->callee->token;
+ call_node->callee = (AstTyped *) implicit_field_access;
+ }
+
SYMRES(expression, (AstTyped **) &call_node);
+ (*mcall)->flags |= Ast_Flag_Has_Been_Symres;
return Symres_Success;
}
assert(template->kind == Ast_Kind_Function);
assert(template->type != NULL);
+ assert(template->type->kind == Type_Kind_Function);
AstBlock* expansion = (AstBlock *) ast_clone(context.ast_alloc, template->body);
expansion->rules = Block_Rule_Macro;
expansion->scope = NULL;
expansion->next = call->next;
+ AstNode* subst = (AstNode *) expansion;
+
+ if (template->type->Function.return_type != &basic_types[Basic_Kind_Void]) {
+ AstDoBlock* doblock = (AstDoBlock *) onyx_ast_node_new(context.ast_alloc, sizeof(AstDoBlock), Ast_Kind_Do_Block);
+ doblock->token = expansion->token;
+ doblock->block = expansion;
+ doblock->type = template->type->Function.return_type;
+ doblock->next = expansion->next;
+ expansion->next = NULL;
+
+ subst = (AstNode *) doblock;
+ }
+
Scope* argument_scope = scope_create(context.ast_alloc, NULL, call->token->pos);
if (expansion->binding_scope != NULL)
scope_include(argument_scope, expansion->binding_scope, call->token->pos);
bh_table_each_end;
}
- *(AstBlock **) pcall = expansion;
+ *(AstNode **) pcall = subst;
return;
}
WIL(WI_LOCAL_GET, result_local);
}
+ local_free(mod->local_alloc, (AstTyped *) if_expr);
+
*pcode = code;
}
}
bh_arr_pop(mod->return_location_stack);
+ local_free(mod->local_alloc, (AstTyped *) doblock);
*pcode = code;
}