diff options
| author | Brian Cully <bjc@spork.org> | 2025-08-23 08:51:24 -0400 |
|---|---|---|
| committer | Brian Cully <bjc@spork.org> | 2025-08-23 08:51:24 -0400 |
| commit | 12c06171b3f94696e852c3910c116f56cbfc5b64 (patch) | |
| tree | 2a595842ae68c23150db63ef87bc01a1e9bfde8e /src/lib.rs | |
| parent | 79441128958669b16ce8dfe39a3684069921f604 (diff) | |
| download | automathon-12c06171b3f94696e852c3910c116f56cbfc5b64.tar.gz automathon-12c06171b3f94696e852c3910c116f56cbfc5b64.zip | |
wip: pass interp between js and rust
Diffstat (limited to 'src/lib.rs')
| -rwxr-xr-x | src/lib.rs | 57 |
1 files changed, 54 insertions, 3 deletions
@@ -5,9 +5,23 @@ use wasm_bindgen::prelude::*; pub mod forth; #[wasm_bindgen] -extern { - #[wasm_bindgen(js_namespace = console)] - fn debug(s: &str); +pub struct ExportedInstructionPointer { + pub word: usize, + pub offset: usize, +} + +#[wasm_bindgen] +pub struct ExportedByteCode(Vec<String>); + +#[wasm_bindgen] +impl ExportedByteCode { + pub fn len(&self) -> usize { + self.0.len() + } + + pub fn at(&self, index: usize) -> String { + self.0[index].clone() + } } #[wasm_bindgen] @@ -26,6 +40,43 @@ pub fn tick() { } #[wasm_bindgen] +pub fn ip() -> ExportedInstructionPointer { + ExportedInstructionPointer { + word: 0, + offset: 0, + } +} + +#[wasm_bindgen] +pub fn wordlist() -> Vec<ExportedByteCode> { + vec![ + ExportedByteCode(vec!["NOP".to_string(), "2".to_string(), "DUP".to_string()]), + ] +} + +#[wasm_bindgen] +pub struct ExportedInterp { + i: forth::interp::Interp, +} + +#[wasm_bindgen] +impl ExportedInterp { + fn from_interp(i: forth::interp::Interp) -> Self { + Self { i } + } + + pub fn foo(&self) { + info!("in interp::foo: {:?}", self.i.wordlist); + } +} + +#[wasm_bindgen] +pub fn interp() -> ExportedInterp { + let i = forth::interp::Interp::new(forth::interp::WordList(vec![])); + ExportedInterp::from_interp(i) +} + +#[wasm_bindgen] pub fn run() { info!("running to completion"); } |
