-
Notifications
You must be signed in to change notification settings - Fork 102
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
[x/programs] add program abstraction #660
Merged
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
c71e603
Move fixtures into tests directory
hexfusion 903fefe
Abstract engine from runtime
hexfusion ff0adb6
React to changes
hexfusion cea5ea5
Nits
hexfusion f25a144
Review comments
hexfusion 29d3bbe
Clarify debug mode
hexfusion a75af73
Nit
hexfusion 3d03b4c
Add host abstraction
hexfusion 2b7ba48
React to changes
hexfusion 3ac1a3f
Cleanup
hexfusion 195c96a
Move program from runtime
hexfusion af1201b
Add program abstraction
hexfusion 597ff1a
Implement runtime instance and react to changes
hexfusion 2fbdc8e
Nit
hexfusion fa5565d
Add RegisterImportWrapFn
hexfusion 7485e7c
Update examples
hexfusion e1bbfc4
Show example of wrap import function impl
hexfusion 8dbe3ed
Remove stale docs
hexfusion 678a8cb
Impliment pstate with wrap functionality
hexfusion 7e5f311
license header lint
samliok 95aa598
remove hardcoded wrapper funcitons, fixed pstate bugs
samliok 13ff0a6
lint
samliok cee952c
lint
samliok 5c359d9
Merge branch 'dynamic_args' into refactor-statekey
samliok 15b84b5
Revert "Merge branch 'dynamic_args' into refactor-statekey"
samliok 3a23ebb
Revert "Revert "Merge branch 'dynamic_args' into refactor-statekey""
samliok 7f323b2
lint
samliok b5e64fb
memory tests
samliok d175d2c
create WAT program instead of memory.wasm
samliok 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
Implement runtime instance and react to changes
Signed-off-by: Sam Batschelet <sam.batschelet@avalabs.org>
- Loading branch information
commit 597ff1a5a09326e6c70c8a7b782818821b362d4c
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright (C) 2023, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package runtime | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/ava-labs/hypersdk/x/programs/engine" | ||
"github.com/ava-labs/hypersdk/x/programs/program" | ||
"github.com/bytecodealliance/wasmtime-go/v14" | ||
) | ||
|
||
var _ program.Instance = (*Instance)(nil) | ||
|
||
// NewInstance creates a new instance wrapper. | ||
func NewInstance(store *engine.Store, inner *wasmtime.Instance) *Instance { | ||
return &Instance{ | ||
inner: inner, | ||
store: store.Get(), | ||
} | ||
} | ||
|
||
// Instance is a wrapper around a wasmtime.Instance | ||
type Instance struct { | ||
inner *wasmtime.Instance | ||
store wasmtime.Storelike | ||
} | ||
|
||
func (i *Instance) GetFunc(name string) (*program.Func, error) { | ||
exp, err := i.GetExport(program.FuncName(name)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
fn, err := exp.Func() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return program.NewFunc(fn, i.store), nil | ||
} | ||
|
||
func (i *Instance) GetExport(name string) (*program.Export, error) { | ||
exp := i.inner.GetExport(i.store, name) | ||
if exp == nil { | ||
return nil, fmt.Errorf("failed to create export %w: %s", program.ErrInvalidType, name) | ||
} | ||
|
||
return program.NewExport(exp), nil | ||
} | ||
|
||
func (i *Instance) Memory() (*program.Memory, error) { | ||
exp, err := i.GetExport(program.MemoryFnName) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
mem, err := exp.Memory() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
exp, err = i.GetExport(program.AllocFnName) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
allocFn, err := exp.Func() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return program.NewMemory(mem, allocFn, i.store), 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
Oops, something went wrong.
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.
we require the instance to export an
alloc
function here, might make sense to make this optional