Skip to content

Commit dc17b03

Browse files
committed
updated wasm adapter to support streaming compilation
1 parent f98cb1a commit dc17b03

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1248
-623
lines changed
File renamed without changes.

oldwasm/wasm/asconfig.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"targets": {
3+
"debug": {
4+
"binaryFile": "build/untouched.wasm",
5+
"textFile": "build/untouched.wat",
6+
"sourceMap": true,
7+
"debug": true
8+
},
9+
"release": {
10+
"binaryFile": "build/optimized.wasm",
11+
"textFile": "build/optimized.wat",
12+
"sourceMap": true,
13+
"optimizeLevel": 3,
14+
"shrinkLevel": 0,
15+
"converge": false,
16+
"noAssert": false
17+
}
18+
},
19+
"options": {}
20+
}

oldwasm/wasm/assembly/index.ts

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
import * as aegis from './aegis'
2+
import * as nn from './neural-net'
3+
//import * as nn from "./neural-net";
4+
//import * as tst from "./test";
5+
6+
const key: i32 = 0
7+
const val: i32 = 1
8+
9+
class ModelSpec {
10+
modelName: string
11+
endpoint: string
12+
constructor (name: string, endpoint: string) {
13+
this.modelName = name
14+
this.endpoint = endpoint
15+
}
16+
}
17+
18+
export function getModelSpec (): ModelSpec {
19+
return new ModelSpec('wasm', 'wasm')
20+
}
21+
22+
export const ArrayOfStrings_ID = idof<string[]>()
23+
24+
function findVal (key: string, keys: string[], vals: string[]): string {
25+
for (let i: i32 = 0; i < keys.length; i++) {
26+
if (keys[i] == key) {
27+
return vals[i].toString()
28+
}
29+
}
30+
return ''
31+
}
32+
33+
export function modelFactory (keys: string[], values: string[]): string[][] {
34+
const arr = new Array<string[]>(3)
35+
arr[0] = ['key1', findVal('key1', keys, values)]
36+
arr[1] = ['key2', findVal('key2', keys, values)]
37+
arr[2] = ['fibonacci', findVal('fibonacci', keys, values)]
38+
return arr
39+
}
40+
41+
export function getPorts (keys: string[], vals: string[]): string[][] {
42+
//aegis.log("getPorts called " + keys[0] + ":" + vals[0]);
43+
const ports = new Array<string[]>(2)
44+
//service,type,consumesEvent,producesEvent,callback,undo
45+
ports[0] = ['port1', 'dFlow,outbound,dFlow_start,port1_done,port1Cb,1']
46+
ports[1] = ['port2', 'dFlow,outbound,port1_done,port2_done,port2Cb,1']
47+
return ports
48+
}
49+
50+
export function port1Cb (keys: string[], vals: string[]): string[][] {
51+
const cfg = [
52+
['port', 'port1'],
53+
['callback', 'port1Cb'],
54+
['consumesEvent', 'dFlow_start'],
55+
['producesEvent', 'port1_done']
56+
]
57+
aegis.log(
58+
'porf invokced' + cfg[0][0] + ' ' + cfg[0][1] + ' ' + cfg[0][2] + cfg[0][3]
59+
)
60+
return cfg
61+
}
62+
63+
export function port2Cb (keys: string[], vals: string[]): string[][] {
64+
const cfg = [
65+
['port', 'port2'],
66+
['callback', 'port2Cb'],
67+
['consumesEvent', 'port1_done'],
68+
['producesEvent', 'port2_done']
69+
]
70+
aegis.log(
71+
'porf invoked' + cfg[0][0] + ' ' + cfg[0][1] + ' ' + cfg[0][2] + cfg[0][3]
72+
)
73+
return cfg
74+
}
75+
76+
export function getCommands (): string[][] {
77+
const commands = new Array<string[]>(7)
78+
commands[0] = ['serviceMeshListen', 'tell wasm module to begin listening']
79+
commands[1] = ['serviceMeshNotify', 'tell wasm module to send broadcast']
80+
commands[2] = ['serviceMeshCallback', 'subscribed event fired']
81+
commands[3] = ['runFibonacci', 'remote calculate fibonacci']
82+
commands[4] = ['fibonacci', 'calculate fibonacci for a number']
83+
commands[5] = ['deployModule', 'request deployment of a module']
84+
commands[6] = ['commandEx', 'command example']
85+
return commands
86+
}
87+
88+
export function commandEx (keys: string[], vals: string[]): string[][] {
89+
aegis.log('\ncommandEx called ' + keys[0] + ':' + vals[0])
90+
const retval = new Array<string[]>(1)
91+
retval[0] = ['key1', 'commandEx_update!']
92+
return retval
93+
}
94+
95+
export function serviceMeshListen (keys: string[], vals: string[]): void {
96+
aegis.log('serviceMeshListen: ' + keys[0] + ': ' + vals[0])
97+
const eventName = findVal('eventName', keys, vals)
98+
aegis.addListener(eventName, 'serviceMeshCallback')
99+
}
100+
101+
export function serviceMeshNotify (keys: string[], vals: string[]): void {
102+
const modelName = findVal('modelName', keys, vals)
103+
const modelId = findVal('modelId', keys, vals)
104+
const eventName = findVal('eventName', keys, vals)
105+
const eventData = new Array<string[]>(3)
106+
aegis.log('wasm notify called with args: ' + modelName + ': ' + modelId)
107+
eventData[0] = [keys[0], vals[0]]
108+
eventData[1] = ['modelName', modelName]
109+
eventData[2] = ['modelId', modelId]
110+
aegis.fireEvent(eventName || 'wasmWebListen', eventData, 1)
111+
}
112+
113+
export function serviceMeshCallback (
114+
keys: string[],
115+
vals: string[]
116+
): string[][] {
117+
aegis.log('websocket callback fired: ' + keys[0] + ': ' + vals[0])
118+
const eventName = findVal('eventName', keys, vals)
119+
const eventData = new Array<string[]>(2)
120+
eventData[0] = [keys[0], vals[0]]
121+
eventData[1] = [keys[1], vals[1]]
122+
aegis.fireEvent(eventName + 'callback', eventData, 1)
123+
return [['key1', 'serviceMeshCallback']]
124+
}
125+
126+
export function fibonacci (x: number): number {
127+
if (x === 0) {
128+
return 0
129+
}
130+
if (x === 1) {
131+
return 1
132+
}
133+
return fibonacci(x - 1) + fibonacci(x - 2)
134+
}
135+
136+
export function runFibonacci (keys: string[], vals: string[]): string[][] {
137+
let val: number = 0
138+
let startTime: i64 = Date.now()
139+
140+
for (let i = 0; i < keys.length; i++) {
141+
if ('fibonacci' == keys[i]) {
142+
val = parseInt(vals[i])
143+
break
144+
}
145+
}
146+
const sum = fibonacci(val)
147+
const ret = new Array<string[]>(2)
148+
ret[0] = ['result', sum.toString()]
149+
ret[1] = ['time', (Date.now() - startTime).toString()]
150+
return ret
151+
}
152+
153+
export function portEx (keys: string[], vals: string[]): void {
154+
aegis.log('portEx calling port wasmTestPort' + keys[0] + ':' + vals[0])
155+
return
156+
}
157+
158+
export function onUpdate (keys: string[], vals: string[]): string[][] {
159+
return [['updatedByWasm', new Date(Date.now()).toISOString()]]
160+
}
161+
162+
export function onDelete (keys: string[], vals: string[]): i8 {
163+
// return negative to stop the action
164+
aegis.log('onDelete called')
165+
return -1
166+
}
167+
168+
export function validate (keys: string[], vals: string[]): void {
169+
aegis.log('onUpdate called')
170+
return
171+
}
172+
173+
export function test (keys: string[], values: string[]): string[][] {
174+
const key1 = keys[0] == 'key1' ? values[0] : 'default'
175+
const key2 = keys[1] == 'key2' ? values[1] : 'default'
176+
const arr = new Array<string[]>(3)
177+
arr[0] = ['key1', key1]
178+
arr[1] = ['key2', key2]
179+
arr[2] = ['key3', 'alwaysThisValue']
180+
aegis.log('test called')
181+
return arr
182+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "assemblyscript/std/assembly.json",
3+
"include": [
4+
"./**/*.ts"
5+
]
6+
}

0 commit comments

Comments
 (0)