mirror of
https://github.com/voltrevo/ValueScript.git
synced 2026-04-18 03:00:27 -04:00
Use &Val for submov key
This commit is contained in:
@@ -70,7 +70,7 @@ where
|
||||
Ok(Self::bo_sub(&key.to_string()))
|
||||
}
|
||||
|
||||
fn submov(&mut self, _key: Val, _value: Val) -> Result<(), Val> {
|
||||
fn submov(&mut self, _key: &Val, _value: Val) -> Result<(), Val> {
|
||||
Err(format!("Cannot assign to subscript of {} builtin", Self::bo_name()).to_type_error())
|
||||
}
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ static SET_MESSAGE: NativeFunction = native_fn(|mut this, params| {
|
||||
None => "".to_string(),
|
||||
};
|
||||
|
||||
op_submov(this.get_mut()?, "message".to_val(), message.to_val())?;
|
||||
op_submov(this.get_mut()?, &"message".to_val(), message.to_val())?;
|
||||
|
||||
Ok(Val::Undefined)
|
||||
});
|
||||
|
||||
@@ -62,7 +62,7 @@ static SET_MESSAGE: NativeFunction = native_fn(|mut this, params| {
|
||||
None => "".to_string(),
|
||||
};
|
||||
|
||||
op_submov(this.get_mut()?, "message".to_val(), message.to_val())?;
|
||||
op_submov(this.get_mut()?, &"message".to_val(), message.to_val())?;
|
||||
|
||||
Ok(Val::Undefined)
|
||||
});
|
||||
|
||||
@@ -70,7 +70,7 @@ static SET_MESSAGE: NativeFunction = native_fn(|mut this, params| {
|
||||
None => "".to_string(),
|
||||
};
|
||||
|
||||
op_submov(this.get_mut()?, "message".to_val(), message.to_val())?;
|
||||
op_submov(this.get_mut()?, &"message".to_val(), message.to_val())?;
|
||||
|
||||
Ok(Val::Undefined)
|
||||
});
|
||||
|
||||
@@ -302,13 +302,13 @@ impl StackFrameTrait for BytecodeStackFrame {
|
||||
Sub => self.apply_binary_op(operations::op_sub)?,
|
||||
|
||||
SubMov => {
|
||||
let subscript = self.decoder.decode_val(&self.registers);
|
||||
let subscript = self.decoder.decode_vallish(&self.registers);
|
||||
let value = self.decoder.decode_val(&self.registers);
|
||||
|
||||
let register_index = self.decoder.decode_register_index().unwrap();
|
||||
let mut target = self.registers[register_index].clone(); // TODO: Lift
|
||||
|
||||
operations::op_submov(&mut target, subscript, value)?;
|
||||
operations::op_submov(&mut target, subscript.get_ref(), value)?;
|
||||
self.registers[register_index] = target;
|
||||
}
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ impl ValTrait for Generator {
|
||||
Ok(Val::Undefined)
|
||||
}
|
||||
|
||||
fn submov(&mut self, _key: Val, _value: Val) -> Result<(), Val> {
|
||||
fn submov(&mut self, _key: &Val, _value: Val) -> Result<(), Val> {
|
||||
Err("Cannot assign to subscript of a generator".to_type_error())
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ impl ValTrait for ArrayEntriesIterator {
|
||||
Ok(Val::Undefined)
|
||||
}
|
||||
|
||||
fn submov(&mut self, _key: Val, _value: Val) -> Result<(), Val> {
|
||||
fn submov(&mut self, _key: &Val, _value: Val) -> Result<(), Val> {
|
||||
Err("Cannot assign to subscript of array iterator".to_type_error())
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ impl ValTrait for ArrayIterator {
|
||||
Ok(Val::Undefined)
|
||||
}
|
||||
|
||||
fn submov(&mut self, _key: Val, _value: Val) -> Result<(), Val> {
|
||||
fn submov(&mut self, _key: &Val, _value: Val) -> Result<(), Val> {
|
||||
Err("Cannot assign to subscript of array iterator".to_type_error())
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ impl ValTrait for IterationResult {
|
||||
})
|
||||
}
|
||||
|
||||
fn submov(&mut self, _key: Val, _value: Val) -> Result<(), Val> {
|
||||
fn submov(&mut self, _key: &Val, _value: Val) -> Result<(), Val> {
|
||||
Err("Cannot assign to subscript of iteration result".to_type_error())
|
||||
}
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@ impl ValTrait for StringIterator {
|
||||
Ok(Val::Undefined)
|
||||
}
|
||||
|
||||
fn submov(&mut self, _key: Val, _value: Val) -> Result<(), Val> {
|
||||
fn submov(&mut self, _key: &Val, _value: Val) -> Result<(), Val> {
|
||||
Err("Cannot assign to subscript of string iterator".to_type_error())
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ impl ValTrait for NativeFrameFunction {
|
||||
Err("TODO: Subscript native function".to_error())
|
||||
}
|
||||
|
||||
fn submov(&mut self, _key: Val, _value: Val) -> Result<(), Val> {
|
||||
fn submov(&mut self, _key: &Val, _value: Val) -> Result<(), Val> {
|
||||
Err("Cannot assign to subscript of native function".to_type_error())
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ impl ValTrait for NativeFunction {
|
||||
Err("TODO: Subscript native function".to_error())
|
||||
}
|
||||
|
||||
fn submov(&mut self, _key: Val, _value: Val) -> Result<(), Val> {
|
||||
fn submov(&mut self, _key: &Val, _value: Val) -> Result<(), Val> {
|
||||
Err("Cannot assign to subscript of native function".to_type_error())
|
||||
}
|
||||
|
||||
|
||||
@@ -470,7 +470,7 @@ pub fn op_sub(left: Vallish, right: Vallish) -> Result<Val, Val> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn op_submov(target: &mut Val, subscript: Val, value: Val) -> Result<(), Val> {
|
||||
pub fn op_submov(target: &mut Val, subscript: &Val, value: Val) -> Result<(), Val> {
|
||||
match target {
|
||||
Val::Void => Err("Internal: Shouldn't happen".to_error()), // TODO: Internal errors
|
||||
Val::Undefined => Err("Cannot assign to subscript of undefined".to_type_error()),
|
||||
@@ -510,7 +510,7 @@ pub fn op_submov(target: &mut Val, subscript: Val, value: Val) -> Result<(), Val
|
||||
|
||||
match subscript {
|
||||
Val::String(string) => object_data_mut.string_map.insert(string.to_string(), value),
|
||||
Val::Symbol(symbol) => object_data_mut.symbol_map.insert(symbol, value),
|
||||
Val::Symbol(symbol) => object_data_mut.symbol_map.insert(symbol.clone(), value),
|
||||
_ => object_data_mut
|
||||
.string_map
|
||||
.insert(subscript.to_string(), value),
|
||||
|
||||
@@ -150,7 +150,7 @@ impl ValTrait for ArrayPrototype {
|
||||
}))
|
||||
}
|
||||
|
||||
fn submov(&mut self, _key: Val, _value: Val) -> Result<(), Val> {
|
||||
fn submov(&mut self, _key: &Val, _value: Val) -> Result<(), Val> {
|
||||
Err("Cannot assign to subscript of Array.prototype".to_type_error())
|
||||
}
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ pub trait ValTrait: fmt::Display {
|
||||
fn load_function(&self) -> LoadFunctionResult;
|
||||
|
||||
fn sub(&self, key: &Val) -> Result<Val, Val>;
|
||||
fn submov(&mut self, key: Val, value: Val) -> Result<(), Val>;
|
||||
fn submov(&mut self, key: &Val, value: Val) -> Result<(), Val>;
|
||||
|
||||
fn pretty_fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result;
|
||||
fn codify(&self) -> String;
|
||||
@@ -356,7 +356,7 @@ impl ValTrait for Val {
|
||||
op_sub(Vallish::Ref(self), Vallish::Ref(key))
|
||||
}
|
||||
|
||||
fn submov(&mut self, key: Val, value: Val) -> Result<(), Val> {
|
||||
fn submov(&mut self, key: &Val, value: Val) -> Result<(), Val> {
|
||||
op_submov(self, key, value)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user