Skip to content

Commit

Permalink
Merge pull request #38 from Plecra/basic-binary
Browse files Browse the repository at this point in the history
Add a basic frontend for experimentation
  • Loading branch information
slightknack authored Apr 16, 2021
2 parents 3796465 + f98a656 commit b92f46e
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use passerine::{
common::{closure::Closure, source::Source},
compiler::{lex, parse, desugar, gen, hoist},
vm::vm::VM,
};

pub fn main() -> Result<(), String> {
let path = std::env::args_os().nth(1).expect("Usage: <path>");

let source = Source::path(path.as_ref())
.map_err(|_| format!("Could not find source entrypoint {:?}", path))?;

let tokens = lex(source).map_err(|e| e.to_string())?;
let ast = parse(tokens).map_err(|e| e.to_string())?;
let cst = desugar(ast).map_err(|e| e.to_string())?;
let sst = hoist(cst).map_err(|e| e.to_string())?;
let bytecode = gen(sst).map_err(|e| e.to_string())?;

let mut vm = VM::init(Closure::wrap(bytecode));
vm.run().map_err(|e| e.to_string())?;

Ok(())
}

0 comments on commit b92f46e

Please sign in to comment.