Skip to content

Commit

Permalink
fix(example): regenerate wasi-http
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-jerry-ye committed Dec 31, 2024
1 parent 4bd69c7 commit ff3532b
Show file tree
Hide file tree
Showing 51 changed files with 921 additions and 334 deletions.
2 changes: 1 addition & 1 deletion legacy/examples/wasi-http/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ build:

regenerate:
@wit-deps update
@wit-bindgen moonbit --out-dir . wit --derive-show --derive-eq
@wit-bindgen moonbit --out-dir . wit --derive-show --derive-eq --derive-error --project-name moonbit-community/wasi-http
@moon fmt
111 changes: 85 additions & 26 deletions legacy/examples/wasi-http/ffi/top.mbt
Original file line number Diff line number Diff line change
@@ -1,62 +1,82 @@
// Generated by `wit-bindgen` 0.34.0. DO NOT EDIT!
// Generated by `wit-bindgen` 0.36.0. DO NOT EDIT!

///|
pub extern "wasm" fn extend16(value : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.extend16_s)

///|
pub extern "wasm" fn extend8(value : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.extend8_s)

///|
pub extern "wasm" fn store8(offset : Int, value : Int) =
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store8)

///|
pub extern "wasm" fn load8_u(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load8_u)

///|
pub extern "wasm" fn load8(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load8_s)

///|
pub extern "wasm" fn store16(offset : Int, value : Int) =
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store16)

///|
pub extern "wasm" fn load16(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load16_s)

///|
pub extern "wasm" fn load16_u(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load16_u)

///|
pub extern "wasm" fn store32(offset : Int, value : Int) =
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store)

///|
pub extern "wasm" fn load32(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load)

///|
pub extern "wasm" fn store64(offset : Int, value : Int64) =
#|(func (param i32) (param i64) local.get 0 local.get 1 i64.store)

///|
pub extern "wasm" fn load64(offset : Int) -> Int64 =
#|(func (param i32) (result i64) local.get 0 i64.load)

///|
pub extern "wasm" fn storef32(offset : Int, value : Float) =
#|(func (param i32) (param f32) local.get 0 local.get 1 f32.store)

///|
pub extern "wasm" fn loadf32(offset : Int) -> Float =
#|(func (param i32) (result f32) local.get 0 f32.load)

///|
pub extern "wasm" fn storef64(offset : Int, value : Double) =
#|(func (param i32) (param f64) local.get 0 local.get 1 f64.store)

///|
pub extern "wasm" fn loadf64(offset : Int) -> Double =
#|(func (param i32) (result f64) local.get 0 f64.load)

///|
pub extern "wasm" fn f32_to_i32(value : Float) -> Int =
#|(func (param f32) (result i32) local.get 0 f32.convert_i32_s)

///|
pub extern "wasm" fn f32_to_i64(value : Float) -> Int64 =
#|(func (param f32) (result i64) local.get 0 f32.convert_i64_s)

///|
extern "wasm" fn malloc_inline(size : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 call $moonbit.malloc)

///|
pub fn malloc(size : Int) -> Int {
let words = size / 4 + 1
let address = malloc_inline(8 + words * 4)
Expand All @@ -66,93 +86,132 @@ pub fn malloc(size : Int) -> Int {
address + 8
}

///|
pub extern "wasm" fn free(position : Int) =
#|(func (param i32) local.get 0 i32.const 8 i32.sub call $moonbit.decref)

///|
pub fn copy(dest : Int, src : Int) -> Unit {
let src = src - 8
let dest = dest - 8
let src_len = load32(src + 4) & 0xFFFFFF
let dest_len = load32(dest + 4) & 0xFFFFFF
let src_len = (load32(src - 12) >> 2) - 4
let dest_len = (load32(dest - 12) >> 2) - 4
let min = if src_len < dest_len { src_len } else { dest_len }
copy_inline(dest, src, min)
}

///|
extern "wasm" fn copy_inline(dest : Int, src : Int, len : Int) =
#|(func (param i32) (param i32) (param i32) local.get 0 local.get 1 local.get 2 memory.copy)

///|
pub extern "wasm" fn str2ptr(str : String) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.const 8 i32.add)

///|
pub extern "wasm" fn ptr2str(ptr : Int) -> String =
#|(func (param i32) (result i32) local.get 0 i32.const 4 i32.sub i32.const 243 i32.store8 local.get 0 i32.const 8 i32.sub)

