rename arith to binary
This commit is contained in:
parent
97e8e32ebc
commit
d185396a1c
6
ir.c
6
ir.c
@ -105,10 +105,10 @@ void print_ir(IRToks *v, const BuiltinFunc *builtin_funcs) {
|
|||||||
case IRSub:
|
case IRSub:
|
||||||
case IRDiv:
|
case IRDiv:
|
||||||
case IRMul:
|
case IRMul:
|
||||||
printf(" %%%zx ", v->toks[i].Arith.addr);
|
printf(" %%%zx ", v->toks[i].Binary.addr);
|
||||||
print_irparam(&v->toks[i].Arith.lhs);
|
print_irparam(&v->toks[i].Binary.lhs);
|
||||||
printf(" ");
|
printf(" ");
|
||||||
print_irparam(&v->toks[i].Arith.rhs);
|
print_irparam(&v->toks[i].Binary.rhs);
|
||||||
break;
|
break;
|
||||||
case IRJmp:
|
case IRJmp:
|
||||||
printf(" %zx", v->toks[i].Jmp.iaddr);
|
printf(" %zx", v->toks[i].Jmp.iaddr);
|
||||||
|
2
ir.h
2
ir.h
@ -59,7 +59,7 @@ typedef struct IRTok {
|
|||||||
struct {
|
struct {
|
||||||
size_t addr;
|
size_t addr;
|
||||||
IRParam lhs, rhs;
|
IRParam lhs, rhs;
|
||||||
} Arith;
|
} Binary;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
size_t iaddr;
|
size_t iaddr;
|
||||||
|
6
parse.c
6
parse.c
@ -52,7 +52,7 @@ static void set_irtok_dest_addr(IRTok *t, size_t addr) {
|
|||||||
case IRSub:
|
case IRSub:
|
||||||
case IRMul:
|
case IRMul:
|
||||||
case IRDiv:
|
case IRDiv:
|
||||||
t->Arith.addr = addr;
|
t->Binary.addr = addr;
|
||||||
break;
|
break;
|
||||||
case IRCallInternal:
|
case IRCallInternal:
|
||||||
t->CallI.ret_addr = addr;
|
t->CallI.ret_addr = addr;
|
||||||
@ -436,7 +436,7 @@ static ExprRet expr(IRToks *out_ir, TokList *toks, Map *funcs, Scope *parent_sc,
|
|||||||
if (lhs->kind == TokVal && rhs->kind == TokVal) {
|
if (lhs->kind == TokVal && rhs->kind == TokVal) {
|
||||||
/* evaluate the constant expression immediately */
|
/* evaluate the constant expression immediately */
|
||||||
lhs->kind = TokVal;
|
lhs->kind = TokVal;
|
||||||
TRY_RET(lhs->Val = eval_arith(instr, &lhs->Val, &rhs->Val), (ExprRet){0});
|
TRY_RET(lhs->Val = eval_binary(instr, &lhs->Val, &rhs->Val), (ExprRet){0});
|
||||||
} else {
|
} else {
|
||||||
bool is_last_operation = t == start && r_op_prec == PREC_DELIM;
|
bool is_last_operation = t == start && r_op_prec == PREC_DELIM;
|
||||||
|
|
||||||
@ -450,7 +450,7 @@ static ExprRet expr(IRToks *out_ir, TokList *toks, Map *funcs, Scope *parent_sc,
|
|||||||
.ln = l_op->ln,
|
.ln = l_op->ln,
|
||||||
.col = l_op->col,
|
.col = l_op->col,
|
||||||
.instr = instr,
|
.instr = instr,
|
||||||
.Arith = {
|
.Binary = {
|
||||||
.addr = res_addr,
|
.addr = res_addr,
|
||||||
.lhs = lhs_irparam,
|
.lhs = lhs_irparam,
|
||||||
.rhs = rhs_irparam,
|
.rhs = rhs_irparam,
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
Value eval_arith(IRInstr instr, const Value *lhs, const Value *rhs) {
|
Value eval_binary(IRInstr instr, const Value *lhs, const Value *rhs) {
|
||||||
switch (instr) {
|
switch (instr) {
|
||||||
case IRAdd:
|
case IRAdd:
|
||||||
case IRSub:
|
case IRSub:
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include "ir.h"
|
#include "ir.h"
|
||||||
|
|
||||||
Value eval_arith(IRInstr instr, const Value *lhs, const Value *rhs);
|
Value eval_binary(IRInstr instr, const Value *lhs, const Value *rhs);
|
||||||
Value eval_unary(IRInstr instr, const Value *v);
|
Value eval_unary(IRInstr instr, const Value *v);
|
||||||
bool is_nonzero(const Value *v);
|
bool is_nonzero(const Value *v);
|
||||||
Value zero_val(Type ty);
|
Value zero_val(Type ty);
|
||||||
|
8
vm.c
8
vm.c
@ -63,10 +63,10 @@ void run(const IRToks *ir, const BuiltinFunc *builtin_funcs) {
|
|||||||
case IRSub:
|
case IRSub:
|
||||||
case IRDiv:
|
case IRDiv:
|
||||||
case IRMul:
|
case IRMul:
|
||||||
stack_fit(&s, instr->Arith.addr);
|
stack_fit(&s, instr->Binary.addr);
|
||||||
TRY_ELSE(s.mem[instr->Arith.addr] = eval_arith(instr->instr,
|
TRY_ELSE(s.mem[instr->Binary.addr] = eval_binary(instr->instr,
|
||||||
irparam_to_val(&s, &instr->Arith.lhs),
|
irparam_to_val(&s, &instr->Binary.lhs),
|
||||||
irparam_to_val(&s, &instr->Arith.rhs)),
|
irparam_to_val(&s, &instr->Binary.rhs)),
|
||||||
{free(fn_args); stack_term(&s);});
|
{free(fn_args); stack_term(&s);});
|
||||||
break;
|
break;
|
||||||
case IRJmp:
|
case IRJmp:
|
||||||
|
Loading…
Reference in New Issue
Block a user