git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 9babf4f2b9100d276b3b4aa9195653cf32fc388d

added globals_getter/setter

wanderer committed on 2/20/2018, 11:41:52 PM
Parent: a338912f819bd6fa4333e0c982768e58f6f2219f

Files changed

customTypes.jschanged
wasmContainer.jschanged
customTypes.jsView
@@ -104,9 +104,8 @@
104104 binEntries.write(entry.params.map(type => LANGUAGE_TYPES[type])) // the paramter types
105105 }
106106
107107 binEntries.write([entry.return_type ? 1 : 0]) // number of return types
108-
109108 if (entry.return_type) {
110109 binEntries.write([LANGUAGE_TYPES[entry.return_type]])
111110 }
112111 }
@@ -158,12 +157,13 @@
158157 function mergeTypeSections (json) {
159158 const result = {
160159 types: [],
161160 indexes: {},
162- exports: {}
161+ exports: {},
162+ globals: []
163163 }
164164
165- const wantedSections = ['types', 'typeMap', 'type', 'import', 'function', 'export']
165+ const wantedSections = ['types', 'typeMap', 'globals', 'type', 'import', 'function', 'export']
166166 const iterator = findSections(json, wantedSections)
167167 const mappedFuncs = new Map()
168168 const mappedTypes = new Map()
169169 const {value: customType} = iterator.next()
@@ -175,8 +175,13 @@
175175 if (typeMap) {
176176 decodeTypeMap(typeMap.payload).forEach(map => mappedFuncs.set(map.func, map.type))
177177 }
178178
179+ let {value: globals} = iterator.next()
180+ if (globals) {
181+ result.globals = decodeGlobals(globals.payload)
182+ }
183+
179184 const {value: type} = iterator.next()
180185 const {value: imports = {entries: []}} = iterator.next()
181186 const {value: functions} = iterator.next()
182187 functions.entries.forEach((typeIndex, funcIndex) => {
wasmContainer.jsView
@@ -3,8 +3,9 @@
33 const ReferanceMap = require('reference-map')
44 const leb128 = require('leb128')
55 const Message = require('./message.js')
66 const customTypes = require('./customTypes.js')
7+const injectGlobals = require('./injectGlobals.js')
78 const typeCheckWrapper = require('./typeCheckWrapper.js')
89
910 const nativeTypes = new Set(['i32', 'i64', 'f32', 'f64'])
1011 const LANGUAGE_TYPES = {
@@ -155,8 +156,11 @@
155156 const json = customTypes.mergeTypeSections(moduleJSON)
156157 moduleJSON = wasmMetering.meterJSON(moduleJSON, {
157158 meterType: 'i32'
158159 })
160+ if (json.globals.length) {
161+ moduleJSON = injectGlobals(moduleJSON, json.globals)
162+ }
159163 wasm = json2wasm(moduleJSON)
160164 await Promise.all([
161165 new Promise((resolve, reject) => {
162166 cachedb.put(id.toString() + 'meta', JSON.stringify(json), resolve)

Built with git-ssb-web