Skip to content

Commit

Permalink
Upgrade, Fix Frege/frege-repl#2
Browse files Browse the repository at this point in the history
  • Loading branch information
mmhelloworld committed Oct 6, 2013
1 parent ce3141f commit 2d97934
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 66 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ Thumbs.db
# Folder config file
Desktop.ini


*.versionsBackup
17 changes: 7 additions & 10 deletions frege-interpreter/pom.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>frege</groupId>
<artifactId>frege-scripting</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
<version>1.0.0</version>
</parent>
<artifactId>frege-interpreter</artifactId>
<packaging>jar</packaging>
Expand All @@ -20,7 +19,6 @@
<plugin>
<groupId>com.theoryinpractise.frege</groupId>
<artifactId>frege-maven-plugin</artifactId>
<version>${frege.plugin.version}</version>
<executions>
<execution>
<id>compile</id>
Expand All @@ -33,7 +31,7 @@
<configuration>
<inline>true</inline>
<hints>true</hints>
<includeStale>false</includeStale>
<includeStale>false</includeStale>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -61,14 +59,13 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jdt.core.compiler</groupId>
<artifactId>ecj</artifactId>
<version>4.2.2</version>
<groupId>org.eclipse.jdt.core.compiler</groupId>
<artifactId>ecj</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>memory-javac</artifactId>
<version>1.0-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ data MemoryJavaCompiler = native frege.memoryjavac.MemoryJavaCompiler where
native new :: ClassLoader -> MutableIO (JMap String ByteArr) -> IOMutable MemoryJavaCompiler
native compile :: MutableIO MemoryJavaCompiler -> String -> String -> IOMutable JavaCompilationInfo
native lastCompilation :: MutableIO MemoryJavaCompiler -> IOMutable JavaCompilationInfo
native classLoader :: MutableIO MemoryJavaCompiler -> IO ClassLoader
native classLoader :: MutableIO MemoryJavaCompiler -> IO URLClassLoader

data JavaCompilationInfo = native frege.memoryjavac.CompilationInfo where
native isSuccess :: MutableIO JavaCompilationInfo -> IO Bool
Expand Down Expand Up @@ -266,9 +266,7 @@ compile src paths libpaths !ow !jw !compiler !predefs !moduleName !modulePrelude
let flags = Flags.fromList [IDE]
let steps = passes jw moduleName compiler
loader <- compiler.classLoader
urlArr <- URLArray.new 0
urlClassLoader <- URLClassLoader.new urlArr loader
runcompiler src predefs paths flags "." libpaths "" ow urlClassLoader steps moduleName modulePrelude
runcompiler src predefs paths flags "." libpaths "" ow loader steps moduleName modulePrelude

isDefined :: [DefinitionT] -> Definition -> Bool
isDefined defs (_@TypDcl{name=x}) = isJust . find (matching x) $ defs
Expand Down Expand Up @@ -323,9 +321,6 @@ getSymbolType _ _ = ""
showSymbols :: Global -> [String]
showSymbols g = map (EU.label g) $ getSymbols g.thisTab

--existsVarSymbol name (s@(SymV {name=x})) | traceLn $ "SymV: " ++ name ++ x.base = x.base == name
--existsVarSymbol name (s@(SymL{name=x})) | traceLn $ "SymL: " ++ name ++ x.base = x.base == name
--existsVarSymbol _ _ | traceLn "Other type of symbol!" = false
existsVarSymbol name SymV{name=x} = x.base == name
existsVarSymbol name SymL{name=x} = x.base == name
existsVarSymbol _ _ = false
Expand Down Expand Up @@ -404,12 +399,12 @@ isVariable !g SymL{alias} = maybe false (isVariable g) $ alias.findit g
isVariable _ _ = false

isIO :: Global -> Symbol -> Bool
isIO !g SymV{typ} = case (U.unAlias g $ RhoT.tau typ.rho) of
TApp (TCon {name}) _ = name.nicer g == "IO"
_ = false
isIO g SymV{typ} = "ST RealWorld" `isPrefix` nice typ g where
isPrefix = isPrefixOf `on` toList
f `on` g = \x \y -> f (g x) (g y)
isIO g SymL{alias} = maybe false (isIO g) $ alias.findit g
isIO _ _ = false

isString !g SymV{typ} = case (U.unAlias g $ RhoT.tau typ.rho) of
TCon {name} = name.nicer g == "String"
_ = false
isString _ _ = false

isString g SymV{typ} = nice typ g == "StringJ Char"
isString g SymL{alias} = maybe false (isString g) $ alias.findit g
isString g _ = false
11 changes: 5 additions & 6 deletions frege-script-engine/pom.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>frege</groupId>
<artifactId>frege-scripting</artifactId>
<version>1.0-SNAPSHOT</version>
<version>1.0.0</version>
</parent>
<artifactId>frege-script-engine</artifactId>
<name>frege-script-engine</name>
Expand All @@ -32,7 +32,7 @@
<configuration>
<inline>true</inline>
<hints>true</hints>
<includeStale>false</includeStale>
<includeStale>false</includeStale>
</configuration>
</plugin>
</plugins>
Expand All @@ -53,12 +53,11 @@
<dependency>
<groupId>org.eclipse.jdt.core.compiler</groupId>
<artifactId>ecj</artifactId>
<version>3.7.2</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>frege-interpreter</artifactId>
<version>1.0-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module frege.scriptengine.FregeScriptEngine where

import frege.compiler.Data (Symbol)
import frege.interpreter.FregeScriptCompiler
import frege.interpreter.FregeInterpreter
import frege.java.Net
Expand All @@ -19,13 +20,10 @@ data Bindings = mutable native javax.script.Bindings where

