Skip to content

Commit

Permalink
Update development environment
Browse files Browse the repository at this point in the history
  • Loading branch information
ngallagher committed Apr 1, 2018
1 parent 3c7e4c3 commit 32db194
Show file tree
Hide file tree
Showing 59 changed files with 297 additions and 276 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
package org.snapscript.studio.agent;

import java.util.List;
import java.util.SortedSet;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import org.snapscript.compile.Executable;
import org.snapscript.compile.ResourceCompiler;
import org.snapscript.compile.verify.VerifyError;
import org.snapscript.compile.verify.VerifyException;
import org.snapscript.core.Model;
import org.snapscript.core.trace.Trace;
import org.snapscript.studio.agent.event.BeginEvent;
import org.snapscript.studio.agent.event.ExitEvent;
import org.snapscript.studio.agent.event.ProcessEventChannel;
import org.snapscript.studio.agent.event.ProfileEvent;
import org.snapscript.studio.agent.event.ScriptErrorEvent;
import org.snapscript.studio.agent.profiler.ProcessProfiler;
import org.snapscript.studio.agent.profiler.ProfileResult;
import org.snapscript.studio.agent.profiler.ProfileResultUpdater;
Expand Down Expand Up @@ -62,6 +67,23 @@ public void run() {
updater.start(process); // start sending profile events!!!
middle = System.nanoTime();
executable.execute(model); // execute the script
} catch(VerifyException e) {
List<VerifyError> errors = e.getErrors();

for(VerifyError error : errors) {
Exception cause = error.getCause();
Trace trace = error.getTrace();
String description = cause.getMessage();
String path = trace.getPath().toString();
int line = trace.getLine();
ScriptErrorEvent message = new ScriptErrorEvent.Builder(process)
.withDescription(description)
.withResource(path)
.withLine(line)
.build();

client.send(message);
}
} catch(Throwable e) {
e.printStackTrace();
}finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import org.snapscript.core.State;
import org.snapscript.core.Table;
import org.snapscript.core.Value;
import org.snapscript.studio.agent.debug.ScopeNode;
import org.snapscript.studio.agent.debug.ScopeNodeBuilder;

public class ScopeNodeTree implements ScopeNode {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

public class TraceAdapter implements TraceListener {
public void before(Scope scope, Trace trace) {}
public void warning(Scope scope, Trace trace, Exception cause) {}
public void error(Scope scope, Trace trace, Exception cause) {}
public void after(Scope scope, Trace trace) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public void onExecute(ProcessEventChannel channel, ExecuteEvent event) throws Ex
public void onWriteError(ProcessEventChannel channel, WriteErrorEvent event) throws Exception {}
public void onWriteOutput(ProcessEventChannel channel, WriteOutputEvent event) throws Exception {}
public void onRegister(ProcessEventChannel channel, RegisterEvent event) throws Exception {}
public void onSyntaxError(ProcessEventChannel channel, SyntaxErrorEvent event) throws Exception {}
public void onScriptError(ProcessEventChannel channel, ScriptErrorEvent event) throws Exception {}
public void onScope(ProcessEventChannel channel, ScopeEvent event) throws Exception {}
public void onBreakpoints(ProcessEventChannel channel, BreakpointsEvent event) throws Exception {}
public void onBegin(ProcessEventChannel channel, BeginEvent event) throws Exception {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public interface ProcessEventListener {
void onWriteError(ProcessEventChannel channel, WriteErrorEvent event) throws Exception;
void onWriteOutput(ProcessEventChannel channel, WriteOutputEvent event) throws Exception;
void onRegister(ProcessEventChannel channel, RegisterEvent event) throws Exception;
void onSyntaxError(ProcessEventChannel channel, SyntaxErrorEvent event) throws Exception;
void onScriptError(ProcessEventChannel channel, ScriptErrorEvent event) throws Exception;
void onScope(ProcessEventChannel channel, ScopeEvent event) throws Exception;
void onBreakpoints(ProcessEventChannel channel, BreakpointsEvent event) throws Exception;
void onBegin(ProcessEventChannel channel, BeginEvent event) throws Exception;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ public void onRegister(ProcessEventChannel channel, RegisterEvent event) throws
}

@Override
public void onSyntaxError(ProcessEventChannel channel, SyntaxErrorEvent event) throws Exception {
public void onScriptError(ProcessEventChannel channel, ScriptErrorEvent event) throws Exception {
long start = System.currentTimeMillis();

try {
listener.onSyntaxError(channel, event);
listener.onScriptError(channel, event);
}finally {
long finish = System.currentTimeMillis();
long duration = finish - start;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public enum ProcessEventType {
PONG(PongEventMarshaller.class, PongEvent.class, 4),
EXECUTE(ExecuteEventMarshaller.class, ExecuteEvent.class, 5),
REGISTER(RegisterEventMarshaller.class, RegisterEvent.class, 6),
SYNTAX_ERROR(SyntaxErrorEventMarshaller.class, SyntaxErrorEvent.class, 7),
SCRIPT_ERROR(ScriptErrorEventMarshaller.class, ScriptErrorEvent.class, 7),
EXIT(ExitEventMarshaller.class, ExitEvent.class, 8),
SCOPE(ScopeEventMarshaller.class, ScopeEvent.class, 9),
BREAKPOINTS(BreakpointsEventMarshaller.class, BreakpointsEvent.class, 10),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.snapscript.studio.agent.event;

public class SyntaxErrorEvent implements ProcessEvent {
public class ScriptErrorEvent implements ProcessEvent {

private final String description;
private final String resource;
private final String process;
private final int line;

private SyntaxErrorEvent(Builder builder) {
private ScriptErrorEvent(Builder builder) {
this.description = builder.description;
this.process = builder.process;
this.resource = builder.resource;
Expand Down Expand Up @@ -62,8 +62,8 @@ public Builder withLine(int line) {
return this;
}

public SyntaxErrorEvent build(){
return new SyntaxErrorEvent(this);
public ScriptErrorEvent build(){
return new ScriptErrorEvent(this);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package org.snapscript.studio.agent.event;

import static org.snapscript.studio.agent.event.ProcessEventType.SYNTAX_ERROR;
import static org.snapscript.studio.agent.event.ProcessEventType.SCRIPT_ERROR;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

public class SyntaxErrorEventMarshaller implements ProcessEventMarshaller<SyntaxErrorEvent> {
public class ScriptErrorEventMarshaller implements ProcessEventMarshaller<ScriptErrorEvent> {

@Override
public SyntaxErrorEvent fromMessage(MessageEnvelope message) throws IOException {
public ScriptErrorEvent fromMessage(MessageEnvelope message) throws IOException {
byte[] array = message.getData();
int length = message.getLength();
int offset = message.getOffset();
Expand All @@ -22,15 +22,15 @@ public SyntaxErrorEvent fromMessage(MessageEnvelope message) throws IOException
String description = input.readUTF();
int line = input.readInt();

return new SyntaxErrorEvent.Builder(process)
return new ScriptErrorEvent.Builder(process)
.withResource(resource)
.withDescription(description)
.withLine(line)
.build();
}

@Override
public MessageEnvelope toMessage(SyntaxErrorEvent event) throws IOException {
public MessageEnvelope toMessage(ScriptErrorEvent event) throws IOException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
DataOutputStream output = new DataOutputStream(buffer);
String process = event.getProcess();
Expand All @@ -45,6 +45,6 @@ public MessageEnvelope toMessage(SyntaxErrorEvent event) throws IOException {
output.flush();

byte[] array = buffer.toByteArray();
return new MessageEnvelope(SYNTAX_ERROR.code, array, 0, array.length);
return new MessageEnvelope(SCRIPT_ERROR.code, array, 0, array.length);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.snapscript.studio.agent.event.RegisterEvent;
import org.snapscript.studio.agent.event.ScopeEvent;
import org.snapscript.studio.agent.event.StepEvent;
import org.snapscript.studio.agent.event.SyntaxErrorEvent;
import org.snapscript.studio.agent.event.ScriptErrorEvent;
import org.snapscript.studio.agent.event.WriteErrorEvent;
import org.snapscript.studio.agent.event.WriteOutputEvent;
import org.snapscript.studio.agent.log.ProcessLogger;
Expand Down Expand Up @@ -117,8 +117,8 @@ public void run() {
listener.onExecute(this, (ExecuteEvent)event);
} else if(event instanceof RegisterEvent) {
listener.onRegister(this, (RegisterEvent)event);
} else if(event instanceof SyntaxErrorEvent) {
listener.onSyntaxError(this, (SyntaxErrorEvent)event);
} else if(event instanceof ScriptErrorEvent) {
listener.onScriptError(this, (ScriptErrorEvent)event);
} else if(event instanceof WriteErrorEvent) {
listener.onWriteError(this, (WriteErrorEvent)event);
} else if(event instanceof WriteOutputEvent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static org.snapscript.core.Reserved.DEFAULT_PACKAGE;

import java.util.concurrent.Callable;
import java.util.List;
import java.util.concurrent.Executor;

import org.snapscript.common.store.Store;
Expand All @@ -11,23 +11,24 @@
import org.snapscript.compile.Executable;
import org.snapscript.compile.ResourceCompiler;
import org.snapscript.compile.StoreContext;
import org.snapscript.compile.verify.VerifyException;
import org.snapscript.compile.verify.VerifyError;
import org.snapscript.core.Context;
import org.snapscript.core.ExpressionEvaluator;
import org.snapscript.core.FilePathConverter;
import org.snapscript.core.Model;
import org.snapscript.core.Path;
import org.snapscript.core.PathConverter;

public class ScriptExecutor implements Callable<Context> {
public class ScriptExecutor {

private final CommandLine line;

public ScriptExecutor(CommandLine line) {
this.line = line;
}

@Override
public Context call() throws Exception {

public void execute() throws Exception {
Store store = line.getStore();
String evaluate = line.getEvaluation();
Path script = line.getScript();
Expand All @@ -44,18 +45,25 @@ public Context call() throws Exception {
Compiler compiler = new ResourceCompiler(context);
Executable executable = null;

if(script != null) {
String file = script.getPath();
try {
if(script != null) {
String file = script.getPath();

module = converter.createModule(file);
executable = compiler.compile(file);
}
if(evaluate != null) {
ExpressionEvaluator evaluator = context.getEvaluator();
evaluator.evaluate(model, evaluate, module);
} else {
executable.execute(model);
}
} catch(VerifyException e){
List<VerifyError> errors = e.getErrors();

module = converter.createModule(file);
executable = compiler.compile(file);
}
if(evaluate != null) {
ExpressionEvaluator evaluator = context.getEvaluator();
evaluator.evaluate(model, evaluate, module);
} else {
executable.execute(model);
}
return context;
for(VerifyError error : errors) {
System.err.println(error);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public static void main(String[] options) throws Exception {

ScriptClassLoader.update(classpath);
line.validate();
executor.call();
executor.execute();
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package org.snapscript.studio.index.tree;

import org.snapscript.core.Bug;
import org.snapscript.core.Compilation;
import org.snapscript.core.InternalStateException;
import org.snapscript.core.Module;
import org.snapscript.core.Path;
import org.snapscript.core.Scope;
import org.snapscript.core.Type;
import org.snapscript.core.Value;
import org.snapscript.parse.StringToken;
import org.snapscript.tree.constraint.ArrayConstraint;
Expand Down Expand Up @@ -35,13 +38,18 @@ public IndexConstraint(TypeReference reference, StringToken... bounds) {
this.bounds = bounds;
}

@Bug("fix this")
@Override
public Value evaluate(Scope scope, Object left) throws Exception {
Value value = reference.evaluate(scope, null);
String entry = value.getValue();
String array = entry + DIMENSIONS[bounds.length];

return Value.getTransient(array);
public Type getType(Scope scope) {
try {
Value value = reference.evaluate(scope, null);
String entry = value.getValue();

//return entry + DIMENSIONS[bounds.length];
return null;
} catch(Exception e) {
throw new InternalStateException("Invalid array constraint", e);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import org.snapscript.core.Path;
import org.snapscript.core.Scope;
import org.snapscript.core.Statement;
import org.snapscript.core.TypePart;
import org.snapscript.studio.index.IndexResult;
import org.snapscript.tree.ModifierList;
import org.snapscript.tree.annotation.AnnotationList;
import org.snapscript.tree.define.ClassConstructor;
import org.snapscript.tree.define.TypePart;
import org.snapscript.tree.function.ParameterList;

public class ClassConstructorIndex implements Compilation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
import org.snapscript.core.Module;
import org.snapscript.core.Path;
import org.snapscript.core.Scope;
import org.snapscript.core.TypePart;
import org.snapscript.studio.index.IndexResult;
import org.snapscript.tree.annotation.AnnotationList;
import org.snapscript.tree.define.ClassDefinition;
import org.snapscript.tree.define.TypeHierarchy;
import org.snapscript.tree.define.TypeName;
import org.snapscript.tree.define.TypePart;

public class ClassDefinitionIndex implements Compilation {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
import org.snapscript.core.Module;
import org.snapscript.core.Path;
import org.snapscript.core.Scope;
import org.snapscript.core.Type;
import org.snapscript.core.Value;
import org.snapscript.core.constraint.Constraint;
import org.snapscript.studio.index.IndexResult;
import org.snapscript.tree.Declaration;
import org.snapscript.tree.constraint.Constraint;
import org.snapscript.tree.literal.TextLiteral;

public class DeclarationIndex implements Compilation {
Expand Down Expand Up @@ -46,9 +47,7 @@ public Object compile(Module module, Path path, int line) throws Exception {
String type = null;

if(constraint != null) {
Value result = constraint.evaluate(scope, null);
Object object = result.getValue();

Type object = constraint.getType(scope);
type = String.valueOf(object);
}
return new IndexResult(VARIABLE, declaration, type, prefix, name, path, line);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
import org.snapscript.core.Module;
import org.snapscript.core.Path;
import org.snapscript.core.Scope;
import org.snapscript.core.TypePart;
import org.snapscript.studio.index.IndexResult;
import org.snapscript.tree.annotation.AnnotationList;
import org.snapscript.tree.define.EnumDefinition;
import org.snapscript.tree.define.EnumList;
import org.snapscript.tree.define.TypeHierarchy;
import org.snapscript.tree.define.TypeName;
import org.snapscript.tree.define.TypePart;

public class EnumDefinitionIndex implements Compilation {

Expand Down
Loading

0 comments on commit 32db194

Please sign in to comment.