stage1 完成07,08测试
This commit is contained in:
@@ -515,6 +515,54 @@ spl_expr_result_t spl_parse_expr(spl_comp_t *ctx, int min_prec) {
|
||||
case TOK_L_BRACKET:
|
||||
left = parse_array_literal(ctx);
|
||||
break;
|
||||
case TOK_AT: {
|
||||
/* @builtin(...) — compiler intrinsic */
|
||||
advance(ctx); /* consume @ */
|
||||
skip_nl(ctx);
|
||||
tok = peek(ctx);
|
||||
if (!tok || tok->type != TOK_IDENT) {
|
||||
spl_comp_error(ctx, "expected builtin name after '@'");
|
||||
break;
|
||||
}
|
||||
char bname[256];
|
||||
usize bnlen = tok->len < 255 ? tok->len : 255;
|
||||
memcpy(bname, tok->lexeme, bnlen); bname[bnlen] = '\0';
|
||||
advance(ctx); /* consume builtin name */
|
||||
|
||||
if (strcmp(bname, "dbg") == 0) {
|
||||
/* @dbg(...) — print VM debug info */
|
||||
if (peek(ctx)->type == TOK_L_PAREN) {
|
||||
advance(ctx); /* skip ( */
|
||||
int nargs = 0;
|
||||
if (peek(ctx)->type != TOK_R_PAREN) {
|
||||
for (;;) {
|
||||
spl_parse_expr(ctx, PREC_MIN);
|
||||
nargs++;
|
||||
if (peek(ctx)->type == TOK_COMMA) { advance(ctx); continue; }
|
||||
break;
|
||||
}
|
||||
}
|
||||
expect(ctx, TOK_R_PAREN);
|
||||
|
||||
/* Emit SPL_DBG and DROP for each arg */
|
||||
for (int i = 0; i < nargs; i++) {
|
||||
spl_emit(ctx, SPL_DBG, SPL_USIZE, 0);
|
||||
spl_emit(ctx, SPL_DROP, SPL_VOID, 0);
|
||||
}
|
||||
if (nargs == 0) {
|
||||
spl_emit(ctx, SPL_DBG, SPL_VOID, 0);
|
||||
}
|
||||
} else {
|
||||
/* @dbg with no parens — just debug */
|
||||
spl_emit(ctx, SPL_DBG, SPL_VOID, 0);
|
||||
}
|
||||
/* @dbg is a void expression */
|
||||
left = (spl_expr_result_t){ spl_type_basic(SPL_VOID), 0 };
|
||||
} else {
|
||||
spl_comp_error(ctx, "unknown builtin '@%s'", bname);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
/* If it's a keyword-as-type (i32, u8, etc.), parse as function call target or type constructor */
|
||||
if (peek(ctx)->type >= KW_AS && peek(ctx)->type <= KW_ANY) {
|
||||
|
||||
Reference in New Issue
Block a user