bm
bm copied to clipboard
Argument passing from CLI
Dear BMers
Imagine an extension of the Fibonacci implementation, where we would pass an argument N (numeric) "into" it.
How would we support it ?
One approach is to have access to argument count and vector, e.g. some form of global variable, like $argc and $argv.
Another way would be to be able to call call some OS input reading function.
A third one would be patching some operand between BM instantiation and its execution.
Say we had the code below, with the initial push instruction to be 10.
Changing this operand to 23 could be accomplished with:
./bme -i examples/fib.bm --patch-at 0 --patch-operand 23
or
./bme -i examples/fib.bm --patch 0:operand 23
Here's an incomplete Fibonacci implementation:
counter:
push 10 # operand could be changed before execution
# First two Fibonacci numbers
push 0
push 1
loop:
# check is counter is now 0
# .......
jmp_if halt
dup 1
dup 1
plusi
# decrement counter
# ......
jmp loop
halt:
halt
Probably via some FFI API.