2019-06-30 08:57:18 -05:00
|
|
|
// Copyright 2019 Jeremy Wall
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2019-07-17 18:54:19 -05:00
|
|
|
use std::rc::Rc;
|
|
|
|
|
|
|
|
mod cache;
|
2019-06-30 08:57:18 -05:00
|
|
|
pub mod pointer;
|
2019-07-17 18:54:19 -05:00
|
|
|
mod runtime;
|
2019-07-01 15:27:09 -05:00
|
|
|
pub mod scope;
|
2019-07-13 10:59:10 -05:00
|
|
|
mod vm;
|
2019-07-01 15:27:09 -05:00
|
|
|
|
2019-07-13 10:59:10 -05:00
|
|
|
pub use vm::VM;
|
2019-07-11 16:48:08 -05:00
|
|
|
|
2019-06-30 08:57:18 -05:00
|
|
|
use pointer::OpPointer;
|
2019-07-01 15:27:09 -05:00
|
|
|
use scope::Stack;
|
2019-06-30 08:57:18 -05:00
|
|
|
|
|
|
|
#[derive(Debug, PartialEq, Clone)]
|
|
|
|
pub enum Primitive {
|
|
|
|
// Primitive Types
|
|
|
|
Int(i64),
|
|
|
|
Float(f64),
|
|
|
|
Str(String),
|
|
|
|
Bool(bool),
|
|
|
|
Empty,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, PartialEq, Clone)]
|
2019-07-11 16:48:08 -05:00
|
|
|
pub enum Composite {
|
2019-07-17 18:54:19 -05:00
|
|
|
List(Vec<Rc<Value>>),
|
|
|
|
Tuple(Vec<(String, Rc<Value>)>),
|
2019-06-30 08:57:18 -05:00
|
|
|
}
|
|
|
|
|
2019-07-01 15:27:09 -05:00
|
|
|
#[derive(Debug, PartialEq, Clone)]
|
2019-07-11 16:48:08 -05:00
|
|
|
pub struct Func {
|
|
|
|
ptr: OpPointer,
|
2019-07-01 15:27:09 -05:00
|
|
|
bindings: Vec<String>,
|
|
|
|
snapshot: Stack,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, PartialEq, Clone)]
|
2019-07-11 16:48:08 -05:00
|
|
|
pub struct Module {
|
|
|
|
ptr: OpPointer,
|
2019-07-01 15:27:09 -05:00
|
|
|
result_ptr: Option<usize>,
|
2019-07-17 18:54:19 -05:00
|
|
|
flds: Vec<(String, Rc<Value>)>,
|
2019-07-01 15:27:09 -05:00
|
|
|
}
|
|
|
|
|
2019-06-30 08:57:18 -05:00
|
|
|
#[derive(Debug, PartialEq, Clone)]
|
2019-07-11 16:48:08 -05:00
|
|
|
pub enum Value {
|
2019-06-30 08:57:18 -05:00
|
|
|
// Binding names.
|
|
|
|
S(String),
|
|
|
|
// Primitive Types
|
|
|
|
P(Primitive),
|
|
|
|
// Composite Types.
|
2019-07-11 16:48:08 -05:00
|
|
|
C(Composite),
|
2019-06-30 08:57:18 -05:00
|
|
|
// Program Pointer
|
|
|
|
T(usize),
|
2019-07-01 15:27:09 -05:00
|
|
|
// Function
|
2019-07-11 16:48:08 -05:00
|
|
|
F(Func),
|
2019-07-01 15:27:09 -05:00
|
|
|
// Module
|
2019-07-11 16:48:08 -05:00
|
|
|
M(Module),
|
2019-06-30 08:57:18 -05:00
|
|
|
}
|
|
|
|
|
2019-07-17 18:54:19 -05:00
|
|
|
#[derive(Debug, PartialEq, Clone)]
|
|
|
|
pub enum Hook {
|
|
|
|
Map,
|
|
|
|
Include,
|
|
|
|
Filter,
|
|
|
|
Reduce,
|
|
|
|
Import,
|
|
|
|
Out,
|
|
|
|
Assert,
|
|
|
|
Convert,
|
|
|
|
}
|
|
|
|
|
2019-06-30 08:57:18 -05:00
|
|
|
#[derive(Debug, PartialEq, Clone)]
|
|
|
|
pub enum Op {
|
|
|
|
// Stack and Name manipulation.
|
|
|
|
Bind, // Bind a Val to a name in the heap
|
|
|
|
Pop, // Pop a Value off the value stack and discard it.
|
|
|
|
// Math ops
|
|
|
|
Add,
|
|
|
|
Sub,
|
|
|
|
Div,
|
|
|
|
Mul,
|
2019-06-30 22:51:47 -05:00
|
|
|
// Comparison Ops
|
|
|
|
Equal,
|
|
|
|
Gt,
|
|
|
|
Lt,
|
|
|
|
GtEq,
|
|
|
|
LtEq,
|
2019-06-30 08:57:18 -05:00
|
|
|
// Primitive Types ops
|
|
|
|
Val(Primitive),
|
|
|
|
// A bareword for use in bindings or lookups
|
|
|
|
Sym(String),
|
2019-07-01 15:27:09 -05:00
|
|
|
// Reference a binding on the heap
|
|
|
|
DeRef(String),
|
2019-06-30 08:57:18 -05:00
|
|
|
// Complex Type ops
|
|
|
|
InitTuple,
|
2019-06-30 22:21:28 -05:00
|
|
|
Field,
|
2019-06-30 08:57:18 -05:00
|
|
|
InitList,
|
|
|
|
Element,
|
2019-07-01 15:27:09 -05:00
|
|
|
// Copy Operation
|
2019-06-30 08:57:18 -05:00
|
|
|
Cp,
|
2019-06-30 22:21:28 -05:00
|
|
|
// Control Flow
|
|
|
|
Bang,
|
2019-07-09 19:40:13 -05:00
|
|
|
Jump(i32),
|
|
|
|
JumpIfTrue(i32),
|
|
|
|
JumpIfFalse(i32),
|
2019-07-10 18:20:01 -05:00
|
|
|
SelectJump(i32),
|
2019-07-05 21:49:10 -05:00
|
|
|
// FIXME(jwall): Short circuiting operations
|
2019-07-01 15:27:09 -05:00
|
|
|
// - And(usize)
|
|
|
|
// - Or(usize)
|
|
|
|
// Spacer operation, Does nothing.
|
2019-07-11 19:28:55 -05:00
|
|
|
Index, // indexing operation
|
2019-06-30 22:21:28 -05:00
|
|
|
Noop,
|
|
|
|
// Pending Computation
|
2019-07-09 19:45:51 -05:00
|
|
|
InitThunk(i32), // Basically just used for module return expressions
|
2019-07-01 15:27:09 -05:00
|
|
|
Module(usize),
|
|
|
|
Func(usize),
|
2019-06-30 08:57:18 -05:00
|
|
|
Return,
|
2019-07-10 18:45:58 -05:00
|
|
|
// Calls
|
2019-07-01 15:27:09 -05:00
|
|
|
FCall,
|
2019-06-30 08:57:18 -05:00
|
|
|
// Runtime hooks
|
2019-07-17 18:54:19 -05:00
|
|
|
Runtime(Hook),
|
2019-06-30 08:57:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Error {}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test;
|