@@ -12,7 +12,6 @@ import (
12
12
"github.com/tetratelabs/wazero"
13
13
"github.com/tetratelabs/wazero/api"
14
14
"github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1"
15
- // "github.com/apexlang/apex-go/parser"
16
15
)
17
16
18
17
//go:embed apex-api.wasm
@@ -98,7 +97,7 @@ func main() {
98
97
return returnString (m , source )
99
98
}
100
99
101
- _ , err = r .NewHostModuleBuilder ("apex" ).
100
+ m , err : = r .NewHostModuleBuilder ("apex" ).
102
101
ExportFunction ("resolve" , resolve ,
103
102
"resolve" ,
104
103
"location_ptr" , "location_len" ,
@@ -107,20 +106,25 @@ func main() {
107
106
if err != nil {
108
107
panic (err )
109
108
}
109
+ defer m .Close (ctx )
110
110
111
- if _ , err := wasi_snapshot_preview1 .Instantiate (ctx , r ); err != nil {
111
+ closer , err := wasi_snapshot_preview1 .Instantiate (ctx , r )
112
+ if err != nil {
112
113
panic (err )
113
114
}
115
+ defer closer .Close (ctx )
114
116
115
117
code , err := r .CompileModule (ctx , apexWasm )
116
118
if err != nil {
117
119
panic (err )
118
120
}
121
+ defer code .Close (ctx )
119
122
120
123
g , err := r .InstantiateModule (ctx , code , config )
121
124
if err != nil {
122
125
panic (err )
123
126
}
127
+ defer g .Close (ctx )
124
128
125
129
parse := g .ExportedFunction ("parse" )
126
130
malloc = g .ExportedFunction ("_malloc" )
@@ -152,17 +156,6 @@ func main() {
152
156
153
157
docBytes , _ := g .Memory ().Read (ctx , ptr , size )
154
158
155
- // doc, err := parser.Parse(parser.ParseParams{
156
- // Source: specBytes,
157
- // })
158
- // if err != nil {
159
- // panic(err)
160
- // }
161
- // docBytes, err := json.MarshalIndent(doc, "", " ")
162
- // if err != nil {
163
- // panic(err)
164
- // }
165
-
166
159
fmt .Println (string (docBytes ))
167
160
}
168
161
0 commit comments