Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
4f66ded
Add EvaluateCommand with EvaluationStrategies
Balletie May 18, 2016
9848549
Pass Context (and thereby LanguageImpl) as method parameter to Evalst…
Balletie May 24, 2016
13451aa
First working implementation, only runs with fresh context
Balletie May 26, 2016
126dbae
Inject custom dependencies in VM using configuration parameters.
Balletie May 31, 2016
2cedca7
Get RuleRegistry via EntryPoint instead of loading it myself.
Balletie May 31, 2016
45c8402
Rename JarInterpreterLoader to ClassPathInterpreterLoader
Balletie May 31, 2016
3839611
Add class comment for ClassPathInterpreterLoader
Balletie May 31, 2016
3c93158
Switch to using refactored dynsem entrypoint
Balletie Jun 2, 2016
ddd245b
Very small bug fixes.
gfokkema Jun 2, 2016
013aeaf
Initialize an execution environment and pass it for each evaluation
Balletie Jun 2, 2016
f998e1f
Override start symbol by using different JSGLRParserConfig
Balletie Jun 2, 2016
6f43e7e
Update execution environment with the new one after invoking a rule
Balletie Jun 2, 2016
a32d76c
Remove shellStartSymbol and getting language singleton, as they're no…
Balletie Jun 4, 2016
bf1b44b
Invoke argumentless constructor of entrypoint, instead of "newInstance"
Balletie Jun 4, 2016
35a3789
Test ClassPathInterpreterLoader with parametrized test
Balletie Jun 4, 2016
fb85a57
Add repository and fix test.
gfokkema Jun 5, 2016
abb35ae
Use lang3.reflect instead of beanutils for MethodUtils class
Balletie Jun 5, 2016
67bfb5f
Fix ParseCommandTest.
gfokkema Jun 5, 2016
4179dc2
Fix PMD errors
Balletie Jun 5, 2016
93daddb
Fix findbugs warnings
Balletie Jun 5, 2016
8c22941
Process test classes for annotations, so that test truffle language i…
Balletie Jun 5, 2016
62aca8b
Update to new dynsem.properties format
Balletie Jun 6, 2016
b1f9937
Remove unimplemented StrategoEvaluationStrategy
Balletie Jun 6, 2016
b2cad8e
Also update ClassPathInterpreterLoaderTest to new dynsem.properties f…
Balletie Jun 6, 2016
0e5b036
Parse again with normal start symbol when parsing with shell start sy…
Balletie Jun 7, 2016
ecce72f
Update java target package default to new default value
Balletie Jun 7, 2016
4f19efa
Store semantic components as environment, instead of a separate "envi…
Balletie Jun 7, 2016
d5a011f
Also support "Cast" type rules of the form "e : Expr --> ..."
Balletie Jun 7, 2016
80f83a9
Inject parser too, split a long method
Balletie Jun 7, 2016
313b80d
Add transform stage before evaluation
Balletie Jun 7, 2016
312c564
Improve testability with injection and proper responsibilities
Balletie Jun 7, 2016
0d5796f
Test DynSemEvaluationStrategy by making a mock interpreter
Balletie Jun 7, 2016
5aae124
Only lookup Cast rule when there's a sort. Add specific error message…
Balletie Jun 7, 2016
5602683
Fix checkstyle method length warning.
gfokkema Jun 8, 2016
a81eafc
Fix empty catch block by filling it with "continue"
Balletie Jun 8, 2016
b76a6bd
Fix ParseCommandTest by mocking an additional method in resultfactory
gfokkema Jun 8, 2016
ee65f71
Fix last dynsem test.
gfokkema Jun 8, 2016
41fe255
Use try-with-resources to close input stream
Balletie Jun 8, 2016
5ca5e8a
Remove EvaluateUnit and replace with wrapped {Parse,Analyze}Result in…
Balletie Jun 8, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 52 additions & 1 deletion org.metaborg.spoofax.shell.core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
order to build our code standalone (which is not only easier for testing locally, but
required on TravisCI). -->
<repositories>
<repository>
<id>custom-snapshot-repo</id>
<url>http://fokkema-ict.nl/maven2</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>metaborg-snapshot-repo</id>
<url>http://artifacts.metaborg.org/content/repositories/snapshots/</url>
Expand Down Expand Up @@ -57,6 +67,22 @@
<artifactId>org.strategoxt.strj</artifactId>
<version>${metaborg-version}</version>
</dependency>
<dependency>
<groupId>org.metaborg</groupId>
<artifactId>org.metaborg.meta.interpreter.framework</artifactId>
<version>${metaborg-version}</version>
</dependency>
<dependency>
<groupId>org.metaborg</groupId>
<artifactId>org.metaborg.meta.lang.dynsem.interpreter</artifactId>
<version>${metaborg-version}</version>
</dependency>
<dependency>
<groupId>com.oracle.truffle</groupId>
<artifactId>truffle-api</artifactId>
<version>0.11</version>
<type>jar</type>
</dependency>

