diff --git a/src/main.rs b/src/main.rs index a780ece..95bc12c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,7 +38,6 @@ use chumsky::{input::Stream, prelude::*}; use rust_embed::Embed; -use std::collections::HashMap; mod spans; @@ -57,14 +56,14 @@ use crate::base::*; mod validator; use crate::validator::*; -mod context; -use crate::context::*; +mod process; +use crate::process::*; #[derive(Embed)] #[folder = "assets/"] struct Asset; -pub fn prelude<'src>() -> Context<'src> { +pub fn prelude<'src>() -> Process<'src> { let prelude = Asset::get("test_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)); @@ -91,7 +90,7 @@ pub fn prelude<'src>() -> Context<'src> { let p_ast = Box::leak(Box::new(p_ast.unwrap().0)); let base_pkg = base(); - let mut base_ctx = Context::<'src> { + let mut base_ctx = Process::<'src> { locals: vec![], ast: p_ast, prelude: base_pkg, @@ -119,7 +118,7 @@ pub fn prelude<'src>() -> Context<'src> { } }; - Context { + Process { locals: vec![], ast: &Ast::Nil, prelude: p_ctx, @@ -167,10 +166,16 @@ pub fn run(src: &'static str) { pub fn main() { let src = " -fn foo () -> { - foo +fn bar + +fn foo { + () -> bar(:foo) + (:bar) -> :done } -foo () () () () + +fn bar (_) -> :bar + +foo () "; run(src); // struct_scalpel::print_dissection_info::() diff --git a/src/context.rs b/src/process.rs similarity index 99% rename from src/context.rs rename to src/process.rs index 90ad3bf..f0f8259 100644 --- a/src/context.rs +++ b/src/process.rs @@ -1,7 +1,7 @@ use crate::base::*; use crate::parser::*; use crate::spans::*; -use crate::value::{Fn, Value}; +use crate::value::Value; use imbl::HashMap; use imbl::Vector; use std::cell::RefCell; @@ -28,14 +28,14 @@ impl LErr { type LResult<'src> = Result, LErr>; -pub struct Context<'src> { +pub struct Process<'src> { pub locals: Vec<(String, Value<'src>)>, pub prelude: Vec<(String, Value<'src>)>, // pub prelude_ast: &'src Ast, pub ast: &'src Ast, } -impl<'src> Context<'src> { +impl<'src> Process<'src> { pub fn resolve(&self, word: &String) -> LResult<'src> { let resolved_local = self.locals.iter().rev().find(|(name, _)| word == name); @@ -61,7 +61,7 @@ impl<'src> Context<'src> { } } - pub fn match_eq(&self, x: T, y: T) -> Option<&Context<'src>> + pub fn match_eq(&self, x: T, y: T) -> Option<&Process<'src>> where T: PartialEq, { @@ -72,7 +72,7 @@ impl<'src> Context<'src> { } } - pub fn match_pattern(&mut self, patt: &Ast, val: &Value<'src>) -> Option<&Context<'src>> { + pub fn match_pattern(&mut self, patt: &Ast, val: &Value<'src>) -> Option<&Process<'src>> { use Ast::*; match (patt, val) { (NilPattern, Value::Nil) => Some(self),