start on the actual execution part

This commit is contained in:
apache 2024-10-27 22:19:31 -05:00
parent f5de0ea259
commit d7bbcea1aa
Signed by: apache
GPG key ID: A6A19F45EF8C6FA7
4 changed files with 32 additions and 0 deletions

0
src/executor.rs Normal file
View file

View file

@ -1,4 +1,6 @@
mod value; mod value;
mod executor;
mod opcodes;
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {

20
src/opcodes.rs Normal file
View file

@ -0,0 +1,20 @@
use crate::value::Value;
type StackLocation = usize;
#[derive(PartialEq, Debug)]
pub enum OpValue {
Literal(Value),
Ref(StackLocation)
}
#[derive(PartialEq, Debug)]
pub enum OpCode {
// Function, arguments
Call(OpValue, Option<Vec<OpValue>>),
// Return Values
Return(Option<Vec<OpValue>>),
// Table, index
Index(OpValue, OpValue),
// Table, index, value
SetIndex(OpValue, OpValue, OpValue),
}

View file

@ -1,4 +1,5 @@
use std::collections::HashMap; use std::collections::HashMap;
use crate::opcodes::OpCode;
#[derive(PartialEq, Debug)] #[derive(PartialEq, Debug)]
pub enum Value { pub enum Value {
@ -10,6 +11,15 @@ pub enum Value {
Table { Table {
arr: Vec<Value>, arr: Vec<Value>,
map: HashMap<String, Value>, map: HashMap<String, Value>,
},
VmFunction {
name: String,
args: Vec<String>,
func: Vec<OpCode>
},
NativeFunction {
name: String,
func: fn(Vec<Value>) -> Option<Vec<Value>>
} }
} }