initial commit
This commit is contained in:
commit
98ee85c579
|
@ -0,0 +1,2 @@
|
||||||
|
*.wasm
|
||||||
|
.tup
|
|
@ -0,0 +1,19 @@
|
||||||
|
Copyright (c) 2018 Christine Dodrill <me@christine.website>
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
|
@ -0,0 +1 @@
|
||||||
|
.gitignore
|
|
@ -0,0 +1 @@
|
||||||
|
*
|
|
@ -0,0 +1 @@
|
||||||
|
: *.go |> go build -o ../../bin/land |> ../../bin/land
|
|
@ -0,0 +1,3 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
func main() {}
|
|
@ -0,0 +1,92 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
gcontext "context"
|
||||||
|
"os"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
"github.com/Xe/ln"
|
||||||
|
"github.com/Xe/uuid"
|
||||||
|
"github.com/go-interpreter/wagon/exec"
|
||||||
|
"github.com/go-interpreter/wagon/validate"
|
||||||
|
"github.com/go-interpreter/wagon/wasm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Process struct {
|
||||||
|
id string
|
||||||
|
vm *exec.VM
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewProcess(vm *exec.VM) *Process {
|
||||||
|
p := &Process{
|
||||||
|
id: uuid.New(),
|
||||||
|
vm: vm,
|
||||||
|
}
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p Process) importer(name string) (*wasm.Module, error) {
|
||||||
|
switch name {
|
||||||
|
case "env":
|
||||||
|
m := wasm.NewModule()
|
||||||
|
m.Types = &wasm.SectionTypes{
|
||||||
|
Entries: []wasm.FunctionSig{
|
||||||
|
{
|
||||||
|
Form: 0,
|
||||||
|
ParamTypes: []wasm.ValueType{wasm.ValueTypeI32, wasm.ValueTypeI32},
|
||||||
|
ReturnTypes: []wasm.ValueType{wasm.ValueTypeI32},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
m.FunctionIndexSpace = []wasm.Function{
|
||||||
|
{
|
||||||
|
Sig: &m.Types.Entries[0],
|
||||||
|
Host: reflect.ValueOf(p.log),
|
||||||
|
Body: &wasm.FunctionBody{},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
m.Export = &wasm.SectionExports{
|
||||||
|
Entries: map[string]wasm.ExportEntry{
|
||||||
|
"log": {
|
||||||
|
FieldStr: "log",
|
||||||
|
Kind: wasm.ExternalFunction,
|
||||||
|
Index: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
|
||||||
|
default:
|
||||||
|
f, err := os.Open(name + ".wasm")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
m, err := wasm.ReadModule(f, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = validate.VerifyModule(m)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ID returns the process ID string.
|
||||||
|
func (p Process) ID() string { return p.id }
|
||||||
|
|
||||||
|
// VM returns the webassembly VM used to execute code. This isn't thread-safe.
|
||||||
|
func (p Process) VM() *exec.VM { return p.vm }
|
||||||
|
|
||||||
|
func (p *Process) log(ptr int32, len int32) int32 {
|
||||||
|
data := p.vm.Memory()[ptr : ptr+len]
|
||||||
|
ln.Log(gcontext.Background(), ln.F{"data": data, "data_string": string(data), "pid": p.id})
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
node_modules
|
|
@ -0,0 +1,11 @@
|
||||||
|
const compileWalt = require('walt-compiler').default;
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
|
fs.readFile(process.argv[2], 'utf8', function (err,data) {
|
||||||
|
if (err) {
|
||||||
|
return console.log(err);
|
||||||
|
}
|
||||||
|
const buffer = compileWalt(data);
|
||||||
|
|
||||||
|
fs.writeFileSync(process.argv[3], new Uint8Array(buffer));
|
||||||
|
});
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,19 @@
|
||||||
|
{
|
||||||
|
"name": "userland",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"devDependencies": {
|
||||||
|
"walt-compiler": "^0.6.2",
|
||||||
|
"webpack": "^4.9.1"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"commander": "^2.15.1"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
include_rules
|
||||||
|
: foreach *.walt |> node ../../compile.js %f %o |> %B.wasm
|
||||||
|
: foreach *.wast |> wat2wasm -o %o %f |> %B.wasm
|
|
@ -0,0 +1,6 @@
|
||||||
|
(module
|
||||||
|
(func $add (param i32 i32) (result i32)
|
||||||
|
(i32.add
|
||||||
|
(get_local 0)
|
||||||
|
(get_local 1)))
|
||||||
|
(export "add" (func $add)))
|
|
@ -0,0 +1,11 @@
|
||||||
|
let counter: i32 = 0;
|
||||||
|
|
||||||
|
export function decrement(): i32 {
|
||||||
|
counter -= 1;
|
||||||
|
return counter;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function increment(): i32 {
|
||||||
|
counter += 1;
|
||||||
|
return counter;
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
(module
|
||||||
|
(func $log (param i32) (nop))
|
||||||
|
(func $hello (nop))
|
||||||
|
(export "log" (func $log))
|
||||||
|
(export "hello" (func $hello))
|
||||||
|
)
|
|
@ -0,0 +1,13 @@
|
||||||
|
const memory: Memory = { 'initial': 0 };
|
||||||
|
|
||||||
|
type File = {
|
||||||
|
'fd': i32,
|
||||||
|
'name': i32
|
||||||
|
};
|
||||||
|
|
||||||
|
export function main(): i32 {
|
||||||
|
let foo: File = 31337;
|
||||||
|
foo['fd'] = 0;
|
||||||
|
foo['name'] = 2;
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue