bring full prelude into Ludus.
This commit is contained in:
parent
49a0b0f8a7
commit
73e60b8ced
|
@ -295,7 +295,13 @@ fn concat {
|
|||
fn contains? {
|
||||
"Returns true if a set or list contains a value."
|
||||
& (value, s as :set) -> bool (base :get (s, value))
|
||||
(value, l as :list) -> contains? (value, set (list))
|
||||
(value, l as :list) -> loop (l) with {
|
||||
([]) -> false
|
||||
([x]) -> eq? (x, value)
|
||||
([x, ...xs]) -> if eq? (x, value)
|
||||
then true
|
||||
else recur (xs)
|
||||
}
|
||||
}
|
||||
|
||||
& fn omit {
|
||||
|
|
|
@ -10,6 +10,8 @@ fn dec (n as :number) -> base :sub (n, 1)
|
|||
|
||||
fn sub (x as :number, y as :number) -> base :sub (x, y)
|
||||
|
||||
fn panics! () -> add ("foo", "bar")
|
||||
|
||||
fn print!(x) -> base :print! (x)
|
||||
|
||||
#{add, dec, sub, print!}
|
||||
#{add, dec, sub, print!, panics!}
|
||||
|
|
|
@ -257,7 +257,9 @@ pub fn or<'src>(x: &Value<'src>, y: &Value<'src>) -> Value<'src> {
|
|||
Value::Boolean(x.bool() || y.bool())
|
||||
}
|
||||
|
||||
// TODO: fix this: x is a list of all the args passed to Ludus's print!
|
||||
pub fn print<'src>(x: &Value<'src>) -> Value<'src> {
|
||||
// dbg!(x)
|
||||
println!("{}", x);
|
||||
Value::Keyword("ok")
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
// * [x] investigate using labels (which is behind a compiler flag, somehow)
|
||||
// * [ ] write parsing errors
|
||||
// * [ ] wire up Ariadne parsing errors
|
||||
// * [ ] add stack traces and code locations to panics
|
||||
// * [x] add stack traces and code locations to panics
|
||||
// * [x] validation
|
||||
// * [x] break this out into multiple files
|
||||
// * [x] write a tree-walk VM
|
||||
|
@ -70,7 +70,7 @@ pub fn prelude<'src>() -> (
|
|||
Vec<(String, Value<'src>)>,
|
||||
std::collections::HashMap<*const Ast, FnInfo>,
|
||||
) {
|
||||
let prelude = Asset::get("test_prelude.ld").unwrap().data.into_owned();
|
||||
let prelude = Asset::get("prelude.ld").unwrap().data.into_owned();
|
||||
// we know for sure Prelude should live through the whole run of the program
|
||||
let leaked = Box::leak(Box::new(prelude));
|
||||
let prelude = std::str::from_utf8(leaked).unwrap();
|
||||
|
|
|
@ -536,7 +536,7 @@ impl<'a, 'src: 'a> Validator<'a, 'src> {
|
|||
unreachable!()
|
||||
};
|
||||
|
||||
dbg!(&input);
|
||||
// dbg!(&input);
|
||||
|
||||
let tailpos = self.status.tail_position;
|
||||
self.status.tail_position = true;
|
||||
|
@ -551,7 +551,7 @@ impl<'a, 'src: 'a> Validator<'a, 'src> {
|
|||
self.ast = expr;
|
||||
self.span = *span;
|
||||
let arity = self.arity();
|
||||
dbg!(&arity);
|
||||
// dbg!(&arity);
|
||||
match arity {
|
||||
Arity::Fixed(clause_arity) => {
|
||||
if clause_arity != loop_arity {
|
||||
|
@ -644,7 +644,7 @@ impl<'a, 'src: 'a> Validator<'a, 'src> {
|
|||
},
|
||||
_ => {
|
||||
println!("internal Ludus error: unexpected splat pattern");
|
||||
dbg!(splatted);
|
||||
// dbg!(splatted);
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user