summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/forth/interp.rs4
-rwxr-xr-xsrc/lib.rs24
2 files changed, 25 insertions, 3 deletions
diff --git a/src/forth/interp.rs b/src/forth/interp.rs
index f1af4ae..c6dcb72 100644
--- a/src/forth/interp.rs
+++ b/src/forth/interp.rs
@@ -1,3 +1,5 @@
+use log::debug;
+
use std::ops::Index;
#[derive(Clone, Debug, PartialEq)]
@@ -106,7 +108,7 @@ impl Interp {
let bc = &self.wordlist.0[self.ip.word];
match bc[self.ip.offset] {
OpCode::Num(n) => self.stack.0.push(n),
- OpCode::Str(start, end) => eprintln!("got str: {} to {}", start, end),
+ OpCode::Str(start, end) => debug!("got str: {} to {}", start, end),
OpCode::Add => {
let n1 = self.stack.0.pop().ok_or(RuntimeError::StackUnderflow)?;
let n2 = self.stack.0.pop().ok_or(RuntimeError::StackUnderflow)?;
diff --git a/src/lib.rs b/src/lib.rs
index da1469b..716ad09 100755
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,3 +1,5 @@
+use log::{Level, debug, info};
+use console_log;
use wasm_bindgen::prelude::*;
mod forth;
@@ -8,8 +10,26 @@ extern {
fn debug(s: &str);
}
+#[wasm_bindgen]
+pub fn compile() {
+ info!("compiling code");
+}
+
+#[wasm_bindgen]
+pub fn tick() {
+ info!("executing single instruction");
+}
+
+#[wasm_bindgen]
+pub fn run() {
+ info!("running to completion");
+}
+
#[wasm_bindgen(start)]
-pub fn run() -> Result<(), JsValue> {
+pub fn init() -> Result<(), JsValue> {
+ console_log::init_with_level(Level::Debug).expect("couldn't init console log");
+ debug!("starting run");
+
let window = web_sys::window().expect("no global `window` exists");
let document = window.document().expect("should have `document` on window");
let body = document.body().expect("document should have `body`");
@@ -18,7 +38,7 @@ pub fn run() -> Result<(), JsValue> {
val.set_text_content(Some("hi there"));
body.append_child(&val)?;
- debug("done in rust's run");
+ debug!("done in rust's run");
Ok(())
}