Commit 1ffd915b15f2f2a528bc6e5329be0be2c9cab33b
added types to persitant globals
wanderer committed on 2/21/2018, 2:25:46 AMParent: cd5644a350c66679340731cc00c9fcf16834bdb9
Files changed
customTypes.js | changed |
injectGlobals.js | changed |
customTypes.js | ||
---|---|---|
@@ -52,9 +52,10 @@ | ||
52 | 52 | |
53 | 53 | function encodeGlobals (json, stream) { |
54 | 54 | leb.unsigned.write(json.length, stream) |
55 | 55 | for (const entry of json) { |
56 | - leb.unsigned.write(entry, stream) | |
56 | + leb.unsigned.write(entry.index, stream) | |
57 | + leb.unsigned.write(LANGUAGE_TYPES[entry.type], stream) | |
57 | 58 | } |
58 | 59 | return stream |
59 | 60 | } |
60 | 61 | |
@@ -62,9 +63,12 @@ | ||
62 | 63 | const stream = new Stream(Buffer.from(buf)) |
63 | 64 | let numOfEntries = leb.unsigned.read(stream) |
64 | 65 | const json = [] |
65 | 66 | while (numOfEntries--) { |
66 | - json.push(leb.unsigned.readBn(stream).toNumber()) | |
67 | + json.push({ | |
68 | + index: leb.unsigned.readBn(stream).toNumber(), | |
69 | + type: LANGUAGE_TYPES[leb.unsigned.readBn(stream).toNumber()] | |
70 | + }) | |
67 | 71 | } |
68 | 72 | return json |
69 | 73 | } |
70 | 74 |
injectGlobals.js | ||
---|---|---|
@@ -16,9 +16,10 @@ | ||
16 | 16 | exports.entries.push(exportEntry('setter_globals', setterIndex)) |
17 | 17 | const {value: code} = iter.next() |
18 | 18 | const getterCode = [] |
19 | 19 | const setterCode = [] |
20 | - globals.forEach((globalIndex, index) => { | |
20 | + globals.forEach((global, index) => { | |
21 | + const globalIndex = global.index | |
21 | 22 | // getter |
22 | 23 | getterCode.push(i32_const(index * 4)) |
23 | 24 | getterCode.push(get_global(globalIndex)) |
24 | 25 | getterCode.push(i32_store()) |
Built with git-ssb-web