Compare commits

..

No commits in common. "51b04be1ab77a59662b480e1a4351cf19bc6213a" and "5331b5a4d2e49c7f8bed8ac98542d475e3523384" have entirely different histories.

2 changed files with 16 additions and 45 deletions

View File

@ -391,11 +391,19 @@ impl <'a> State <'a> {
let v_b = self.reg (*b);
let v_c = self.reg (*c);
let v_b = v_b.as_float ().unwrap_or_else (|| panic! ("{v_b}"));
let x = if let (Some (v_b), Some (v_c)) = (v_b.as_int (), v_c.as_int ())
{
Value::from (v_b / v_c)
}
else {
let v_b = v_b.as_float ().unwrap_or_else (|| panic! ("{v_b}"));
let v_c = v_c.as_float ().ok_or_else (|| make_step_error ("C must be a number"))?;
Value::from (v_b / v_c)
};
let v_c = v_c.as_float ().ok_or_else (|| make_step_error ("C must be a number"))?;
*self.reg_mut (*a) = Value::from (v_b / v_c);
*self.reg_mut (*a) = x;
},
Instruction::EqI (a, sb, k_flag) => {
if (self.reg (*a).as_int ().unwrap () == *sb as i64) != *k_flag
@ -449,7 +457,7 @@ impl <'a> State <'a> {
_ => panic! ("K[C] must be a string"),
};
let val = t.borrow ().get_str (key.as_str ()).clone ();
let val = t.borrow ().get (Value::String (Rc::clone (key)));
*self.reg_mut (*a) = val;
},
@ -725,13 +733,13 @@ impl <'a> State <'a> {
let key = match k.get (b).unwrap () {
Value::String (s) => s.as_ref (),
_ => panic! ("SetField only supports string keys"),
_ => panic! ("GetTabUp only supports string keys"),
};
let mut dst = self.reg (*a).as_table ()
.expect ("SetField only works on tables").borrow_mut ();
dst.insert_str (key.as_str (), value);
dst.insert (Value::from (key.as_str ()), value);
},
Instruction::SetI (a, b, c, k_flag) => {
let value = if *k_flag {

View File

@ -36,8 +36,6 @@ pub enum Value {
BogusClosure (Rc <RefCell <BogusClosure>>),
}
const NIL: Value = Value::Nil;
impl fmt::Debug for Value {
fn fmt (&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
@ -256,14 +254,7 @@ impl fmt::Debug for Table {
impl Table {
fn get_inner (&self, key: &Value) -> Value {
// self.hash.get (key).cloned ().unwrap_or_default ()
for (hay, value) in &self.hash {
if key == hay {
return value.clone ();
}
}
Value::Nil
self.hash.get (key).cloned ().unwrap_or_default ()
}
pub fn get <A: Into <Value>> (&self, key: A) -> Value {
@ -274,24 +265,7 @@ impl Table {
self.get_inner (&(key.into ()))
}
pub fn get_str (&self, key: &str) -> &Value {
for (hay, value) in &self.hash {
if Some (key) == hay.as_str () {
return value;
}
}
&NIL
}
fn insert_inner (&mut self, a: Value, b: Value) {
for (hay, value) in &mut self.hash {
if &a == hay {
*value = b;
return;
}
}
self.hash.insert (a, b);
}
@ -312,17 +286,6 @@ impl Table {
self.insert_inner (k.into (), v.into ())
}
pub fn insert_str (&mut self, key: &str, v: Value) {
for (hay, value) in &mut self.hash {
if Some (key) == hay.as_str () {
*value = v;
return;
}
}
self.hash.insert (key.into (), v);
}
pub fn length (&self) -> i64 {
for i in 1..i64::MAX {
if self.get (i) == Value::Nil {