Load16,
Load32,
Store, // ! ( x addr -- ) -- Store x at addr
+ Store8,
+ Store16,
+ Store32,
// These ones might not be inlined, but should be built-in, so a compiler might
// turn this into `Call(String)` before translating to assembly/machine-code, but
"std:mem" => Ok(include_str!("../../stdlib/mem.sorel")),
"std:out" => Ok(include_str!("../../stdlib/out.sorel")),
"std:string" => Ok(include_str!("../../stdlib/string.sorel")),
+ "std:process" => Ok(include_str!("../../stdlib/process.sorel")),
_ => bail!("{} is not a standard library module", specifier),
}
}
impl ImportTree {
fn import(&mut self, importer_dir: &PathBuf, specifier: &str, is_entrypoint: bool) -> Result<Rc<IRModule>> {
Ok(if specifier.starts_with("std:") {
+ if self.all_modules.contains_key(specifier) {
+ let module = self.all_modules.get(specifier).unwrap().clone();
+ return Ok(module);
+ }
let contents = std_import(specifier)?;
let parsed = &Module::parse(tokenize(&contents)?, is_entrypoint)?;
let module = self.generate_internal(None, Some(specifier.to_string()), parsed);
"@:16" => IR::Load16,
"@:32" => IR::Load32,
"!" => IR::Store,
+ "!:8" => IR::Store8,
+ "!:16" => IR::Store16,
+ "!:32" => IR::Store32,
"dup" => IR::Dup,
"swap" => IR::Swap,
"drop" => IR::Drop,
self.line("ld t0, 0(t0)"); // deref pointer in t0 to t0
self.copy_to_top_of_stack("t0");
},
+ IR::Store8 => { // ( x addr -- )
+ self.pop_some_to("t0 t1");
+ self.line("sbu t0, 0(t1)"); // store x at addr
+ },
+ IR::Store16 => { // ( x addr -- )
+ self.pop_some_to("t0 t1");
+ self.line("shu t0, 0(t1)"); // store x at addr
+ },
+ IR::Store32 => { // ( x addr -- )
+ self.pop_some_to("t0 t1");
+ self.line("shu t0, 0(t1)"); // store x at addr
+ },
IR::Store => { // ( x addr -- )
self.pop_some_to("t0 t1");
- self.line("sd t0, 0(t1)"); // store x at addr
+ self.line("sd t0, 0(t1)"); // store x at addr
},
IR::StackPush(num) => {
self.label(format!("# stackpush {}", num));
--- /dev/null
+\ vim: filetype=forth
+
+export exit
+
+: exit ( code -- )
+ 93
+ sys1
+;
--- /dev/null
+\ vim: filetype=forth
+
+import "std:process"
+import "std:out"
+
+export assert
+
+: assert ( x -- )
+ if
+ "pass\n" puts drop
+ else
+ 1 exit
+ endif
+;
\ vim: filetype=forth
import "std:out"
+import "./assert.sorel"
"Hello, World! \n" puts
drop
64 alloc
free
+
+\ 0 assert