feat: usable?
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
use derive_more::Constructor;
|
||||
|
||||
use crate::vm::VM;
|
||||
|
||||
use super::Value;
|
||||
|
||||
#[derive(Debug, Clone, Constructor)]
|
||||
pub struct PrimOp {
|
||||
pub name: &'static str,
|
||||
arity: u8,
|
||||
func: fn(Vec<Value>) -> Value,
|
||||
func: fn(&VM, Vec<Value>) -> Value,
|
||||
}
|
||||
|
||||
impl PartialEq for PrimOp {
|
||||
@@ -16,7 +18,7 @@ impl PartialEq for PrimOp {
|
||||
}
|
||||
|
||||
impl PrimOp {
|
||||
pub fn call(self, args: Vec<Value>) -> Value {
|
||||
pub fn call(self, vm: &VM, args: Vec<Value>) -> Value {
|
||||
if (args.len() as u8) < self.arity {
|
||||
Value::PartialPrimOp(PartialPrimOp {
|
||||
name: self.name,
|
||||
@@ -25,7 +27,7 @@ impl PrimOp {
|
||||
func: self.func,
|
||||
})
|
||||
} else if args.len() as u8 == self.arity {
|
||||
(self.func)(args)
|
||||
(self.func)(vm, args)
|
||||
} else {
|
||||
unimplemented!()
|
||||
}
|
||||
@@ -37,7 +39,7 @@ pub struct PartialPrimOp {
|
||||
pub name: &'static str,
|
||||
arity: u8,
|
||||
args: Vec<Value>,
|
||||
func: fn(Vec<Value>) -> Value,
|
||||
func: fn(&VM, Vec<Value>) -> Value,
|
||||
}
|
||||
|
||||
impl PartialEq for PartialPrimOp {
|
||||
@@ -47,7 +49,7 @@ impl PartialEq for PartialPrimOp {
|
||||
}
|
||||
|
||||
impl PartialPrimOp {
|
||||
pub fn call(mut self, args: Vec<Value>) -> Value {
|
||||
pub fn call(mut self, vm: &VM, args: Vec<Value>) -> Value {
|
||||
let len = args.len() as u8;
|
||||
self.args.extend(args);
|
||||
if len < self.arity {
|
||||
@@ -58,10 +60,9 @@ impl PartialPrimOp {
|
||||
func: self.func,
|
||||
})
|
||||
} else if len == self.arity {
|
||||
(self.func)(self.args)
|
||||
(self.func)(vm, self.args)
|
||||
} else {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user