blue-sky
blue-sky

Reputation: 53876

How to run generated frege java code on jvm?

hello world in haskell frege :

hello.fr :

module Hello where

main args = do
    putStrLn "Hello, World!"

This code generates hello.java :

/*
  Source code is in UTF-8 encoding. The following symbols may appear, among others:
  α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ ς σ τ υ φ χ ψ ω « • ¦ » ∀ ∃ ∷ … → ← fi fl ƒ
  If you can't read this, you're out of luck. This code was generated with the frege compiler version 3.24.80
  from hello.fr Do not edit this file! Instead, edit the source file and recompile.
*/

import frege.run8.Func;
import frege.run8.Lazy;
import frege.run8.Thunk;
import frege.run.Kind;
import frege.run.RunTM;
import frege.runtime.Meta;
import frege.runtime.Phantom.RealWorld;
import frege.Prelude;
import frege.control.Category;
import frege.control.Semigroupoid;
import frege.java.IO;
import frege.java.Lang;
import frege.java.Util;
import frege.java.util.Regex;
import frege.prelude.Maybe;
import frege.prelude.PreludeArrays;
import frege.prelude.PreludeBase;
import frege.prelude.PreludeIO;
import frege.prelude.PreludeList;
import frege.prelude.PreludeMonad;
import frege.prelude.PreludeText;

@SuppressWarnings("unused")
@Meta.FregePackage(
  source="hello.fr", time=1470398249962L, jmajor=1, jminor=8,
  imps={
    "frege.Prelude", "frege.prelude.PreludeArrays", "frege.prelude.PreludeBase", "frege.prelude.PreludeIO",
    "frege.prelude.PreludeList", "frege.prelude.PreludeMonad", "frege.prelude.PreludeText", "frege.java.util.Regex"
  },
  nmss={"Prelude", "PreludeArrays", "PreludeBase", "PreludeIO", "PreludeList", "PreludeMonad", "PreludeText", "Regexp"},
  symas={}, symcs={}, symis={}, symts={},
  symvs={@Meta.SymV(offset=20, [email protected](pack="Hello", base="main"), stri="s(u)", sig=1, depth=1, rkind=49)},
  symls={},
  taus={
    @Meta.Tau(kind=2, suba=0, tcon={@Meta.QName(kind=0, pack="frege.prelude.PreludeBase", base="[]")}),
    @Meta.Tau(kind=2, suba=0, tcon={@Meta.QName(kind=0, pack="frege.prelude.PreludeBase", base="StringJ")}),
    @Meta.Tau(kind=2, suba=0, tcon={@Meta.QName(kind=0, pack="frege.prelude.PreludeBase", base="Char")}),
    @Meta.Tau(kind=0, suba=1, subb=2), @Meta.Tau(kind=0, suba=0, subb=3),
    @Meta.Tau(kind=2, suba=0, tcon={@Meta.QName(kind=0, pack="frege.prelude.PreludeBase", base="ST")}),
    @Meta.Tau(kind=2, suba=0, tcon={@Meta.QName(kind=0, pack="frege.prelude.PreludeBase", base="RealWorld")}),
    @Meta.Tau(kind=0, suba=5, subb=6),
    @Meta.Tau(kind=2, suba=0, tcon={@Meta.QName(kind=0, pack="frege.prelude.PreludeBase", base="()")}),
    @Meta.Tau(kind=0, suba=7, subb=8)
  },
  rhos={@Meta.Rho(rhofun=false, rhotau=4), @Meta.Rho(rhofun=false, rhotau=9), @Meta.Rho(sigma=0, rhotau=1)},
  sigmas={@Meta.Sigma(rho=0), @Meta.Sigma(rho=2)}, exprs={@Meta.Expr()}
)
final public class Hello  {





final public static Func.U<RealWorld, Short> $main(final Lazy<PreludeBase.TList<String/*<Character>*/>> arg$1) {
  return Prelude.putStrLn("Hello, World!");
}

  public static void main(final java.lang.String[] argv) {
    try {
      frege.run.RunTM.argv = argv;

        PreludeBase.TST.<Short>performUnsafe($main
               (Thunk.lazy(PreludeArrays.IListSource_JArray.<String/*<Character>*/>toList(argv)))
          ).call();
      frege.runtime.Runtime.stdout.get().close();
      frege.runtime.Runtime.stderr.get().close();

    } finally { frege.run.Concurrent.shutDownIfExists(); }
  }
}

I then compile the generated java code with no error :

javac -cp frege3.jar build/Hello.class

I then attempt to run the code :

cd build
java Hello

But this returns an error :

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: frege/run8/Lazy
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
    at java.lang.Class.getMethod0(Class.java:3018)
    at java.lang.Class.getMethod(Class.java:1784)
    at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: frege.run8.Lazy
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 7 more

How to run the generated frege java code on jvm ?

I'm using java8

Upvotes: 2

Views: 245

Answers (2)

Ingo
Ingo

Reputation: 36349

  1. You don't need an extra javac compilation, this is automatically done by the frege compiler (unless suppressed by a flag).
  2. Yes, there is a getting started document here: https://github.com/Frege/frege/wiki/Getting-Started

Upvotes: 0

Nicolas Filotto
Nicolas Filotto

Reputation: 45005

You need to add frege3.jar in your classpath also when you launch the command, so try this:

java -cp .:frege3.jar Hello

Assuming that frege3.jar and Hello.class are both in the current directory

Upvotes: 4

Related Questions