initScript = "import scripting.Setting"

native curThread Thread.currentThread :: () -> IO Thread
native curClassLoader getContextClassLoader :: Thread -> IO ClassLoader

initInterpreterState :: ScriptContext -> IO InterpreterState
initInterpreterState session = do
urlarr <- URLArray.new 0
loader <- curThread () >>= curClassLoader >>= URLClassLoader.new urlarr
loader <- ClassLoader.current >>= URLClassLoader.new urlarr
classesMaybe <- session.getAttribute "classes" ScriptContext.engineScope
classes <- maybe (HashMap.new () :: IOMutable (JMap String ByteArr)) asClassesMap classesMaybe
strMaybe <- session.getAttribute "script" ScriptContext.engineScope
Expand Down Expand Up @@ -108,6 +106,9 @@ fetchVariableValue var g context = do
Nothing -> return $ Right Nothing
Just symbol -> fetchSymbolValue var symbol g context

fetchSymbolValue var SymL{alias} g context =
maybe (return $ Right Nothing) f $ alias.findit g where
f s = fetchSymbolValue s.name.base s g context
fetchSymbolValue var symbol g context | isVariable g symbol = do
state <- Interpreter.get
bindingseither <- liftIO $ getBindings g.sub.loader
Expand Down Expand Up @@ -171,10 +172,4 @@ native asString "(java.lang.String)" :: Object -> IO String
native asURLClassLoader "(java.net.URLClassLoader)" :: Object -> IO URLClassLoader
native asBindingsMap "(java.util.Map)" :: Object -> IOMutable (JMap String Object)

main _ = do
context <- SimpleScriptContext.new ()
res <- load "module t.Hello where {x = 4;}" context
case res of
Left errs -> println errs
_ -> println "successful"

22 changes: 15 additions & 7 deletions jfrege-script-engine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
<parent>
<groupId>frege</groupId>
<artifactId>frege-scripting</artifactId>
<version>1.0-SNAPSHOT</version>
<version>1.0.0</version>
</parent>
<groupId>frege</groupId>
<artifactId>jfrege-script-engine</artifactId>
<version>1.0-SNAPSHOT</version>
<name>jfrege-script-engine</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand All @@ -20,11 +19,20 @@
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version>
<configuration>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>distro-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineFactory;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import javax.script.SimpleBindings;

Expand All @@ -21,6 +22,7 @@
import frege.prelude.PreludeBase.TList;
import frege.prelude.PreludeBase.TList.DCons;
import frege.prelude.PreludeBase.TMaybe;
import frege.runtime.Delayed;
import frege.runtime.Lambda;
import frege.runtime.Lazy;
import frege.scriptengine.FregeScriptEngine;
Expand Down Expand Up @@ -63,7 +65,14 @@ public Object eval(final String script, final ScriptContext context)
final List<String> errMsgs = toJavaList(errs);
throw new ScriptException(errMsgs.toString());
} else {
return getRightMaybe(intpRes);
final Object evalRes = getRightMaybe(intpRes);
final Object result;
if (evalRes instanceof Delayed) {
result = ((Delayed) evalRes).result().forced();
} else {
result = evalRes;
}
return result;
}
}

Expand Down Expand Up @@ -206,11 +215,12 @@ public CompiledScript compile(final Reader reader) throws ScriptException {
@Override
public void put(final String key, final Object value) {
final String[] nameAndType = key.split("::");
if (nameAndType.length == 0)
if (nameAndType.length < 2) {
super.put(key, value);
return;
}
final String name = nameAndType[0].trim();
final String type = nameAndType.length > 1 ? nameAndType[1].trim()
: "Object";
final String type = nameAndType[1].trim();
final String script = (String) context.getAttribute("script",
ScriptContext.ENGINE_SCOPE);
final String newScript = String.format(
Expand All @@ -221,5 +231,4 @@ public void put(final String key, final Object value) {
super.put(name, value);
}


}
15 changes: 6 additions & 9 deletions memory-javac/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>frege</groupId>
<artifactId>frege-scripting</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
<groupId>frege</groupId>
<artifactId>frege-scripting</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>memory-javac</artifactId>
<packaging>jar</packaging>

<build>
<pluginManagement>
<pluginManagement>
<plugins>
<!--For Eclipse m2e -->
<plugin>
Expand Down Expand Up @@ -66,9 +64,8 @@
<version>${frege.plugin.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jdt.core.compiler</groupId>
<artifactId>ecj</artifactId>
<version>4.2.2</version>
<groupId>org.eclipse.jdt.core.compiler</groupId>
<artifactId>ecj</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public CompilationInfo lastCompilation() {
return lastCompilation;
}

public ClassLoader classLoader() {
public URLClassLoader classLoader() {
return classLoader;
}

Expand Down
11 changes: 9 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>frege</groupId>
<artifactId>frege-scripting</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<version>1.0.0</version>
<name>frege-scripting</name>
<url>https://github.com/Frege/frege-scripting</url>
<modules>
Expand All @@ -17,6 +18,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<frege.version>frege-3.21.232-g7b05453</frege.version>
<frege.plugin.version>1.0.5</frege.plugin.version>
<ecj.version>4.2.2</ecj.version>
</properties>
<build>
<plugins>
Expand Down Expand Up @@ -73,6 +75,11 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.eclipse.jdt.core.compiler</groupId>
<artifactId>ecj</artifactId>
<version>${ecj.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
Expand Down

0 comments on commit 2d97934

Please sign in to comment.