Skip to content

Commit

Permalink
Merge pull request #254 from moonbitlang/driver_ffi
Browse files Browse the repository at this point in the history
internal: rename driver ffi external type
  • Loading branch information
Young-Flash authored Sep 4, 2024
2 parents 2ac9377 + b068f17 commit d6143e8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
moonc build-package ./src/lib/hello.mbt ./target/wasm-gc/debug/test/lib/__generated_driver_for_internal_test.mbt -o ./target/wasm-gc/debug/test/lib/lib.internal_test.core -pkg username/hello/lib -is-main -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources username/hello/lib:./src/lib -target wasm-gc -g
moonc link-core $MOON_HOME/lib/core/target/wasm-gc/release/bundle/core.core ./target/wasm-gc/debug/test/lib/lib.internal_test.core -main username/hello/lib -o ./target/wasm-gc/debug/test/lib/lib.internal_test.wasm -test-mode -pkg-sources username/hello/lib:./src/lib -pkg-sources moonbitlang/core:$MOON_HOME/lib/core -target wasm-gc -g

$ moon check
$ moon check --sort-input

Finished. moon: ran 3 tasks, now up to date

Expand Down
16 changes: 8 additions & 8 deletions crates/moonbuild/template/test_driver_template.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -171,26 +171,26 @@ fn main {

// =========== ffi start ===========

fn _moonbit_test_driver_internal_get_file_name() -> ExternString = "test" "get_file_name"
fn _moonbit_test_driver_internal_get_file_name() -> MoonbitTestDriverInternalExternString = "test" "get_file_name"
fn moonbit_test_driver_internal_get_file_name() -> String {
let file_name = _moonbit_test_driver_internal_get_file_name()
moonbit_test_driver_internal_string_from_extern(file_name)
}

fn moonbit_test_driver_internal_get_index() -> Int = "test" "get_index"

type StringReadHandle
type MoonbitTestDriverInternalStringReadHandle

type ExternString
type MoonbitTestDriverInternalExternString

fn moonbit_test_driver_internal_begin_read_string(s : ExternString) -> StringReadHandle = "__moonbit_fs_unstable" "begin_read_string"
fn moonbit_test_driver_internal_begin_read_string(s : MoonbitTestDriverInternalExternString) -> MoonbitTestDriverInternalStringReadHandle = "__moonbit_fs_unstable" "begin_read_string"

fn moonbit_test_driver_internal_string_read_char(handle : StringReadHandle) -> Int = "__moonbit_fs_unstable" "string_read_char"
fn moonbit_test_driver_internal_string_read_char(handle : MoonbitTestDriverInternalStringReadHandle) -> Int = "__moonbit_fs_unstable" "string_read_char"

fn moonbit_test_driver_internal_finish_read_string(handle : StringReadHandle) = "__moonbit_fs_unstable" "finish_read_string"
fn moonbit_test_driver_internal_finish_read_string(handle : MoonbitTestDriverInternalStringReadHandle) = "__moonbit_fs_unstable" "finish_read_string"

fn moonbit_test_driver_internal_string_from_extern(e : ExternString) -> String {
let buf = Buffer::new()
fn moonbit_test_driver_internal_string_from_extern(e : MoonbitTestDriverInternalExternString) -> String {
let buf = @moonbitlang/core/builtin.Buffer::new()
let handle = moonbit_test_driver_internal_begin_read_string(e)
while true {
let ch = moonbit_test_driver_internal_string_read_char(handle)
Expand Down
16 changes: 8 additions & 8 deletions crates/moonbuild/template/test_driver_template2.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -129,26 +129,26 @@ fn main {

// =========== ffi start ===========

fn _moonbit_test_driver_internal_get_file_name() -> ExternString = "test" "get_file_name"
fn _moonbit_test_driver_internal_get_file_name() -> MoonbitTestDriverInternalExternString = "test" "get_file_name"
fn moonbit_test_driver_internal_get_file_name() -> String {
let file_name = _moonbit_test_driver_internal_get_file_name()
moonbit_test_driver_internal_string_from_extern(file_name)
}

fn moonbit_test_driver_internal_get_index() -> Int = "test" "get_index"

type StringReadHandle
type MoonbitTestDriverInternalStringReadHandle

type ExternString
type MoonbitTestDriverInternalExternString

fn moonbit_test_driver_internal_begin_read_string(s : ExternString) -> StringReadHandle = "__moonbit_fs_unstable" "begin_read_string"
fn moonbit_test_driver_internal_begin_read_string(s : MoonbitTestDriverInternalExternString) -> MoonbitTestDriverInternalStringReadHandle = "__moonbit_fs_unstable" "begin_read_string"

fn moonbit_test_driver_internal_string_read_char(handle : StringReadHandle) -> Int = "__moonbit_fs_unstable" "string_read_char"
fn moonbit_test_driver_internal_string_read_char(handle : MoonbitTestDriverInternalStringReadHandle) -> Int = "__moonbit_fs_unstable" "string_read_char"

fn moonbit_test_driver_internal_finish_read_string(handle : StringReadHandle) = "__moonbit_fs_unstable" "finish_read_string"
fn moonbit_test_driver_internal_finish_read_string(handle : MoonbitTestDriverInternalStringReadHandle) = "__moonbit_fs_unstable" "finish_read_string"

fn moonbit_test_driver_internal_string_from_extern(e : ExternString) -> String {
let buf = Buffer::new()
fn moonbit_test_driver_internal_string_from_extern(e : MoonbitTestDriverInternalExternString) -> String {
let buf = @moonbitlang/core/builtin.Buffer::new()
let handle = moonbit_test_driver_internal_begin_read_string(e)
while true {
let ch = moonbit_test_driver_internal_string_read_char(handle)
Expand Down

0 comments on commit d6143e8

Please sign in to comment.