pub extern "wasm" fn bytes2ptr(bytes : Bytes) -> Int =
///|
pub extern "wasm" fn bytes2ptr(bytes : FixedArray[Byte]) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.const 8 i32.add)

pub extern "wasm" fn ptr2bytes(ptr : Int) -> Bytes =
#|(func (param i32) (result i32) local.get 0 i32.const 8 i32.sub)
///|
pub extern "wasm" fn ptr2bytes(ptr : Int, _len : Int) -> FixedArray[Byte] =
#|(func (param i32) (param i32) (result i32) local.get 0 i32.const 8 i32.sub)

///|
pub extern "wasm" fn uint_array2ptr(array : FixedArray[UInt]) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.const 8 i32.add)

///|
pub extern "wasm" fn uint64_array2ptr(array : FixedArray[UInt64]) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.const 8 i32.add)

///|
pub extern "wasm" fn int_array2ptr(array : FixedArray[Int]) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.const 8 i32.add)

///|
pub extern "wasm" fn int64_array2ptr(array : FixedArray[Int64]) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.const 8 i32.add)

///|
pub extern "wasm" fn float_array2ptr(array : FixedArray[Float]) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.const 8 i32.add)

///|
pub extern "wasm" fn double_array2ptr(array : FixedArray[Double]) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.const 8 i32.add)

pub extern "wasm" fn ptr2uint_array(ptr : Int) -> FixedArray[UInt] =
#|(func (param i32) (result i32) local.get 0 i32.const 4 i32.sub i32.const 241 i32.store8 local.get 0 i32.const 8 i32.sub)
///|
extern "wasm" fn ptr2uint_array_ffi(ptr : Int) -> FixedArray[UInt] =
#|(func (param i32) (result i32) local.get 0 i32.const 8 i32.sub)

///|
pub fn ptr2uint_array(ptr : Int, len : Int) -> FixedArray[UInt] {
set_header_ffi(ptr - 4, len)
ptr2uint_array_ffi(ptr)
}

///|
extern "wasm" fn ptr2int_array_ffi(ptr : Int) -> FixedArray[Int] =
#|(func (param i32) (result i32) local.get 0 i32.const 8 i32.sub)

pub extern "wasm" fn ptr2int_array(ptr : Int) -> FixedArray[Int] =
#|(func (param i32) (result i32) local.get 0 i32.const 4 i32.sub i32.const 241 i32.store8 local.get 0 i32.const 8 i32.sub)
///|
pub fn ptr2int_array(ptr : Int, len : Int) -> FixedArray[Int] {
set_header_ffi(ptr - 4, len)
ptr2int_array_ffi(ptr)
}

pub extern "wasm" fn ptr2float_array(ptr : Int) -> FixedArray[Float] =
#|(func (param i32) (result i32) local.get 0 i32.const 4 i32.sub i32.const 241 i32.store8 local.get 0 i32.const 8 i32.sub)
///|
extern "wasm" fn ptr2float_array_ffi(ptr : Int) -> FixedArray[Float] =
#|(func (param i32) (result i32) local.get 0 i32.const 8 i32.sub)

///|
pub fn ptr2float_array(ptr : Int, len : Int) -> FixedArray[Float] {
set_header_ffi(ptr - 4, len)
ptr2float_array_ffi(ptr)
}

///|
extern "wasm" fn ptr2uint64_array_ffi(ptr : Int) -> FixedArray[UInt64] =
#|(func (param i32) (result i32) local.get 0 i32.const 8 i32.sub)

