[noop] 3 new revisions pushed by aeagle22206 on 2010-06-27 20:25 GMT

1 view
Skip to first unread message

no...@googlecode.com

unread,
Jun 27, 2010, 4:26:15 PM6/27/10
to noop-c...@googlegroups.com
3 new revisions:

Revision: 1d4360350e
Author: Alex Eagle <alex...@google.com>
Date: Sat May 8 14:36:45 2010
Log: Initial skeleton for a new interpreter, written in Java, which will
wo...
http://code.google.com/p/noop/source/detail?r=1d4360350e

Revision: 5c93932b4c
Author: Alex Eagle <alex...@google.com>
Date: Tue May 18 22:10:03 2010
Log: Load serialized libraries from XML to find the interpreter entry point
http://code.google.com/p/noop/source/detail?r=5c93932b4c

Revision: 3c3769ac2e
Author: Alex Eagle <alex...@google.com>
Date: Sun Jun 27 13:24:51 2010
Log: Composite visitor to allow verbose output while interpreting. Start
po...
http://code.google.com/p/noop/source/detail?r=3c3769ac2e

==============================================================================
Revision: 1d4360350e
Author: Alex Eagle <alex...@google.com>
Date: Sat May 8 14:36:45 2010
Log: Initial skeleton for a new interpreter, written in Java, which will
work with the new semantic model representation.
http://code.google.com/p/noop/source/detail?r=1d4360350e

Added:
/interpreter/pom.xml
/interpreter/src/main/java/noop/interpreter/Interpreter.java
/interpreter/src/main/java/noop/interpreter/InterpreterMain.java
/interpreter/src/main/java/noop/interpreter/config/CommandLineOptions.java
/interpreter/src/main/java/noop/interpreter/config/ConfigModule.java
/interpreter/src/main/java/noop/interpreter/config/Error.java
/interpreter/src/main/java/noop/interpreter/config/InterpreterOptions.java
/interpreter/src/main/java/noop/interpreter/config/Output.java
/interpreter/src/test/java/noop/interpreter/InterpreterMainTest.java
/interpreter/src/test/java/noop/interpreter/InterpreterSystemTest.java
Modified:
/core/pom.xml
/pom.xml

