-
Notifications
You must be signed in to change notification settings - Fork 2
/
worker-z3.js
55 lines (47 loc) · 1.29 KB
/
worker-z3.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
console.log('Worker: Hi!')
console.log('Worker: Inviting WebPPL to the chat..')
const INPUT_FNAME = 'input.smt2'
const STUB_MSG = 'Calling stub instead of signal()'
let ready = false
let res = ''
self.importScripts('assets/z3w.js')
function onRuntimeInitialized () {
ready = true
console.log('[Z3 worker] Ready!')
}
const solver = Z3({
ENVIRONMENT: 'WORKER',
onRuntimeInitialized: onRuntimeInitialized,
print: function (message) {
console.log('[Z3 worker] Print:', message)
message = message.replace(STUB_MSG, '')
if (message.trim() === '---') { // || (message.includes('error'))) {
console.log('[Z3 worker] Result:', res)
postMessage({
'data': res
})
res = ''
} else {
res += message + '\n'
}
},
printErr: function (message) {
console.log('[Z3 worker] Error:', message)
postMessage({
'data': message
})
}
})
console.log(Z3)
onmessage = function (e) {
console.log('[Z3 worker] received message from Vue. Calling Z3...')
console.log(e)
if (!ready) {
console.error('[Z3 worker] Cannot run SMT solver yet...')
return
}
const args = ['-smt2', INPUT_FNAME]
console.log('[Z3 worker] Running SMT solver with', args)
solver.FS.writeFile(INPUT_FNAME, e.data, { encoding: 'utf8' })
solver.callMain(args)
}