14 | * When a block or object literal is nested inside of another
15 | * block, a method, or an object literal its context is the activation
16 | * of that block, method, or object literal.
17 | */
18 |
19 | public interface SObjectWithContext {
20 |
21 | /**
22 | * Return the block or object literal's enclosing activation, referred to
23 | * here as a context since it is surrounding/enclosing the current
24 | * object.
25 | */
26 | MaterializedFrame getContext();
27 |
28 | /**
29 | * Return the object enclosing the current object,
30 | * which is the receiver of this object.
31 | */
32 | default SObjectWithContext getOuterSelf() {
33 | return (SObjectWithContext) SArguments.rcvr(getContext());
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/src/som/interpreter/nodes/specialized/OrBoolMessageNode.java:
--------------------------------------------------------------------------------
1 | package som.interpreter.nodes.specialized;
2 |
3 | import com.oracle.truffle.api.dsl.GenerateNodeFactory;
4 | import com.oracle.truffle.api.dsl.Specialization;
5 | import com.oracle.truffle.api.instrumentation.Tag;
6 |
7 | import bd.tools.nodes.Operation;
8 | import som.interpreter.nodes.nary.BinaryBasicOperation;
9 | import tools.dym.Tags.OpComparison;
10 |
11 |
12 | @GenerateNodeFactory
13 | public abstract class OrBoolMessageNode extends BinaryBasicOperation
14 | implements Operation {
15 | @Override
16 | protected boolean hasTagIgnoringEagerness(final Class extends Tag> tag) {
17 | if (tag == OpComparison.class) {
18 | return true;
19 | } else {
20 | return super.hasTagIgnoringEagerness(tag);
21 | }
22 | }
23 |
24 | @Specialization
25 | public final boolean doOr(final boolean receiver, final boolean argument) {
26 | return receiver || argument;
27 | }
28 |
29 | @Override
30 | public String getOperation() {
31 | return "||";
32 | }
33 |
34 | @Override
35 | public int getNumArguments() {
36 | return 2;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/docs/vs-code.md:
--------------------------------------------------------------------------------
1 | ## VS Code to Develop with the SOMns Language
2 |
3 | Currently, we provide IDE support for [VS Code](https://code.visualstudio.com/).
4 | The SOMns support can be installed via the
5 | [VS Code marketplace](https://marketplace.visualstudio.com/items?itemName=MetaConcProject.SOMns).
6 |
7 | The extension provides support for:
8 |
9 | - syntax highlighting
10 | - parse errors
11 | - code navigation
12 | - code completion
13 | - basic linting
14 | - CodeLens for running minitests
15 | - and debugging of SOMns programs
16 |
17 | This support is based on the
18 | [Language Server Protocol](https://github.com/Microsoft/language-server-protocol#readme)
19 | and could be used in other IDEs as well, but we do not currently provide
20 | extensions for them. It is however confirmed to work with NetBeans and Eclipse.
21 |
22 | #### Screenshot of SOMns Syntax Highlighting
23 |
24 | 
25 |
26 | #### Screencast of Debugging a SOMns Program
27 |
28 | 
29 |
--------------------------------------------------------------------------------
/src/tools/dym/profiles/Counter.java:
--------------------------------------------------------------------------------
1 | package tools.dym.profiles;
2 |
3 | import com.oracle.truffle.api.source.SourceSection;
4 | import com.oracle.truffle.api.utilities.JSONHelper;
5 | import com.oracle.truffle.api.utilities.JSONHelper.JSONObjectBuilder;
6 | import com.oracle.truffle.api.utilities.JSONHelper.JSONStringBuilder;
7 |
8 | import tools.dym.JsonSerializable;
9 |
10 |
11 | public class Counter implements JsonSerializable {
12 | protected final SourceSection source;
13 |
14 | private int invocationCount;
15 |
16 | public Counter(final SourceSection source) {
17 | this.source = source;
18 | }
19 |
20 | public SourceSection getSourceSection() {
21 | return source;
22 | }
23 |
24 | public void inc() {
25 | invocationCount += 1;
26 | }
27 |
28 | public int getValue() {
29 | return invocationCount;
30 | }
31 |
32 | @Override
33 | public String toString() {
34 | return "Cnt[" + invocationCount + "]";
35 | }
36 |
37 | @Override
38 | public JSONStringBuilder toJson() {
39 | JSONObjectBuilder result = JSONHelper.object();
40 | result.add("count", invocationCount);
41 | return result;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/som/UncaughtExceptions.java:
--------------------------------------------------------------------------------
1 | package som;
2 |
3 | import java.lang.Thread.UncaughtExceptionHandler;
4 |
5 | import tools.concurrency.TracingActivityThread;
6 |
7 |
8 | /**
9 | * In case an actor processing thread terminates, provide some info.
10 | */
11 | public final class UncaughtExceptions implements UncaughtExceptionHandler {
12 |
13 | private final VM vm;
14 |
15 | public UncaughtExceptions(final VM vm) {
16 | this.vm = vm;
17 | }
18 |
19 | @Override
20 | public void uncaughtException(final Thread t, final Throwable e) {
21 | if (e instanceof ThreadDeath) {
22 | // Ignore those, we already signaled an error
23 | return;
24 | }
25 |
26 | Output.errorPrintln("Uncaught exception on " + t.getName());
27 |
28 | TracingActivityThread thread = (TracingActivityThread) t;
29 | if (thread.getActivity() != null) {
30 | Output.errorPrintln("Processing failed for: "
31 | + thread.getActivity().toString());
32 | }
33 |
34 | Output.errorPrintln(
35 | "Stack Trace: (printing may fail in some situation with a null pointer exception");
36 | e.printStackTrace();
37 |
38 | vm.requestExit(2);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/tools/superinstructions/TypeCounter.java:
--------------------------------------------------------------------------------
1 | package tools.superinstructions;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
7 | import com.oracle.truffle.api.source.SourceSection;
8 |
9 |
10 | /**
11 | * A counter which keeps track of the number of node activations
12 | * and their respective result types (that is, Java types).
13 | */
14 | final class TypeCounter {
15 | protected final SourceSection source;
16 | private final Map
12 | * This is useful to have dynamic semantic highlighting for a dynamic language.
13 | * The highlighting can then also indicate field reads done by slot getters,
14 | * distinguish local accesses from message sends in a uniform language, etc.
15 | */
16 | @SuppressWarnings("unused")
17 | public class UpdateSourceSections extends OutgoingMessage {
18 | private final SourceInfo[] updates;
19 |
20 | public UpdateSourceSections(final SourceInfo[] updates) {
21 | this.updates = updates;
22 | }
23 |
24 | private static final class SourceInfo {
25 | private final String sourceUri;
26 | private final TaggedSourceCoordinate[] sections;
27 |
28 | private SourceInfo(final String sourceUri,
29 | final TaggedSourceCoordinate[] sections) {
30 | this.sourceUri = sourceUri;
31 | this.sections = sections;
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/tools/snapshot/nodes/SerializerRootNode.java:
--------------------------------------------------------------------------------
1 | package tools.snapshot.nodes;
2 |
3 | import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
4 | import com.oracle.truffle.api.frame.VirtualFrame;
5 | import com.oracle.truffle.api.nodes.RootNode;
6 |
7 | import som.interpreter.SomLanguage;
8 |
9 |
10 | public final class SerializerRootNode extends RootNode {
11 | @CompilationFinal private static SomLanguage lang;
12 |
13 | @Child protected AbstractSerializationNode serializer;
14 |
15 | public static void initializeSerialization(final SomLanguage lang) {
16 | if (lang != null && SerializerRootNode.lang == null) {
17 | SerializerRootNode.lang = lang;
18 | }
19 | }
20 |
21 | public SerializerRootNode(final AbstractSerializationNode serializer) {
22 | super(lang);
23 | assert lang != null;
24 | this.serializer = insert(serializer);
25 | }
26 |
27 | @Override
28 | public Object execute(final VirtualFrame frame) {
29 | throw new UnsupportedOperationException(
30 | "Don't use this execute method, instead directly use the serializer");
31 | }
32 |
33 | public AbstractSerializationNode getSerializer() {
34 | return serializer;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/tools/kompos/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "2.0.0",
3 | "echoCommand": true,
4 | "options": {
5 | "cwd": "${workspaceRoot}"
6 | },
7 | "tasks": [
8 | {
9 | "type": "process",
10 | "group": "build",
11 | "label": "continuous compilation",
12 | "command": "npm",
13 | "isBackground": true,
14 | "args": ["run", "watch"],
15 | "problemMatcher": "$tsc-watch",
16 | "presentation": {
17 | "reveal": "silent",
18 | "panel": "shared"
19 | }
20 | },
21 | {
22 | "type": "process",
23 | "label": "test",
24 | "group": "test",
25 | "command": "npm",
26 | "isBackground": false,
27 | "args": ["test"],
28 | "presentation": {
29 | "echo": true,
30 | "reveal": "always",
31 | "focus": true,
32 | "clear": true
33 | }
34 | },
35 | {
36 | "type": "process",
37 | "command": "npm",
38 | "label": "format",
39 | "group": "build",
40 | "isBackground": false,
41 | "args": ["run", "format"],
42 | "presentation": {
43 | "reveal": "silent",
44 | "panel": "shared"
45 | }
46 | }
47 | ]
48 | }
49 |
--------------------------------------------------------------------------------
/src/tools/debugger/nodes/BreakpointNode.java:
--------------------------------------------------------------------------------
1 | package tools.debugger.nodes;
2 |
3 | import com.oracle.truffle.api.Assumption;
4 | import com.oracle.truffle.api.dsl.Cached;
5 | import com.oracle.truffle.api.dsl.Specialization;
6 |
7 | import tools.debugger.session.BreakpointEnabling;
8 |
9 |
10 | /**
11 | * Node to represent a breakpoint at the AST level.
12 | * It has two possible states, enable or disable.
13 | */
14 | public abstract class BreakpointNode extends AbstractBreakpointNode {
15 |
16 | protected final BreakpointEnabling breakpoint;
17 |
18 | protected BreakpointNode(final BreakpointEnabling breakpoint) {
19 | this.breakpoint = breakpoint;
20 | }
21 |
22 | @Specialization(assumptions = "bpUnchanged", guards = "!breakpoint.guardedEnabled()")
23 | public final boolean breakpointDisabled(
24 | @Cached("breakpoint.getAssumption()") final Assumption bpUnchanged) {
25 | return breakpoint.getSteppingType().isSet();
26 | }
27 |
28 | @Specialization(assumptions = "bpUnchanged", guards = "breakpoint.guardedEnabled()")
29 | public final boolean breakpointEnabled(
30 | @Cached("breakpoint.getAssumption()") final Assumption bpUnchanged) {
31 | return true;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/tools/snapshot/deserialization/FixupInformation.java:
--------------------------------------------------------------------------------
1 | package tools.snapshot.deserialization;
2 |
3 | import java.util.Iterator;
4 |
5 |
6 | public abstract class FixupInformation {
7 |
8 | public abstract void fixUp(Object o);
9 |
10 | protected FixupInformation next;
11 |
12 | public static class FixupList implements Iterable>> getNodeSignatures() {
33 | throw new UnsupportedOperationException("Should never be called");
34 | }
35 |
36 | @Override
37 | public List