Skip to content

Commit

Permalink
fix bf parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
p7g committed Jul 28, 2024
1 parent 2ad754f commit fb80f00
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
5 changes: 3 additions & 2 deletions bf.rbcvm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import array;
import arraylist;
import fs;
import iter;
import string;

struct Tape { get, inc, move }
Expand Down Expand Up @@ -31,7 +32,7 @@ function parse(it) {
let ops = arraylist.new();
let c;

while ((c = it())) {
while ((c = it()) != iter.STOP) {
if (c == '+') {
arraylist.push(ops, Op{type="inc", value=1});
} else if (c == '-') {
Expand Down Expand Up @@ -78,4 +79,4 @@ if (array.length(args) != 1) {
} else {
let it = array.iter(string.chars(fs.read_file(args[0])));
run(tape_new(), parse(it));
}
}
10 changes: 5 additions & 5 deletions eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,15 @@ static void debug_state(cb_bytecode *bytecode, size_t pc, struct cb_frame *frame
modname = cb_strptr(&modname_str);
}
if (!CB_VALUE_IS_USER_FN(frame->func)) {
if (!CB_VALUE_IS_USER_FN(&frame->func)) {
funcname = "top";
} else {
_name = cb_vm_state.stack[frame->bp].val.as_function->name;
funcname_str = cb_agent_get_string(_name);
funcname = cb_strptr(&funcname_str);
}
printf("%s%s%s\n", modname, !CB_VALUE_IS_USER_FN(frame->func)
printf("%s%s%s\n", modname, !CB_VALUE_IS_USER_FN(&frame->func)
? " " : ".", funcname);
printf("pc: %zu, bp: %zu, sp: %ld\n", pc, frame->bp,
cb_vm_state.stack_top - cb_vm_state.stack);
Expand Down Expand Up @@ -255,10 +255,10 @@ int cb_eval(struct cb_vm_state *state, size_t pc, struct cb_frame *frame)

#define NEXT() (code[pc++])
#define DISPATCH() ({ \
/*if (cb_options.debug_vm) {\
/*if (cb_options.debug_vm) { \
state->stack_top = stack_pointer; \
debug_state(state->bytecode, pc, frame); \
} */\
}*/ \
size_t _next = NEXT(); \
assert(_next < OP_MAX); \
goto *dispatch_table[_next]; \
Expand Down Expand Up @@ -1164,4 +1164,4 @@ DO_OP_ROT_2: {
}

#undef PUSH
#undef POP
#undef POP

0 comments on commit fb80f00

Please sign in to comment.