context -> process
This commit is contained in:
parent
36c5d125fb
commit
f4fbae10e6
23
src/main.rs
23
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::<value::Value>()
|
||||
|
|
|
@ -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<Value<'src>, 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<T>(&self, x: T, y: T) -> Option<&Context<'src>>
|
||||
pub fn match_eq<T>(&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),
|
Loading…
Reference in New Issue
Block a user