@@ -234,8 +234,8 @@ func (g *guest) handleResponse(ctx context.Context, reqCtx uint32, err error) er
234234}
235235
236236// enableFeatures implements the WebAssembly host function handler.FuncEnableFeatures.
237- func (m * middleware ) enableFeatures (ctx context.Context , params []uint64 ) [] uint64 {
238- features := handler .Features (params [0 ])
237+ func (m * middleware ) enableFeatures (ctx context.Context , stack []uint64 ) {
238+ features := handler .Features (stack [0 ])
239239
240240 var enabled handler.Features
241241 if s , ok := ctx .Value (requestStateKey {}).(* requestState ); ok {
@@ -246,35 +246,31 @@ func (m *middleware) enableFeatures(ctx context.Context, params []uint64) []uint
246246 enabled = m .features
247247 }
248248
249- return [] uint64 { uint64 (enabled )}
249+ stack [ 0 ] = uint64 (enabled )
250250}
251251
252252// getConfig implements the WebAssembly host function handler.FuncGetConfig.
253- func (m * middleware ) getConfig (ctx context.Context , mod wazeroapi.Module , params []uint64 ) [] uint64 {
254- buf := uint32 (params [0 ])
255- bufLimit := handler .BufLimit (params [1 ])
253+ func (m * middleware ) getConfig (ctx context.Context , mod wazeroapi.Module , stack []uint64 ) {
254+ buf := uint32 (stack [0 ])
255+ bufLimit := handler .BufLimit (stack [1 ])
256256
257257 configLen := writeIfUnderLimit (ctx , mod , buf , bufLimit , m .guestConfig )
258258
259- return [] uint64 { uint64 (configLen )}
259+ stack [ 0 ] = uint64 (configLen )
260260}
261261
262- var (
263- resultTrue = []uint64 {1 }
264- resultFalse = []uint64 {0 }
265- )
266-
267262// log implements the WebAssembly host function handler.FuncLogEnabled.
268- func (m * middleware ) logEnabled (_ context.Context , params []uint64 ) [] uint64 {
269- level := api .LogLevel (params [0 ])
263+ func (m * middleware ) logEnabled (_ context.Context , stack []uint64 ) {
264+ level := api .LogLevel (stack [0 ])
270265 if m .logger .IsEnabled (level ) {
271- return resultTrue
266+ stack [0 ] = 1 // true
267+ } else {
268+ stack [0 ] = 0 // false
272269 }
273- return resultFalse
274270}
275271
276272// log implements the WebAssembly host function handler.FuncLog.
277- func (m * middleware ) log (ctx context.Context , mod wazeroapi.Module , params []uint64 ) ( _ [] uint64 ) {
273+ func (m * middleware ) log (ctx context.Context , mod wazeroapi.Module , params []uint64 ) {
278274 level := api .LogLevel (params [0 ])
279275 message := uint32 (params [1 ])
280276 messageLen := uint32 (params [2 ])
@@ -287,22 +283,21 @@ func (m *middleware) log(ctx context.Context, mod wazeroapi.Module, params []uin
287283 msg = mustReadString (ctx , mod .Memory (), "message" , message , messageLen )
288284 }
289285 m .logger .Log (ctx , level , msg )
290- return
291286}
292287
293288// getMethod implements the WebAssembly host function handler.FuncGetMethod.
294- func (m * middleware ) getMethod (ctx context.Context , mod wazeroapi.Module , params []uint64 ) [] uint64 {
295- buf := uint32 (params [0 ])
296- bufLimit := handler .BufLimit (params [1 ])
289+ func (m * middleware ) getMethod (ctx context.Context , mod wazeroapi.Module , stack []uint64 ) {
290+ buf := uint32 (stack [0 ])
291+ bufLimit := handler .BufLimit (stack [1 ])
297292
298293 method := m .host .GetMethod (ctx )
299294 methodLen := writeStringIfUnderLimit (ctx , mod , buf , bufLimit , method )
300295
301- return [] uint64 { uint64 (methodLen )}
296+ stack [ 0 ] = uint64 (methodLen )
302297}
303298
304299// getHeader implements the WebAssembly host function handler.FuncSetMethod.
305- func (m * middleware ) setMethod (ctx context.Context , mod wazeroapi.Module , params []uint64 ) ( _ [] uint64 ) {
300+ func (m * middleware ) setMethod (ctx context.Context , mod wazeroapi.Module , params []uint64 ) {
306301 method := uint32 (params [0 ])
307302 methodLen := uint32 (params [1 ])
308303
@@ -314,23 +309,21 @@ func (m *middleware) setMethod(ctx context.Context, mod wazeroapi.Module, params
314309 }
315310 p = mustReadString (ctx , mod .Memory (), "method" , method , methodLen )
316311 m .host .SetMethod (ctx , p )
317-
318- return
319312}
320313
321314// getURI implements the WebAssembly host function handler.FuncGetURI.
322- func (m * middleware ) getURI (ctx context.Context , mod wazeroapi.Module , params []uint64 ) [] uint64 {
323- buf := uint32 (params [0 ])
324- bufLimit := handler .BufLimit (params [1 ])
315+ func (m * middleware ) getURI (ctx context.Context , mod wazeroapi.Module , stack []uint64 ) {
316+ buf := uint32 (stack [0 ])
317+ bufLimit := handler .BufLimit (stack [1 ])
325318
326319 uri := m .host .GetURI (ctx )
327320 uriLen := writeStringIfUnderLimit (ctx , mod , buf , bufLimit , uri )
328321
329- return [] uint64 { uint64 (uriLen )}
322+ stack [ 0 ] = uint64 (uriLen )
330323}
331324
332325// setURI implements the WebAssembly host function handler.FuncSetURI.
333- func (m * middleware ) setURI (ctx context.Context , mod wazeroapi.Module , params []uint64 ) ( _ [] uint64 ) {
326+ func (m * middleware ) setURI (ctx context.Context , mod wazeroapi.Module , params []uint64 ) {
334327 uri := uint32 (params [0 ])
335328 uriLen := uint32 (params [1 ])
336329
@@ -339,31 +332,29 @@ func (m *middleware) setURI(ctx context.Context, mod wazeroapi.Module, params []
339332 p = mustReadString (ctx , mod .Memory (), "uri" , uri , uriLen )
340333 }
341334 m .host .SetURI (ctx , p )
342-
343- return
344335}
345336
346337// getProtocolVersion implements the WebAssembly host function
347338// handler.FuncGetProtocolVersion.
348- func (m * middleware ) getProtocolVersion (ctx context.Context , mod wazeroapi.Module , params []uint64 ) [] uint64 {
349- buf := uint32 (params [0 ])
350- bufLimit := handler .BufLimit (params [1 ])
339+ func (m * middleware ) getProtocolVersion (ctx context.Context , mod wazeroapi.Module , stack []uint64 ) {
340+ buf := uint32 (stack [0 ])
341+ bufLimit := handler .BufLimit (stack [1 ])
351342
352343 protocolVersion := m .host .GetProtocolVersion (ctx )
353344 if len (protocolVersion ) == 0 {
354345 panic ("HTTP protocol version cannot be empty" )
355346 }
356347 protocolVersionLen := writeStringIfUnderLimit (ctx , mod , buf , bufLimit , protocolVersion )
357348
358- return [] uint64 { uint64 (protocolVersionLen )}
349+ stack [ 0 ] = uint64 (protocolVersionLen )
359350}
360351
361352// getHeaderNames implements the WebAssembly host function
362353// handler.FuncGetHeaderNames.
363- func (m * middleware ) getHeaderNames (ctx context.Context , mod wazeroapi.Module , params []uint64 ) [] uint64 {
364- kind := handler .HeaderKind (params [0 ])
365- buf := uint32 (params [1 ])
366- bufLimit := handler .BufLimit (params [2 ])
354+ func (m * middleware ) getHeaderNames (ctx context.Context , mod wazeroapi.Module , stack []uint64 ) {
355+ kind := handler .HeaderKind (stack [0 ])
356+ buf := uint32 (stack [1 ])
357+ bufLimit := handler .BufLimit (stack [2 ])
367358
368359 var names []string
369360 switch kind {
@@ -380,17 +371,17 @@ func (m *middleware) getHeaderNames(ctx context.Context, mod wazeroapi.Module, p
380371 }
381372 countLen := writeNULTerminated (ctx , mod .Memory (), buf , bufLimit , names )
382373
383- return [] uint64 { countLen }
374+ stack [ 0 ] = countLen
384375}
385376
386377// getHeaderValues implements the WebAssembly host function
387378// handler.FuncGetHeaderValues.
388- func (m * middleware ) getHeaderValues (ctx context.Context , mod wazeroapi.Module , params []uint64 ) [] uint64 {
389- kind := handler .HeaderKind (params [0 ])
390- name := uint32 (params [1 ])
391- nameLen := uint32 (params [2 ])
392- buf := uint32 (params [3 ])
393- bufLimit := handler .BufLimit (params [4 ])
379+ func (m * middleware ) getHeaderValues (ctx context.Context , mod wazeroapi.Module , stack []uint64 ) {
380+ kind := handler .HeaderKind (stack [0 ])
381+ name := uint32 (stack [1 ])
382+ nameLen := uint32 (stack [2 ])
383+ buf := uint32 (stack [3 ])
384+ bufLimit := handler .BufLimit (stack [4 ])
394385
395386 if nameLen == 0 {
396387 panic ("HTTP header name cannot be empty" )
@@ -412,12 +403,12 @@ func (m *middleware) getHeaderValues(ctx context.Context, mod wazeroapi.Module,
412403 }
413404 countLen := writeNULTerminated (ctx , mod .Memory (), buf , bufLimit , values )
414405
415- return [] uint64 { countLen }
406+ stack [ 0 ] = countLen
416407}
417408
418409// setHeaderValue implements the WebAssembly host function
419410// handler.FuncSetHeaderValue.
420- func (m * middleware ) setHeaderValue (ctx context.Context , mod wazeroapi.Module , params []uint64 ) ( _ [] uint64 ) {
411+ func (m * middleware ) setHeaderValue (ctx context.Context , mod wazeroapi.Module , params []uint64 ) {
421412 kind := handler .HeaderKind (params [0 ])
422413 name := uint32 (params [1 ])
423414 nameLen := uint32 (params [2 ])
@@ -443,13 +434,11 @@ func (m *middleware) setHeaderValue(ctx context.Context, mod wazeroapi.Module, p
443434 default :
444435 panic ("unsupported header kind: " + strconv .Itoa (int (kind )))
445436 }
446-
447- return
448437}
449438
450439// addHeaderValue implements the WebAssembly host function
451440// handler.FuncAddHeaderValue.
452- func (m * middleware ) addHeaderValue (ctx context.Context , mod wazeroapi.Module , params []uint64 ) ( _ [] uint64 ) {
441+ func (m * middleware ) addHeaderValue (ctx context.Context , mod wazeroapi.Module , params []uint64 ) {
453442 kind := handler .HeaderKind (params [0 ])
454443 name := uint32 (params [1 ])
455444 nameLen := uint32 (params [2 ])
@@ -475,13 +464,11 @@ func (m *middleware) addHeaderValue(ctx context.Context, mod wazeroapi.Module, p
475464 default :
476465 panic ("unsupported header kind: " + strconv .Itoa (int (kind )))
477466 }
478-
479- return
480467}
481468
482469// removeHeader implements the WebAssembly host function
483470// handler.FuncRemoveHeader.
484- func (m * middleware ) removeHeader (ctx context.Context , mod wazeroapi.Module , params []uint64 ) ( _ [] uint64 ) {
471+ func (m * middleware ) removeHeader (ctx context.Context , mod wazeroapi.Module , params []uint64 ) {
485472 kind := handler .HeaderKind (params [0 ])
486473 name := uint32 (params [1 ])
487474 nameLen := uint32 (params [2 ])
@@ -504,15 +491,13 @@ func (m *middleware) removeHeader(ctx context.Context, mod wazeroapi.Module, par
504491 default :
505492 panic ("unsupported header kind: " + strconv .Itoa (int (kind )))
506493 }
507-
508- return
509494}
510495
511496// readBody implements the WebAssembly host function handler.FuncReadBody.
512- func (m * middleware ) readBody (ctx context.Context , mod wazeroapi.Module , params []uint64 ) [] uint64 {
513- kind := handler .BodyKind (params [0 ])
514- buf := uint32 (params [1 ])
515- bufLimit := handler .BufLimit (params [2 ])
497+ func (m * middleware ) readBody (ctx context.Context , mod wazeroapi.Module , stack []uint64 ) {
498+ kind := handler .BodyKind (stack [0 ])
499+ buf := uint32 (stack [1 ])
500+ bufLimit := handler .BufLimit (stack [2 ])
516501
517502 var r io.ReadCloser
518503 switch kind {
@@ -538,11 +523,11 @@ func (m *middleware) readBody(ctx context.Context, mod wazeroapi.Module, params
538523
539524 eofLen := readBody (ctx , mod , buf , bufLimit , r )
540525
541- return [] uint64 { eofLen }
526+ stack [ 0 ] = eofLen
542527}
543528
544529// writeBody implements the WebAssembly host function handler.FuncWriteBody.
545- func (m * middleware ) writeBody (ctx context.Context , mod wazeroapi.Module , params []uint64 ) ( _ [] uint64 ) {
530+ func (m * middleware ) writeBody (ctx context.Context , mod wazeroapi.Module , params []uint64 ) {
546531 kind := handler .BodyKind (params [0 ])
547532 buf := uint32 (params [1 ])
548533 bufLen := uint32 (params [2 ])
@@ -570,8 +555,6 @@ func (m *middleware) writeBody(ctx context.Context, mod wazeroapi.Module, params
570555 }
571556
572557 writeBody (ctx , mod , buf , bufLen , w )
573-
574- return
575558}
576559
577560func writeBody (ctx context.Context , mod wazeroapi.Module , buf , bufLen uint32 , w io.Writer ) {
@@ -587,24 +570,22 @@ func writeBody(ctx context.Context, mod wazeroapi.Module, buf, bufLen uint32, w
587570
588571// getStatusCode implements the WebAssembly host function
589572// handler.FuncGetStatusCode.
590- func (m * middleware ) getStatusCode (ctx context.Context , _ []uint64 ) [] uint64 {
573+ func (m * middleware ) getStatusCode (ctx context.Context , results []uint64 ) {
591574 _ = mustBeforeNextOrFeature (ctx , handler .FeatureBufferResponse , "get" , "status code" )
592575
593576 statusCode := m .host .GetStatusCode (ctx )
594577
595- return [] uint64 { uint64 (statusCode )}
578+ results [ 0 ] = uint64 (statusCode )
596579}
597580
598581// setStatusCode implements the WebAssembly host function
599582// handler.FuncSetStatusCode.
600- func (m * middleware ) setStatusCode (ctx context.Context , params []uint64 ) ( _ [] uint64 ) {
583+ func (m * middleware ) setStatusCode (ctx context.Context , params []uint64 ) {
601584 statusCode := uint32 (params [0 ])
602585
603586 _ = mustBeforeNextOrFeature (ctx , handler .FeatureBufferResponse , "set" , "status code" )
604587
605588 m .host .SetStatusCode (ctx , statusCode )
606-
607- return
608589}
609590
610591func readBody (ctx context.Context , mod wazeroapi.Module , buf uint32 , bufLimit handler.BufLimit , r io.Reader ) (eofLen uint64 ) {
0 commit comments