Compare commits

..

No commits in common. "ef63742015255fa04c668089f0bfa966b43e6258" and "298883939b3cd4b0c02d1fcaf9ba45a153ea9d6e" have entirely different histories.

3 changed files with 10 additions and 30 deletions

View File

@ -5,11 +5,7 @@ iterations := 100
while k - iterations { while k - iterations {
k_f := float(k) k_f := float(k)
sum = sum + 1.0 / pow(16.0, k_f) * sum = sum + 1.0 / pow(16.0, k_f) * (4.0 / (8.0 * k_f + 1.0) - 2.0 / (8.0 * k_f + 4.0) - 1.0 / (8.0 * k_f + 5.0) - 1.0 / (8.0 * k_f + 6.0))
(4.0 / (8.0 * k_f + 1.0) -
2.0 / (8.0 * k_f + 4.0) -
1.0 / (8.0 * k_f + 5.0) -
1.0 / (8.0 * k_f + 6.0))
k = k + 1 k = k + 1
} }

View File

@ -177,14 +177,6 @@ static ExprRet expr(IRToks *out_ir, TokList *toks, Map *funcs, Scope *parent_sc,
negate = true; negate = true;
} }
/* Delete newline if we're definitely expecting an operand. */
if (t->tok.kind == TokOp && t->tok.Op == OpNewLn) {
if (t == start)
start = t->next;
t = t->next;
toklist_del(toks, t->prev, t->prev);
}
/* Collapse parentheses. */ /* Collapse parentheses. */
if (t->tok.kind == TokOp && t->tok.Op == OpLParen) { if (t->tok.kind == TokOp && t->tok.Op == OpLParen) {
ExprRet r; ExprRet r;

26
vm.c
View File

@ -43,10 +43,6 @@ static Value *irparam_to_val(Stack *s, IRParam *v) {
} }
void run(const IRToks *ir, const BuiltinFunc *builtin_funcs) { void run(const IRToks *ir, const BuiltinFunc *builtin_funcs) {
/* so we don't have to call malloc on every function call */
size_t fn_args_cap = 16;
Value *fn_args = xmalloc(sizeof(Value) * fn_args_cap);
Stack s = stack_make(); Stack s = stack_make();
for (size_t i = 0; i < ir->len;) { for (size_t i = 0; i < ir->len;) {
IRTok *instr = &ir->toks[i]; IRTok *instr = &ir->toks[i];
@ -56,18 +52,17 @@ void run(const IRToks *ir, const BuiltinFunc *builtin_funcs) {
case IRSet: case IRSet:
case IRNeg: case IRNeg:
stack_fit(&s, instr->Unary.addr); stack_fit(&s, instr->Unary.addr);
TRY_ELSE(s.mem[instr->Unary.addr] = eval_unary(instr->instr, irparam_to_val(&s, &instr->Unary.val)), TRY(s.mem[instr->Unary.addr] = eval_unary(instr->instr, irparam_to_val(&s, &instr->Unary.val)));
{free(fn_args); stack_term(&s);});
break; break;
case IRAdd: case IRAdd:
case IRSub: case IRSub:
case IRDiv: case IRDiv:
case IRMul: case IRMul:
stack_fit(&s, instr->Arith.addr); stack_fit(&s, instr->Arith.addr);
TRY_ELSE(s.mem[instr->Arith.addr] = eval_arith(instr->instr, TRY(s.mem[instr->Arith.addr] = eval_arith(instr->instr,
irparam_to_val(&s, &instr->Arith.lhs), irparam_to_val(&s, &instr->Arith.lhs),
irparam_to_val(&s, &instr->Arith.rhs)), irparam_to_val(&s, &instr->Arith.rhs)
{free(fn_args); stack_term(&s);}); ));
break; break;
case IRJmp: case IRJmp:
i = instr->Jmp.iaddr; i = instr->Jmp.iaddr;
@ -80,16 +75,14 @@ void run(const IRToks *ir, const BuiltinFunc *builtin_funcs) {
break; break;
case IRCallInternal: { case IRCallInternal: {
const BuiltinFunc *f = &builtin_funcs[instr->CallI.fid]; const BuiltinFunc *f = &builtin_funcs[instr->CallI.fid];
/* make sure enough space for our arguments is allocated */ Value *args = xmalloc(sizeof(Value) * f->n_args);
if (f->n_args > fn_args_cap)
fn_args = xrealloc(fn_args, sizeof(Value) * (fn_args_cap = f->n_args));
/* copy arguments into buffer */
for (size_t i = 0; i < f->n_args; i++) for (size_t i = 0; i < f->n_args; i++)
fn_args[i] = *irparam_to_val(&s, &instr->CallI.args[i]); args[i] = *irparam_to_val(&s, &instr->CallI.args[i]);
stack_fit(&s, instr->CallI.ret_addr); stack_fit(&s, instr->CallI.ret_addr);
TRY_ELSE(s.mem[instr->CallI.ret_addr] = f->func(fn_args), TRY_ELSE(s.mem[instr->CallI.ret_addr] = f->func(args), free(args));
{free(fn_args); stack_term(&s);});
free(args);
break; break;
} }
default: default:
@ -99,5 +92,4 @@ void run(const IRToks *ir, const BuiltinFunc *builtin_funcs) {
i++; i++;
} }
stack_term(&s); stack_term(&s);
free(fn_args);
} }