Skip to content

Commit

Permalink
wip: new GHC JS backend
Browse files Browse the repository at this point in the history
  • Loading branch information
ncfavier committed Nov 5, 2023
1 parent e2b0392 commit 68b89c9
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 19 deletions.
3 changes: 2 additions & 1 deletion cabal.project
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
packages: glam
packages: glam ~/th-abstraction
allow-newer: base, template-haskell, deepseq
25 changes: 21 additions & 4 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
inputs.nixpkgs.url = "nixpkgs/nixpkgs-unstable";
inputs.nixpkgs2.url = "github:ncfavier/nixpkgs/ghc98";

outputs = { self, nixpkgs }: let
outputs = { self, nixpkgs, nixpkgs2 }: let
examples = [
{ name = "fibonacci"; description = "Fibonacci sequence"; }
{ name = "primes"; description = "Prime numbers"; }
Expand All @@ -26,6 +27,9 @@
overlays = [ haskellOverlay ];
};
hpkgs = pkgs.haskell.packages.ghc94;
pkgs2 = import nixpkgs2 {
inherit system;
};
in {
packages.${system} = rec {
default = glam;
Expand All @@ -34,7 +38,8 @@

glam-min-js = pkgs.runCommand "glam.min.js" {
nativeBuildInputs = with pkgs; [ closurecompiler ];
glam = "${glam-js}/bin/glam.jsexe";
glam = "${pkgs.pkgsCross.ghcjs.haskell.packages.ghc98.glam}/bin/glam.jsexe";
# glam = /home/n/git/glam/dist-newstyle/build/javascript-ghcjs/ghc-9.7.20230505/glam-0.0/x/glam/build/glam/glam.jsexe;
} ''
closure-compiler -O advanced -W quiet --jscomp_off undefinedVars \
--externs "$glam/all.js.externs" --js "$glam/all.js" --js_output_file "$out"
Expand Down Expand Up @@ -62,7 +67,7 @@
devShells.${system}.default = hpkgs.shellFor {
packages = ps: with ps; [ glam self.packages.${system}.glam-js ];
nativeBuildInputs = with pkgs; [
haskell.compiler.ghcjs
pkgs2.pkgsCross.ghcjs.buildPackages.haskell.compiler.ghc98
cabal-install
haskell-language-server
];
Expand Down
18 changes: 10 additions & 8 deletions glam/MainJS.hs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
{-# LANGUAGE ViewPatterns #-}
import GHCJS.Marshal
import GHCJS.Foreign.Callback
import Control.Monad
import GHC.JS.Prim
import GHC.JS.Foreign.Callback

import Glam.Run

foreign import javascript unsafe "glam = $1"
foreign import javascript unsafe "(f => glam = f)"
setGlam :: Callback a -> IO ()

main = do
setGlam =<< syncCallback1' \v -> do
Just input <- fromJSVal v
toJSVal $ either id unlines
$ runGlam
$ runFile "" input
setGlam <=< syncCallback1' $
pure . toJSString
. either id unlines
. runGlam
. runFile ""
. fromJSString
4 changes: 1 addition & 3 deletions glam/glam.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,9 @@ executable glam
ghc-options: -W
ghcjs-options: -dedupe

if impl(ghcjs)
if os(ghcjs)
main-is: MainJS.hs
cpp-options: -DGHCJS_BROWSER
build-depends:
ghcjs-base
else
main-is: Main.hs
build-depends:
Expand Down

0 comments on commit 68b89c9

Please sign in to comment.