[fine] WIP: Classes
This commit is contained in:
parent
e6c96fde38
commit
0ee89bf26b
7 changed files with 370 additions and 59 deletions
|
|
@ -39,6 +39,12 @@ pub struct VMError {
|
|||
|
||||
type Result<T> = std::result::Result<T, VMErrorCode>;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Object {
|
||||
name: Rc<str>,
|
||||
values: Box<[StackValue]>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum StackValue {
|
||||
Nothing,
|
||||
|
|
@ -47,6 +53,7 @@ pub enum StackValue {
|
|||
String(Rc<str>),
|
||||
Function(Rc<Function>),
|
||||
ExternFunction(usize),
|
||||
Object(Rc<Object>),
|
||||
}
|
||||
|
||||
enum FuncValue {
|
||||
|
|
@ -130,6 +137,10 @@ impl Frame {
|
|||
self.push_value(StackValue::ExternFunction(v));
|
||||
}
|
||||
|
||||
fn push_object(&mut self, v: Rc<Object>) {
|
||||
self.push_value(StackValue::Object(v));
|
||||
}
|
||||
|
||||
fn get_argument(&self, i: usize) -> Result<StackValue> {
|
||||
self.args
|
||||
.get(i)
|
||||
|
|
@ -384,6 +395,21 @@ fn eval_one(
|
|||
let y = f.pop_string()?;
|
||||
f.push_bool(x == y);
|
||||
}
|
||||
|
||||
Instruction::NewObject(slots) => {
|
||||
let name = f.pop_string()?;
|
||||
let mut values = Vec::with_capacity(slots);
|
||||
for _ in 0..slots {
|
||||
values.push(f.pop_value()?);
|
||||
}
|
||||
|
||||
let object = Object {
|
||||
name,
|
||||
values: values.into(),
|
||||
};
|
||||
|
||||
f.push_object(object.into());
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Flow::Continue)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue