From 075bd910c14f33933ad18b64ca7970483823d20c Mon Sep 17 00:00:00 2001 From: pjh456 <147148383@qq.com> Date: Sat, 6 Jun 2026 10:08:34 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E8=B5=8B=E5=80=BC=E8=BF=90=E7=AE=97=E7=BC=96=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/oxide_compiler/src/compiler.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/crates/oxide_compiler/src/compiler.rs b/crates/oxide_compiler/src/compiler.rs index c0858714..041428b5 100644 --- a/crates/oxide_compiler/src/compiler.rs +++ b/crates/oxide_compiler/src/compiler.rs @@ -4,7 +4,7 @@ use crate::symbol_table::SymbolTable; pub use crate::hash::structural_hash; pub use crate::module::Constant; -pub use oxide_parser::{BinaryOperator, Expression, Statement, UnaryOperator}; +pub use oxide_parser::{AssignmentOperator, BinaryOperator, Expression, Statement, UnaryOperator}; pub struct Compiler; @@ -78,7 +78,6 @@ impl CompileCtx { self.symbols.lookup(name) } - #[allow(dead_code)] fn lookup_or_global(&mut self, name: &str) -> u8 { let reg = self.alloc_reg(); self.symbols.lookup_or_global(name, reg) @@ -551,6 +550,17 @@ impl Compiler { val_reg, )); Ok(val_reg) + } else if let oxide_parser::AssignmentTarget::AssignmentTargetIdentifier(id_ref) = + &assign.left + { + if assign.operator != AssignmentOperator::Assign { + return Err("compound assignment not yet supported".into()); + } + let val_reg = self.emit_expression(&assign.right, ctx)?; + let name = id_ref.name.as_str(); + let var_reg = ctx.lookup_or_global(name); + ctx.emit(opcode::encode(OpCode::STORE_VAR, var_reg, val_reg, 0)); + Ok(val_reg) } else { Err("assignment target not supported".into()) }