rename passes
This commit is contained in:
parent
d8079f34f6
commit
5cec67bb01
9 changed files with 24 additions and 24 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::ast_compiler::Expression::{
|
use crate::ast_pass::Expression::{
|
||||||
Assignment, FieldGet, FunctionCall, ListGet, MapGet, MethodCall, NamedParameter, Stop, Variable,
|
Assignment, FieldGet, FunctionCall, ListGet, MapGet, MethodCall, NamedParameter, Stop, Variable,
|
||||||
};
|
};
|
||||||
use crate::errors::CompilerError::{
|
use crate::errors::CompilerError::{
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::ast_compiler::Parameter;
|
use crate::ast_pass::Parameter;
|
||||||
use crate::builtins::{FunctionMap, Signature, add, expected};
|
use crate::builtins::{FunctionMap, Signature, add, expected};
|
||||||
use crate::errors::RuntimeError;
|
use crate::errors::RuntimeError;
|
||||||
use crate::tokens::TokenType;
|
use crate::tokens::TokenType;
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ use crate::tokens::TokenType;
|
||||||
use crate::value::Value;
|
use crate::value::Value;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::LazyLock;
|
use std::sync::LazyLock;
|
||||||
use crate::ast_compiler::Parameter;
|
use crate::ast_pass::Parameter;
|
||||||
use crate::builtins::list::list_functions;
|
use crate::builtins::list::list_functions;
|
||||||
|
|
||||||
pub(crate) struct Signature {
|
pub(crate) struct Signature {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::ast_compiler::Expression::NamedParameter;
|
use crate::ast_pass::Expression::NamedParameter;
|
||||||
use crate::ast_compiler::{Expression, Function, Parameter, Statement};
|
use crate::ast_pass::{Expression, Function, Parameter, Statement};
|
||||||
use crate::builtins::lookup;
|
use crate::builtins::lookup;
|
||||||
use crate::chunk::Chunk;
|
use crate::chunk::Chunk;
|
||||||
use crate::errors::CompilerError::{IncompatibleTypes, UndeclaredVariable};
|
use crate::errors::CompilerError::{IncompatibleTypes, UndeclaredVariable};
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::ast_compiler::Parameter;
|
use crate::ast_pass::Parameter;
|
||||||
use crate::tokens::TokenType;
|
use crate::tokens::TokenType;
|
||||||
use crate::value::Value;
|
use crate::value::Value;
|
||||||
use crate::vm::{
|
use crate::vm::{
|
||||||
|
|
|
||||||
26
src/lib.rs
26
src/lib.rs
|
|
@ -1,24 +1,24 @@
|
||||||
use crate::ast_compiler::{Expression, Statement};
|
use crate::ast_pass::{Expression, Statement};
|
||||||
use crate::chunk::Chunk;
|
use crate::chunk::Chunk;
|
||||||
use crate::errors::CrudLangError::Platform;
|
use crate::errors::CrudLangError::Platform;
|
||||||
use crate::errors::{CompilerErrorAtLine, CrudLangError};
|
use crate::errors::{CompilerErrorAtLine, CrudLangError};
|
||||||
use crate::scanner::scan;
|
use crate::scan_pass::scan;
|
||||||
use crate::symbol_builder::Symbol;
|
use crate::symbol_builder::Symbol;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
use crate::value::Value::Void;
|
use crate::value::Value::Void;
|
||||||
|
|
||||||
pub mod ast_compiler;
|
pub mod ast_pass;
|
||||||
mod builtins;
|
mod builtins;
|
||||||
pub mod bytecode_compiler;
|
pub mod bytecode_pass;
|
||||||
pub mod chunk;
|
pub mod chunk;
|
||||||
mod compiler_tests;
|
mod compiler_tests;
|
||||||
pub mod errors;
|
pub mod errors;
|
||||||
pub mod file_watch;
|
pub mod file_watch;
|
||||||
mod keywords;
|
mod keywords;
|
||||||
pub mod repl;
|
pub mod repl;
|
||||||
pub mod scanner;
|
pub mod scan_pass;
|
||||||
mod symbol_builder;
|
mod symbol_builder;
|
||||||
mod tokens;
|
mod tokens;
|
||||||
mod value;
|
mod value;
|
||||||
|
|
@ -39,12 +39,12 @@ pub fn compile_sourcedir(source_dir: &str) -> Result<HashMap<String, Chunk>, Cru
|
||||||
let source = fs::read_to_string(path).map_err(map_underlying())?;
|
let source = fs::read_to_string(path).map_err(map_underlying())?;
|
||||||
let tokens = scan(&source)?;
|
let tokens = scan(&source)?;
|
||||||
let mut symbol_table = HashMap::new();
|
let mut symbol_table = HashMap::new();
|
||||||
match ast_compiler::compile(Some(path), tokens, &mut symbol_table) {
|
match ast_pass::compile(Some(path), tokens, &mut symbol_table) {
|
||||||
Ok(statements) => {
|
Ok(statements) => {
|
||||||
let path = path.strip_prefix(source_dir).unwrap().replace(".crud", "");
|
let path = path.strip_prefix(source_dir).unwrap().replace(".crud", "");
|
||||||
|
|
||||||
symbol_builder::build(&path, &statements, &mut symbol_table);
|
symbol_builder::build(&path, &statements, &mut symbol_table);
|
||||||
bytecode_compiler::compile(
|
bytecode_pass::compile(
|
||||||
Some(&path),
|
Some(&path),
|
||||||
&statements,
|
&statements,
|
||||||
&symbol_table,
|
&symbol_table,
|
||||||
|
|
@ -69,9 +69,9 @@ pub fn map_underlying() -> fn(std::io::Error) -> CrudLangError {
|
||||||
pub fn recompile(src: &str, registry: &mut HashMap<String, Chunk>) -> Result<(), CrudLangError> {
|
pub fn recompile(src: &str, registry: &mut HashMap<String, Chunk>) -> Result<(), CrudLangError> {
|
||||||
let tokens = scan(src)?;
|
let tokens = scan(src)?;
|
||||||
let mut symbol_table = HashMap::new();
|
let mut symbol_table = HashMap::new();
|
||||||
let ast = ast_compiler::compile(None, tokens, &mut symbol_table)?;
|
let ast = ast_pass::compile(None, tokens, &mut symbol_table)?;
|
||||||
symbol_builder::build("", &ast, &mut symbol_table);
|
symbol_builder::build("", &ast, &mut symbol_table);
|
||||||
bytecode_compiler::compile(None, &ast, &symbol_table, registry)?;
|
bytecode_pass::compile(None, &ast, &symbol_table, registry)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -79,9 +79,9 @@ pub fn compile(src: &str) -> Result<HashMap<String, Chunk>, CrudLangError> {
|
||||||
let tokens = scan(src)?;
|
let tokens = scan(src)?;
|
||||||
let mut registry = HashMap::new();
|
let mut registry = HashMap::new();
|
||||||
let mut symbol_table = HashMap::new();
|
let mut symbol_table = HashMap::new();
|
||||||
let ast = ast_compiler::compile(None, tokens, &mut symbol_table)?;
|
let ast = ast_pass::compile(None, tokens, &mut symbol_table)?;
|
||||||
symbol_builder::build("", &ast, &mut symbol_table);
|
symbol_builder::build("", &ast, &mut symbol_table);
|
||||||
bytecode_compiler::compile(None, &ast, &symbol_table, &mut registry)?;
|
bytecode_pass::compile(None, &ast, &symbol_table, &mut registry)?;
|
||||||
Ok(registry)
|
Ok(registry)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -89,10 +89,10 @@ pub fn compile(src: &str) -> Result<HashMap<String, Chunk>, CrudLangError> {
|
||||||
pub(crate) fn run(src: &str) -> Result<value::Value, CrudLangError> {
|
pub(crate) fn run(src: &str) -> Result<value::Value, CrudLangError> {
|
||||||
let tokens = scan(src)?;
|
let tokens = scan(src)?;
|
||||||
let mut symbol_table = HashMap::new();
|
let mut symbol_table = HashMap::new();
|
||||||
let ast = ast_compiler::compile(None, tokens, &mut symbol_table)?;
|
let ast = ast_pass::compile(None, tokens, &mut symbol_table)?;
|
||||||
symbol_builder::build("", &ast, &mut symbol_table);
|
symbol_builder::build("", &ast, &mut symbol_table);
|
||||||
let mut registry = HashMap::new();
|
let mut registry = HashMap::new();
|
||||||
bytecode_compiler::compile(None, &ast, &symbol_table, &mut registry)?;
|
bytecode_pass::compile(None, &ast, &symbol_table, &mut registry)?;
|
||||||
|
|
||||||
let registry = arc_swap::ArcSwap::from(std::sync::Arc::new(registry));
|
let registry = arc_swap::ArcSwap::from(std::sync::Arc::new(registry));
|
||||||
vm::interpret(registry.load(), "main").map_err(CrudLangError::from)
|
vm::interpret(registry.load(), "main").map_err(CrudLangError::from)
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
use crate::chunk::Chunk;
|
use crate::chunk::Chunk;
|
||||||
use crate::errors::CrudLangError;
|
use crate::errors::CrudLangError;
|
||||||
use crate::scanner::scan;
|
use crate::scan_pass::scan;
|
||||||
use crate::vm::Vm;
|
use crate::vm::Vm;
|
||||||
use crate::{ast_compiler, bytecode_compiler, map_underlying, symbol_builder};
|
use crate::{ast_pass, bytecode_pass, map_underlying, symbol_builder};
|
||||||
use arc_swap::ArcSwap;
|
use arc_swap::ArcSwap;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
@ -15,7 +15,7 @@ pub fn start(registry: Arc<ArcSwap<HashMap<String, Chunk>>>) -> Result<(), CrudL
|
||||||
println!(":h for help");
|
println!(":h for help");
|
||||||
let mut symbol_table = HashMap::new();
|
let mut symbol_table = HashMap::new();
|
||||||
let mut vm = Vm::new(®istry.load());
|
let mut vm = Vm::new(®istry.load());
|
||||||
let mut bytecode_compiler = bytecode_compiler::Compiler::new("main");
|
let mut bytecode_compiler = bytecode_pass::Compiler::new("main");
|
||||||
loop {
|
loop {
|
||||||
print!(">");
|
print!(">");
|
||||||
io::stdout().flush().map_err(map_underlying())?;
|
io::stdout().flush().map_err(map_underlying())?;
|
||||||
|
|
@ -34,7 +34,7 @@ pub fn start(registry: Arc<ArcSwap<HashMap<String, Chunk>>>) -> Result<(), CrudL
|
||||||
|
|
||||||
let tokens = scan(input)?;
|
let tokens = scan(input)?;
|
||||||
|
|
||||||
let ast = match ast_compiler::compile(None, tokens, &mut symbol_table){
|
let ast = match ast_pass::compile(None, tokens, &mut symbol_table){
|
||||||
Ok(ast) => ast,
|
Ok(ast) => ast,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("{}", e);
|
println!("{}", e);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::ast_compiler::{Expression, Parameter, Statement};
|
use crate::ast_pass::{Expression, Parameter, Statement};
|
||||||
use crate::builtins::lookup;
|
use crate::builtins::lookup;
|
||||||
use crate::errors::CompilerError;
|
use crate::errors::CompilerError;
|
||||||
use crate::errors::CompilerError::IncompatibleTypes;
|
use crate::errors::CompilerError::IncompatibleTypes;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue