Problem Description:
PUSH_STRING currently only accepts a single whitespace-separated value.
If the string contains spaces (like: hello world), the assembler treats the extra token as an opcode and errors with UnknownOpcode.
So, instruction like PUSH_STRING hello world fails with error UnknownOpcode { opcode: "world" }
Expected behavior
assembler should parse multi word value associated with PUSH_STRING.
Reason behind bug:
The assembler tokenizes instructions using split_whitespace() :
let mut tokens = src.split_whitespace().enumerate();
assembler.rs
and PUSH_STRING use 1 token
"PUSH_STRING" => {
bytecode.push(PUSH_STRING);
let (_pos, text) = next_token(&mut tokens, i, "missing String")?;
let idx = string_pool.intern_string(text.to_string());
bytecode.extend_from_slice(&idx.to_be_bytes());
}
assembler.rs
Potential solutions
- Require quoted strings:
PUSH_STRING "hello world!"
- Split instructions into tokens line by line , instead of using split_whitespace()?
Problem Description:
PUSH_STRING currently only accepts a single whitespace-separated value.
If the string contains spaces (like: hello world), the assembler treats the extra token as an opcode and errors with UnknownOpcode.
So, instruction like
PUSH_STRING hello worldfails with errorUnknownOpcode { opcode: "world" }Expected behavior
assembler should parse multi word value associated with PUSH_STRING.
Reason behind bug:
The assembler tokenizes instructions using split_whitespace() :
let mut tokens = src.split_whitespace().enumerate();assembler.rs
and
PUSH_STRINGuse 1 tokenassembler.rs
Potential solutions
PUSH_STRING "hello world!"