walt-compiler
Advanced tools
Comparing version 0.8.0 to 0.8.1
{ | ||
"name": "walt-compiler", | ||
"version": "0.8.0", | ||
"version": "0.8.1", | ||
"description": "Alternative syntax for WebAssembly text format", | ||
@@ -5,0 +5,0 @@ "main": "dist/walt.js", |
@@ -65,1 +65,12 @@ import test from "ava"; | ||
}); | ||
test("memory & table exports", t => { | ||
const source = ` | ||
export const memory: Memory = { initial: 1 }; | ||
export const table: Table = { initial: 1, element: 'anyfunc' }; | ||
`; | ||
return compileAndRun(source).then(({ instance }) => { | ||
t.is(instance.exports.memory instanceof WebAssembly.Memory, true); | ||
t.is(instance.exports.table instanceof WebAssembly.Table, true); | ||
}); | ||
}); |
// @flow | ||
import { GLOBAL_INDEX, FUNCTION_INDEX } from "../semantics/metadata"; | ||
import { EXTERN_GLOBAL, EXTERN_FUNCTION } from "../emitter/external_kind"; | ||
import { | ||
EXTERN_GLOBAL, | ||
EXTERN_MEMORY, | ||
EXTERN_TABLE, | ||
EXTERN_FUNCTION, | ||
} from "../emitter/external_kind"; | ||
import type { NodeType, IntermediateExportType } from "./flow/types"; | ||
const externaKindMap = { | ||
Memory: EXTERN_MEMORY, | ||
Table: EXTERN_TABLE, | ||
}; | ||
export default function generateExport(node: NodeType): IntermediateExportType { | ||
@@ -11,5 +21,9 @@ const functionIndexMeta = node.meta[FUNCTION_INDEX]; | ||
if (globalIndexMeta != null) { | ||
const kind = externaKindMap[String(node.type)] || EXTERN_GLOBAL; | ||
const index = [EXTERN_MEMORY, EXTERN_TABLE].includes(kind) | ||
? 0 | ||
: globalIndexMeta; | ||
return { | ||
index: globalIndexMeta, | ||
kind: EXTERN_GLOBAL, | ||
index, | ||
kind, | ||
field: node.value, | ||
@@ -16,0 +30,0 @@ }; |
15349741
14154