<!-- From here on, all dependencies are inherited. -->
<dependency>
Expand Down Expand Up @@ -89,7 +115,7 @@
<version>1.10.19</version>
<scope>test</scope>
</dependency>

<!-- From here on, all test dependencies are inherited. -->
<dependency>
<groupId>junit</groupId>
Expand Down Expand Up @@ -132,13 +158,38 @@
</plugins>
</pluginManagement>
<plugins>
<!-- Generate sources from annotations. -->
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<goals>
<goal>process-test</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources/annotations</outputDirectory>
<!--processor>com.oracle.truffle.dsl.processor.LanguageRegistrationProcessor</processor-->
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.oracle.truffle</groupId>
<artifactId>truffle-dsl-processor</artifactId>
<version>0.11</version>
</dependency>
</dependencies>
</plugin>
<!-- Compile Java 8 sources. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArgument>-proc:none</compilerArgument>
</configuration>
</plugin>
<!-- Checkstyle -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package org.metaborg.spoofax.shell.commands;

import java.io.IOException;
import java.util.Map;

import org.metaborg.core.MetaborgException;
import org.metaborg.core.context.IContext;
import org.metaborg.core.context.IContextService;
import org.metaborg.core.language.ILanguageImpl;
import org.metaborg.core.project.IProject;
import org.metaborg.spoofax.core.shell.ShellFacet;
import org.metaborg.spoofax.shell.core.IEvaluationStrategy;
import org.metaborg.spoofax.shell.hooks.IResultHook;
import org.metaborg.spoofax.shell.invoker.ICommandFactory;
import org.metaborg.spoofax.shell.output.AnalyzeResult;
import org.metaborg.spoofax.shell.output.EvaluateResult;
import org.metaborg.spoofax.shell.output.IResultFactory;
import org.metaborg.spoofax.shell.output.InputResult;
import org.metaborg.spoofax.shell.output.ParseResult;
import org.spoofax.interpreter.terms.IStrategoTerm;

import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;

