FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
binaryen.js/tests/example.js at dcodeIO-patch-3 · AssemblyScript/binaryen.js · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
AssemblyScript
/
binaryen.js
Public
Notifications
You must be signed in to change notification settings
Fork
54
Star
403
Code
Issues
8
Pull requests
5
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
binaryen.js
/
tests
/
example.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
33 lines (27 loc) · 933 Bytes
Breadcrumbs
binaryen.js
/
tests
/
example.js
Copy path
File metadata and controls
33 lines (27 loc) · 933 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
binaryen
from
"../index.js"
;
// Create a module with a single function
var
myModule
=
new
binaryen
.
Module
(
)
;
myModule
.
addFunction
(
"add"
,
binaryen
.
createType
(
[
binaryen
.
i32
,
binaryen
.
i32
]
)
,
binaryen
.
i32
,
[
binaryen
.
i32
]
,
myModule
.
block
(
null
,
[
myModule
.
local
.
set
(
2
,
myModule
.
i32
.
add
(
myModule
.
local
.
get
(
0
,
binaryen
.
i32
)
,
myModule
.
local
.
get
(
1
,
binaryen
.
i32
)
)
)
,
myModule
.
return
(
myModule
.
local
.
get
(
2
,
binaryen
.
i32
)
)
]
)
)
;
myModule
.
addFunctionExport
(
"add"
,
"add"
)
;
// Optimize the module using default passes and levels
myModule
.
optimize
(
)
;
// Validate the module
if
(
!
myModule
.
validate
(
)
)
throw
new
Error
(
"validation error"
)
;
// Generate text format and binary
var
textData
=
myModule
.
emitText
(
)
;
var
wasmData
=
myModule
.
emitBinary
(
)
;
console
.
log
(
textData
)
;
console
.
log
(
"1 + 2 = "
+
new
WebAssembly
.
Instance
(
new
WebAssembly
.
Module
(
wasmData
)
)
.
exports
.
add
(
1
,
2
)
)
;
Back
|
FazBrowse Home
|
New Git URL