=======================================
--- /dev/null
+++ /interpreter/pom.xml Sat May 8 14:36:45 2010
@@ -0,0 +1,44 @@
+<!--
+ ~ Copyright 2010 Google Inc.
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<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>
+ <parent>
+ <groupId>com.google.noop</groupId>
+ <artifactId>noop</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>noop-interpreter</artifactId>
+ <name>Noop Interpreter</name>
+ <description>Directly executes Noop source code.</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>args4j</groupId>
+ <artifactId>args4j</artifactId>
+ <version>2.0.8</version>
+ </dependency>
+ <dependency>
+ <groupId>com.google.inject</groupId>
+ <artifactId>guice</artifactId>
+ <version>2.0</version>
+ </dependency>
+ </dependencies>
+</project>
=======================================
--- /dev/null
+++ /interpreter/src/main/java/noop/interpreter/Interpreter.java Sat May 8
14:36:45 2010
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package noop.interpreter;
+
+import com.google.inject.Inject;
+
+/**
+ * @author alex...@google.com (Alex Eagle)
+ */
+public class Interpreter {
+
+ @Inject
+ public Interpreter() {
+ }
+
+ public int run() {
+ return 0;
+ }
+}
=======================================
--- /dev/null
+++ /interpreter/src/main/java/noop/interpreter/InterpreterMain.java Sat
May 8 14:36:45 2010
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package noop.interpreter;
+
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import noop.interpreter.config.CommandLineOptions;
+import noop.interpreter.config.ConfigModule;
+import org.kohsuke.args4j.CmdLineException;
+
+/**
+ * @author alex...@google.com (Alex Eagle)
+ */
+public class InterpreterMain {
+ public static int exitCodeForTesting;
+ private static boolean testing = false;
+
+ public static void disableSystemExitForTesting() {
+ testing = true;
+ }
+
+ public static void main(String[] args) throws Exception {
+ try {
+ CommandLineOptions options =
CommandLineOptions.fromCmdLineArgs(args);
+ Injector injector = Guice.createInjector(new ConfigModule(options));
+ exit(injector.getInstance(Interpreter.class).run());
+ } catch (CmdLineException e) {
+ exit(1);
+ }
+ }
+
+ private static void exit(int exitCode) {
+ if (testing) {
+ exitCodeForTesting = exitCode;
+ } else {
+ System.exit(exitCode);
+ }
+ }
+}
=======================================
--- /dev/null
+++
/interpreter/src/main/java/noop/interpreter/config/CommandLineOptions.java
Sat May 8 14:36:45 2010
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package noop.interpreter.config;
+
+import org.kohsuke.args4j.Argument;
+import org.kohsuke.args4j.CmdLineException;
+import org.kohsuke.args4j.CmdLineParser;
+
+/**
+ * @author alex...@google.com (Alex Eagle)
+ */
+public class CommandLineOptions implements InterpreterOptions {
+
+ @Argument(usage = "Entry point of the application to execute", metaVar
= "entryPoint", required = true)
+ public String entryPoint;
+
+ public static CommandLineOptions fromCmdLineArgs(String[] args) throws
CmdLineException {
+ CommandLineOptions options = new CommandLineOptions();
+ CmdLineParser parser = new CmdLineParser(options);
+ try {
+ parser.parseArgument(args);
+ } catch (CmdLineException e) {
+ System.err.println("Invalid command line: " + e.getMessage());
+ parser.printUsage(System.err);
+ throw e;
+ }
+ return options;
+ }
+
+}
=======================================
--- /dev/null
+++ /interpreter/src/main/java/noop/interpreter/config/ConfigModule.java
Sat May 8 14:36:45 2010
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package noop.interpreter.config;
+
+import com.google.inject.AbstractModule;
+
+import java.io.PrintStream;
+
+/**
+ * @author alex...@google.com (Alex Eagle)
+ */
+public class ConfigModule extends AbstractModule {
+
+ private final InterpreterOptions options;
+
+ public ConfigModule(InterpreterOptions options) {
+ this.options = options;
+ }
+
+ @Override
+ protected void configure() {
+
bind(PrintStream.class).annotatedWith(Output.class).toInstance(System.out);
+
bind(PrintStream.class).annotatedWith(Error.class).toInstance(System.err);
+ bind(InterpreterOptions.class).toInstance(options);
+ }
+}
=======================================
--- /dev/null
+++ /interpreter/src/main/java/noop/interpreter/config/Error.java Sat May
8 14:36:45 2010
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package noop.interpreter.config;
+
+import com.google.inject.BindingAnnotation;
+
+import java.lang.annotation.Retention;
+
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * Binding for printing errors.
+ * @author alex...@google.com (Alex Eagle)
+ */
+@Retention(RUNTIME)
+@BindingAnnotation
+public @interface Error {}
=======================================
--- /dev/null
+++
/interpreter/src/main/java/noop/interpreter/config/InterpreterOptions.java
Sat May 8 14:36:45 2010
@@ -0,0 +1,23 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package noop.interpreter.config;
+
+/**
+ * @author alex...@google.com (Alex Eagle)
+ */
+public interface InterpreterOptions {
+}
=======================================
--- /dev/null
+++ /interpreter/src/main/java/noop/interpreter/config/Output.java Sat May
8 14:36:45 2010
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package noop.interpreter.config;
+
+import com.google.inject.BindingAnnotation;
+
+import java.lang.annotation.Retention;
+
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * Binding for printing informational outputs.
+ * @author alex...@google.com (Alex Eagle)
+ */
+@Retention(RUNTIME)
+@BindingAnnotation
+public @interface Output {}
=======================================
--- /dev/null
+++ /interpreter/src/test/java/noop/interpreter/InterpreterMainTest.java
Sat May 8 14:36:45 2010
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package noop.interpreter;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author alex...@google.com (Alex Eagle)
+ */
+public class InterpreterMainTest {
+ @Before public void setUp() {
+ InterpreterMain.disableSystemExitForTesting();
+ }
+
+ @Test public void shouldExitWithFailingExitCodeWhenGivenBadCommandLine()
throws Exception {
+ InterpreterMain.main(new String[]{});
+ assertEquals(1, InterpreterMain.exitCodeForTesting);
+ }
+
+}
=======================================
--- /dev/null
+++ /interpreter/src/test/java/noop/interpreter/InterpreterSystemTest.java
Sat May 8 14:36:45 2010
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package noop.interpreter;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author alex...@google.com (Alex Eagle)
+ */
+public class InterpreterSystemTest {
+ @Before public void setUp() {
+ InterpreterMain.disableSystemExitForTesting();
+ }
+
+ @Test public void shouldRunTheHelloWorldProgram() throws Exception {
+ InterpreterMain.main(new String[] {"Say Hello"});
+ assertEquals(0, InterpreterMain.exitCodeForTesting);
+ }
+}
=======================================
--- /core/pom.xml Fri Apr 23 03:26:30 2010
+++ /core/pom.xml Sat May 8 14:36:45 2010
@@ -15,12 +15,6 @@

<dependencies>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.7</version>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>com.google.collections</groupId>
<artifactId>google-collections</artifactId>
<version>0.9</version>
=======================================
--- /pom.xml Sat May 8 13:26:32 2010
+++ /pom.xml Sat May 8 14:36:45 2010
@@ -44,11 +44,21 @@
<!-- tests failing
<module>translator</module>
-->
+ <module>interpreter</module>
</modules>

<properties>
<mavenVersion>2.1</mavenVersion>
</properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.7</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>

<build>
<plugins>

==============================================================================
Revision: 5c93932b4c
Author: Alex Eagle <alex...@google.com>
Date: Tue May 18 22:10:03 2010
Log: Load serialized libraries from XML to find the interpreter entry point
http://code.google.com/p/noop/source/detail?r=5c93932b4c

