New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose dhall as javascript library via ghcjs WIP #58

Open
Profpatsch opened this Issue Nov 22, 2017 · 6 comments

Comments

Projects
None yet
2 participants
@Profpatsch
Member

Profpatsch commented Nov 22, 2017

I plan on playing a bit with compiling the compiler to JS, depending on the free-time I have.

A first (trivial) success:

On current nixpkgs master, nix-build -A haskell.packages.ghcjsHEAD.dhall gives us node binaries that basically work (you have to split the shebang line of the binary manually, then it works).

philip@katara ~/nixpkgs (current-build)> ~/tmp/dhall
{ foo = "bar" }   
{ foo : Text }

{ foo = "bar" }
philip@katara ~/nixpkgs (current-build)> file ~/tmp/dhall
/home/philip/tmp/dhall: a /nix/store/gbladqk26m3mhmaj147lfv5rpsiilfxb-nodejs-slim-6.11.5/bin/node script, UTF-8 Unicode text executable, with very long lines
philip@katara ~/nixpkgs (current-build)> head /nix/store/z8kb2pgilq0083van0faqghkj21p2m2q-dhall-1.8.0/bin/dhall
#!/nix/store/gbladqk26m3mhmaj147lfv5rpsiilfxb-nodejs-slim-6.11.5/bin/node var h$currentThread = null;
var h$stack = null;
var h$sp = 0;
var h$initStatic = [];
var h$staticThunks = {};
var h$staticThunksArr = [];
var h$regs = [];
var h$r1 = 0;
var h$r2 = 0;
var h$r3 = 0;
philip@katara ~/nixpkgs (current-build)> 
@Gabriel439

This comment has been minimized.

Show comment
Hide comment
@Gabriel439

Gabriel439 Nov 22, 2017

Contributor

Yeah, I already test drove using GHCJS on Dhall. If I remember correctly, the main issue I ran into was that the import system didn't work for URLs, but I suppose that it's still useful if people want to "Try Dhall" in the browser. The main limitation will be the absence of the Prelude

Contributor

Gabriel439 commented Nov 22, 2017

Yeah, I already test drove using GHCJS on Dhall. If I remember correctly, the main issue I ran into was that the import system didn't work for URLs, but I suppose that it's still useful if people want to "Try Dhall" in the browser. The main limitation will be the absence of the Prelude

@Profpatsch

This comment has been minimized.

Show comment
Hide comment
@Profpatsch

Profpatsch Nov 22, 2017

Member

The main limitation will be the absence of the Prelude

Since we already put the whole Haskell runtime as JS into the browser, supplying the Prelude should not be that much overhead, right?
I’d love to expose the library parts to Purescript and reuse the typechecker, parser and awesome error reporting. Maybe by going through yet another json export-/import step it’s possible get something like (very non-performant) Purescript import.

Member

Profpatsch commented Nov 22, 2017

The main limitation will be the absence of the Prelude

Since we already put the whole Haskell runtime as JS into the browser, supplying the Prelude should not be that much overhead, right?
I’d love to expose the library parts to Purescript and reuse the typechecker, parser and awesome error reporting. Maybe by going through yet another json export-/import step it’s possible get something like (very non-performant) Purescript import.

@Gabriel439

This comment has been minimized.

Show comment
Hide comment
@Gabriel439

Gabriel439 Nov 22, 2017

Contributor

Oh yeah, I forgot that we support customizable import resolution, so this should be doable if we use the Haskell API translated to JavaScript

Contributor

Gabriel439 commented Nov 22, 2017

Oh yeah, I forgot that we support customizable import resolution, so this should be doable if we use the Haskell API translated to JavaScript

@Profpatsch

This comment has been minimized.

Show comment
Hide comment
@Profpatsch

Profpatsch Nov 22, 2017

Member

Now we just need somebody to implement a zero-copy data view from GHCJS output to Purescript structures. :P

Member

Profpatsch commented Nov 22, 2017

Now we just need somebody to implement a zero-copy data view from GHCJS output to Purescript structures. :P

@Profpatsch

This comment has been minimized.

Show comment
Hide comment
@Profpatsch

Profpatsch Nov 25, 2017

Member

So, I’ve had some success and set up a repo.

philip@katara ~/c/h/dhall-js (master)> 
nix-build -I nixpkgs=/home/philip/nixpkgs release.nix  --option build-use-substitutes false -A small
/nix/store/mxlcim7c9binajhgny02my3fp3lzy310-export-test-small
philip@katara ~/c/h/dhall-js (master)> nix-shell -p nodejs --run "node ./result"
Object (fromList [("bar",String "Hello DhallJS!"),("foo",Number 23.0)])

^C⏎                           

philip@katara ~/c/h/dhall-js (master)> 
nix-build -I nixpkgs=/home/philip/nixpkgs release.nix  --option build-use-substitutes false -A small
/nix/store/mxlcim7c9binajhgny02my3fp3lzy310-export-test-small
philip@katara ~/c/h/dhall-js (master)> 
du -ha /nix/store/mxlcim7c9binajhgny02my3fp3lzy310-export-test-small
624K	/nix/store/mxlcim7c9binajhgny02my3fp3lzy310-export-test-small
philip@katara ~/c/h/dhall-js (master)> 
nix-build -I nixpkgs=/home/philip/nixpkgs release.nix  --option build-use-substitutes false -A orig
/nix/store/zmp0qarqnd3c1i7yva0jmfypn89smmv8-export-test
philip@katara ~/c/h/dhall-js (master)> 
du -ha /nix/store/zmp0qarqnd3c1i7yva0jmfypn89smmv8-export-test
2.3M	/nix/store/zmp0qarqnd3c1i7yva0jmfypn89smmv8-export-test

Member

Profpatsch commented Nov 25, 2017

So, I’ve had some success and set up a repo.

philip@katara ~/c/h/dhall-js (master)> 
nix-build -I nixpkgs=/home/philip/nixpkgs release.nix  --option build-use-substitutes false -A small
/nix/store/mxlcim7c9binajhgny02my3fp3lzy310-export-test-small
philip@katara ~/c/h/dhall-js (master)> nix-shell -p nodejs --run "node ./result"
Object (fromList [("bar",String "Hello DhallJS!"),("foo",Number 23.0)])

^C⏎                           

philip@katara ~/c/h/dhall-js (master)> 
nix-build -I nixpkgs=/home/philip/nixpkgs release.nix  --option build-use-substitutes false -A small
/nix/store/mxlcim7c9binajhgny02my3fp3lzy310-export-test-small
philip@katara ~/c/h/dhall-js (master)> 
du -ha /nix/store/mxlcim7c9binajhgny02my3fp3lzy310-export-test-small
624K	/nix/store/mxlcim7c9binajhgny02my3fp3lzy310-export-test-small
philip@katara ~/c/h/dhall-js (master)> 
nix-build -I nixpkgs=/home/philip/nixpkgs release.nix  --option build-use-substitutes false -A orig
/nix/store/zmp0qarqnd3c1i7yva0jmfypn89smmv8-export-test
philip@katara ~/c/h/dhall-js (master)> 
du -ha /nix/store/zmp0qarqnd3c1i7yva0jmfypn89smmv8-export-test
2.3M	/nix/store/zmp0qarqnd3c1i7yva0jmfypn89smmv8-export-test

@Gabriel439

This comment has been minimized.

Show comment
Hide comment
@Gabriel439

Gabriel439 Nov 27, 2017

Contributor

Nice job! :)

Contributor

Gabriel439 commented Nov 27, 2017

Nice job! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment