Skip to content

Commit

Permalink
Update for Frege Summer 2013 version, Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mmhelloworld committed Sep 2, 2013
1 parent e9e51c2 commit 691e832
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
16 changes: 14 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
<modelVersion>4.0.0</modelVersion>
<groupId>frege</groupId>
<artifactId>frege-repl</artifactId>
<version>1.0-SNAPSHOT</version>
<version>1.0.0</version>
<packaging>jar</packaging>
<name>frege-repl</name>
<url>https://github.com/Frege/frege-repl</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.sourceDirectory>src/main/frege</project.build.sourceDirectory>
<frege.version>3.21.190-g714a7cc</frege.version>
</properties>
<build>
<pluginManagement>
Expand Down Expand Up @@ -112,10 +113,21 @@
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<finalName>frege-repl-${version}</finalName>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand All @@ -134,7 +146,7 @@
<dependency>
<groupId>frege</groupId>
<artifactId>frege</artifactId>
<version>3.21.107-g4bd09eb</version>
<version>${frege.version}</version>
</dependency>
<dependency>
<groupId>frege</groupId>
Expand Down
10 changes: 4 additions & 6 deletions src/main/assembly/assembly.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>bin</id>
<id>jar-with-dependencies</id>
<formats>
<format>tar.gz</format>
<format>tar.bz2</format>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</assembly>
</assembly>
21 changes: 11 additions & 10 deletions src/main/frege/frege/repl/FregeRepl.fr
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ evalScript Browse = do
if isEmpty . trim $ interpreterState.currentScript then
return NoOutput
else
evalScript $ BrowseModule state.options.moduleName
evalScript $ BrowseModule state.moduleName

evalScript (Type expr) = Repl.get >>= Repl . lift . interpret where
interpret replState = do
Expand All @@ -95,7 +95,7 @@ evalScript (Load (urlSpec@#.*?://#)) = do
let update res = case res of
ReplSuccess message -> updateExternalScript urlSpec >> return res
otherwise -> return res
either handleMalformedURLException (\url -> evalURL url >>= update) urle
evalURL urle >>= update

evalScript (Load filePath) = do
scriptMay <- liftIO $ safeSlurp filePath
Expand Down Expand Up @@ -166,12 +166,10 @@ showVariable source var g = do
showSymbol source var symbol g | isVariable g symbol = do
state <- Interpreter.get
if isString g symbol then do
v <- liftIO $ fieldValue state.options.moduleName var g.sub.loader
v <- liftIO $ fieldValue state.moduleName var g.sub.loader
case v of
Left err -> return $ Left [err.getMessage]
Right value -> do
s <- liftIO $ value.toString
return $ Right s
Right value -> return . Right $ toString value
else do
Interpreter.put $ state.{currentScript <- (++ newLine ++ var ++ " = " ++ source)}
let showScript = buildShowScript var g symbol
Expand Down Expand Up @@ -334,20 +332,24 @@ initInterpreterState = do
urlarr <- URLArray.new 0
loader <- ClassLoader.current >>= URLClassLoader.new urlarr
classes <- HashMap.new ()
time <- currentTimeMillis ()
let history = ""
let options = Options {moduleName = "script.Main"}
let interpreterState = InterpreterState {
loader = loader,
classes = classes,
options = options,
currentScript = ""
moduleName = "script.Main" ++ show time,
currentScript = "",
modulePrelude = ""
}
return interpreterState

vmVendor = maybe "" id $ System.getProperty "java.vm.vendor"
vmName = maybe "" id $ System.getProperty "java.vm.name"
javaVersion = maybe "" id $ System.getProperty "java.version"

pure native toString :: Object -> String
native currentTimeMillis java.lang.System.currentTimeMillis :: () -> IO Long

welcome = "Welcome to Frege " ++ version ++ " (" ++ vmVendor ++ " " ++ vmName ++
", " ++ javaVersion ++ ")"

Expand All @@ -367,4 +369,3 @@ main _ = do
interpreterState <- initInterpreterState
evalInterpreter (runRepl (repl console) initReplState) interpreterState


0 comments on commit 691e832

Please sign in to comment.