delete guileslop and add haskellslop
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
(module
|
||||
(func $add (param $a i32) (param $b i32) (result i32)
|
||||
local.get $a
|
||||
local.get $b
|
||||
i32.add)
|
||||
|
||||
(export "demo:addcomponent/adder@0.1.0#add" (func $add)))
|
||||
@@ -0,0 +1,9 @@
|
||||
package demo:addcomponent@0.1.0;
|
||||
|
||||
interface adder {
|
||||
add: func (a: u32, b: u32) -> u32;
|
||||
}
|
||||
|
||||
world example {
|
||||
export adder;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import Development.Shake
|
||||
import Development.Shake.Command
|
||||
import Development.Shake.FilePath
|
||||
import Development.Shake.Util
|
||||
|
||||
main = shakeArgs shakeOptions $ do
|
||||
-- action $ do
|
||||
-- sourceFiles <- getDirectoryFiles "" ["//*.luasm"]
|
||||
-- need $ (-<.> "luac") <$> sourceFiles
|
||||
want ["cont-stack.wasm"]
|
||||
alternatives $ do
|
||||
"*.wasm" %> \out -> do
|
||||
let wat = out -<.> "wat"
|
||||
need [wat]
|
||||
cmd_ "wasm-tools parse" [wat] "-o" [out]
|
||||
phony "run" $ do
|
||||
need ["cont-stack.wasm"]
|
||||
cmd_ "./run.js"
|
||||
phony "clean" $ do
|
||||
removeFilesAfter ".shake" ["//*"]
|
||||
liftIO $ removeFiles "." ["*.wasm"]
|
||||
@@ -0,0 +1,85 @@
|
||||
(module
|
||||
;; import console.log.
|
||||
(func $print (import "guppy" "print") (param i32))
|
||||
|
||||
;; declare a table with a reference to $halt in it. idk why, but this
|
||||
;; is necessary to use funcrefs lmfao.
|
||||
;; (table 2 funcref)
|
||||
;; (elem (i32.const 0) $halt)
|
||||
(elem declare funcref (ref.func $halt))
|
||||
|
||||
;; an array of return continuations.
|
||||
(type $cont (func (param i32)))
|
||||
(type $cont-stack-type (array (mut (ref null $cont))))
|
||||
(global $cont-stack (ref $cont-stack-type)
|
||||
(array.new_default $cont-stack-type (i32.const 128)))
|
||||
(global $cont-stack-top (mut i32) (i32.const 0))
|
||||
|
||||
;; a global array on which we pass arguments.
|
||||
(type $arg-array-type (array (mut (ref null eq))))
|
||||
(global $arg-array (ref $arg-array-type)
|
||||
(array.new_default $arg-array-type (i32.const 32)))
|
||||
|
||||
;; cps'd function. takes the number of scheme arguments as the sole
|
||||
;; wasm argument. arguments are read into locals from
|
||||
;; $arg-array. does not return, instead popping a continuation from
|
||||
;; $cont-stack and tail-calling it.
|
||||
(func $add (param $nargs i32)
|
||||
(local $x (ref eq))
|
||||
(local $y (ref eq))
|
||||
(local $return (ref $cont))
|
||||
(local.set $x (ref.as_non_null
|
||||
(array.get $arg-array-type
|
||||
(global.get $arg-array)
|
||||
(i32.const 0))))
|
||||
(local.set $y (ref.as_non_null
|
||||
(array.get $arg-array-type
|
||||
(global.get $arg-array)
|
||||
(i32.const 1))))
|
||||
(array.set $arg-array-type
|
||||
(global.get $arg-array)
|
||||
(i32.const 0)
|
||||
(ref.i31
|
||||
(i32.add (i31.get_s (ref.cast (ref i31) (local.get $x)))
|
||||
(i31.get_s (ref.cast (ref i31) (local.get $y))))))
|
||||
(return_call_ref
|
||||
$cont
|
||||
(i32.const 1)
|
||||
(block (result (ref $cont))
|
||||
(ref.as_non_null
|
||||
(array.get $cont-stack-type
|
||||
(global.get $cont-stack)
|
||||
(global.get $cont-stack-top)))
|
||||
(global.set $cont-stack-top
|
||||
(i32.sub (global.get $cont-stack-top)
|
||||
(i32.const 1))))))
|
||||
;; for demo purposes, this continuation calls console.log and stops.
|
||||
(func $halt (param $nargs i32)
|
||||
(call $print
|
||||
(i31.get_s
|
||||
(ref.cast
|
||||
(ref i31)
|
||||
(ref.as_non_null
|
||||
(array.get $arg-array-type
|
||||
(global.get $arg-array)
|
||||
(i32.const 0)))))))
|
||||
;; entry point }:3
|
||||
(func (export "main")
|
||||
;; push args
|
||||
(array.set $arg-array-type
|
||||
(global.get $arg-array)
|
||||
(i32.const 0)
|
||||
(ref.i31 (i32.const 4)))
|
||||
(array.set $arg-array-type
|
||||
(global.get $arg-array)
|
||||
(i32.const 1)
|
||||
(ref.i31 (i32.const 5)))
|
||||
;; push return continuation
|
||||
(array.set $cont-stack-type
|
||||
(global.get $cont-stack)
|
||||
(i32.const 0)
|
||||
(ref.func $halt))
|
||||
;; make call }:)
|
||||
(return_call $add
|
||||
;; inform $add how many arguments we called it with
|
||||
(i32.const 2))))
|
||||
Executable
+14
@@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env node
|
||||
const fs = require('node:fs');
|
||||
|
||||
const imports = {
|
||||
guppy: {
|
||||
print: (arg) => console.log (arg)
|
||||
}
|
||||
}
|
||||
|
||||
const wasmBuffer = fs.readFileSync ('cont-stack.wasm');
|
||||
WebAssembly.instantiate (wasmBuffer, imports).then (wasmModule => {
|
||||
const { main } = wasmModule.instance.exports;
|
||||
main ()
|
||||
});
|
||||
@@ -0,0 +1,32 @@
|
||||
import Development.Shake
|
||||
import Development.Shake.Command
|
||||
import Development.Shake.FilePath
|
||||
import Development.Shake.Util
|
||||
|
||||
main = shakeArgs shakeOptions $ do
|
||||
-- action $ do
|
||||
-- sourceFiles <- getDirectoryFiles "" ["//*.luasm"]
|
||||
-- need $ (-<.> "luac") <$> sourceFiles
|
||||
want ["hello.component.wasm"]
|
||||
alternatives $ do
|
||||
"*.component.wasm" %> \out -> do
|
||||
let wasm = out `replaceExtensions` "wasm"
|
||||
need [wasm]
|
||||
cmd_
|
||||
"wasm-tools component new"
|
||||
[wasm]
|
||||
"-o" [out]
|
||||
"*.wasm" %> \out -> do
|
||||
let wit = out -<.> "wit"
|
||||
let wat = out -<.> "wat"
|
||||
need [wit,wat]
|
||||
cmd_
|
||||
"wasm-tools component embed"
|
||||
[wit] [wat] "-o" [out]
|
||||
phony "run" $ do
|
||||
need ["hello.component.wasm"]
|
||||
-- cmd_ "wasmtime run --invoke hello() hello.component.wasm"
|
||||
cmd_ "wasmtime run hello.component.wasm"
|
||||
phony "clean" $ do
|
||||
removeFilesAfter ".shake" ["//*"]
|
||||
liftIO $ removeFiles "." ["*.wasm"]
|
||||
@@ -0,0 +1,23 @@
|
||||
(module
|
||||
;; Correct module name: stdio, not stdout
|
||||
(import "wasi:cli/stdout@0.2.6" "get-stdout"
|
||||
(func $get-stdout (result i32)))
|
||||
|
||||
;; Write and flush a buffer.
|
||||
(import
|
||||
"wasi:io/streams@0.2.6"
|
||||
"[method]output-stream.blocking-write-and-flush"
|
||||
(func $print (param i32 i32 i32 i32)))
|
||||
|
||||
(memory 1)
|
||||
(export "memory" (memory 0))
|
||||
|
||||
(data (i32.const 16) "hello worms\n")
|
||||
|
||||
(func (export "wasi:cli/run@0.2.6#run") (result i32)
|
||||
(call $print
|
||||
(call $get-stdout)
|
||||
(i32.const 16) ;; offset to print
|
||||
(i32.const 12) ;; length to print
|
||||
(i32.const 32)) ;; offset for result
|
||||
(i32.const 0)))
|
||||
@@ -0,0 +1,49 @@
|
||||
package root:component;
|
||||
|
||||
world root {
|
||||
import wasi:cli/stdin@0.2.6;
|
||||
import wasi:cli/stdout@0.2.6;
|
||||
import wasi:io/streams@0.2.6;
|
||||
|
||||
export wasi:cli/run@0.2.6;
|
||||
}
|
||||
|
||||
package wasi:cli@0.2.6 {
|
||||
interface stdout {
|
||||
use wasi:io/streams@0.2.6.{output-stream};
|
||||
|
||||
get-stdout: func() -> output-stream;
|
||||
}
|
||||
interface stdin {
|
||||
}
|
||||
interface run {
|
||||
run: func () -> result;
|
||||
}
|
||||
}
|
||||
|
||||
package wasi:io@0.2.6 {
|
||||
interface poll {
|
||||
resource pollable {
|
||||
block: func();
|
||||
}
|
||||
}
|
||||
interface error {
|
||||
resource error;
|
||||
}
|
||||
interface streams {
|
||||
use error.{error};
|
||||
use poll.{pollable};
|
||||
|
||||
resource input-stream;
|
||||
|
||||
resource output-stream {
|
||||
write: func(contents: list<u8>) -> result<_, stream-error>;
|
||||
blocking-write-and-flush: func(contents: list<u8>) ->result<_,stream-error>;
|
||||
}
|
||||
|
||||
variant stream-error {
|
||||
last-operation-failed(error),
|
||||
closed,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import Development.Shake
|
||||
import Development.Shake.Command
|
||||
import Development.Shake.FilePath
|
||||
import Development.Shake.Util
|
||||
|
||||
main = shakeArgs shakeOptions $ do
|
||||
-- action $ do
|
||||
-- sourceFiles <- getDirectoryFiles "" ["//*.luasm"]
|
||||
-- need $ (-<.> "luac") <$> sourceFiles
|
||||
want ["complete.component.wasm"]
|
||||
alternatives $ do
|
||||
"complete.component.wasm" %> \out -> do
|
||||
need ["provider.component.wasm","importing.component.wasm"]
|
||||
cmd_
|
||||
"wac plug --plug"
|
||||
"provider.component.wasm" "importing.component.wasm"
|
||||
"-o" "complete.component.wasm"
|
||||
"*.component.wasm" %> \out -> do
|
||||
let wasm = out `replaceExtensions` "wasm"
|
||||
need [wasm]
|
||||
cmd_
|
||||
"wasm-tools component new"
|
||||
[wasm]
|
||||
"-o" [out]
|
||||
"*.wasm" %> \out -> do
|
||||
let wit = out -<.> "wit"
|
||||
let wat = out -<.> "wat"
|
||||
need [wit,wat]
|
||||
cmd_
|
||||
"wasm-tools component embed"
|
||||
[wit] [wat] "-o" [out]
|
||||
phony "run" $ do
|
||||
need ["complete.component.wasm"]
|
||||
cmd_ "wasmtime run --invoke add(1) complete.component.wasm"
|
||||
phony "clean" $ do
|
||||
removeFilesAfter ".shake" ["//*"]
|
||||
liftIO $ removeFiles "." ["*.wasm"]
|
||||
@@ -0,0 +1,12 @@
|
||||
(module
|
||||
(import "demo:importing/provider@0.1.0" "get" (func $get (result i32)))
|
||||
(func $add (param $other i32) (result i32)
|
||||
call $get
|
||||
local.get $other
|
||||
i32.add)
|
||||
(func $mul (param $other i32) (result i32)
|
||||
call $get
|
||||
local.get $other
|
||||
i32.mul)
|
||||
(export "demo:importing/adder@0.1.0#add" (func $add))
|
||||
(export "demo:importing/adder@0.1.0#mul" (func $mul)))
|
||||
@@ -0,0 +1,15 @@
|
||||
package demo:importing@0.1.0;
|
||||
|
||||
interface provider {
|
||||
get: func () -> u32;
|
||||
}
|
||||
|
||||
interface adder {
|
||||
add: func (other: u32) -> u32;
|
||||
mul: func (other: u32) -> u32;
|
||||
}
|
||||
|
||||
world example {
|
||||
import provider;
|
||||
export adder;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
(module
|
||||
(func $get (result i32)
|
||||
i32.const 123)
|
||||
|
||||
(export "demo:importing/provider@0.1.0#get" (func $get)))
|
||||
@@ -0,0 +1,9 @@
|
||||
package demo:importing@0.1.0;
|
||||
|
||||
interface provider {
|
||||
get: func() -> u32;
|
||||
}
|
||||
|
||||
world example {
|
||||
export provider;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import Development.Shake
|
||||
import Development.Shake.Command
|
||||
import Development.Shake.FilePath
|
||||
import Development.Shake.Util
|
||||
|
||||
main = shakeArgs shakeOptions $ do
|
||||
-- action $ do
|
||||
-- sourceFiles <- getDirectoryFiles "" ["//*.luasm"]
|
||||
-- need $ (-<.> "luac") <$> sourceFiles
|
||||
want ["silly.component.wasm"]
|
||||
alternatives $ do
|
||||
"*.component.wasm" %> \out -> do
|
||||
let wasm = out `replaceExtensions` "wasm"
|
||||
need [wasm]
|
||||
cmd_
|
||||
"wasm-tools component new"
|
||||
[wasm]
|
||||
"-o" [out]
|
||||
"*.wasm" %> \out -> do
|
||||
let wit = out -<.> "wit"
|
||||
let wat = out -<.> "wat"
|
||||
need [wit,wat]
|
||||
cmd_
|
||||
"wasm-tools component embed"
|
||||
[wit] [wat] "-o" [out]
|
||||
phony "run" $ do
|
||||
need ["silly.component.wasm"]
|
||||
cmd_ "wasmtime run --invoke silly() silly.component.wasm"
|
||||
phony "clean" $ do
|
||||
removeFilesAfter ".shake" ["//*"]
|
||||
liftIO $ removeFiles "." ["*.wasm"]
|
||||
@@ -0,0 +1,20 @@
|
||||
(module
|
||||
(import "wasi:cli/stdout@0.2.6" "get-stdout"
|
||||
(func $get-stdout (result i32)))
|
||||
(import
|
||||
"wasi:io/streams@0.2.6"
|
||||
"[method]output-stream.blocking-write-and-flush"
|
||||
(func $print (param i32 i32 i32 i32)))
|
||||
|
||||
(memory 1)
|
||||
(export "memory" (memory 0))
|
||||
|
||||
(data (i32.const 16) "hello worms\n")
|
||||
|
||||
(func (export "wasi:cli/run@0.2.6#run") (result i32)
|
||||
(call $print
|
||||
(call $get-stdout)
|
||||
(i32.const 16) ;; offset to print
|
||||
(i32.const 12) ;; length to print
|
||||
(i32.const 32)) ;; offset for result
|
||||
(i32.const 0)))
|
||||
@@ -0,0 +1,49 @@
|
||||
package root:component;
|
||||
|
||||
world root {
|
||||
import wasi:cli/stdin@0.2.6;
|
||||
import wasi:cli/stdout@0.2.6;
|
||||
import wasi:io/streams@0.2.6;
|
||||
|
||||
export wasi:cli/run@0.2.6;
|
||||
}
|
||||
|
||||
package wasi:cli@0.2.6 {
|
||||
interface stdout {
|
||||
use wasi:io/streams@0.2.6.{output-stream};
|
||||
|
||||
get-stdout: func() -> output-stream;
|
||||
}
|
||||
interface stdin {
|
||||
}
|
||||
interface run {
|
||||
run: func () -> result;
|
||||
}
|
||||
}
|
||||
|
||||
package wasi:io@0.2.6 {
|
||||
interface poll {
|
||||
resource pollable {
|
||||
block: func();
|
||||
}
|
||||
}
|
||||
interface error {
|
||||
resource error;
|
||||
}
|
||||
interface streams {
|
||||
use error.{error};
|
||||
use poll.{pollable};
|
||||
|
||||
resource input-stream;
|
||||
|
||||
resource output-stream {
|
||||
write: func(contents: list<u8>) -> result<_, stream-error>;
|
||||
blocking-write-and-flush: func(contents: list<u8>) ->result<_,stream-error>;
|
||||
}
|
||||
|
||||
variant stream-error {
|
||||
last-operation-failed(error),
|
||||
closed,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user