fix tests }:3
build / build (push) Successful in 4m52s

This commit is contained in:
2026-07-18 02:49:34 -06:00
parent 9334373f96
commit a97a0ad7bb
14 changed files with 217 additions and 91 deletions
+6 -10
View File
@@ -16,11 +16,10 @@
"x86_64-darwin" "x86_64-linux" "x86_64-darwin" "x86_64-linux"
]; ];
overlays = [ overlays = [
haskellNix.overlay haskellNix.overlay
(final: prev: { (final: prev: {
gyehoek-wasmtime-wrapper = final.callPackage ./wasmtime.nix {}; shake-wrapper = final.callPackage ./shake-wrapper.nix {};
gyehoek-runtime = final.callPackage ./runtime {}; gyehoek-runtime = final.callPackage ./runtime {};
gyehoek = final.haskell-nix.project' { gyehoek = final.haskell-nix.project' {
src = ./.; src = ./.;
@@ -29,13 +28,10 @@
packages.gyehoek.components.tests.test.preCheck = packages.gyehoek.components.tests.test.preCheck =
let let
bin = [ bin = [
pkgs.gyehoek-wasmtime-wrapper pkgs.git # tasty uses git diff
pkgs.git
]; ];
in '' in ''
# Wasmtime requires a cache in $HOME. This is less export GYEHOEK_RUNTIME=${lib.getExe final.gyehoek-runtime}
# painful than reconfiguring the cache location.
export HOME=$(mktemp -d)
export PATH=${lib.makeBinPath bin}:$PATH export PATH=${lib.makeBinPath bin}:$PATH
''; '';
})]; })];
@@ -50,14 +46,14 @@
}; };
buildInputs = with final; [ buildInputs = with final; [
haskellPackages.cabal-fmt haskellPackages.cabal-fmt
self.packages.${final.stdenv.hostPlatform.system}.shake shake-wrapper
wabt wabt
nodejs nodejs
wasm-tools wasm-tools
wac-cli wac-cli
guile guile
gyehoek-wasmtime-wrapper
rust-analyzer rust-analyzer
wasmtime
]; ];
}; };
}; };
@@ -89,7 +85,7 @@
hf.packages.${system} // lib.fix (packages: { hf.packages.${system} // lib.fix (packages: {
gyehoek = hf.packages.${system}."gyehoek:exe:gyehoek"; gyehoek = hf.packages.${system}."gyehoek:exe:gyehoek";
default = packages.gyehoek; default = packages.gyehoek;
shake = pkgs.callPackage ./shake-wrapper.nix {}; inherit (pkgs) gyehoek-runtime shake-wrapper;
})); }));
devShells = each-system devShells = each-system
+4
View File
@@ -3,6 +3,10 @@
"gyehoek" "gyehoek"
"write" "write"
(func $gh-write (param (ref eq)))) (func $gh-write (param (ref eq))))
(import
"gyehoek"
"to-bool"
(func $gh-to-bool (param (ref eq)) (result i32)))
(type $heap-object (sub (struct (field $hash (mut i32))))) (type $heap-object (sub (struct (field $hash (mut i32)))))
(type $cont-type (func (param i32))) (type $cont-type (func (param i32)))
(type $cont-stack-type (array (mut (ref null $cont-type)))) (type $cont-stack-type (array (mut (ref null $cont-type))))
-3
View File
@@ -1,5 +1,2 @@
ret > ExitSuccess ret > ExitSuccess
out > 555 out > 555
out >
err > warning: using `--invoke` with a function that returns values is experimental and may break in the future
err >
+56 -8
View File
@@ -1,13 +1,61 @@
(module (module
(type (sub (struct (field (mut i32))))) (import
"gyehoek"
"write"
(func $gh-write (param (ref eq))))
(import
"gyehoek"
"to-bool"
(func $gh-to-bool (param (ref eq)) (result i32)))
(type $heap-object (sub (struct (field $hash (mut i32)))))
(type $cont-type (func (param i32)))
(type $cont-stack-type (array (mut (ref null $cont-type))))
(global $cont-stack-top (mut i32) (i32.const 0))
(global
$cont-stack
(ref $cont-stack-type)
(array.new_default $cont-stack-type (i32.const 128)))
(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)))
(global $result (mut (ref null eq)) (ref.null eq))
(func (func
(param) $halt
(result (ref eq)) (param i32)
(local (ref eq) (ref eq) (ref eq) (ref eq) (ref eq)) (global.get $arg-array)
(i32.const 0) (i32.const 0)
(array.get $arg-array-type)
ref.as_non_null
(global.set $result))
(func
$scm-entry
(param i32)
(local (ref eq) (ref eq) (ref eq) (ref eq) (ref eq))
(i32.const 1)
ref.i31 ref.i31
(call $gh-to-bool)
(if (if
(result i32) (then
(then (i32.const 777) ref.i31) (global.get $arg-array)
(else (i32.const 555) ref.i31))) (global.get 0)
(export "main" (func 0))) (i32.const 777)
(i32.const 1)
i32.shl
ref.i31
(array.set $arg-array-type)
(return_call $halt (i32.const 1)))
(else
(global.get $arg-array)
(global.get 0)
(i32.const 555)
(i32.const 1)
i32.shl
ref.i31
(array.set $arg-array-type)
(return_call $halt (i32.const 1)))))
(func
(export "main")
(call $scm-entry (i32.const 0))
(call $gh-write (ref.as_non_null (global.get $result)))))
-3
View File
@@ -1,5 +1,2 @@
ret > ExitSuccess ret > ExitSuccess
out > 777 out > 777
out >
err > warning: using `--invoke` with a function that returns values is experimental and may break in the future
err >
+56 -8
View File
@@ -1,13 +1,61 @@
(module (module
(type (sub (struct (field (mut i32))))) (import
"gyehoek"
"write"
(func $gh-write (param (ref eq))))
(import
"gyehoek"
"to-bool"
(func $gh-to-bool (param (ref eq)) (result i32)))
(type $heap-object (sub (struct (field $hash (mut i32)))))
(type $cont-type (func (param i32)))
(type $cont-stack-type (array (mut (ref null $cont-type))))
(global $cont-stack-top (mut i32) (i32.const 0))
(global
$cont-stack
(ref $cont-stack-type)
(array.new_default $cont-stack-type (i32.const 128)))
(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)))
(global $result (mut (ref null eq)) (ref.null eq))
(func (func
(param) $halt
(result (ref eq)) (param i32)
(global.get $arg-array)
(i32.const 0)
(array.get $arg-array-type)
ref.as_non_null
(global.set $result))
(func
$scm-entry
(param i32)
(local (ref eq) (ref eq) (ref eq) (ref eq) (ref eq)) (local (ref eq) (ref eq) (ref eq) (ref eq) (ref eq))
(i32.const 1) (i32.const 3)
ref.i31 ref.i31
(call $gh-to-bool)
(if (if
(result i32) (then
(then (i32.const 777) ref.i31) (global.get $arg-array)
(else (i32.const 555) ref.i31))) (global.get 0)
(export "main" (func 0))) (i32.const 777)
(i32.const 1)
i32.shl
ref.i31
(array.set $arg-array-type)
(return_call $halt (i32.const 1)))
(else
(global.get $arg-array)
(global.get 0)
(i32.const 555)
(i32.const 1)
i32.shl
ref.i31
(array.set $arg-array-type)
(return_call $halt (i32.const 1)))))
(func
(export "main")
(call $scm-entry (i32.const 0))
(call $gh-write (ref.as_non_null (global.get $result)))))
+1
View File
@@ -9,4 +9,5 @@ rustPlatform.buildRustPackage (finalAttrs: {
lockFile = ./Cargo.lock; lockFile = ./Cargo.lock;
}; };
doCheck = true; doCheck = true;
meta.mainProgram = "gyehoek-runtime";
}) })
+9
View File
@@ -20,3 +20,12 @@ pub fn write (caller : Caller<'_, u32>, x : Rooted<EqRef>) {
Scm::Immediate (x) => write_immediate (caller, x) Scm::Immediate (x) => write_immediate (caller, x)
} }
} }
pub fn truthy_p (caller : Caller<'_, u32>, x : Rooted<EqRef>,) -> u32 {
let r = scm::interpret (&caller, x).unwrap ();
if let Scm::Immediate (Immediate::Bool (false)) = r {
0
} else {
1
}
}
+28
View File
@@ -40,3 +40,31 @@ pub fn interpret (store : impl AsContext, x : Rooted<EqRef>) -> Option<Scm> {
todo! () todo! ()
} }
} }
pub fn encode_immediate (
store : impl AsContext,
imm : Immediate
) -> scm_bits {
use Immediate::*;
match imm {
SmallFixnum (n) => (n << 1).try_into ().unwrap (),
Bool (false) => scm_false,
Bool (true) => scm_true,
}
}
pub fn encode (store : impl AsContextMut, x : Scm) -> Rooted<EqRef> {
match x {
Scm::Immediate (imm) => {
let i31 = I31::new_u32 (encode_immediate (&store, imm))
.unwrap ();
EqRef::from_i31 (store, i31)
}
}
}
pub fn encode_bool (store : impl AsContextMut, b : bool) -> Rooted<EqRef> {
let x = if b { scm_true } else { scm_false };
let i31 = I31::new_u32 (x).unwrap ();
EqRef::from_i31 (store, i31)
}
+7 -1
View File
@@ -31,13 +31,19 @@ fn get_config () -> Config {
cfg cfg
} }
fn link_primitives (linker : &mut Linker<u32>) -> wasmtime::Result<()> {
linker.func_wrap ("gyehoek", "write", gyehoek::write)?;
linker.func_wrap ("gyehoek", "to-bool", gyehoek::truthy_p)?;
Ok (())
}
pub fn main () -> wasmtime::Result<()> { pub fn main () -> wasmtime::Result<()> {
let args = Args::parse (); let args = Args::parse ();
let wasm_config = get_config (); let wasm_config = get_config ();
let engine = Engine::new (&wasm_config)?; let engine = Engine::new (&wasm_config)?;
let module = Module::new (&engine, read (args.wasm)?)?; let module = Module::new (&engine, read (args.wasm)?)?;
let mut linker = Linker::new (&engine); let mut linker = Linker::new (&engine);
linker.func_wrap ("gyehoek", "write", gyehoek::write)?; link_primitives (&mut linker)?;
let mut store : Store<u32> = Store::new (&engine, 4); let mut store : Store<u32> = Store::new (&engine, 4);
let instance = linker.instantiate (&mut store, &module)?; let instance = linker.instantiate (&mut store, &module)?;
let main = instance.get_typed_func::<(),()> (&mut store, "main")?; let main = instance.get_typed_func::<(),()> (&mut store, "main")?;
+17 -1
View File
@@ -39,6 +39,7 @@ import Debug.Pretty.Simple
import Control.Monad.Fix import Control.Monad.Fix
import Language.Sexp.Located (Sexp) import Language.Sexp.Located (Sexp)
import Data.Functor.Foldable (cata) import Data.Functor.Foldable (cata)
import qualified Gyehoek.Sexp
data Env = MkEnv data Env = MkEnv
@@ -132,6 +133,19 @@ lower' g (ExpPrim p rs e) =
where where
r = head rs r = head rs
lower' g (ExpIf c t f) = do
t' <- lower' g t
f' <- lower' g f
let c' = lowerVal g c
pure [expr|
##{c'}
(call $gh-to-bool)
(if (then ##{t'})
(else ##{f'}))
|]
lower' g e = error . show $ e
-- lower' g (ExpIf c t f) = do -- lower' g (ExpIf c t f) = do
-- t' <- lower' g t -- t' <- lower' g t
-- f' <- lower' g f -- f' <- lower' g f
@@ -241,8 +255,10 @@ lowerBinOp op g x y r e = do
emitRuntime :: GenMod :> es => Eff es () emitRuntime :: GenMod :> es => Eff es ()
emitRuntime = mfix \runtime -> do emitRuntime = mfix \runtime -> do
Wasm.emit [wat| Wasm.emit [wats|
(import "gyehoek" "write" (func $gh-write (param (ref eq)))) (import "gyehoek" "write" (func $gh-write (param (ref eq))))
(import "gyehoek" "to-bool" (func $gh-to-bool (param (ref eq))
(result i32)))
|] |]
-- cont stack -- cont stack
Wasm.defineType [wat| Wasm.defineType [wat|
+8 -3
View File
@@ -31,6 +31,7 @@ module Gyehoek.Wasm
, emit , emit
, renderModule , renderModule
, wat , wat
, wats
) )
where where
@@ -69,6 +70,7 @@ import Data.Data (Data)
import Data.Functor.Foldable (cata) import Data.Functor.Foldable (cata)
import Gyehoek.Sexp (sx) import Gyehoek.Sexp (sx)
import qualified Language.Sexp as SL import qualified Language.Sexp as SL
import Data.Foldable (traverse_)
newtype Module = MkModule { inner :: Vector Sexp } newtype Module = MkModule { inner :: Vector Sexp }
@@ -137,12 +139,12 @@ defineType = send . DefineType
defineGlobal :: GenMod :> es => Sexp -> Eff es Idx defineGlobal :: GenMod :> es => Sexp -> Eff es Idx
defineGlobal = send . DefineGlobal defineGlobal = send . DefineGlobal
emit :: GenMod :> es => Sexp -> Eff es () emit :: GenMod :> es => List Sexp -> Eff es ()
emit = send . Emit emit = traverse_ (send . Emit)
appendAndIncrement appendAndIncrement
:: State GenModState :> es :: State GenModState :> es
=> LensLike' ((,) _) GenModState Natural => LensLike' ((,) Natural) GenModState Natural
-> Sexp -> Sexp
-> Eff es Idx -> Eff es Idx
appendAndIncrement l s = appendAndIncrement l s =
@@ -197,3 +199,6 @@ expr = Gyehoek.Sexp.makeSxs
wat :: QuasiQuoter wat :: QuasiQuoter
wat = Gyehoek.Sexp.makeSx [|| id ||] wat = Gyehoek.Sexp.makeSx [|| id ||]
wats :: QuasiQuoter
wats = Gyehoek.Sexp.makeSxs [|| id ||]
+24 -54
View File
@@ -3,6 +3,10 @@
"gyehoek" "gyehoek"
"write" "write"
(func $gh-write (param (ref eq)))) (func $gh-write (param (ref eq))))
(import
"gyehoek"
"to-bool"
(func $gh-to-bool (param (ref eq)) (result i32)))
(type $heap-object (sub (struct (field $hash (mut i32))))) (type $heap-object (sub (struct (field $hash (mut i32)))))
(type $cont-type (func (param i32))) (type $cont-type (func (param i32)))
(type $cont-stack-type (array (mut (ref null $cont-type)))) (type $cont-stack-type (array (mut (ref null $cont-type))))
@@ -30,61 +34,27 @@
(param i32) (param i32)
(local (ref eq) (ref eq) (ref eq) (ref eq) (ref eq)) (local (ref eq) (ref eq) (ref eq) (ref eq) (ref eq))
(i32.const 3) (i32.const 3)
(i32.const 1)
i32.shl
ref.i31 ref.i31
(i31.get_s (ref.cast (ref i31))) (call $gh-to-bool)
(i32.const 1) (if
i32.shr_u (then
(i32.const 4) (global.get $arg-array)
(i32.const 1) (global.get 0)
i32.shl (i32.const 777)
ref.i31 (i32.const 1)
(i31.get_s (ref.cast (ref i31))) i32.shl
(i32.const 1) ref.i31
i32.shr_u (array.set $arg-array-type)
i32.mul (return_call $halt (i32.const 1)))
(i32.const 1) (else
i32.shl (global.get $arg-array)
ref.i31 (global.get 0)
(local.set 1) (i32.const 555)
(i32.const 2) (i32.const 1)
(i32.const 1) i32.shl
i32.shl ref.i31
ref.i31 (array.set $arg-array-type)
(i31.get_s (ref.cast (ref i31))) (return_call $halt (i32.const 1)))))
(i32.const 1)
i32.shr_u
(i32.const 5)
(i32.const 1)
i32.shl
ref.i31
(i31.get_s (ref.cast (ref i31)))
(i32.const 1)
i32.shr_u
i32.mul
(i32.const 1)
i32.shl
ref.i31
(local.set 2)
(local.get 1)
(i31.get_s (ref.cast (ref i31)))
(i32.const 1)
i32.shr_u
(local.get 2)
(i31.get_s (ref.cast (ref i31)))
(i32.const 1)
i32.shr_u
i32.add
(i32.const 1)
i32.shl
ref.i31
(local.set 3)
(global.get $arg-array)
(global.get 0)
(local.get 3)
(array.set $arg-array-type)
(return_call $halt (i32.const 1)))
(func (func
(export "main") (export "main")
(call $scm-entry (i32.const 0)) (call $scm-entry (i32.const 0))
+1
View File
@@ -16,6 +16,7 @@ import System.Environment.Blank (getEnvDefault)
disabled :: List String disabled :: List String
disabled = disabled =
[ "square" [ "square"
, "lambda"
] ]
main :: IO () main :: IO ()