/**
* Represents an evaluate command sent to Spoofax.
*/
public class EvaluateCommand extends SpoofaxCommand {
private static final String DESCRIPTION = "Evaluate an expression";

private IContextService contextService;
private ParseCommand parseCommand;
private AnalyzeCommand analyzeCommand;
private IResultFactory unitFactory;

@Inject
private Map<String, IEvaluationStrategy> evaluationStrategies;
private EvaluationInvocationStrategy invocationStrategy;

/**
* Interface for what happens before evaluation of parsed input (i.e. either analyze or evaluate
* as-is).
*/
private interface EvaluationInvocationStrategy {
EvaluateResult performEvaluation(IContext context, ParseResult parsed,
IEvaluationStrategy evalStrategy)
throws MetaborgException;
}

/**
* Analyze before invoking the evaluation strategy.
*/
private class AnalyzedInvocationStrategy implements EvaluationInvocationStrategy {
@Override
public EvaluateResult performEvaluation(IContext context, ParseResult parsed,
IEvaluationStrategy evalStrategy)
throws MetaborgException {
AnalyzeResult analyzed = analyzeCommand.analyze(parsed);
IStrategoTerm ast = evalStrategy.evaluate(analyzed, context);
return unitFactory.createEvaluateResult(analyzed, ast);
}
}

/**
* Analyze before invoking the evaluation strategy.
*/
private class NonAnalyzedInvocationStrategy implements EvaluationInvocationStrategy {
@Override
public EvaluateResult performEvaluation(IContext context, ParseResult parsed,
IEvaluationStrategy evalStrategy)
throws MetaborgException {
IStrategoTerm ast = evalStrategy.evaluate(parsed, context);
return unitFactory.createEvaluateResult(parsed, ast);
}
}

/**
* Instantiate an {@link EvaluateCommand}.
*
* @param contextService
* The {@link IContextService}.
* @param commandFactory
* The {@link ICommandFactory} for creating delegate commands.
* @param resultHook
* Called upon success of evaluation of this command.
* @param project
* The project in which this command should operate.
* @param lang
* The language to which this command applies.
*/
@Inject
// CHECKSTYLE.OFF: |
public EvaluateCommand(IContextService contextService, ICommandFactory commandFactory,
IResultFactory unitFactory, IResultHook resultHook,
@Assisted IProject project, @Assisted ILanguageImpl lang,
@Assisted boolean analyzed) {
// CHECKSTYLE.ON: |
super(resultHook, unitFactory, project, lang);
this.contextService = contextService;
this.parseCommand = commandFactory.createParse(project, lang);
this.analyzeCommand = commandFactory.createAnalyze(project, lang);
this.unitFactory = unitFactory;

this.invocationStrategy =
analyzed ? new AnalyzedInvocationStrategy() : new NonAnalyzedInvocationStrategy();
}

@Override
public String description() {
return DESCRIPTION;
}

private EvaluateResult evaluate(ParseResult parsed) throws MetaborgException {
IContext context =
parsed.context().orElse(contextService.get(parsed.source(), project, lang));
ShellFacet facet = context.language().facet(ShellFacet.class);
IEvaluationStrategy evalStrategy = evaluationStrategies.get(facet.getEvaluationMethod());
return invocationStrategy.performEvaluation(context, parsed, evalStrategy);
}

@Override
public void execute(String... args) throws MetaborgException {
try {
InputResult input = unitFactory.createInputResult(lang, write(args[0]), args[0]);
ParseResult parse = parseCommand.parse(input);
EvaluateResult result = this.evaluate(parse);
resultHook.accept(result);
} catch (IOException e) {
throw new MetaborgException("Cannot write to temporary source file.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ public void execute(String... args) throws MetaborgException {
invoker.addCommand("analyze", commandFactory.createAnalyze(project, lang));
}

invoker.addCommand("eval", commandFactory.createEvaluate(project, lang, analyze));

messageHook.accept(new StyledText("Loaded language" + lang));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import java.io.IOException;
import java.util.stream.Collectors;

import org.apache.commons.vfs2.FileObject;
import org.metaborg.core.MetaborgException;
import org.metaborg.core.language.ILanguageImpl;
import org.metaborg.core.messages.IMessage;
import org.metaborg.core.project.IProject;
import org.metaborg.spoofax.core.shell.ShellFacet;
import org.metaborg.spoofax.core.syntax.ISpoofaxSyntaxService;
import org.metaborg.spoofax.core.syntax.JSGLRParserConfiguration;
import org.metaborg.spoofax.core.syntax.SpoofaxSyntaxService;
import org.metaborg.spoofax.core.unit.ISpoofaxParseUnit;
import org.metaborg.spoofax.shell.hooks.IResultHook;
Expand Down Expand Up @@ -75,8 +78,18 @@ public ParseResult parse(InputResult unit) throws MetaborgException {
@Override
public void execute(String... args) throws MetaborgException {
try {
InputResult input = resultFactory.createInputResult(lang, write(args[0]), args[0]);
resultHook.accept(parse(input));
String source = args[0];
FileObject file = write(args[0]);
ShellFacet shellFacet = lang.facet(ShellFacet.class);

InputResult input = resultFactory
.createInputResult(lang, file, source,
new JSGLRParserConfiguration(shellFacet.getShellStartSymbol()));
try {
resultHook.accept(parse(input));
} catch (MetaborgException e) {
resultHook.accept(parse(resultFactory.createInputResult(lang, file, source)));
}
} catch (IOException e) {
throw new MetaborgException("Cannot write to temporary source file.");
}
Expand Down
Loading