examples: fix brainvuck.v (handle [ and ] properly); allow both brainvuck.v wasm_codegen/bf_compiler.v to work with .b files too

This commit is contained in:
Delyan Angelov 2023-10-03 17:01:55 +03:00
parent fae46a8d85
commit 7a49f24eb1
No known key found for this signature in database
GPG key ID: 66886C0F12D595ED
2 changed files with 151 additions and 52 deletions

View file

@ -104,13 +104,19 @@ fn generate_code(mut start wasm.Function, bf_expr string) {
@[noreturn]
fn usage() {
eprintln('Usage: bf <expr> <outfile>')
eprintln('Usage: bf <expr> <outfile.wasm>')
eprintln(' or: bf <path/input.b> <outfile.wasm> (note the `.b` extension)')
exit(1)
}
fn main() {
bf_expr := os.args[1] or { usage() }
mut bf_expr := os.args[1] or { usage() }
if bf_expr.ends_with('.b') {
bf_expr = os.read_file(bf_expr) or {
eprintln('file ${bf_expr} could not be read, error: ${err}')
usage()
}
}
outfile := os.args[2] or { usage() }
mut m := wasm.Module{}