-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a large change that introduces a proxy-like tokenizer that buffers tokens and should allow us to implement things like automatic semicolon insertion in the future. This means that we had to rewrite all the parser code from the previous functional style into a SLL-like style with lookaheads (its also easier to reason about and debug)
- Loading branch information
1 parent
1174402
commit 2be7a27
Showing
22 changed files
with
796 additions
and
386 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use std::{ | ||
env, fs, | ||
io::{self, Write}, | ||
}; | ||
|
||
fn main() -> io::Result<()> { | ||
if let Some(filename) = env::args().nth(1) { | ||
let script = fs::read_to_string(&filename)?; | ||
|
||
let program: js::bytecode::Program = script.parse().unwrap(); | ||
|
||
println!("{program:#?}"); | ||
|
||
let mut vm = js::bytecode::Vm::default(); | ||
vm.execute_program(&program); | ||
vm.dump(); | ||
} else { | ||
run_shell()?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
fn run_shell() -> io::Result<()> { | ||
let mut buffer = String::new(); | ||
let stdin = io::stdin(); | ||
|
||
loop { | ||
buffer.clear(); | ||
let mut stdout = io::stdout(); | ||
write!(stdout, ">>> ")?; | ||
stdout.flush()?; | ||
|
||
stdin.read_line(&mut buffer)?; | ||
|
||
match buffer.parse::<js::bytecode::Program>() { | ||
Ok(program) => { | ||
writeln!(stdout, "{program:#?}")?; | ||
|
||
let mut vm = js::bytecode::Vm::default(); | ||
vm.execute_program(&program); | ||
vm.dump(); | ||
}, | ||
Err(error) => error.get_context(&buffer).dump(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.