wire up stub:w prelude from external file
This commit is contained in:
parent
e06a24cf20
commit
a2ae53f8e4
|
@ -1,11 +1,7 @@
|
|||
& base :print! ("Hello from Prelude")
|
||||
|
||||
& I can't figure out why I need this, but I do
|
||||
& Otherwise the validator won't close over `base`
|
||||
let base = base
|
||||
|
||||
fn add (x as :number, y as :number) -> base :add (x, y)
|
||||
|
||||
fn inc (n as :number) -> base :add (n, 1)
|
||||
|
||||
fn dec (n as :number) -> base :sub (n, 1)
|
||||
|
||||
fn sub (x as :number, y as :number) -> base :sub (x, y)
|
||||
|
@ -14,4 +10,6 @@ fn panics! () -> add ("foo", "bar")
|
|||
|
||||
fn print!(x) -> base :print! (x)
|
||||
|
||||
#{add, dec, sub, print!, panics!}
|
||||
fn eq? (x, y) -> base :eq? (x, y)
|
||||
|
||||
#{add, inc, dec, sub, print!, panics!, eq?}
|
||||
|
|
|
@ -305,10 +305,10 @@ So this is my near-term TODO:
|
|||
* [x] update that declaration to a definition after compiling the function...
|
||||
* [x] but BEFORE we close over any upvalues, so the function will be an upvalue for itself
|
||||
- I suspect this can be done not using anything other than an index into a chunk's `constants` vec--no fancy memory swapping or anything; and also--done in the compiler rather than the VM.
|
||||
* [ ] getting to prelude
|
||||
- [ ] `base` should load into Prelude
|
||||
- [ ] write a mock prelude with a few key functions from real prelude
|
||||
- [ ] a prelude should be loaded into every context
|
||||
* [x] getting to prelude
|
||||
- [x] `base` should load into Prelude
|
||||
- [x] write a mock prelude with a few key functions from real prelude
|
||||
- [x] a prelude should be loaded into every context
|
||||
- [ ] the full prelude should run properly
|
||||
* [ ] packaging things up
|
||||
- [ ] add a `to_json` method for values
|
||||
|
|
|
@ -328,23 +328,24 @@ impl LoopInfo {
|
|||
}
|
||||
|
||||
fn get_builtin(name: &str, arity: usize) -> Option<Op> {
|
||||
match (name, arity) {
|
||||
("type", 1) => Some(Op::TypeOf),
|
||||
("eq?", 2) => Some(Op::Eq),
|
||||
("add", 2) => Some(Op::Add),
|
||||
("sub", 2) => Some(Op::Sub),
|
||||
("mult", 2) => Some(Op::Mult),
|
||||
("div", 2) => Some(Op::Div),
|
||||
("unbox", 1) => Some(Op::Unbox),
|
||||
("store!", 2) => Some(Op::BoxStore),
|
||||
("assert!", 1) => Some(Op::Assert),
|
||||
("get", 2) => Some(Op::Get),
|
||||
("at", 2) => Some(Op::At),
|
||||
("not", 1) => Some(Op::Not),
|
||||
("print!", 1) => Some(Op::Print),
|
||||
// match (name, arity) {
|
||||
// ("type", 1) => Some(Op::TypeOf),
|
||||
// ("eq?", 2) => Some(Op::Eq),
|
||||
// ("add", 2) => Some(Op::Add),
|
||||
// ("sub", 2) => Some(Op::Sub),
|
||||
// ("mult", 2) => Some(Op::Mult),
|
||||
// ("div", 2) => Some(Op::Div),
|
||||
// ("unbox", 1) => Some(Op::Unbox),
|
||||
// ("store!", 2) => Some(Op::BoxStore),
|
||||
// ("assert!", 1) => Some(Op::Assert),
|
||||
// ("get", 2) => Some(Op::Get),
|
||||
// ("at", 2) => Some(Op::At),
|
||||
// ("not", 1) => Some(Op::Not),
|
||||
// ("print!", 1) => Some(Op::Print),
|
||||
|
||||
_ => None,
|
||||
}
|
||||
// _ => None,
|
||||
// }
|
||||
None
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
16
src/main.rs
16
src/main.rs
|
@ -27,14 +27,7 @@ use value::Value;
|
|||
mod vm;
|
||||
use vm::Vm;
|
||||
|
||||
const PRELUDE: &str = "
|
||||
fn print! (...args) -> base :print! (args)
|
||||
fn inc (x) -> base :inc (x)
|
||||
fn dec (x) -> base :dec (x)
|
||||
fn eq? (x, y) -> base :eq? (x, y)
|
||||
|
||||
#{print!, inc, dec, eq?}
|
||||
";
|
||||
const PRELUDE: &str = include_str!("../assets/test_prelude.ld");
|
||||
|
||||
pub fn prelude() -> HashMap<&'static str, Value> {
|
||||
let tokens = lexer().parse(PRELUDE).into_output_errors().0.unwrap();
|
||||
|
@ -112,12 +105,7 @@ pub fn run(src: &'static str) {
|
|||
pub fn main() {
|
||||
env::set_var("RUST_BACKTRACE", "1");
|
||||
let src = "
|
||||
[
|
||||
eq? (1, 2)
|
||||
eq? (:foo, :foo)
|
||||
inc (3)
|
||||
dec (0)
|
||||
]
|
||||
panics! ()
|
||||
";
|
||||
run(src);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user