rename arith to binary

This commit is contained in:
r4 2021-12-23 20:10:02 +01:00
parent 97e8e32ebc
commit d185396a1c
6 changed files with 13 additions and 13 deletions

6
ir.c
View File

@ -105,10 +105,10 @@ void print_ir(IRToks *v, const BuiltinFunc *builtin_funcs) {
case IRSub:
case IRDiv:
case IRMul:
printf(" %%%zx ", v->toks[i].Arith.addr);
print_irparam(&v->toks[i].Arith.lhs);
printf(" %%%zx ", v->toks[i].Binary.addr);
print_irparam(&v->toks[i].Binary.lhs);
printf(" ");
print_irparam(&v->toks[i].Arith.rhs);
print_irparam(&v->toks[i].Binary.rhs);
break;
case IRJmp:
printf(" %zx", v->toks[i].Jmp.iaddr);

2
ir.h
View File

@ -59,7 +59,7 @@ typedef struct IRTok {
struct {
size_t addr;
IRParam lhs, rhs;
} Arith;
} Binary;
struct {
size_t iaddr;

View File

@ -52,7 +52,7 @@ static void set_irtok_dest_addr(IRTok *t, size_t addr) {
case IRSub:
case IRMul:
case IRDiv:
t->Arith.addr = addr;
t->Binary.addr = addr;
break;
case IRCallInternal:
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) {
/* evaluate the constant expression immediately */
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 {
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,
.col = l_op->col,
.instr = instr,
.Arith = {
.Binary = {
.addr = res_addr,
.lhs = lhs_irparam,
.rhs = rhs_irparam,

View File

@ -2,7 +2,7 @@
#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) {
case IRAdd:
case IRSub:

View File

@ -3,7 +3,7 @@
#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);
bool is_nonzero(const Value *v);
Value zero_val(Type ty);

8
vm.c
View File

@ -63,10 +63,10 @@ void run(const IRToks *ir, const BuiltinFunc *builtin_funcs) {
case IRSub:
case IRDiv:
case IRMul:
stack_fit(&s, instr->Arith.addr);
TRY_ELSE(s.mem[instr->Arith.addr] = eval_arith(instr->instr,
irparam_to_val(&s, &instr->Arith.lhs),
irparam_to_val(&s, &instr->Arith.rhs)),
stack_fit(&s, instr->Binary.addr);
TRY_ELSE(s.mem[instr->Binary.addr] = eval_binary(instr->instr,
irparam_to_val(&s, &instr->Binary.lhs),
irparam_to_val(&s, &instr->Binary.rhs)),
{free(fn_args); stack_term(&s);});
break;
case IRJmp: