Remove prelude

This commit is contained in:
Remko Tronçon 2019-11-08 16:19:11 +01:00
parent eaf52649f9
commit 46cbda1f6a
5 changed files with 4 additions and 69 deletions

View file

@ -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

View file

@ -77,9 +77,6 @@ WebAssembly.instantiate(coreWasm, {
const dictionaryStart = latest();
// Load prelude
core.exports.loadPrelude();
// Load code
run(input);

View file

@ -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();
}
});
}

View file

@ -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 #<<EOF
\ 6.2.0210
: .R
SWAP
DUP 0< IF NEGATE 1 SWAP ROT 1- ELSE 0 SWAP ROT THEN
SWAP DUP UWIDTH ROT SWAP -
SPACES SWAP
IF 45 EMIT THEN
U.
;
EOF
)
;; Initializes compilation.
;; Parameter indicates the type of code we're compiling: type 0 (no params),
;; or type 1 (1 param)
@ -2227,11 +2197,6 @@ EOF
(return (get_local $n)))))
(unreachable))
(func $loadPrelude (export "loadPrelude")
(call $push (i32.const !preludeDataBase))
(call $push (i32.const (!+ (string-length !preludeData) 0)))
(call $EVALUATE))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; A sieve with direct calls. Only here for benchmarking
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -2360,7 +2325,6 @@ EOF
"\u00FE\u0000\u0000\u0000" ;; Body size (padded)
"\u0001" ;; #locals
"\u00FD\u0000\u0000\u0000\u007F") ;; # #i32 locals (padded)
(data (i32.const !preludeDataBase) !preludeData)
(func (export "tos") (result i32)
(get_global $tos))

View file

@ -14,7 +14,7 @@ function loadTests(wasmModule, arrayToBase64) {
output = output + String.fromCharCode(c);
// console.log(output);
};
const x = forth.start({ skipPrelude: true }).then(
const x = forth.start().then(
() => {
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 !");
});