From 46cbda1f6a478d00e7f85fa0b66e380ff8884bfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Fri, 8 Nov 2019 16:19:11 +0100 Subject: [PATCH] Remove prelude --- README.md | 3 +-- experiments/waforth2c/waforth2c.js | 3 --- src/shell/WAForth.js | 6 +---- src/waforth.wat | 38 +----------------------------- tests/tests.js | 23 +----------------- 5 files changed, 4 insertions(+), 69 deletions(-) diff --git a/README.md b/README.md index 9adebf4..eb94193 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,7 @@ yet](https://webassembly.org/docs/future-features/#platform-independent-just-in- and the I/O primitives to read and write a character. Parts of the implementation were influenced by -[jonesforth](http://git.annexia.org/?p=jonesforth.git;a=summary), and I -shamelessly stole the Forth code of some of its high-level words. +[jonesforth](http://git.annexia.org/?p=jonesforth.git;a=summary). WAForth is still in an experimental stage. It implements most of the [ANS Core Words](http://lars.nocrew.org/dpans/dpans6.htm#6.1), and passes most of the diff --git a/experiments/waforth2c/waforth2c.js b/experiments/waforth2c/waforth2c.js index 405b4e5..8fc6ae7 100755 --- a/experiments/waforth2c/waforth2c.js +++ b/experiments/waforth2c/waforth2c.js @@ -77,9 +77,6 @@ WebAssembly.instantiate(coreWasm, { const dictionaryStart = latest(); - // Load prelude - core.exports.loadPrelude(); - // Load code run(input); diff --git a/src/shell/WAForth.js b/src/shell/WAForth.js index f24a72c..75ba704 100644 --- a/src/shell/WAForth.js +++ b/src/shell/WAForth.js @@ -21,8 +21,7 @@ class WAForth { }; } - start(options = {}) { - const { skipPrelude } = options; + start() { let table; let memory; const buffer = (this.buffer = []); @@ -97,9 +96,6 @@ class WAForth { this.core = instance.instance; table = this.core.exports.table; memory = this.core.exports.memory; - if (!skipPrelude) { - this.core.exports.loadPrelude(); - } }); } diff --git a/src/waforth.wat b/src/waforth.wat index 7be6011..daadc67 100644 --- a/src/waforth.wat +++ b/src/waforth.wat @@ -28,8 +28,7 @@ ;; Compiled modules are limited to 4096 bytes until Chrome refuses to load ;; them synchronously (define !moduleHeaderBase #x1000) -(define !preludeDataBase #x2000) -(define !returnStackBase #x4000) +(define !returnStackBase #x2000) (define !stackBase #x10000) (define !dictionaryBase #x21000) (define !memorySize 104857600) ;; 100*1024*1024 @@ -79,18 +78,6 @@ (define !nextTableIndex #xa7) -(define (!+ x y) (list (+ x y))) - -(define !preludeData "") -(define (!prelude c) - (set! !preludeData - (regexp-replace* #px"[ ]?\n[ ]?" - (regexp-replace* #px"[ ]+" - (regexp-replace* #px"[\n]+" (string-append !preludeData "\n" c) "\n") - " ") - "\n")) - (list)) - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; WebAssembly module definition ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -1582,23 +1569,6 @@ (call $shell_emit (i32.add (get_local $m) (i32.const 0x30)))))) - ;; 15.6.1.0220 - ;; : .S DSP@ S0 BEGIN 2DUP > WHILE DUP @ U. SPACE 4 + REPEAT 2DROP ; - - ;; High-level words - (!prelude #< { core = forth.core.exports; @@ -1297,10 +1297,6 @@ function loadTests(wasmModule, arrayToBase64) { }); describe("CONSTANT", () => { - beforeEach(() => { - core.loadPrelude(); - }); - it("should work", () => { run("12 CONSTANT FOO"); run("FOO 5"); @@ -1318,10 +1314,6 @@ function loadTests(wasmModule, arrayToBase64) { }); describe("VALUE", () => { - beforeEach(() => { - core.loadPrelude(); - }); - it("should store a value", () => { run("12 VALUE FOO"); run("FOO 5"); @@ -1350,10 +1342,6 @@ function loadTests(wasmModule, arrayToBase64) { }); describe("UWIDTH", () => { - beforeEach(() => { - core.loadPrelude(); - }); - it("should work with 3 digits", () => { run("123 UWIDTH"); expect(stack[0]).to.eql(3); @@ -1366,10 +1354,6 @@ function loadTests(wasmModule, arrayToBase64) { }); describe("[']", () => { - beforeEach(() => { - core.loadPrelude(); - }); - it("should work", () => { run(': HELLO ." Hello " ;'); run(': GOODBYE ." Goodbye " ;'); @@ -1418,10 +1402,6 @@ function loadTests(wasmModule, arrayToBase64) { }); describe("system", () => { - beforeEach(() => { - core.loadPrelude(); - }); - it("should run sieve", () => { run(sieve); run("100 sieve"); @@ -1437,7 +1417,6 @@ function loadTests(wasmModule, arrayToBase64) { describe("standard test suite", () => { beforeEach(() => { - core.loadPrelude(); run(standardTestSuiteTester); run("TRUE VERBOSE !"); });