Modified:
/core/pom.xml
/core/src/main/java/noop/model/Project.java
/interpreter/pom.xml
/interpreter/src/main/java/noop/interpreter/Interpreter.java
/interpreter/src/main/java/noop/interpreter/config/CommandLineOptions.java
/interpreter/src/main/java/noop/interpreter/config/InterpreterOptions.java
/interpreter/src/test/java/noop/interpreter/InterpreterSystemTest.java
/pom.xml

=======================================
--- /core/pom.xml Sat May 8 14:36:45 2010
+++ /core/pom.xml Tue May 18 22:10:03 2010
@@ -15,11 +15,6 @@

<dependencies>
<dependency>
- <groupId>com.google.collections</groupId>
- <artifactId>google-collections</artifactId>
- <version>0.9</version>
- </dependency>
- <dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.4</version>
=======================================
--- /core/src/main/java/noop/model/Project.java Sun Apr 25 01:04:21 2010
+++ /core/src/main/java/noop/model/Project.java Tue May 18 22:10:03 2010
@@ -25,6 +25,7 @@
import java.util.List;

/**
+ * TODO: seems like the library could be the top level entity.
* @author alex...@google.com (Alex Eagle)
*/
public class Project extends LanguageElement<Project> {
=======================================
--- /interpreter/pom.xml Sat May 8 14:36:45 2010
+++ /interpreter/pom.xml Tue May 18 22:10:03 2010
@@ -31,6 +31,16 @@

<dependencies>
<dependency>
+ <groupId>com.google.noop</groupId>
+ <artifactId>noop-core</artifactId>
+ <version>${version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.thoughtworks.xstream</groupId>
+ <artifactId>xstream</artifactId>
+ <version>1.3.1</version>
+ </dependency>
+ <dependency>
<groupId>args4j</groupId>
<artifactId>args4j</artifactId>
<version>2.0.8</version>
=======================================
--- /interpreter/src/main/java/noop/interpreter/Interpreter.java Sat May 8
14:36:45 2010
+++ /interpreter/src/main/java/noop/interpreter/Interpreter.java Tue May 18
22:10:03 2010
@@ -17,17 +17,54 @@
package noop.interpreter;

import com.google.inject.Inject;
+import com.thoughtworks.xstream.XStream;
+import noop.graph.Controller;
+import noop.graph.VertexCreatingVisitor;
+import noop.graph.Workspace;
+import noop.interpreter.config.InterpreterOptions;
+import noop.model.Block;
+import noop.model.Library;
+import noop.model.Project;
+import noop.operations.NewProjectOperation;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.util.UUID;

/**
* @author alex...@google.com (Alex Eagle)
*/
public class Interpreter {
+ private final InterpreterOptions options;

@Inject
- public Interpreter() {
+ public Interpreter(InterpreterOptions options) {
+ this.options = options;
}

- public int run() {
+ public int run() throws FileNotFoundException {
+ Workspace workspace = new Workspace();
+ Controller controller = new Controller(workspace, new
VertexCreatingVisitor());
+
+ Project project = new Project("runtime", "", "");
+ for (String libraryPath : options.getLibraryPaths()) {
+ XStream xStream = new XStream();
+ project.addLibrary((Library) xStream.fromXML(new FileReader(new
File(libraryPath))));
+ }
+ controller.addProject(new NewProjectOperation(project));
+
+ Library mainLib =
workspace.lookupLibrary(UUID.fromString(options.getMainLib()));
+ if (mainLib == null) {
+ throw new IllegalArgumentException("No library found with id " +
options.getMainLib());
+ }
+
+ Block entryPoint = (Block)
mainLib.getElements().get(options.getEntryPoint());
+ if (entryPoint == null) {
+ throw new IllegalArgumentException("No block found named " +
options.getEntryPoint());
+ }
+
+ System.out.println("entryPoint to execute: " + entryPoint.name);
return 0;
}
}
=======================================
---
/interpreter/src/main/java/noop/interpreter/config/CommandLineOptions.java
Sat May 8 14:36:45 2010
+++
/interpreter/src/main/java/noop/interpreter/config/CommandLineOptions.java
Tue May 18 22:10:03 2010
@@ -19,14 +19,26 @@
import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
+import org.kohsuke.args4j.Option;
+
+import java.util.List;

/**
* @author alex...@google.com (Alex Eagle)
*/
public class CommandLineOptions implements InterpreterOptions {

- @Argument(usage = "Entry point of the application to execute", metaVar
= "entryPoint", required = true)
- public String entryPoint;
+ @Argument(metaVar = "mainLib", required = true, index = 0,
+ usage = "Library containing the entry point")
+ private String mainLib;
+
+ @Argument(metaVar = "entryPoint", required = true, index = 1,
+ usage = "Entry point of the application to execute")
+ private Integer entryPoint;
+
+ @Option(name = "-lib", aliases = "--library",
+ usage = "A relative paths to a library to load. May be used
multiple times.")
+ private List<String> libraryPaths;

public static CommandLineOptions fromCmdLineArgs(String[] args) throws
CmdLineException {
CommandLineOptions options = new CommandLineOptions();
@@ -34,11 +46,26 @@
try {
parser.parseArgument(args);
} catch (CmdLineException e) {
- System.err.println("Invalid command line: " + e.getMessage());
+ System.err.printf("Invalid command line: %s\n\nUsage:\n",
e.getMessage());
+ parser.setUsageWidth(100);
parser.printUsage(System.err);
throw e;
}
return options;
}

-}
+ @Override
+ public Integer getEntryPoint() {
+ return entryPoint;
+ }
+
+ @Override
+ public String getMainLib() {
+ return mainLib;
+ }
+
+ @Override
+ public List<String> getLibraryPaths() {
+ return libraryPaths;
+ }
+}
=======================================
---
/interpreter/src/main/java/noop/interpreter/config/InterpreterOptions.java
Sat May 8 14:36:45 2010
+++
/interpreter/src/main/java/noop/interpreter/config/InterpreterOptions.java
Tue May 18 22:10:03 2010
@@ -16,8 +16,15 @@

package noop.interpreter.config;

+import java.util.List;
+
/**
* @author alex...@google.com (Alex Eagle)
*/
public interface InterpreterOptions {
-}
+ Integer getEntryPoint();
+
+ String getMainLib();
+
+ List<String> getLibraryPaths();
+}
=======================================
--- /interpreter/src/test/java/noop/interpreter/InterpreterSystemTest.java
Sat May 8 14:36:45 2010
+++ /interpreter/src/test/java/noop/interpreter/InterpreterSystemTest.java
Tue May 18 22:10:03 2010
@@ -30,7 +30,13 @@
}

@Test public void shouldRunTheHelloWorldProgram() throws Exception {
- InterpreterMain.main(new String[] {"Say Hello"});
+ InterpreterMain.main(new String[] {
+ // TODO: fix absolute paths on my machine!
+ "-lib", "/Users/alexeagle/IdeaProjects/noop/dumps/com.google.noop/Noop/io.xml",
+ "-lib", "/Users/alexeagle/IdeaProjects/noop/dumps/com.google.noop/Noop/lang.xml",
+ "-lib", "/Users/alexeagle/IdeaProjects/noop/dumps/com.example/Hello
World/hello.xml",
+ "dcf83cb3-9457-4695-b4b6-94389fef5a5b", "1"
+ });
assertEquals(0, InterpreterMain.exitCodeForTesting);
}
}
=======================================
--- /pom.xml Sat May 8 14:36:45 2010
+++ /pom.xml Tue May 18 22:10:03 2010
@@ -53,6 +53,11 @@

<dependencies>
<dependency>
+ <groupId>com.google.collections</groupId>
+ <artifactId>google-collections</artifactId>
+ <version>0.9</version>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>

==============================================================================
Revision: 3c3769ac2e
Author: Alex Eagle <alex...@google.com>
Date: Sun Jun 27 13:24:51 2010
Log: Composite visitor to allow verbose output while interpreting. Start
porting existing interpreter to Java.
http://code.google.com/p/noop/source/detail?r=3c3769ac2e

Added:
/core/src/main/java/noop/graph/CompositeModelVisitor.java
/core/src/main/java/noop/graph/DefaultModelVisitor.java
/interpreter/src/main/java/noop/interpreter/Context.java
/interpreter/src/main/java/noop/interpreter/Frame.java
/interpreter/src/main/java/noop/interpreter/InterpreterVisitor.java
/interpreter/src/main/java/noop/interpreter/config/InterpreterModule.java
Deleted:
/interpreter/src/main/java/noop/interpreter/config/ConfigModule.java
Modified:
/core/src/main/java/noop/graph/ModelVisitor.java
/core/src/main/java/noop/graph/PrintingVisitor.java
/core/src/main/java/noop/graph/VertexCreatingVisitor.java
/core/src/main/java/noop/graph/Workspace.java
/core/src/main/java/noop/model/Library.java
/interpreter/pom.xml
/interpreter/src/main/java/noop/interpreter/Interpreter.java
/interpreter/src/main/java/noop/interpreter/InterpreterMain.java
/interpreter/src/main/java/noop/interpreter/config/CommandLineOptions.java
/interpreter/src/main/java/noop/interpreter/config/InterpreterOptions.java
/interpreter/src/test/java/noop/interpreter/InterpreterSystemTest.java

=======================================
--- /dev/null
+++ /core/src/main/java/noop/graph/CompositeModelVisitor.java Sun Jun 27
13:24:51 2010
@@ -0,0 +1,188 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package noop.graph;
+
+import com.google.inject.Inject;
+import noop.model.*;
+
+import java.util.Set;
+
+/**
+ * @author alex...@google.com (Alex Eagle)
+ */
+public class CompositeModelVisitor implements ModelVisitor {
+ private final Set<ModelVisitor> delegates;
+
+ @Inject
+ public CompositeModelVisitor(Set<ModelVisitor> delegates) {
+ this.delegates = delegates;
+ }
+
+ @Override
+ public void enter(LanguageElement element) {
+ for (ModelVisitor delegate : delegates) {
+ delegate.enter(element);
+ }
+ }
+
+ @Override
+ public void leave(LanguageElement element) {
+ for (ModelVisitor delegate : delegates) {
+ delegate.leave(element);
+ }
+ }
+
+ @Override
+ public void visit(Edge edge) {
+ for (ModelVisitor delegate : delegates) {
+ delegate.visit(edge);
+ }
+ }
+
+ @Override
+ public void visit(Workspace workspace) {
+ for (ModelVisitor delegate : delegates) {
+ delegate.visit(workspace);
+ }
+ }
+
+ @Override
+ public void visit(Method method) {
+ for (ModelVisitor delegate : delegates) {
+ delegate.visit(method);
+ }
+ }
+
+ @Override
+ public void visit(Function function) {
+ for (ModelVisitor delegate : delegates) {
+ delegate.visit(function);
+ }
+ }
+
+ @Override
+ public void visit(UnitTest unitTest) {
+ for (ModelVisitor delegate : delegates) {
+ delegate.visit(unitTest);
+ }
+ }
+
+ @Override
+ public void visit(Project project) {
+ for (ModelVisitor delegate : delegates) {
+ delegate.visit(project);
+ }
+ }
+
+ @Override
+ public void visit(MethodInvocation methodInvocation) {
+ for (ModelVisitor delegate : delegates) {
+ delegate.visit(methodInvocation);
+ }
+ }
+
+ @Override
+ public void visit(Parameter parameter) {
+ for (ModelVisitor delegate : delegates) {
+ delegate.visit(parameter);
+ }
+ }
+
+ @Override
+ public void visit(Library library) {
+ for (ModelVisitor delegate : delegates) {
+ delegate.visit(library);
+ }
+ }
+
+ @Override
+ public void visit(Clazz clazz) {
+ for (ModelVisitor delegate : delegates) {
+ delegate.visit(clazz);
+ }
+ }
+
+ @Override
+ public void visit(StringLiteral stringLiteral) {
+ for (ModelVisitor delegate : delegates) {
+ delegate.visit(stringLiteral);
+ }
+ }
+
+ @Override
+ public void visit(Return aReturn) {
+ for (ModelVisitor delegate : delegates) {
+ delegate.visit(aReturn);
+ }
+ }
+
+ @Override
+ public void visit(IntegerLiteral integerLiteral) {
+ for (ModelVisitor delegate : delegates) {
+ delegate.visit(integerLiteral);
+ }
+ }
+
+ @Override
+ public void visit(Documentation documentation) {
+ for (ModelVisitor delegate : delegates) {
+ delegate.visit(documentation);
+ }
+ }
+
+ @Override
+ public void visit(Assignment assignment) {
+ for (ModelVisitor delegate : delegates) {
+ delegate.visit(assignment);
+ }
+ }
+
+ @Override
+ public void visit(IdentifierDeclaration identifierDeclaration) {
+ for (ModelVisitor delegate : delegates) {
+ delegate.visit(identifierDeclaration);
+ }
+ }
+
+ @Override
+ public void visit(Binding binding) {
+ for (ModelVisitor delegate : delegates) {
+ delegate.visit(binding);
+ }
+ }
+
+ @Override
+ public void visit(Comment comment) {
+ for (ModelVisitor delegate : delegates) {
+ delegate.visit(comment);
+ }
+ }
+
+ @Override
+ public void visit(Loop loop) {
+ for (ModelVisitor delegate : delegates) {
+ delegate.visit(loop);
+ }
+ }
+
+ @Override
+ public void visit(AnonymousBlock block) {
+ for (ModelVisitor delegate : delegates) {
+ delegate.visit(block);
+ }
+ }
+}
=======================================
--- /dev/null
+++ /core/src/main/java/noop/graph/DefaultModelVisitor.java Sun Jun 27
13:24:51 2010
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package noop.graph;
+
+import noop.model.*;
+
+/**
+ * @author alex...@google.com (Alex Eagle)
+ */
+public abstract class DefaultModelVisitor implements ModelVisitor {
+ @Override
+ public void enter(LanguageElement element) {}
+
+ @Override
+ public void leave(LanguageElement element) {}
+
+ @Override
+ public void visit(Edge edge) {}
+
+ @Override
+ public void visit(Workspace workspace) {}
+
+ @Override
+ public void visit(Method method) {}
+
+ @Override
+ public void visit(Function function) {}
+
+ @Override
+ public void visit(UnitTest unitTest) {}
+
+ @Override
+ public void visit(Project project) {}
+
+ @Override
+ public void visit(MethodInvocation methodInvocation) {}
+
+ @Override
+ public void visit(Parameter parameter) {}
+
+ @Override
+ public void visit(Library library) {}
+
+ @Override
+ public void visit(Clazz clazz) {}
+
+ @Override
+ public void visit(StringLiteral stringLiteral) {}
+
+ @Override
+ public void visit(Return aReturn) {}
+
+ @Override
+ public void visit(IntegerLiteral integerLiteral) {}
+
+ @Override
+ public void visit(Documentation documentation) {}
+
+ @Override
+ public void visit(Assignment assignment) {}
+
+ @Override
+ public void visit(IdentifierDeclaration identifierDeclaration) {}
+
+ @Override
+ public void visit(Binding binding) {}
+
+ @Override
+ public void visit(Comment comment) {}
+
+ @Override
+ public void visit(Loop loop) {}
+
+ @Override
+ public void visit(AnonymousBlock block) {}
+}
=======================================
--- /dev/null
+++ /interpreter/src/main/java/noop/interpreter/Context.java Sun Jun 27
13:24:51 2010
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package noop.interpreter;
+
+import java.util.Stack;
+
+/**
+ * The execution context of the interpreter. A snapshot of the state of
frames on the stack.
+ * @author alex...@google.com (Alex Eagle)
+ */
+public class Context {
+ private Stack<Frame> stack;
+
+ public Frame currentFrame() {
+ return stack.peek();
+ }
+}
=======================================
--- /dev/null
+++ /interpreter/src/main/java/noop/interpreter/Frame.java Sun Jun 27
13:24:51 2010
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package noop.interpreter;
+
+/**
+ * @author alex...@google.com (Alex Eagle)
+ */
+public class Frame {
+
+}
=======================================
--- /dev/null
+++ /interpreter/src/main/java/noop/interpreter/InterpreterVisitor.java Sun
Jun 27 13:24:51 2010
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package noop.interpreter;
+
+import com.google.inject.Inject;
+import noop.graph.DefaultModelVisitor;
+import noop.graph.Edge;
+import noop.graph.ModelVisitor;
+import noop.graph.Workspace;
+import noop.model.LanguageElement;
+import noop.model.Library;
+import noop.model.MethodInvocation;
+
+/**
+ * @author alex...@google.com (Alex Eagle)
+ */
+public class InterpreterVisitor extends DefaultModelVisitor {
+ private final Context context;
+ private final Workspace workspace;
+ private final ModelVisitor modelVisitor;
+
+ @Inject
+ public InterpreterVisitor(Context context, Workspace workspace,
ModelVisitor modelVisitor) {
+ this.context = context;
+ this.workspace = workspace;
+ this.modelVisitor = modelVisitor;
+ }
+
+ @Override
+ public void visit(MethodInvocation methodInvocation) {
+ Library library =
workspace.lookupLibrary(methodInvocation.vertex.libraryUid);
+ Iterable<Edge> edges = library.edgesFrom(methodInvocation.vertex);
+ LanguageElement target = null;
+ for (Edge edge : edges) {
+ switch (edge.type) {
+ case TARGET:
+ target = workspace.resolve(edge.dest);
+ break;
+ }
+ }
+
+ modelVisitor.enter(target);
+ target.accept(modelVisitor);
+ modelVisitor.leave(target);
+
+ }
+}
=======================================
--- /dev/null
+++
/interpreter/src/main/java/noop/interpreter/config/InterpreterModule.java
Sun Jun 27 13:24:51 2010
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package noop.interpreter.config;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.multibindings.Multibinder;
+import noop.graph.CompositeModelVisitor;
+import noop.graph.ModelVisitor;
+import noop.interpreter.InterpreterVisitor;
+
+import java.io.PrintStream;
+
+/**
+ * @author alex...@google.com (Alex Eagle)
+ */
+public class InterpreterModule extends AbstractModule {
+
+ private final InterpreterOptions options;
+
+ public InterpreterModule(InterpreterOptions options) {
+ this.options = options;
+ }
+
+ @Override
+ protected void configure() {
+
bind(PrintStream.class).annotatedWith(Output.class).toInstance(System.out);
+
bind(PrintStream.class).annotatedWith(Error.class).toInstance(System.err);
+ bind(InterpreterOptions.class).toInstance(options);
+ bind(ModelVisitor.class).to(CompositeModelVisitor.class);
+ Multibinder<ModelVisitor> visitors =
Multibinder.newSetBinder(binder(), ModelVisitor.class);
+ visitors.addBinding().to(InterpreterVisitor.class);
+ }
+}
=======================================
--- /interpreter/src/main/java/noop/interpreter/config/ConfigModule.java
Sat May 8 14:36:45 2010
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright 2010 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package noop.interpreter.config;
-
-import com.google.inject.AbstractModule;
-
-import java.io.PrintStream;
-
-/**
- * @author alex...@google.com (Alex Eagle)
- */
-public class ConfigModule extends AbstractModule {
-
- private final InterpreterOptions options;
-
- public ConfigModule(InterpreterOptions options) {
- this.options = options;
- }
-
- @Override
- protected void configure() {
-
bind(PrintStream.class).annotatedWith(Output.class).toInstance(System.out);
-
bind(PrintStream.class).annotatedWith(Error.class).toInstance(System.err);
- bind(InterpreterOptions.class).toInstance(options);
- }
-}
=======================================
--- /core/src/main/java/noop/graph/ModelVisitor.java Sun Apr 25 01:04:21
2010
+++ /core/src/main/java/noop/graph/ModelVisitor.java Sun Jun 27 13:24:51
2010
@@ -1,19 +1,3 @@
-/*
- * Copyright 2010 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
package noop.graph;

import noop.model.*;
@@ -21,48 +5,48 @@
/**
* @author alex...@google.com (Alex Eagle)
*/
-public abstract class ModelVisitor {
- public void enter(LanguageElement element) {}
-
- public void leave(LanguageElement element) {}
-
- public void visit(Edge edge) {}
-
- public void visit(Workspace workspace) {}
-
- public void visit(Method method) {}
-
- public void visit(Function function) {}
-
- public void visit(UnitTest unitTest) {}
-
- public void visit(Project project) {}
-
- public void visit(MethodInvocation methodInvocation) {}
-
- public void visit(Parameter parameter) {}
-
- public void visit(Library library) {}
-
- public void visit(Clazz clazz) {}
-
- public void visit(StringLiteral stringLiteral) {}
-
- public void visit(Return aReturn) {}
-
- public void visit(IntegerLiteral integerLiteral) {}
-
- public void visit(Documentation documentation) {}
-
- public void visit(Assignment assignment) {}
-
- public void visit(IdentifierDeclaration identifierDeclaration) {}
-
- public void visit(Binding binding) {}
-
- public void visit(Comment comment) {}
-
- public void visit(Loop loop) {}
-
- public void visit(AnonymousBlock block) {}
-}
+public interface ModelVisitor {
+ void enter(LanguageElement element);
+
+ void leave(LanguageElement element);
+
+ void visit(Edge edge);
+
+ void visit(Workspace workspace);
+
+ void visit(Method method);
+
+ void visit(Function function);
+
+ void visit(UnitTest unitTest);
+
+ void visit(Project project);
+
+ void visit(MethodInvocation methodInvocation);
+
+ void visit(Parameter parameter);
+
+ void visit(Library library);
+
+ void visit(Clazz clazz);
+
+ void visit(StringLiteral stringLiteral);
+
+ void visit(Return aReturn);
+
+ void visit(IntegerLiteral integerLiteral);
+
+ void visit(Documentation documentation);
+
+ void visit(Assignment assignment);
+
+ void visit(IdentifierDeclaration identifierDeclaration);
+
+ void visit(Binding binding);
+
+ void visit(Comment comment);
+
+ void visit(Loop loop);
+
+ void visit(AnonymousBlock block);
+}
=======================================
--- /core/src/main/java/noop/graph/PrintingVisitor.java Sat May 8 12:33:33
2010
+++ /core/src/main/java/noop/graph/PrintingVisitor.java Sun Jun 27 13:24:51
2010
@@ -23,7 +23,7 @@
/**
* @author alex...@google.com (Alex Eagle)
*/
-public abstract class PrintingVisitor extends ModelVisitor {
+public abstract class PrintingVisitor extends DefaultModelVisitor {
protected Workspace workspace;
protected Library library;
protected int currentDepth;
@@ -119,6 +119,4 @@
public void visit(StringLiteral stringLiteral) {
print(stringLiteral, "literal \"%s\"", stringLiteral.value);
}
-
-
-}
+}
=======================================
--- /core/src/main/java/noop/graph/VertexCreatingVisitor.java Sat May 8
12:33:33 2010
+++ /core/src/main/java/noop/graph/VertexCreatingVisitor.java Sun Jun 27
13:24:51 2010
@@ -23,7 +23,7 @@
* Creates the vertex in the element graph for each element encountered
which doesn't have one already.
* @author alex...@google.com (Alex Eagle)
*/
-public class VertexCreatingVisitor extends ModelVisitor {
+public class VertexCreatingVisitor extends DefaultModelVisitor {
private Library currentLibrary;

@Override
=======================================
--- /core/src/main/java/noop/graph/Workspace.java Sun Apr 25 07:46:55 2010
+++ /core/src/main/java/noop/graph/Workspace.java Sun Jun 27 13:24:51 2010
@@ -18,6 +18,7 @@

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
+import com.google.inject.Singleton;
import noop.model.LanguageElement;
import noop.model.Library;
import noop.model.Project;
@@ -28,6 +29,7 @@
/**
* @author alex...@google.com (Alex Eagle)
*/
+@Singleton
public class Workspace extends LanguageElement<Workspace> {
private List<Project> projects = Lists.newArrayList();

@@ -61,4 +63,9 @@
}
return null;
}
-}
+
+ // Look up the language element from the target pointer
+ public LanguageElement resolve(Vertex target) {
+ return
lookupLibrary(target.libraryUid).getElements().get(target.index);
+ }
+}
=======================================
--- /core/src/main/java/noop/model/Library.java Sun Apr 25 07:46:55 2010
+++ /core/src/main/java/noop/model/Library.java Sun Jun 27 13:24:51 2010
@@ -34,6 +34,7 @@
public class Library extends LanguageElement<Library> {
public final UUID uid;
public final String name;
+ // TODO list of list of edges, first list indexed same as 'src' node
private final List<Edge> edges = Lists.newArrayList();
private final List<LanguageElement> elements = Lists.newArrayList();
private final List<Clazz> classes = Lists.newArrayList();
=======================================
--- /interpreter/pom.xml Tue May 18 22:10:03 2010
+++ /interpreter/pom.xml Sun Jun 27 13:24:51 2010
@@ -50,5 +50,10 @@
<artifactId>guice</artifactId>
<version>2.0</version>
</dependency>
+ <dependency>
+ <groupId>com.google.inject.extensions</groupId>
+ <artifactId>guice-multibindings</artifactId>
+ <version>2.0</version>
+ </dependency>
</dependencies>
</project>
=======================================
--- /interpreter/src/main/java/noop/interpreter/Interpreter.java Tue May 18
22:10:03 2010
+++ /interpreter/src/main/java/noop/interpreter/Interpreter.java Sun Jun 27
13:24:51 2010
@@ -19,6 +19,7 @@
import com.google.inject.Inject;
import com.thoughtworks.xstream.XStream;
import noop.graph.Controller;
+import noop.graph.ModelVisitor;
import noop.graph.VertexCreatingVisitor;
import noop.graph.Workspace;
import noop.interpreter.config.InterpreterOptions;
@@ -37,14 +38,17 @@
*/
public class Interpreter {
private final InterpreterOptions options;
+ private final ModelVisitor visitor;
+ private final Workspace workspace;

@Inject
- public Interpreter(InterpreterOptions options) {
+ public Interpreter(InterpreterOptions options, ModelVisitor visitor,
Workspace workspace) {
this.options = options;
+ this.visitor = visitor;
+ this.workspace = workspace;
}

public int run() throws FileNotFoundException {
- Workspace workspace = new Workspace();
Controller controller = new Controller(workspace, new
VertexCreatingVisitor());

Project project = new Project("runtime", "", "");
=======================================
--- /interpreter/src/main/java/noop/interpreter/InterpreterMain.java Sat
May 8 14:36:45 2010
+++ /interpreter/src/main/java/noop/interpreter/InterpreterMain.java Sun
Jun 27 13:24:51 2010
@@ -17,9 +17,8 @@
package noop.interpreter;

import com.google.inject.Guice;
-import com.google.inject.Injector;
import noop.interpreter.config.CommandLineOptions;
-import noop.interpreter.config.ConfigModule;
+import noop.interpreter.config.InterpreterModule;
import org.kohsuke.args4j.CmdLineException;

/**
@@ -36,8 +35,9 @@
public static void main(String[] args) throws Exception {
try {
CommandLineOptions options =
CommandLineOptions.fromCmdLineArgs(args);
- Injector injector = Guice.createInjector(new ConfigModule(options));
- exit(injector.getInstance(Interpreter.class).run());
+ exit(Guice.createInjector(new InterpreterModule(options))
+ .getInstance(Interpreter.class)
+ .run());
} catch (CmdLineException e) {
exit(1);
}
=======================================
---
/interpreter/src/main/java/noop/interpreter/config/CommandLineOptions.java
Tue May 18 22:10:03 2010
+++
/interpreter/src/main/java/noop/interpreter/config/CommandLineOptions.java
Sun Jun 27 13:24:51 2010
@@ -37,9 +37,13 @@
private Integer entryPoint;

@Option(name = "-lib", aliases = "--library",
- usage = "A relative paths to a library to load. May be used
multiple times.")
+ usage = "A relative path to a library to load. May be used
multiple times.")
private List<String> libraryPaths;

+ @Option(name = "-v", aliases = "--verbose",
+ usage = "Whether to print the graph as the interpreter visits
it")
+ private boolean verbose;
+
public static CommandLineOptions fromCmdLineArgs(String[] args) throws
CmdLineException {
CommandLineOptions options = new CommandLineOptions();
CmdLineParser parser = new CmdLineParser(options);
@@ -68,4 +72,9 @@
public List<String> getLibraryPaths() {
return libraryPaths;
}
-}
+
+ @Override
+ public boolean isVerbose() {
+ return verbose;
+ }
+}
=======================================
---
/interpreter/src/main/java/noop/interpreter/config/InterpreterOptions.java
Tue May 18 22:10:03 2010
+++
/interpreter/src/main/java/noop/interpreter/config/InterpreterOptions.java
Sun Jun 27 13:24:51 2010
@@ -27,4 +27,6 @@
String getMainLib();

List<String> getLibraryPaths();
-}
+
+ boolean isVerbose();
+}
=======================================
--- /interpreter/src/test/java/noop/interpreter/InterpreterSystemTest.java
Tue May 18 22:10:03 2010
+++ /interpreter/src/test/java/noop/interpreter/InterpreterSystemTest.java
Sun Jun 27 13:24:51 2010
@@ -35,6 +35,7 @@
"-lib", "/Users/alexeagle/IdeaProjects/noop/dumps/com.google.noop/Noop/io.xml",
"-lib", "/Users/alexeagle/IdeaProjects/noop/dumps/com.google.noop/Noop/lang.xml",
"-lib", "/Users/alexeagle/IdeaProjects/noop/dumps/com.example/Hello
World/hello.xml",
+ "-v",
"dcf83cb3-9457-4695-b4b6-94389fef5a5b", "1"
});
assertEquals(0, InterpreterMain.exitCodeForTesting);

Reply all
Reply to author
Forward
0 new messages