Skip to content

Commit

Permalink
Generate Code, and run it successfully!
Browse files Browse the repository at this point in the history
  • Loading branch information
nbp committed Oct 12, 2017
1 parent 025459c commit e4ed3be
Show file tree
Hide file tree
Showing 6 changed files with 1,294 additions and 202 deletions.
9 changes: 4 additions & 5 deletions examples/brainfuck.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#![feature(plugin, custom_attribute)]
#![plugin(holyjit_plugin)]
#![feature(unboxed_closures)]

#[macro_use] extern crate holyjit_lib as hj;


jit!{ fn eval(jc: hj::JitContext, program: String) -> Result<(), ()> = eval_impl in jc; }
fn eval_impl(_jc: hj::JitContext, program: String) -> Result<(), ()> {
let prog = program.as_bytes();
Expand All @@ -19,8 +17,8 @@ fn eval_impl(_jc: hj::JitContext, program: String) -> Result<(), ()> {
match prog[pc] {
b'>' => { val += 1; }
b'<' => { val -= 1; }
b'-' => { mem[val as usize] += 1; }
b'+' => { mem[val as usize] -= 1; }
b'-' => { mem[val as usize] -= 1; }
b'+' => { mem[val as usize] += 1; }
b'.' => { panic!("putchar: NYI"); }
b',' => { panic!("getchar: NYI"); }
b'[' => {
Expand Down Expand Up @@ -61,5 +59,6 @@ fn eval_impl(_jc: hj::JitContext, program: String) -> Result<(), ()> {

fn main() {
let jc : hj::JitContext = Default::default();
eval(jc, "".into()).unwrap()
let res = eval(jc, "++".into());
res.unwrap();
}
Loading

0 comments on commit e4ed3be

Please sign in to comment.