pub fn ptr2uint64_array(ptr : Int) -> FixedArray[UInt64] {
set_64_header_ffi(ptr - 4)
///|
pub fn ptr2uint64_array(ptr : Int, len : Int) -> FixedArray[UInt64] {
set_header_ffi(ptr - 4, len)
ptr2uint64_array_ffi(ptr)
}

///|
extern "wasm" fn ptr2int64_array_ffi(ptr : Int) -> FixedArray[Int64] =
#|(func (param i32) (result i32) local.get 0 i32.const 8 i32.sub)

pub fn ptr2int64_array(ptr : Int) -> FixedArray[Int64] {
set_64_header_ffi(ptr - 4)
///|
pub fn ptr2int64_array(ptr : Int, len : Int) -> FixedArray[Int64] {
set_header_ffi(ptr - 4, len)
ptr2int64_array_ffi(ptr)
}

///|
extern "wasm" fn ptr2double_array_ffi(ptr : Int) -> FixedArray[Double] =
#|(func (param i32) (result i32) local.get 0 i32.const 8 i32.sub)

pub fn ptr2double_array(ptr : Int) -> FixedArray[Double] {
set_64_header_ffi(ptr - 4)
///|
pub fn ptr2double_array(ptr : Int, len : Int) -> FixedArray[Double] {
set_header_ffi(ptr - 4, len)
ptr2double_array_ffi(ptr)
}

fn set_64_header_ffi(offset : Int) -> Unit {
let len = load32(offset)
store32(offset, len >> 1)
store8(offset, 241)
///|
fn set_header_ffi(offset : Int, len : Int) -> Unit {
store32(offset, (len << 8) | 241)
}

pub trait Any {}
///|
pub(open) trait Any {}

pub struct Cleanup {
///|
pub(all) struct Cleanup {
address : Int
size : Int
align : Int
Expand Down
3 changes: 2 additions & 1 deletion legacy/examples/wasi-http/gen/ffi.mbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Generated by `wit-bindgen` 0.34.0. DO NOT EDIT!
// Generated by `wit-bindgen` 0.36.0. DO NOT EDIT!

///|
pub fn cabi_realloc(
src_offset : Int,
src_size : Int,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Generated by `wit-bindgen` 0.34.0. DO NOT EDIT!
// Generated by `wit-bindgen` 0.36.0. DO NOT EDIT!

///|
pub fn wasmExportHandle(p0 : Int, p1 : Int) -> Unit {
let _ = @incomingHandler.handle(
@types.IncomingRequest::IncomingRequest(p0),
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "import": [{ "path" : "moonbit/example/interface/wasi/http/types", "alias" : "types" }] }
{ "import": [{ "path" : "moonbit-community/wasi-http/interface/wasi/http/types", "alias" : "types" }] }
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Generated by `wit-bindgen` 0.34.0.
/// This function is invoked with an incoming HTTP Request, and a resource
// Generated by `wit-bindgen` 0.36.0.
///| This function is invoked with an incoming HTTP Request, and a resource
/// `response-outparam` which provides the capability to reply with an HTTP
/// Response. The response is sent by calling the `response-outparam.set`
/// method, which allows execution to continue after the response has been
Expand All @@ -13,5 +13,5 @@ pub fn handle(
_request : @types.IncomingRequest,
_response_out : @types.ResponseOutparam
) -> Unit {
abort("todo")
...
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
// Generated by `wit-bindgen` 0.34.0. DO NOT EDIT!
// Generated by `wit-bindgen` 0.36.0. DO NOT EDIT!
2 changes: 1 addition & 1 deletion legacy/examples/wasi-http/gen/moon.pkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"heap-start-address": 16
}
}
,"import": [{ "path" : "moonbit/example/ffi", "alias" : "ffi" }, { "path" : "moonbit/example/gen/interface/wasi/http/incomingHandler", "alias" : "incomingHandler" }, { "path" : "moonbit/example/interface/wasi/http/types", "alias" : "types" }]
,"import": [{ "path" : "moonbit-community/wasi-http/ffi", "alias" : "ffi" }, { "path" : "moonbit-community/wasi-http/gen/interface/wasi/http/incomingHandler", "alias" : "incomingHandler" }, { "path" : "moonbit-community/wasi-http/interface/wasi/http/types", "alias" : "types" }]
}
2 changes: 1 addition & 1 deletion legacy/examples/wasi-http/gen/world/server/stub.mbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
// Generated by `wit-bindgen` 0.34.0.
// Generated by `wit-bindgen` 0.36.0.
2 changes: 1 addition & 1 deletion legacy/examples/wasi-http/gen/world_server_export.mbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
// Generated by `wit-bindgen` 0.34.0. DO NOT EDIT!
// Generated by `wit-bindgen` 0.36.0. DO NOT EDIT!
3 changes: 3 additions & 0 deletions legacy/examples/wasi-http/interface/wasi/cli/stderr/ffi.mbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Generated by `wit-bindgen` 0.36.0. DO NOT EDIT!
///|
fn wasmImportGetStderr() -> Int = "wasi:cli/[email protected]" "get-stderr"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "import": [{ "path" : "moonbit-community/wasi-http/interface/wasi/io/streams", "alias" : "streams" }] }
7 changes: 7 additions & 0 deletions legacy/examples/wasi-http/interface/wasi/cli/stderr/top.mbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Generated by `wit-bindgen` 0.36.0. DO NOT EDIT!

///|
pub fn get_stderr() -> @streams.OutputStream {
let result : Int = wasmImportGetStderr()
return @streams.OutputStream::OutputStream(result)
}
3 changes: 3 additions & 0 deletions legacy/examples/wasi-http/interface/wasi/cli/stdin/ffi.mbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Generated by `wit-bindgen` 0.36.0. DO NOT EDIT!
///|
fn wasmImportGetStdin() -> Int = "wasi:cli/[email protected]" "get-stdin"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "import": [{ "path" : "moonbit-community/wasi-http/interface/wasi/io/streams", "alias" : "streams" }] }
7 changes: 7 additions & 0 deletions legacy/examples/wasi-http/interface/wasi/cli/stdin/top.mbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Generated by `wit-bindgen` 0.36.0. DO NOT EDIT!

///|
pub fn get_stdin() -> @streams.InputStream {
let result : Int = wasmImportGetStdin()
return @streams.InputStream::InputStream(result)
}
3 changes: 3 additions & 0 deletions legacy/examples/wasi-http/interface/wasi/cli/stdout/ffi.mbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Generated by `wit-bindgen` 0.36.0. DO NOT EDIT!
///|
fn wasmImportGetStdout() -> Int = "wasi:cli/[email protected]" "get-stdout"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "import": [{ "path" : "moonbit-community/wasi-http/interface/wasi/io/streams", "alias" : "streams" }] }
7 changes: 7 additions & 0 deletions legacy/examples/wasi-http/interface/wasi/cli/stdout/top.mbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Generated by `wit-bindgen` 0.36.0. DO NOT EDIT!

///|
pub fn get_stdout() -> @streams.OutputStream {
let result : Int = wasmImportGetStdout()
return @streams.OutputStream::OutputStream(result)
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
// Generated by `wit-bindgen` 0.34.0. DO NOT EDIT!
// Generated by `wit-bindgen` 0.36.0. DO NOT EDIT!
///|
fn wasmImportNow() -> Int64 = "wasi:clocks/[email protected]" "now"

///|
fn wasmImportResolution() -> Int64 = "wasi:clocks/[email protected]" "resolution"

///|
fn wasmImportSubscribeInstant(p0 : Int64) -> Int = "wasi:clocks/[email protected]" "subscribe-instant"

///|
fn wasmImportSubscribeDuration(p0 : Int64) -> Int = "wasi:clocks/[email protected]" "subscribe-duration"
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "import": [{ "path" : "moonbit/example/ffi", "alias" : "ffi" }, { "path" : "moonbit/example/interface/wasi/io/poll", "alias" : "poll" }] }
{ "import": [{ "path" : "moonbit-community/wasi-http/interface/wasi/io/poll", "alias" : "poll" }] }
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Generated by `wit-bindgen` 0.34.0. DO NOT EDIT!
/// Read the current value of the clock.
// Generated by `wit-bindgen` 0.36.0. DO NOT EDIT!
///| Read the current value of the clock.
///
/// The clock is monotonic, therefore calling this function repeatedly will
/// produce a sequence of non-decreasing values.
Expand All @@ -8,21 +8,21 @@ pub fn now() -> UInt64 {
return result.reinterpret_as_uint64()
}

/// Query the resolution of the clock. Returns the duration of time
///| Query the resolution of the clock. Returns the duration of time
/// corresponding to a clock tick.
pub fn resolution() -> UInt64 {
let result : Int64 = wasmImportResolution()
return result.reinterpret_as_uint64()
}

/// Create a `pollable` which will resolve once the specified instant
///| Create a `pollable` which will resolve once the specified instant
/// has occurred.
pub fn subscribe_instant(when : UInt64) -> @poll.Pollable {
let result : Int = wasmImportSubscribeInstant(when.reinterpret_as_int64())
return @poll.Pollable::Pollable(result)
}

/// Create a `pollable` that will resolve after the specified duration has
///| Create a `pollable` that will resolve after the specified duration has
/// elapsed from the time this function is invoked.
pub fn subscribe_duration(when : UInt64) -> @poll.Pollable {
let result : Int = wasmImportSubscribeDuration(when.reinterpret_as_int64())
Expand Down
Loading

0 comments on commit ff3532b

Please sign in to comment.