Arc Forumnew | comments | leaders | submitlogin
Can you create a binary for arc apps ?
6 points by thaddeus 5628 days ago | 3 comments
Just curious... I read somewhere that scheme can compile to a binary. Wondering if there was a way to covert arc code to scheme to accomplish the same thing - or is this against arc ideology ?

Thanks, T.



8 points by fallintothis 5628 days ago | link

MzScheme has mzc, which does bytecode compilation. You can create something like standalone executables by embedding a copy of MzScheme into the module you're compiling. See http://download.plt-scheme.org/doc/372/html/mzc/ for more details.

Using some work done on Anarki (http://github.com/nex3/arc/blob/dca901c0cb59ebb533a511df3a84... and http://github.com/nex3/arc/blob/dca901c0cb59ebb533a511df3a84...), you could throw together something like:

test.arc

  (prn "Hello, world")
arc-exe-init.scm

  (module arc-exe-init mzscheme
    (provide (all-from-except mzscheme read read-syntax)))
test.arc.scm

  (module test.arc "arc-exe-init.scm"

    (require "ac.scm")
    (namespace-require "ac.scm")
    (require "brackets.scm")
    (use-bracket-readtable)

    (aload "arc.arc")
    (aload "libs.arc")

    (aload "test.arc") ; or the output of (acompile "test.arc") could work
  )
Then

  $ mzc --exe test test.arc.scm
  mzc version 360, Copyright (c) 2004-2006 PLT Scheme Inc. 
  [output to "test"]
  $ ./test
  Hello, world
The results you get hardly seem worth the effort. With this, you'd still need to distribute with some form of ac.scm et al.

  $ mv test ~/Desktop/
  $ cd ~/Desktop/
  $ ./test
  default-load-handler: cannot open input file: "~/Desktop/ac.scm" (No such file or directory; errno=2)

   === context ===
  #f::352: loop
There are probably smarter ways of compiling that don't have this hang-up, but in the end you'll still have kind of a large binary with MzScheme embedded.

If you just want the Scheme equivalent of Arc code, Arc already compiles down to Scheme. To get this compiled version (even if you can't run it directly without loading ac.scm, brackets.scm, arc.arc, and libs.arc):

  $ cat test.arc
  (prn "Hello, world")
  $ mzscheme -m -f as.scm
  Use (quit) to quit, (tl) to return here after an interrupt.
  arc> :a
  > (acompile "test.arc")
  Hello, world
  #t
  > ^D
  $ cat test.arc.scm
  (ar-funcall1 _prn "Hello, world")

-----

4 points by thaddeus 5627 days ago | link

Not to worried about about mzscheme being embedded as it's only 24MB. This is good to know... I plan to experiment with it a little so thanks for guidance.

T.

-----

2 points by tokipin 5628 days ago | link

hmmmm. i have no idea myself, but i'm curious how easy it may be since i'd like to have it as a feature in the little Arc-in-a-box i'm making

-----