Add string reference word

This commit is contained in:
Dominic Grimm 2022-09-10 11:58:16 +02:00
parent d27acb2fa7
commit f997fdaf64
No known key found for this signature in database
GPG key ID: A6C051C716D2CE65
3 changed files with 20 additions and 4 deletions

View file

@ -1,2 +1,3 @@
depth dup dup dup dup dup debug ." test-string" cr
r" bliblablub" debug

View file

@ -55,7 +55,11 @@ impl Data {
instructions.push(match mode.as_str() { instructions.push(match mode.as_str() {
"." => { "." => {
let id = self.strings.insert_full(string).0; let id = self.strings.insert_full(string).0;
Instruction::DotQuote(id) Instruction::StringPrint(id)
}
"r" => {
let id = self.strings.insert_full(string).0;
Instruction::StringReference(id)
} }
"asm" => Instruction::AsmQuote(string), "asm" => Instruction::AsmQuote(string),
_ => bail!("Unknown string mode: {}", mode), _ => bail!("Unknown string mode: {}", mode),

View file

@ -31,7 +31,8 @@ pub enum Instruction {
Space, Space,
Spaces, Spaces,
Cr, Cr,
DotQuote(usize), StringPrint(usize),
StringReference(usize),
Count, Count,
Not, Not,
And, And,
@ -653,7 +654,7 @@ impl compiler::Compilable<compiler::Data, hence::parser::ast::Body> for Instruct
args: vec![hence::arg::Arg::Variable("CORE_MEM_CHR".to_string())], args: vec![hence::arg::Arg::Variable("CORE_MEM_CHR".to_string())],
}, },
]), ]),
Instruction::DotQuote(x) => { Instruction::StringPrint(x) => {
let loop_label = format!("loop_strings_{}", x); let loop_label = format!("loop_strings_{}", x);
let data_label = format!("data_strings_{}", x); let data_label = format!("data_strings_{}", x);
let data_end_label = format!("data_strings_end_{}", x); let data_end_label = format!("data_strings_end_{}", x);
@ -719,6 +720,16 @@ impl compiler::Compilable<compiler::Data, hence::parser::ast::Body> for Instruct
}, },
]) ])
} }
Instruction::StringReference(x) => Ok(vec![
hence::parser::ast::Node::Call {
name: "push".to_string(),
arg: Some(hence::arg::Arg::Variable(format!("data_strings_end_{}", x))),
},
hence::parser::ast::Node::Call {
name: "push".to_string(),
arg: Some(hence::arg::Arg::Variable(format!("data_strings_{}", x))),
},
]),
Instruction::Count => Ok(vec![]), Instruction::Count => Ok(vec![]),
Instruction::Not => Ok(vec![ Instruction::Not => Ok(vec![
hence::parser::ast::Node::MacroCall { hence::parser::ast::Node::MacroCall {