forked from MightyPork/crsn
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
1.6 KiB
81 lines
1.6 KiB
4 years ago
|
#[macro_use]
|
||
|
extern crate log;
|
||
|
|
||
|
use simple_logger::SimpleLogger;
|
||
4 years ago
|
|
||
4 years ago
|
use crsn::asm::data::literal::Addr;
|
||
|
use crsn::runtime::program::Program;
|
||
|
use crsn::runtime::run_thread::{RunThread, ThreadToken};
|
||
|
use crsn_arith::ArithOpParser;
|
||
4 years ago
|
|
||
|
fn main() {
|
||
|
SimpleLogger::new().init().unwrap();
|
||
|
|
||
|
// ;(dec r0 (z? (ret)))
|
||
4 years ago
|
/*let program = "
|
||
4 years ago
|
(
|
||
|
(main
|
||
|
(ld r0 2)
|
||
|
(:again)
|
||
|
(dec r0)
|
||
|
(jif nz :again)
|
||
|
(fault \"that's it\")
|
||
|
)
|
||
|
)
|
||
4 years ago
|
";*/
|
||
4 years ago
|
/*
|
||
|
let program = "
|
||
|
(
|
||
|
(main
|
||
|
(ld r0 2)
|
||
|
(call add2x r0 15)
|
||
|
(ld r0 res0)
|
||
|
(fault \"that's it\")
|
||
|
)
|
||
|
(add2x
|
||
|
(ld r0 arg0)
|
||
|
(ld r1 arg1)
|
||
|
(add r0 r1)
|
||
|
(add r0 r1)
|
||
|
(ret r0)
|
||
|
)
|
||
4 years ago
|
)
|
||
4 years ago
|
";*/
|
||
4 years ago
|
|
||
|
let program = "
|
||
|
(
|
||
|
(main
|
||
4 years ago
|
(ld _ arg0)
|
||
4 years ago
|
(call fibo 5)
|
||
|
(ld r0 res0)
|
||
|
)
|
||
|
(fibo
|
||
|
(cmp arg0 2
|
||
|
(eq? (ret 2)))
|
||
|
(ld r0 arg0)
|
||
|
(dec r0)
|
||
|
(call fibo r0)
|
||
|
(ld r0 arg0)
|
||
|
(mul r0 res0)
|
||
|
(ret r0)
|
||
|
)
|
||
|
)
|
||
4 years ago
|
";
|
||
|
|
||
4 years ago
|
let parsers = vec![
|
||
|
ArithOpParser::new()
|
||
|
];
|
||
|
|
||
|
let parsed = crsn::asm::assemble(program, parsers.as_slice()).unwrap();
|
||
4 years ago
|
|
||
|
debug!("---");
|
||
|
for op in &parsed {
|
||
|
debug!("{:?}", op);
|
||
|
}
|
||
|
debug!("---");
|
||
|
|
||
|
let thread = RunThread::new(ThreadToken(0), Program::new(parsed), Addr(0), &[]);
|
||
|
|
||
|
thread.start().join().unwrap();
|
||
|
}
|