stage1 修改部分测试 完成17-19测试
This commit is contained in:
@@ -96,7 +96,44 @@ static void parse_var_decl(spl_comp_t *ctx, int is_const) {
|
||||
|
||||
/* Store init value */
|
||||
if (has_init) {
|
||||
if (var_type && (var_type->kind == TYPE_STRUCT || var_type->kind == TYPE_ENUM)) {
|
||||
/* Handle slice struct literal: { .ptr = ..., .len = ... } */
|
||||
if (var_type && var_type->kind == TYPE_SLICE && peek(ctx)->type == TOK_L_BRACE && !init.type) {
|
||||
advance(ctx); /* { */
|
||||
skip_nl(ctx);
|
||||
while (peek(ctx)->type != TOK_R_BRACE && peek(ctx)->type != TOK_EOF) {
|
||||
if (peek(ctx)->type == TOK_COMMA) {
|
||||
advance(ctx);
|
||||
skip_nl(ctx);
|
||||
continue;
|
||||
}
|
||||
if (peek(ctx)->type == TOK_DOT)
|
||||
advance(ctx);
|
||||
spl_tok_t *ftok = advance(ctx);
|
||||
char fname[256];
|
||||
usize fnl = ftok->len < 255 ? ftok->len : 255;
|
||||
memcpy(fname, ftok->lexeme, fnl);
|
||||
fname[fnl] = '\0';
|
||||
skip_nl(ctx);
|
||||
if (peek(ctx)->type == TOK_ASSIGN)
|
||||
advance(ctx);
|
||||
skip_nl(ctx);
|
||||
|
||||
spl_expr_result_t fv = spl_parse_expr(ctx, PREC_MIN);
|
||||
(void)fv;
|
||||
|
||||
if (strcmp(fname, "ptr") == 0) {
|
||||
spl_emit(ctx, SPL_LADDR, SPL_PTR, offset);
|
||||
spl_emit(ctx, SPL_SWAP, SPL_VOID, 0);
|
||||
spl_emit(ctx, SPL_STORE, SPL_PTR, 0);
|
||||
} else if (strcmp(fname, "len") == 0) {
|
||||
spl_emit(ctx, SPL_LADDR, SPL_PTR, offset + (int)sizeof(spl_val_t));
|
||||
spl_emit(ctx, SPL_SWAP, SPL_VOID, 0);
|
||||
spl_emit(ctx, SPL_STORE, SPL_USIZE, 0);
|
||||
}
|
||||
skip_nl(ctx);
|
||||
}
|
||||
expect(ctx, TOK_R_BRACE);
|
||||
} else if (var_type && (var_type->kind == TYPE_STRUCT || var_type->kind == TYPE_ENUM)) {
|
||||
/* Struct/enum initialization */
|
||||
usize sz = spl_type_size(var_type);
|
||||
if (sz <= sizeof(spl_val_t)) {
|
||||
@@ -364,7 +401,6 @@ static void parse_for_stmt(spl_comp_t *ctx) {
|
||||
}
|
||||
|
||||
/* ===== Slice iteration: for slice [as val |, range as val, idx] ===== */
|
||||
int has_idx = 0;
|
||||
if (peek(ctx)->type == TOK_COMMA) {
|
||||
advance(ctx); /* , */
|
||||
spl_parse_expr(ctx, PREC_MIN); /* parse start of range (e.g. 0) */
|
||||
@@ -376,7 +412,6 @@ static void parse_for_stmt(spl_comp_t *ctx) {
|
||||
peek(ctx)->type != TOK_EOF)
|
||||
spl_parse_expr(ctx, PREC_MIN);
|
||||
}
|
||||
has_idx = 1;
|
||||
/* Range pushed a value; we manage our own idx, drop it */
|
||||
spl_emit(ctx, SPL_DROP, SPL_VOID, 0);
|
||||
}
|
||||
@@ -614,7 +649,6 @@ static void parse_match_stmt(spl_comp_t *ctx) {
|
||||
|
||||
/* Find the variant in the enum type */
|
||||
spl_enum_variant_t *variant = NULL;
|
||||
int vi;
|
||||
vec_for(enum_type->variants, vi) {
|
||||
if (strcmp(vec_at(enum_type->variants, vi).name, vname) == 0) {
|
||||
variant = &vec_at(enum_type->variants, vi);
|
||||
@@ -853,7 +887,7 @@ static void parse_expr_stmt(spl_comp_t *ctx) {
|
||||
return;
|
||||
}
|
||||
|
||||
int prev = ctx->tok_idx;
|
||||
usize prev = ctx->tok_idx;
|
||||
|
||||
/* Look ahead for assignment operator (scan past expression tokens) */
|
||||
int is_assign = 0;
|
||||
|
||||
Reference in New Issue
Block a user