summaryrefslogtreecommitdiffstats
path: root/src/lib.rs
blob: f4fc2949ce1adbabb538b7fc8eaf82337b94ae5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use log::{Level, debug, info};
use console_log;
use wasm_bindgen::prelude::*;

pub mod forth;

#[wasm_bindgen]
extern {
    #[wasm_bindgen(js_namespace = console)]
    fn debug(s: &str);
}

#[wasm_bindgen]
pub fn compile(text: &str) {
    info!("compiling code: `{}`", text);
    let mut p = forth::parser::Parser::new(&text);
    p.parse().expect("couldn't parse text");
    debug!("wordlist: {:?}", &p.wordlist);
    let interp = forth::interp::Interp::new(p.wordlist);
    debug!("interp: {:?}", interp);
}

#[wasm_bindgen]
pub fn tick() {
    info!("executing single instruction");
}

#[wasm_bindgen]
pub fn run() {
    info!("running to completion");
}

#[wasm_bindgen(start)]
pub fn init() -> Result<(), JsValue> {
    console_log::init_with_level(Level::Debug).expect("couldn't init console log");
    info!("wasm init");

    Ok(())
}