浏览代码

Merge pull request #67 from Aursen/fix/call

fix: call with equ constant
Dean 利迪恩 1 周之前
父节点
当前提交
ec770bd952
共有 1 个文件被更改,包括 7 次插入2 次删除
  1. 7 2
      crates/assembler/src/parser.rs

+ 7 - 2
crates/assembler/src/parser.rs

@@ -412,7 +412,7 @@ fn process_instruction(
                 });
             }
             Rule::instr_lddw => return process_lddw(inner, const_map, span_range),
-            Rule::instr_call => return process_call(inner, span_range),
+            Rule::instr_call => return process_call(inner, const_map, span_range),
             Rule::instr_callx => return process_callx(inner, span_range),
             Rule::instr_neg64 => return process_neg64(inner, span_range),
             Rule::instr_alu64_imm | Rule::instr_alu32_imm => {
@@ -747,13 +747,18 @@ fn process_jump_uncond(
 
 fn process_call(
     pair: Pair<Rule>,
+    const_map: &HashMap<String, Number>,
     span: std::ops::Range<usize>,
 ) -> Result<Instruction, CompileError> {
     let mut imm = None;
 
     for inner in pair.into_inner() {
         if inner.as_rule() == Rule::symbol {
-            imm = Some(Either::Left(inner.as_str().to_string()));
+            if let Some(symbol) = const_map.get(inner.as_str()) {
+                imm = Some(Either::Right(symbol.to_owned()));
+            } else {
+                imm = Some(Either::Left(inner.as_str().to_string()));
+            }
         }
     }