Example extension: Stacks; fixes to allow module data storage in thread context

This commit is contained in:
2020-09-26 22:49:06 +02:00
parent 3e0aaa71e9
commit 0cd800653f
21 changed files with 285 additions and 74 deletions
+27 -6
View File
@@ -4,9 +4,10 @@ extern crate log;
use simple_logger::SimpleLogger;
use crsn::asm::data::literal::Addr;
use crsn::runtime::program::Program;
use crsn::runtime::run_thread::{RunThread, ThreadToken};
use crsn_arith::ArithOpParser;
use crsn_arith::ArithOps;
use crsn_stacks::StackOps;
fn main() {
SimpleLogger::new().init().unwrap();
@@ -42,7 +43,7 @@ fn main() {
)
";*/
let program = "
/* let program = "
(
(main
(j :lbl)
@@ -63,15 +64,35 @@ fn main() {
(ret r0)
)
)
";*/
let program = "
(
(main
(push 0 10)
(push 0 20)
(push 0 30)
(pop r0 0)
(pop r0 0)
(pop r0 0)
(halt)
)
)
";
let parsers = vec![
ArithOpParser::new()
ArithOps::new(),
StackOps::new(),
];
let parsed = crsn::asm::assemble(program, parsers.as_slice()).unwrap();
let thread = RunThread::new(ThreadToken(0), parsed, Addr(0), &[]);
let thread1 = RunThread::new(ThreadToken(0), parsed.clone(), Addr(0), &[]);
let thread2 = RunThread::new(ThreadToken(1), parsed.clone(), Addr(0), &[]);
thread.start().join().unwrap();
let a = thread1.start();
let b = thread2.start();
a.join().unwrap();
b.join().unwrap();
}