stage1 完成14测试
This commit is contained in:
@@ -195,6 +195,23 @@ static int spl_resolve_type_member(spl_comp_t *ctx, spl_type_info_t *type,
|
||||
* SIR opcode for binary operator
|
||||
* ============================================================ */
|
||||
|
||||
/* Map assignment operator token (e.g. +=) to corresponding binary operator (e.g. +) */
|
||||
static spl_tok_type_t assign_to_binop(spl_tok_type_t t) {
|
||||
switch (t) {
|
||||
case TOK_ASSIGN_ADD: return TOK_ADD;
|
||||
case TOK_ASSIGN_SUB: return TOK_SUB;
|
||||
case TOK_ASSIGN_MUL: return TOK_MUL;
|
||||
case TOK_ASSIGN_DIV: return TOK_DIV;
|
||||
case TOK_ASSIGN_MOD: return TOK_MOD;
|
||||
case TOK_ASSIGN_AND: return TOK_AND;
|
||||
case TOK_ASSIGN_OR: return TOK_OR;
|
||||
case TOK_ASSIGN_XOR: return TOK_XOR;
|
||||
case TOK_ASSIGN_L_SH: return TOK_L_SH;
|
||||
case TOK_ASSIGN_R_SH: return TOK_R_SH;
|
||||
default: return (spl_tok_type_t)-1;
|
||||
}
|
||||
}
|
||||
|
||||
static int binop_to_sir(spl_tok_type_t t, spl_type_t bt) {
|
||||
int is_signed = (bt == SPL_I32 || bt == SPL_I64 || bt == SPL_I8 || bt == SPL_I16);
|
||||
switch (t) {
|
||||
@@ -981,11 +998,12 @@ static spl_expr_result_t parse_infix(spl_comp_t *ctx, spl_expr_result_t left, sp
|
||||
spl_emit(ctx, SPL_STORE, bt, 0);
|
||||
} else {
|
||||
/* Compound: left = left op right — stack: [addr, rhs] */
|
||||
spl_emit(ctx, SPL_DUP, SPL_VOID, 0); /* [addr, rhs, addr] */
|
||||
spl_emit(ctx, SPL_LOAD, bt, 0); /* [addr, rhs, old_val] */
|
||||
/* FIXME: compound needs to compute old_val op rhs, then store */
|
||||
/* For now just drop old_val and store rhs */
|
||||
spl_emit(ctx, SPL_DROP, SPL_VOID, 0); /* [addr, rhs] */
|
||||
spl_emit(ctx, SPL_PICK, SPL_VOID, 1); /* [addr, rhs, addr] */
|
||||
spl_emit(ctx, SPL_LOAD, bt, 0); /* [addr, rhs, old_val] */
|
||||
spl_emit(ctx, SPL_SWAP, SPL_VOID, 0); /* [addr, old_val, rhs] */
|
||||
int sop = binop_to_sir(assign_to_binop(op), bt);
|
||||
if (sop >= 0)
|
||||
spl_emit(ctx, sop, bt, 0); /* [addr, result] */
|
||||
spl_emit(ctx, SPL_STORE, bt, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ type Color = enum {
|
||||
|
||||
type Expr = enum {
|
||||
val: i32,
|
||||
add: struct { left: *Expr, right: *Expr },
|
||||
tag: Tag,
|
||||
|
||||
type Tag = enum {
|
||||
|
||||
Reference in New Issue
Block a user