-
Notifications
You must be signed in to change notification settings - Fork 2
Prompt interface and bug fixes #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dhil
wants to merge
3
commits into
main
Choose a base branch
from
prompt
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| /** A basic fiber interface. **/ | ||
| #ifdef WASMFX_FIBER_C_H | ||
| #error "the prompt implementation conflicts with the standard implementation" | ||
| #endif | ||
| #ifndef WASMFX_FIBER_C_PROMPT_H | ||
| #define WASMFX_FIBER_C_PROMPT_H | ||
|
|
||
| #define export(NAME) __attribute__((export_name(NAME))) | ||
|
|
||
| #include <stdint.h> | ||
|
|
||
| /** Type of a prompt. **/ | ||
| typedef uint32_t prompt_t; | ||
|
|
||
| /** The result type of a yield. **/ | ||
| typedef struct yield_result { | ||
| prompt_t prompt; | ||
| void* value; | ||
| } yield_result_t; | ||
|
|
||
| /** The signature of a fiber entry point. **/ | ||
| typedef void* (*fiber_entry_point_t)(prompt_t, void*); | ||
|
|
||
| /** The abstract type of a fiber object. **/ | ||
| typedef struct fiber* fiber_t; | ||
|
|
||
| /** Allocates a new fiber with the default stack size. **/ | ||
| export("fiber_alloc") | ||
| fiber_t fiber_alloc(fiber_entry_point_t entry); | ||
|
|
||
| /** Reclaims the memory occupied by the fiber object. **/ | ||
| export("fiber_free") | ||
| void fiber_free(fiber_t fiber); | ||
|
|
||
| /** Yields control to the context of the provided prompt. This | ||
| function must be called from within a fiber context. **/ | ||
| export("fiber_yield_to") | ||
| yield_result_t fiber_yield_to(prompt_t p, void *arg); | ||
|
|
||
| /** Possible status codes for `fiber_resume`. **/ | ||
| typedef enum { FIBER_OK = 0, FIBER_YIELD = 1, FIBER_ERROR = 2, FIBER_FORWARD = 3 } fiber_result_t; | ||
|
|
||
| /** Resumes a given `fiber` with argument `arg`, returning some value | ||
| of type `void*`. The output parameter `status` indicates whether | ||
| the fiber ran to completion (`FIBER_OK`), yielded control | ||
| (`FIBER_YIELD`), or failed (`FIBER_ERROR`), in the latter case the | ||
| return value will always be `NULL`. **/ | ||
| export("fiber_resume_with") | ||
| void* fiber_resume_with(fiber_t fiber, void *arg, fiber_result_t *status); | ||
|
|
||
|
|
||
| /** Runs the provided `main` function in a fiber context. **/ | ||
| export("fiber_main") | ||
| int fiber_main(int (*main)(int,char**), int, char**); | ||
|
|
||
| #undef export | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| #ifndef __WASI_IO_H | ||
| #define __WASI_IO_H | ||
|
|
||
| #include <stdint.h> | ||
| #include <unistd.h> | ||
| #include <wasi/api.h> | ||
|
|
||
| // NOTE: We cannot use printf() and most friends because asyncify | ||
| // attempts to transform them and inadvertently ending up corrupting | ||
| // its own state resulting in an "unreachable" error at runtime. | ||
| // The following code is adapted from | ||
| // https://gist.github.com/s-macke/6dd78c78be46214d418454abb667a1ba | ||
| #define wasi_print(str) do { \ | ||
| const uint8_t *start = (uint8_t *)str; \ | ||
| const uint8_t *end = start; \ | ||
| for (; *end != '\0'; end++) {} \ | ||
| __wasi_ciovec_t iov = {.buf = start, .buf_len = end - start}; \ | ||
| size_t nwritten; \ | ||
| (void)__wasi_fd_write(STDOUT_FILENO, &iov, 1, &nwritten); \ | ||
| } while (0) | ||
| #define wasi_print_debug(str) \ | ||
| wasi_print(__FILE__ ":" STRINGIZE(__LINE__) ": " str "\n") | ||
| #define wasi_printc(ch) do { \ | ||
| const char str[] = { ch }; \ | ||
| wasi_print(str); \ | ||
| } while (0) | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think the
examples/promptfolder wasn't committedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. The latest commit adds them.