initial commit

This commit is contained in:
Cadey Ratio 2018-06-07 15:31:01 -07:00
commit 98ee85c579
16 changed files with 2580 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.wasm
.tup

19
LICENSE Normal file
View File

@ -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.

1
Tupfile.rules Normal file
View File

@ -0,0 +1 @@
.gitignore

1
bin/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*

1
cmd/land/Tupfile Normal file
View File

@ -0,0 +1 @@
: *.go |> go build -o ../../bin/land |> ../../bin/land

3
cmd/land/main.go Normal file
View File

@ -0,0 +1,3 @@
package main
func main() {}

92
cmd/land/process.go Normal file
View File

@ -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
}

1
userland/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules

11
userland/compile.js Normal file
View File

@ -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));
});

2391
userland/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

19
userland/package.json Normal file
View File

@ -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"
}
}

3
userland/src/lib/Tupfile Normal file
View File

@ -0,0 +1,3 @@
include_rules
: foreach *.walt |> node ../../compile.js %f %o |> %B.wasm
: foreach *.wast |> wat2wasm -o %o %f |> %B.wasm

View File

@ -0,0 +1,6 @@
(module
(func $add (param i32 i32) (result i32)
(i32.add
(get_local 0)
(get_local 1)))
(export "add" (func $add)))

View File

@ -0,0 +1,11 @@
let counter: i32 = 0;
export function decrement(): i32 {
counter -= 1;
return counter;
}
export function increment(): i32 {
counter += 1;
return counter;
}

View File

@ -0,0 +1,6 @@
(module
(func $log (param i32) (nop))
(func $hello (nop))
(export "log" (func $log))
(export "hello" (func $hello))
)

View File

@ -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;
}