Skip to content

Commit

Permalink
feat: compile frege files (#35)
Browse files Browse the repository at this point in the history
Local frege imports are resolved with .class files on the classpath.
For this we need to compile the frege files to java first and then run
the java compiler to compile to .class files.

However, since make mode is not yet completely implemented, the imports
are not resolved interactively. As a result, you may have to restart the
language server completely if you change the dependency of a module.
  • Loading branch information
tricktron committed Aug 2, 2022
1 parent 7dee1d7 commit 7e8e563
Show file tree
Hide file tree
Showing 15 changed files with 1,164 additions and 720 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ lib
bin
.vscode
.idea
frege-native-gen*
frege-native-gen*
.frege-ls
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = 3.3.0-alpha
version = 3.4.0-alpha
gradleVersion = 7.4.2
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import Compiler.passes.GlobalLam as GL()
import Compiler.passes.Easy as EA()
import Compiler.passes.Strict as SC()
import Compiler.passes.Final as FI()
import Compiler.passes.GenCode()
import Compiler.GenMeta as GM()
import Compiler.Classes()
import Compiler.Typecheck as TC()
import Compiler.grammar.Lexer as L()
Expand All @@ -29,6 +31,8 @@ import Compiler.common.Desugar
import Compiler.types.Tokens
import Compiler.enums.TokenID
import Compiler.types.Packs
import Compiler.Main(openFilePrinter, closePrinter, javac)
import frege.Version(version)
import Test.QuickCheck (Property, once, morallyDubiousIOProperty)

instance Show Message where
Expand All @@ -51,9 +55,19 @@ passes =
(liftStG EA.pass, "simplify expressions"), -- TRACE9
(liftStG GL.pass, "globalize anonymous lambdas"), -- TRACE8
(liftStG SC.pass, "strictness analysis"), -- TRACES
(liftStG FI.cleanSymtab, "clean up")
(openPrinter, "open file"),
(GM.genmeta, "generate meta data"), -- none
(GenCode.pass, "generate java code"), -- TRACEG
(closePrinter, "close java file"),
(javac, "run java compiler"),
(liftStG FI.cleanSymtab, "clean up"),
]

openPrinter = do
openFilePrinter ".java"
GM.banner version
return ("file", 1)

switchState :: Global -> StG Global
switchState new = do
old <- getST
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ standardCompileOptions :: Options
standardCompileOptions = Options
{
source = "-",
sourcePath = [ getEnvDefault "." "FREGE_LS_SOURCE_DIR" ],
dir = ".",
sourcePath = [ getEnvDefault "./src/main/frege" "FREGE_LS_SOURCE_DIR" ],
dir = "./.frege-ls/classes/frege",
path = [ getEnvDefault "" "FREGE_LS_EXTRA_CLASSPATH" ],
prefix = "",
encoding = Just "UTF-8",
Expand All @@ -26,6 +26,9 @@ standardCompileOptions = Options
HINTS,
VERBOSE,
IDEMODE,
IDETOKENS
IDETOKENS,
WITHCP,
RUNJAVAC,
MAKE
]
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
@SuppressWarnings("unused")
@Meta.FregePackage(
source="/Users/tricktron/github/master/frege-lsp-server/src/main/frege/ch/fhnw/thga/fregelanguageserver/compile/CompileGlobal.fr",
time=1659200052355L, jmajor=11, jminor=-1,
time=1659433739745L, jmajor=11, jminor=-1,
imps={
"ch.fhnw.thga.fregelanguageserver.compile.CompileOptions", "frege.compiler.common.CompilerOptions",
"frege.compiler.types.Global", "frege.Prelude", "frege.prelude.PreludeArrays", "frege.prelude.PreludeBase",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
@SuppressWarnings("unused")
@Meta.FregePackage(
source="/Users/tricktron/github/master/frege-lsp-server/src/main/frege/ch/fhnw/thga/fregelanguageserver/compile/CompileOptions.fr",
time=1659200051382L, jmajor=11, jminor=-1,
time=1659433738980L, jmajor=11, jminor=-1,
imps={
"frege.compiler.enums.Flags", "frege.compiler.types.Global", "frege.Prelude", "frege.prelude.PreludeArrays",
"frege.prelude.PreludeBase", "frege.prelude.PreludeDecimal", "frege.prelude.PreludeIO", "frege.prelude.PreludeList",
Expand Down Expand Up @@ -130,8 +130,8 @@ final public class CompileOptions {
) {
return PreludeBase.<String/*<Character>*/, String/*<Character>*/>maybe(
arg$1,
(Func.U<String/*<Character>*/, String/*<Character>*/>)((final Lazy<String/*<Character>*/> arg$12943) -> {
return arg$12943;
(Func.U<String/*<Character>*/, String/*<Character>*/>)((final Lazy<String/*<Character>*/> arg$12949) -> {
return arg$12949;
}),
PreludeBase._toMaybe(System.getenv(arg$2))
);
Expand All @@ -143,7 +143,7 @@ final public class CompileOptions {
PreludeBase.TList.DCons.<String/*<Character>*/>mk(
Thunk.<String/*<Character>*/>nested(
(Lazy<Lazy<String/*<Character>*/>>)(() -> CompileOptions.getEnvDefault(
Thunk.<String/*<Character>*/>lazy("."), "FREGE_LS_SOURCE_DIR"
Thunk.<String/*<Character>*/>lazy("./src/main/frege"), "FREGE_LS_SOURCE_DIR"
))
),
PreludeBase.TList.DList.<String/*<Character>*/>mk()
Expand All @@ -160,14 +160,26 @@ final public class CompileOptions {
Thunk.<Short>lazy(Flags.TFlag.IDEMODE),
PreludeBase.TList.DCons.<Short>mk(
Thunk.<Short>lazy(Flags.TFlag.IDETOKENS),
PreludeBase.TList.DList.<Short>mk()
PreludeBase.TList.DCons.<Short>mk(
Thunk.<Short>lazy(Flags.TFlag.WITHCP),
PreludeBase.TList.DCons.<
Short
>mk(
Thunk.<Short>lazy(
Flags.TFlag.RUNJAVAC
),
PreludeBase.TList.DList.<
Short
>mk()
)
)
)
)
)
)
)
),
".",
"./.frege-ls/classes/frege",
PreludeBase.TList.DCons.<String/*<Character>*/>mk(
Thunk.<String/*<Character>*/>nested(
(Lazy<Lazy<String/*<Character>*/>>)(() -> CompileOptions.getEnvDefault(
Expand Down
Loading

0 comments on commit 7e8e563

Please sign in to comment.