Skip to content

PUSH_STRING bug - fails for strings containing spaces #5

@tracyspacy

Description

@tracyspacy

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

  1. Require quoted strings: PUSH_STRING "hello world!"
  2. Split instructions into tokens line by line , instead of using split_whitespace()?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions