@@ -36,22 +36,29 @@ func NewExampleFactory(
3636) (*ExampleFactory, error) {
3737 wazeroRuntime := wazero.NewRuntime(ctx)
3838
39+ // Instantiate import host modules
3940 _, err0 := wazeroRuntime.NewHostModuleBuilder("arcjet:example/runtime").
4041 NewFunctionBuilder().
4142 WithFunc(func(
4243 ctx context.Context,
4344 mod api.Module,
4445 arg0 uint32,
4546 ) {
47+ // CallInterface { func: Function { name: "os", kind: Freestanding, params: [], result: Some(String), docs: Docs { contents: None }, stability: Unknown }, async_: false }
4648 value0 := runtime.Os(ctx, )
49+ // GetArg { nth: 0 }
50+ // StringLower { realloc: Some("cabi_realloc") }
4751 memory1 := mod.Memory()
4852 realloc1 := mod.ExportedFunction("cabi_realloc")
4953 ptr1, len1, err1 := writeString(ctx, value0, memory1, realloc1)
5054 if err1 != nil {
5155 panic(err1)
5256 }
53- mod.Memory().WriteUint32Le(arg0+4, uint32(len1))
54- mod.Memory().WriteUint32Le(arg0+0, uint32(ptr1))
57+ // LengthStore { offset: ptrsz }
58+ mod.Memory().WriteUint32Le(uint32(arg0+4), uint32(len1))
59+ // PointerStore { offset: 0 }
60+ mod.Memory().WriteUint32Le(uint32(arg0+0), uint32(ptr1))
61+ // Return { amt: 0, func: Function { name: "os", kind: Freestanding, params: [], result: Some(String), docs: Docs { contents: None }, stability: Unknown } }
5562 }).
5663 Export("os").
5764 NewFunctionBuilder().
@@ -60,15 +67,21 @@ func NewExampleFactory(
6067 mod api.Module,
6168 arg0 uint32,
6269 ) {
70+ // CallInterface { func: Function { name: "arch", kind: Freestanding, params: [], result: Some(String), docs: Docs { contents: None }, stability: Unknown }, async_: false }
6371 value0 := runtime.Arch(ctx, )
72+ // GetArg { nth: 0 }
73+ // StringLower { realloc: Some("cabi_realloc") }
6474 memory1 := mod.Memory()
6575 realloc1 := mod.ExportedFunction("cabi_realloc")
6676 ptr1, len1, err1 := writeString(ctx, value0, memory1, realloc1)
6777 if err1 != nil {
6878 panic(err1)
6979 }
70- mod.Memory().WriteUint32Le(arg0+4, uint32(len1))
71- mod.Memory().WriteUint32Le(arg0+0, uint32(ptr1))
80+ // LengthStore { offset: ptrsz }
81+ mod.Memory().WriteUint32Le(uint32(arg0+4), uint32(len1))
82+ // PointerStore { offset: 0 }
83+ mod.Memory().WriteUint32Le(uint32(arg0+0), uint32(ptr1))
84+ // Return { amt: 0, func: Function { name: "arch", kind: Freestanding, params: [], result: Some(String), docs: Docs { contents: None }, stability: Unknown } }
7285 }).
7386 Export("arch").
7487 NewFunctionBuilder().
@@ -78,12 +91,17 @@ func NewExampleFactory(
7891 arg0 uint32,
7992 arg1 uint32,
8093 ) {
94+ // GetArg { nth: 0 }
95+ // GetArg { nth: 1 }
96+ // StringLift
8197 buf0, ok0 := mod.Memory().Read(arg0, arg1)
8298 if !ok0 {
8399 panic(errors.New("failed to read bytes from memory"))
84100 }
85101 str0 := string(buf0)
102+ // CallInterface { func: Function { name: "puts", kind: Freestanding, params: [("msg", String)], result: None, docs: Docs { contents: None }, stability: Unknown }, async_: false }
86103 runtime.Puts(ctx, str0)
104+ // Return { amt: 0, func: Function { name: "puts", kind: Freestanding, params: [("msg", String)], result: None, docs: Docs { contents: None }, stability: Unknown } }
87105 }).
88106 Export("puts").
89107 Instantiate(ctx)
@@ -154,6 +172,7 @@ func writeString(
154172func (i *ExampleInstance) Hello(
155173 ctx context.Context,
156174) (string, error) {
175+ // CallWasm { name: "hello", sig: WasmSignature { params: [], results: [Pointer], indirect_params: false, retptr: true } }
157176 raw0, err0 := i.module.ExportedFunction("hello").Call(ctx, )
158177 if err0 != nil {
159178 var default0 string
@@ -173,25 +192,30 @@ func (i *ExampleInstance) Hello(
173192 }()
174193
175194 results0 := raw0[0]
195+ // I32Load8U { offset: 0 }
176196 value1, ok1 := i.module.Memory().ReadByte(uint32(results0 + 0))
177197 if !ok1 {
178198 var default1 string
179199 return default1, errors.New("failed to read byte from memory")
180200 }
201+ // ResultLift { result: Result_ { ok: Some(String), err: Some(String) }, ty: Id { idx: 0 } }
181202 var value8 string
182203 var err8 error
183204 switch value1 {
184205 case 0:
206+ // PointerLoad { offset: ptrsz }
185207 ptr2, ok2 := i.module.Memory().ReadUint32Le(uint32(results0 + 4))
186208 if !ok2 {
187209 var default2 string
188210 return default2, errors.New("failed to read pointer from memory")
189211 }
212+ // LengthLoad { offset: (2*ptrsz) }
190213 len3, ok3 := i.module.Memory().ReadUint32Le(uint32(results0 + 8))
191214 if !ok3 {
192215 var default3 string
193216 return default3, errors.New("failed to read length from memory")
194217 }
218+ // StringLift
195219 buf4, ok4 := i.module.Memory().Read(ptr2, len3)
196220 if !ok4 {
197221 var default4 string
@@ -200,16 +224,19 @@ func (i *ExampleInstance) Hello(
200224 str4 := string(buf4)
201225 value8 = str4
202226 case 1:
227+ // PointerLoad { offset: ptrsz }
203228 ptr5, ok5 := i.module.Memory().ReadUint32Le(uint32(results0 + 4))
204229 if !ok5 {
205230 var default5 string
206231 return default5, errors.New("failed to read pointer from memory")
207232 }
233+ // LengthLoad { offset: (2*ptrsz) }
208234 len6, ok6 := i.module.Memory().ReadUint32Le(uint32(results0 + 8))
209235 if !ok6 {
210236 var default6 string
211237 return default6, errors.New("failed to read length from memory")
212238 }
239+ // StringLift
213240 buf7, ok7 := i.module.Memory().Read(ptr5, len6)
214241 if !ok7 {
215242 var default7 string
@@ -220,6 +247,8 @@ func (i *ExampleInstance) Hello(
220247 default:
221248 err8 = errors.New("invalid variant discriminant for expected")
222249 }
250+ // Flush { amt: 1 }
251+ // Return { amt: 1, func: Function { name: "hello", kind: Freestanding, params: [], result: Some(Id(Id { idx: 0 })), docs: Docs { contents: None }, stability: Unknown } }
223252 return value8, err8
224253}
225254
0 commit comments