-
Notifications
You must be signed in to change notification settings - Fork 120
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
Problem sending string concatenated with variable #29
Comments
AssemblyScript always import abort function from host. So you got this errors because life can't execute wasm file. You should implement |
That actually doesnt solve the problem, just create a new one. If i implement 'abort' function, here is what i get: And here is the ts code that is being compiled:
2 and v are printed and then the code reaches that error. |
What do you mean by "this error does not appear in any other instances"? If you mean this error only appears in life but not other WebAssembly runtimes, can you post the |
Closing due to inactivity. |
Hello, Tried it out just now and it appears to work just fine. index.ts: import "allocator/arena";
declare namespace env {
function log(offset: usize, len: usize): void
}
function log(str: string): void {
env.log(str.toUTF8(), str.lengthUTF8);
}
export function main(): void {
let v = 'teste';
let number = "2";
log(v);
log(number);
log("1" + number);
} main.go: package main
import (
"errors"
"github.com/perlin-network/life/exec"
"io/ioutil"
"fmt"
)
func check(err error) {
if err != nil {
panic(err)
}
}
var _ exec.ImportResolver = (*resolver)(nil)
type resolver struct {}
func (resolver) ResolveFunc(module, field string) exec.FunctionImport {
switch module {
case "env":
switch field {
case "abort":
return func(vm *exec.VirtualMachine) int64 {
return 0
}
case "log":
return func(vm *exec.VirtualMachine) int64 {
frame := vm.GetCurrentFrame()
msgPtr := int(uint32(frame.Locals[0]))
msgLen := int(uint32(frame.Locals[1]))
msg := string(vm.Memory[msgPtr : msgPtr+msgLen])
fmt.Println(msg)
return 0
}
default:
panic(fmt.Errorf("unknown import resolved: %s", field))
}
}
panic(fmt.Errorf("unknown module: %s", module))
}
func (resolver) ResolveGlobal(module, field string) int64 {
panic("implement me")
}
func main() {
code, err := ioutil.ReadFile("build/optimized.wasm")
check(err)
vm, err := exec.NewVirtualMachine(code, exec.VMConfig{}, new(resolver), nil)
check(err)
entrypoint, exists := vm.GetFunctionExport("main")
if !exists {
check(errors.New("failed to find entry point"))
}
_, err = vm.Run(entrypoint)
check(err)
} |
Hello all,
I am trying to run a ts (compiled with Assemblyscript) file that implements a simple function, it logs on the terminal a string concatenated with a variable (that is also a string). The code is imported through Perlin and runs in a Golang Vm.
Here is a Go code chunk that is handling the generated wasm,;-the string is reconstructed ffollowing AssemblyScript documentation on how strings are allocated in the memory(https://github.com/AssemblyScript/assemblyscript/wiki/Memory-Layout-&-Management):
This is a ts code that when compiled works fine :
Here is another ts code that also runs without any problem:
But here is a code that not only does not work but also returns an error:
And here is the error that Life returns:
Resolve func: env abort
panic: unknown field: abort
It is important to emphasize that this error does not appear in any other instances.
So, anyone has a workaround for this issue??
The text was updated successfully, but these errors were encountered: