1
0
This commit is contained in:
Jeff 2024-03-23 20:36:23 -04:00
parent b392a4c7aa
commit 7dfc026be5
2 changed files with 5 additions and 15 deletions

View File

@ -6,21 +6,9 @@ use std::{
use crate::{ use crate::{
abstract_tree::{Identifier, Type}, abstract_tree::{Identifier, Type},
error::{RwLockPoisonError, ValidationError}, error::{RwLockPoisonError, ValidationError},
Interpreter, Value, Value,
}; };
pub fn std_context() -> Context {
let context = Context::new();
let mut interpreter = Interpreter::new(context.clone());
interpreter.run(include_str!("../../std/io.ds")).unwrap();
interpreter
.run(include_str!("../../std/thread.ds"))
.unwrap();
context
}
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Context { pub struct Context {
inner: Arc<RwLock<BTreeMap<Identifier, ValueData>>>, inner: Arc<RwLock<BTreeMap<Identifier, ValueData>>>,

View File

@ -6,15 +6,17 @@ pub mod lexer;
pub mod parser; pub mod parser;
pub mod value; pub mod value;
use context::{std_context, Context}; use context::Context;
use error::Error; use error::Error;
use lexer::lex; use lexer::lex;
use parser::parse; use parser::parse;
pub use value::Value; pub use value::Value;
pub fn interpret(source: &str) -> Result<Option<Value>, Vec<Error>> { pub fn interpret(source: &str) -> Result<Option<Value>, Vec<Error>> {
let mut interpreter = Interpreter::new(std_context()); let mut interpreter = Interpreter::new(Context::new());
interpreter.run(include_str!("../../std/io.ds"))?;
interpreter.run(include_str!("../../std/thread.ds"))?;
interpreter.run(source) interpreter.run(source)
} }