Add helper to create dictionary entry

This commit is contained in:
Remko Tronçon 2019-11-08 11:14:22 +01:00
parent fa5bf0558a
commit 9cfd1100dd
4 changed files with 86 additions and 20 deletions

View file

@ -20,6 +20,7 @@
"eslint": "5.15.1",
"eslint-plugin-react": "^7.12.4",
"html-webpack-plugin": "^3.2.0",
"lodash": "^4.17.15",
"mocha": "^6.1.4",
"style-loader": "^0.23.1",
"webpack": "^4.29.6",

View file

@ -0,0 +1,48 @@
#!/usr/bin/env node
// Usage: ./src/tools/generate-dictionary-entry.js "\$foo" FOO 0 0x21820 0x2182c 0xa1
const _ = require("lodash");
const process = require("process");
function encodeLE(n, align) {
return (
"\\u00" +
_.padStart(n.toString(16), align * 2, "0")
.match(/.{2}/g)
.reverse()
.join("\\u00")
);
}
const funcName = process.argv[2];
const name = process.argv[3];
const flags = parseInt(process.argv[4]);
const latest = parseInt(process.argv[5]);
const here = parseInt(process.argv[6]);
const nextTableIndex = parseInt(process.argv[7]);
const dictionaryEntry = [
encodeLE(latest, 4),
encodeLE(name.length | flags, 1),
_.padEnd(name, 4 * Math.floor((name.length + 4) / 4) - 1, "0"),
encodeLE(nextTableIndex, 4)
];
console.log(
"(data (i32.const 0x" +
here.toString(16) +
') "' +
dictionaryEntry.join('" "') +
'")'
);
console.log(
"(elem (i32.const 0x" + nextTableIndex.toString(16) + ") " + funcName + ")"
);
console.log("latest: 0x" + here.toString(16));
console.log(
"here: 0x" +
(here + dictionaryEntry.join("").replace(/\\u..../g, "_").length).toString(
16
)
);
console.log("!nextTableIndex: 0x" + (nextTableIndex + 1).toString(16));

View file

@ -75,7 +75,7 @@
(define !typeIndex #x85)
(define !abortIndex #x39)
(define !nextTableIndex #xa1)
(define !nextTableIndex #xa5)
(define (!+ x y) (list (+ x y)))
@ -766,10 +766,10 @@
(elem (i32.const 0x53) $DOES>) ;; immediate
;; 6.1.1260
(func $drop
(func $DROP
(set_global $tos (i32.sub (get_global $tos) (i32.const 4))))
(data (i32.const 136104) "\u0098\u0013\u0002\u0000\u0004DROP\u0000\u0000\u0000T\u0000\u0000\u0000")
(elem (i32.const 0x54) $drop)
(elem (i32.const 0x54) $DROP)
;; 6.1.1290
(func $DUP
@ -1503,23 +1503,35 @@
(data (i32.const #x21820) "\u0008\u0018\u0002\u0000\u0003HEX\u00a0\u0000\u0000\u0000")
(elem (i32.const #xa0) $HEX)
;; 6.2.2298
(func $TRUE
(call $push (i32.const 0xffffffff)))
(data (i32.const #x2182c) "\u0020\u0018\u0002\u0000" "\u0004" "TRUE000" "\u00a1\u0000\u0000\u0000")
(elem (i32.const #xa1) $TRUE)
;; 6.2.1485
(func $FALSE
(call $push (i32.const 0x0)))
(data (i32.const #x2183c) "\u002c\u0018\u0002\u0000" "\u0005" "FALSE00" "\u00a2\u0000\u0000\u0000")
(elem (i32.const #xa2) $FALSE)
;; 6.2.1930
(func $NIP
(call $SWAP) (call $DROP))
(data (i32.const #x2184c) "\u003c\u0018\u0002\u0000" "\u0003" "NIP" "\u00a3\u0000\u0000\u0000")
(elem (i32.const #xa3) $NIP)
;; 6.2.2300
(func $TUCK
(call $SWAP) (call $OVER))
(data (i32.const #x21858) "\u004c\u0018\u0002\u0000" "\u0003" "NIP" "\u00a4\u0000\u0000\u0000")
(elem (i32.const #xa4) $TUCK)
;; High-level words
(!prelude #<<EOF
\ 6.1.0950
: CONSTANT CREATE , DOES> @ ;
\ 6.2.2298
: TRUE -1 ;
\ 6.2.1485
: FALSE 0 ;
\ 6.2.1930
: NIP ( x y -- y ) SWAP DROP ;
\ 6.2.2300
: TUCK ( x y -- y x y ) SWAP OVER ;
: UWIDTH BASE @ / ?DUP IF RECURSE 1+ ELSE 1 THEN ;
\ 6.1.2320
@ -2240,7 +2252,7 @@ EOF
(br $loop2)))))
(call $one-plus)
(br $loop1)))
(call $drop)
(call $DROP)
(call $push (i32.const 1))
(call $SWAP)
(call $push (i32.const 2))
@ -2252,12 +2264,12 @@ EOF
(call $sieve_prime)
(if (i32.ne (call $pop) (i32.const 0))
(block
(call $drop)
(call $DROP)
(call $push (get_local $i))))
(set_local $i (i32.add (i32.const 1) (get_local $i)))
(br_if $endLoop3 (i32.ge_s (get_local $i) (get_local $end)))
(br $loop3))))
(data (i32.const 137224) "\u00f8\u0017\u0002\u0000\u000csieve_direct\u0000\u0000\u0000\u009f\u0000\u0000\u0000")
(data (i32.const 137224) "\u00f8\u0017\u0002\u0000" "\u000c" "sieve_direct\u0000\u0000\u0000" "\u009f\u0000\u0000\u0000")
(elem (i32.const 0x9f) $sieve)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -2353,8 +2365,8 @@ EOF
;; words start.
(table (export "table") !nextTableIndex anyfunc)
(global $latest (mut i32) (i32.const #x21820))
(global $here (mut i32) (i32.const #x2182C))
(global $latest (mut i32) (i32.const #x21858))
(global $here (mut i32) (i32.const #x21864))
(global $nextTableIndex (mut i32) (i32.const !nextTableIndex))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

View file

@ -3253,6 +3253,11 @@ lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.3:
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.14.tgz#9ce487ae66c96254fe20b599f21b6816028078ba"
integrity sha512-mmKYbW3GLuJeX+iGP+Y7Gp1AiGHGbXHCOh/jZmrawMmsE7MS4znI3RL2FsjbqOyMayHInjOeykW7PEajUk1/xw==
lodash@^4.17.15:
version "4.17.15"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"
integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==
log-symbols@2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-2.2.0.tgz#5740e1c5d6f0dfda4ad9323b5332107ef6b4c40a"