-
Notifications
You must be signed in to change notification settings - Fork 28
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
Refactor TinyGo API into separate packages #183
Merged
+276
−282
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d0d5a12
Refactor TinyGo API into separate packages
8824153
Revert accidental Makefile change
7aa1bb4
Bump subo version to rc-v0.2.1
482ad6f
Merge main in
f1b856a
Fix GitHub sanity checkflow test stage
774a604
Merge main in and rebuild TinyGo runnables
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 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 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 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,13 @@ | ||
package cache | ||
|
||
import ( | ||
"github.com/suborbital/reactr/api/tinygo/runnable/internal/ffi" | ||
) | ||
|
||
func Get(key string) ([]byte, error) { | ||
return ffi.CacheGet(key) | ||
} | ||
|
||
func Set(key, val string, ttl int) { | ||
ffi.CacheSet(key, val, ttl) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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
File renamed without changes.
6 changes: 3 additions & 3 deletions
6
api/tinygo/runnable/cache.go → api/tinygo/runnable/internal/ffi/cache.go
This file contains 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 |
---|---|---|
@@ -1,20 +1,20 @@ | ||
//go:build tinygo.wasm | ||
|
||
package runnable | ||
package ffi | ||
|
||
// #include <reactr.h> | ||
import "C" | ||
|
||
func CacheGet(key string) ([]byte, error) { | ||
ptr, size := rawSlicePointer([]byte(key)) | ||
|
||
return result(C.cache_get(ptr, size, ident())) | ||
return result(C.cache_get(ptr, size, Ident())) | ||
} | ||
|
||
func CacheSet(key, val string, ttl int) { | ||
keyPtr, keySize := rawSlicePointer([]byte(key)) | ||
valPtr, valSize := rawSlicePointer([]byte(val)) | ||
|
||
C.cache_set(keyPtr, keySize, valPtr, valSize, int32(ttl), ident()) | ||
C.cache_set(keyPtr, keySize, valPtr, valSize, int32(ttl), Ident()) | ||
return | ||
} |
This file contains 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,18 @@ | ||
//go:build tinygo.wasm | ||
|
||
package ffi | ||
|
||
import ( | ||
"github.com/suborbital/reactr/api/tinygo/runnable/runnable" | ||
) | ||
|
||
var runnable_ runnable.Runnable | ||
var ident_ int32 | ||
|
||
func Ident() int32 { | ||
return ident_ | ||
} | ||
|
||
func Use(runnable runnable.Runnable) { | ||
runnable_ = runnable | ||
} |
This file contains 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,15 @@ | ||
//go:build tinygo.wasm | ||
|
||
package ffi | ||
|
||
// #include <reactr.h> | ||
import "C" | ||
|
||
func DoHTTPRequest(method int32, urlStr string, body []byte, headers map[string]string) ([]byte, error) { | ||
urlPtr, urlSize := rawSlicePointer([]byte(urlStr)) | ||
bodyPtr, bodySize := rawSlicePointer(body) | ||
|
||
size := C.fetch_url(method, urlPtr, urlSize, bodyPtr, bodySize, Ident()) | ||
|
||
return result(size) | ||
} |
This file contains 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,12 @@ | ||
//go:build tinygo.wasm | ||
|
||
package ffi | ||
|
||
// #include <reactr.h> | ||
import "C" | ||
|
||
func LogAtLevel(message string, level int32) { | ||
msgPtr, size := rawSlicePointer([]byte(message)) | ||
|
||
C.log_msg(msgPtr, size, level, Ident()) | ||
} |
File renamed without changes.
This file contains 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,23 @@ | ||
//go:build tinygo.wasm | ||
|
||
package ffi | ||
|
||
// #include <reactr.h> | ||
import "C" | ||
|
||
func ReqGetField(fieldType int32, key string) []byte { | ||
ptr, size := rawSlicePointer([]byte(key)) | ||
|
||
res, err := result(C.request_get_field(fieldType, ptr, size, Ident())) | ||
if err != nil { | ||
return []byte{} | ||
} | ||
return res | ||
} | ||
|
||
func ReqSetField(fieldType int32, key string, value string) ([]byte, error) { | ||
keyPtr, keySize := rawSlicePointer([]byte(key)) | ||
valPtr, valSize := rawSlicePointer([]byte(value)) | ||
|
||
return result(C.request_set_field(fieldType, keyPtr, keySize, valPtr, valSize, Ident())) | ||
} |
This file contains 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,34 @@ | ||
//go:build tinygo.wasm | ||
|
||
package ffi | ||
|
||
// #include <reactr.h> | ||
import "C" | ||
import ( | ||
"github.com/suborbital/reactr/api/tinygo/runnable/runnable" | ||
) | ||
|
||
func result(size int32) ([]byte, runnable.HostErr) { | ||
allocSize := size | ||
|
||
if size < 0 { | ||
if size == -1 { | ||
return nil, runnable.NewHostError("unknown error returned from host") | ||
} | ||
|
||
allocSize = -size | ||
} | ||
|
||
result := make([]byte, allocSize) | ||
resultPtr, _ := rawSlicePointer(result) | ||
|
||
if code := C.get_ffi_result(resultPtr, Ident()); code != 0 { | ||
return nil, runnable.NewHostError("unknown error returned from host") | ||
} | ||
|
||
if size < 0 { | ||
return nil, runnable.NewHostError(string(result)) | ||
} | ||
|
||
return result, nil | ||
} |
This file contains 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
2 changes: 1 addition & 1 deletion
2
api/tinygo/runnable/alloc.go → api/tinygo/runnable/internal/ffi/unsafe.go
This file contains 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
//go:build tinygo.wasm | ||
|
||
package runnable | ||
package ffi | ||
|
||
import ( | ||
"reflect" | ||
|
14 changes: 6 additions & 8 deletions
14
api/tinygo/runnable/log.go → api/tinygo/runnable/log/log.go
This file contains 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 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.
Do the other languages return here? I'm wondering because not calling get_ffi_result can cause the host to retain that data in the buffer and can cause issues for subsequent host calls. Can't remember if a
-1
error from the host means it never filled the buffer at all.