mirror of
https://github.com/enso-org/enso.git
synced 2024-09-11 13:15:52 +03:00
Introducing engine/runtime-compiler project (#8197)
This commit is contained in:
parent
1480f50207
commit
3fd2249864
24
build.sbt
24
build.sbt
@ -281,6 +281,7 @@ lazy val enso = (project in file("."))
|
||||
launcher,
|
||||
downloader,
|
||||
`runtime-parser`,
|
||||
`runtime-compiler`,
|
||||
`runtime-language-epb`,
|
||||
`runtime-instrument-common`,
|
||||
`runtime-instrument-id-execution`,
|
||||
@ -1352,8 +1353,7 @@ lazy val runtime = (project in file("engine/runtime"))
|
||||
"org.typelevel" %% "cats-core" % catsVersion,
|
||||
"junit" % "junit" % junitVersion % Test,
|
||||
"com.github.sbt" % "junit-interface" % junitIfVersion % Test,
|
||||
"org.hamcrest" % "hamcrest-all" % hamcrestVersion % Test,
|
||||
"com.lihaoyi" %% "fansi" % fansiVersion
|
||||
"org.hamcrest" % "hamcrest-all" % hamcrestVersion % Test
|
||||
),
|
||||
Compile / compile / compileInputs := (Compile / compile / compileInputs)
|
||||
.dependsOn(CopyTruffleJAR.preCompileTask)
|
||||
@ -1418,8 +1418,7 @@ lazy val runtime = (project in file("engine/runtime"))
|
||||
.dependsOn(`logging-truffle-connector`)
|
||||
.dependsOn(`polyglot-api`)
|
||||
.dependsOn(`text-buffer`)
|
||||
.dependsOn(`runtime-parser`)
|
||||
.dependsOn(pkg)
|
||||
.dependsOn(`runtime-compiler`)
|
||||
.dependsOn(`connected-lock-manager`)
|
||||
.dependsOn(testkit % Test)
|
||||
.dependsOn(`logging-service-logback` % "test->test")
|
||||
@ -1438,6 +1437,23 @@ lazy val `runtime-parser` =
|
||||
.dependsOn(syntax)
|
||||
.dependsOn(`syntax-rust-definition`)
|
||||
|
||||
lazy val `runtime-compiler` =
|
||||
(project in file("engine/runtime-compiler"))
|
||||
.settings(
|
||||
frgaalJavaCompilerSetting,
|
||||
instrumentationSettings,
|
||||
libraryDependencies ++= Seq(
|
||||
"junit" % "junit" % junitVersion % Test,
|
||||
"com.github.sbt" % "junit-interface" % junitIfVersion % Test,
|
||||
"org.scalatest" %% "scalatest" % scalatestVersion % Test,
|
||||
"com.lihaoyi" %% "fansi" % fansiVersion
|
||||
)
|
||||
)
|
||||
.dependsOn(`runtime-parser`)
|
||||
.dependsOn(pkg)
|
||||
.dependsOn(`polyglot-api`)
|
||||
.dependsOn(editions)
|
||||
|
||||
lazy val `runtime-instrument-common` =
|
||||
(project in file("engine/runtime-instrument-common"))
|
||||
.configs(Benchmark)
|
||||
|
@ -0,0 +1,7 @@
|
||||
package org.enso.compiler.context;
|
||||
|
||||
/**
|
||||
* A representation of a pointer into a stack frame at a given number of levels above the current.
|
||||
*/
|
||||
public record FramePointer(int parentLevel, int frameSlotIdx) {
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
package org.enso.compiler.context
|
||||
|
||||
import org.enso.compiler.PackageRepository
|
||||
import org.enso.compiler.context.LocalScope
|
||||
import org.enso.compiler.data.CompilerConfig
|
||||
import org.enso.compiler.pass.PassConfiguration
|
||||
import org.enso.interpreter.runtime.scope.LocalScope
|
||||
|
||||
/** A type containing the information about the execution context for an inline
|
||||
* expression.
|
@ -1,6 +1,5 @@
|
||||
package org.enso.interpreter.runtime.scope
|
||||
package org.enso.compiler.context
|
||||
|
||||
import com.oracle.truffle.api.frame.{FrameDescriptor, FrameSlotKind}
|
||||
import org.enso.compiler.pass.analyse.AliasAnalysis.Graph
|
||||
import org.enso.compiler.pass.analyse.AliasAnalysis.Graph.{
|
||||
Id,
|
||||
@ -8,11 +7,6 @@ import org.enso.compiler.pass.analyse.AliasAnalysis.Graph.{
|
||||
Scope => AliasScope
|
||||
}
|
||||
import org.enso.compiler.pass.analyse.{AliasAnalysis, DataflowAnalysis}
|
||||
import org.enso.interpreter.runtime.error.DataflowError
|
||||
import org.enso.interpreter.runtime.scope.LocalScope.{
|
||||
internalSlots,
|
||||
monadicStateSlotName
|
||||
}
|
||||
|
||||
import scala.jdk.CollectionConverters._
|
||||
|
||||
@ -45,7 +39,6 @@ class LocalScope(
|
||||
final val flattenToParent: Boolean = false,
|
||||
private val parentFrameSlotIdxs: Map[Graph.Id, Int] = Map()
|
||||
) {
|
||||
lazy val frameDescriptor: FrameDescriptor = buildFrameDescriptor()
|
||||
private lazy val localFrameSlotIdxs: Map[Graph.Id, Int] =
|
||||
gatherLocalFrameSlotIdxs()
|
||||
|
||||
@ -82,20 +75,6 @@ class LocalScope(
|
||||
)
|
||||
}
|
||||
|
||||
/** Returns frame slot index to a monadic state, which is considered an internal slot.
|
||||
* @return
|
||||
*/
|
||||
def monadicStateSlotIdx: Int = {
|
||||
internalSlots.zipWithIndex
|
||||
.find { case ((_, name), _) => name == monadicStateSlotName }
|
||||
.map(_._2)
|
||||
.getOrElse(
|
||||
throw new IllegalStateException(
|
||||
s"$monadicStateSlotName slot should be present in every frame descriptor"
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
/** Get a frame slot index for a given identifier.
|
||||
*
|
||||
* The identifier must be present in the local scope.
|
||||
@ -138,39 +117,6 @@ class LocalScope(
|
||||
def flattenBindings: java.util.Map[String, FramePointer] =
|
||||
flattenBindingsWithLevel(0).asJava
|
||||
|
||||
private def addInternalSlots(
|
||||
descriptorBuilder: FrameDescriptor.Builder
|
||||
): Unit = {
|
||||
for ((slotKind, name) <- internalSlots) {
|
||||
descriptorBuilder.addSlot(slotKind, name, null)
|
||||
}
|
||||
}
|
||||
|
||||
/** Builds a [[FrameDescriptor]] from the alias analysis scope metadata for the local scope.
|
||||
* See [[AliasAnalysis.Graph.Scope.allDefinitions]].
|
||||
*
|
||||
* @return [[FrameDescriptor]] built from the variable definitions in the local scope.
|
||||
*/
|
||||
private def buildFrameDescriptor(): FrameDescriptor = {
|
||||
val descriptorBuilder = FrameDescriptor.newBuilder()
|
||||
addInternalSlots(descriptorBuilder)
|
||||
for (definition <- scope.allDefinitions) {
|
||||
val returnedFrameIdx =
|
||||
descriptorBuilder.addSlot(
|
||||
FrameSlotKind.Illegal,
|
||||
definition.symbol,
|
||||
null
|
||||
)
|
||||
assert(localFrameSlotIdxs(definition.id) == returnedFrameIdx)
|
||||
}
|
||||
descriptorBuilder.defaultValue(DataflowError.UNINITIALIZED)
|
||||
val frameDescriptor = descriptorBuilder.build()
|
||||
assert(
|
||||
internalSlots.length + localFrameSlotIdxs.size == frameDescriptor.getNumberOfSlots
|
||||
)
|
||||
frameDescriptor
|
||||
}
|
||||
|
||||
/** Gather local variables from the alias scope information.
|
||||
* Does not include any variables from the parent scopes.
|
||||
* @return Mapping of local variable identifiers to their
|
||||
@ -179,7 +125,7 @@ class LocalScope(
|
||||
*/
|
||||
private def gatherLocalFrameSlotIdxs(): Map[Id, Int] = {
|
||||
scope.allDefinitions.zipWithIndex.map { case (definition, i) =>
|
||||
definition.id -> (i + internalSlots.size)
|
||||
definition.id -> (i + LocalScope.internalSlotsSize)
|
||||
}.toMap
|
||||
}
|
||||
|
||||
@ -207,13 +153,12 @@ class LocalScope(
|
||||
}
|
||||
|
||||
override def toString: String = {
|
||||
s"LocalScope(${frameDescriptor.toString})"
|
||||
s"LocalScope(${allFrameSlotIdxs.keySet})"
|
||||
}
|
||||
}
|
||||
object LocalScope {
|
||||
|
||||
/** Constructs a local scope for an
|
||||
* [[org.enso.interpreter.node.EnsoRootNode]].
|
||||
/** Constructs a local scope for an [[EnsoRootNode]].
|
||||
*
|
||||
* @return a defaulted local scope
|
||||
*/
|
||||
@ -227,13 +172,11 @@ object LocalScope {
|
||||
)
|
||||
}
|
||||
|
||||
private val monadicStateSlotName = "<<monadic_state>>"
|
||||
|
||||
/** Internal slots are prepended at the beginning of every [[FrameDescriptor]].
|
||||
* Every tuple of the list denotes frame slot kind and its name.
|
||||
* Note that `info` for a frame slot is not used by Enso.
|
||||
*/
|
||||
def internalSlots: List[(FrameSlotKind, String)] = List(
|
||||
(FrameSlotKind.Object, monadicStateSlotName)
|
||||
)
|
||||
def monadicStateSlotName: String = "<<monadic_state>>"
|
||||
private def internalSlotsSize: Int = 1
|
||||
|
||||
}
|
@ -14,7 +14,7 @@ import org.enso.compiler.core.ir.expression.errors
|
||||
import org.enso.compiler.core.ir.module.scope.definition
|
||||
import org.enso.compiler.pass.PassManager
|
||||
import org.enso.compiler.test.CompilerTest
|
||||
import org.enso.interpreter.runtime.scope.LocalScope
|
||||
import org.enso.compiler.context.LocalScope
|
||||
import org.enso.text.buffer.Rope
|
||||
import org.enso.text.editing.JavaEditorAdapter
|
||||
import org.enso.text.editing.model.{Position, Range, TextEdit}
|
||||
|
@ -17,6 +17,7 @@ import java.net.URI;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.enso.compiler.context.FramePointer;
|
||||
import org.enso.interpreter.node.expression.builtin.debug.DebugBreakpointNode;
|
||||
import org.enso.interpreter.node.expression.builtin.text.util.ToJavaStringNode;
|
||||
import org.enso.interpreter.node.expression.debug.CaptureResultScopeNode;
|
||||
@ -25,7 +26,6 @@ import org.enso.interpreter.runtime.EnsoContext;
|
||||
import org.enso.interpreter.runtime.callable.CallerInfo;
|
||||
import org.enso.interpreter.runtime.callable.function.Function;
|
||||
import org.enso.interpreter.runtime.data.text.Text;
|
||||
import org.enso.interpreter.runtime.scope.FramePointer;
|
||||
import org.enso.interpreter.runtime.state.State;
|
||||
import org.enso.polyglot.debugger.DebugServerInfo;
|
||||
import org.graalvm.options.OptionDescriptor;
|
||||
@ -105,12 +105,12 @@ public class ReplDebuggerInstrument extends TruffleInstrument {
|
||||
}
|
||||
|
||||
private Object getValue(MaterializedFrame frame, FramePointer ptr) {
|
||||
return getProperFrame(frame, ptr).getValue(ptr.getFrameSlotIdx());
|
||||
return getProperFrame(frame, ptr).getValue(ptr.frameSlotIdx());
|
||||
}
|
||||
|
||||
private MaterializedFrame getProperFrame(MaterializedFrame frame, FramePointer ptr) {
|
||||
MaterializedFrame currentFrame = frame;
|
||||
for (int i = 0; i < ptr.getParentLevel(); i++) {
|
||||
for (int i = 0; i < ptr.parentLevel(); i++) {
|
||||
currentFrame = Function.ArgumentsHelper.getLocalScope(currentFrame.getArguments());
|
||||
}
|
||||
return currentFrame;
|
||||
|
@ -24,7 +24,7 @@ import org.enso.interpreter.node.ExpressionNode;
|
||||
import org.enso.interpreter.node.ProgramRootNode;
|
||||
import org.enso.interpreter.runtime.EnsoContext;
|
||||
import org.enso.interpreter.runtime.IrToTruffle;
|
||||
import org.enso.interpreter.runtime.scope.LocalScope;
|
||||
import org.enso.compiler.context.LocalScope;
|
||||
import org.enso.interpreter.runtime.state.ExecutionEnvironment;
|
||||
import org.enso.interpreter.runtime.tag.AvoidIdInstrumentationTag;
|
||||
import org.enso.interpreter.runtime.tag.IdentifiedTag;
|
||||
|
@ -5,8 +5,8 @@ import com.oracle.truffle.api.dsl.ReportPolymorphism;
|
||||
import com.oracle.truffle.api.frame.VirtualFrame;
|
||||
import com.oracle.truffle.api.nodes.NodeInfo;
|
||||
import com.oracle.truffle.api.source.SourceSection;
|
||||
import org.enso.compiler.context.LocalScope;
|
||||
import org.enso.interpreter.EnsoLanguage;
|
||||
import org.enso.interpreter.runtime.scope.LocalScope;
|
||||
import org.enso.interpreter.runtime.scope.ModuleScope;
|
||||
|
||||
/**
|
||||
|
@ -4,11 +4,18 @@ import com.oracle.truffle.api.nodes.NodeInfo;
|
||||
import com.oracle.truffle.api.nodes.RootNode;
|
||||
import com.oracle.truffle.api.source.Source;
|
||||
import com.oracle.truffle.api.source.SourceSection;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.enso.interpreter.EnsoLanguage;
|
||||
import org.enso.interpreter.runtime.EnsoContext;
|
||||
import org.enso.interpreter.runtime.scope.LocalScope;
|
||||
import org.enso.interpreter.runtime.error.DataflowError;
|
||||
import org.enso.compiler.context.LocalScope;
|
||||
import org.enso.interpreter.runtime.scope.ModuleScope;
|
||||
import org.enso.interpreter.util.ScalaConversions;
|
||||
|
||||
import com.oracle.truffle.api.frame.FrameDescriptor;
|
||||
import com.oracle.truffle.api.frame.FrameSlotKind;
|
||||
|
||||
/** A common base class for all kinds of root node in Enso. */
|
||||
@NodeInfo(shortName = "Root", description = "A root node for Enso computations")
|
||||
@ -35,7 +42,7 @@ public abstract class EnsoRootNode extends RootNode {
|
||||
ModuleScope moduleScope,
|
||||
String name,
|
||||
SourceSection sourceSection) {
|
||||
super(language, localScope.frameDescriptor());
|
||||
super(language, buildFrameDescriptor(localScope));
|
||||
Objects.requireNonNull(language);
|
||||
this.name = name;
|
||||
this.localScope = localScope;
|
||||
@ -49,6 +56,26 @@ public abstract class EnsoRootNode extends RootNode {
|
||||
this.sourceLength = sourceSection == null ? NO_SOURCE : sourceSection.getCharLength();
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a {@link FrameDescriptor} from the alias analysis scope metadata
|
||||
* for the local scope. See [[AliasAnalysis.Graph.Scope.allDefinitions]].
|
||||
*
|
||||
* @return {@link FrameDescriptor} built from the variable definitions in
|
||||
* the local localScope.
|
||||
*/
|
||||
private static FrameDescriptor buildFrameDescriptor(LocalScope localScope) {
|
||||
var descriptorBuilder = FrameDescriptor.newBuilder();
|
||||
descriptorBuilder.addSlot(FrameSlotKind.Object, LocalScope.monadicStateSlotName(), null);
|
||||
for (var definition : ScalaConversions.asJava(localScope.scope().allDefinitions())) {
|
||||
descriptorBuilder.addSlot(
|
||||
FrameSlotKind.Illegal, definition.symbol(), null
|
||||
);
|
||||
}
|
||||
descriptorBuilder.defaultValue(DataflowError.UNINITIALIZED);
|
||||
var frameDescriptor = descriptorBuilder.build();
|
||||
return frameDescriptor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a reference to the language context associated with this program.
|
||||
*
|
||||
|
@ -3,12 +3,12 @@ package org.enso.interpreter.node;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.enso.compiler.core.CompilerError;
|
||||
import org.enso.compiler.context.LocalScope;
|
||||
import org.enso.interpreter.EnsoLanguage;
|
||||
import org.enso.interpreter.runtime.EnsoContext;
|
||||
import org.enso.interpreter.runtime.data.Type;
|
||||
import org.enso.interpreter.runtime.data.text.Text;
|
||||
import org.enso.interpreter.runtime.error.PanicException;
|
||||
import org.enso.interpreter.runtime.scope.LocalScope;
|
||||
import org.enso.interpreter.runtime.scope.ModuleScope;
|
||||
|
||||
import com.oracle.truffle.api.CompilerDirectives;
|
||||
|
@ -10,9 +10,9 @@ import com.oracle.truffle.api.dsl.Specialization;
|
||||
import com.oracle.truffle.api.frame.MaterializedFrame;
|
||||
import com.oracle.truffle.api.nodes.Node;
|
||||
import com.oracle.truffle.api.nodes.NodeInfo;
|
||||
import org.enso.compiler.context.LocalScope;
|
||||
import org.enso.interpreter.node.EnsoRootNode;
|
||||
import org.enso.interpreter.runtime.callable.CallerInfo;
|
||||
import org.enso.interpreter.runtime.scope.LocalScope;
|
||||
import org.enso.interpreter.runtime.scope.ModuleScope;
|
||||
|
||||
/**
|
||||
|
@ -8,6 +8,7 @@ import com.oracle.truffle.api.dsl.ReportPolymorphism;
|
||||
import com.oracle.truffle.api.dsl.Specialization;
|
||||
import com.oracle.truffle.api.nodes.NodeInfo;
|
||||
import org.enso.compiler.context.InlineContext;
|
||||
import org.enso.compiler.context.LocalScope;
|
||||
import org.enso.interpreter.Constants;
|
||||
import org.enso.interpreter.node.BaseNode;
|
||||
import org.enso.interpreter.node.ClosureRootNode;
|
||||
@ -18,7 +19,6 @@ import org.enso.interpreter.runtime.IrToTruffle;
|
||||
import org.enso.interpreter.runtime.callable.CallerInfo;
|
||||
import org.enso.interpreter.runtime.callable.function.Function;
|
||||
import org.enso.interpreter.runtime.data.text.Text;
|
||||
import org.enso.interpreter.runtime.scope.LocalScope;
|
||||
import org.enso.interpreter.runtime.scope.ModuleScope;
|
||||
import org.enso.interpreter.runtime.state.State;
|
||||
|
||||
|
@ -8,9 +8,9 @@ import com.oracle.truffle.api.frame.MaterializedFrame;
|
||||
import com.oracle.truffle.api.frame.VirtualFrame;
|
||||
import com.oracle.truffle.api.nodes.ExplodeLoop;
|
||||
import com.oracle.truffle.api.nodes.NodeInfo;
|
||||
import org.enso.compiler.context.FramePointer;
|
||||
import org.enso.interpreter.node.ExpressionNode;
|
||||
import org.enso.interpreter.runtime.callable.function.Function;
|
||||
import org.enso.interpreter.runtime.scope.FramePointer;
|
||||
|
||||
/**
|
||||
* Reads from a local target (variable or call target).
|
||||
@ -45,10 +45,10 @@ public abstract class ReadLocalVariableNode extends ExpressionNode {
|
||||
*/
|
||||
@Specialization(rewriteOn = FrameSlotTypeException.class)
|
||||
protected long readLong(VirtualFrame frame) throws FrameSlotTypeException {
|
||||
if (getFramePointer().getParentLevel() == 0)
|
||||
return frame.getLong(getFramePointer().getFrameSlotIdx());
|
||||
if (getFramePointer().parentLevel() == 0)
|
||||
return frame.getLong(getFramePointer().frameSlotIdx());
|
||||
MaterializedFrame currentFrame = getProperFrame(frame);
|
||||
return currentFrame.getLong(getFramePointer().getFrameSlotIdx());
|
||||
return currentFrame.getLong(getFramePointer().frameSlotIdx());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -61,18 +61,18 @@ public abstract class ReadLocalVariableNode extends ExpressionNode {
|
||||
*/
|
||||
@Specialization(rewriteOn = FrameSlotTypeException.class)
|
||||
protected Object readGeneric(VirtualFrame frame) throws FrameSlotTypeException {
|
||||
if (getFramePointer().getParentLevel() == 0)
|
||||
return frame.getObject(getFramePointer().getFrameSlotIdx());
|
||||
if (getFramePointer().parentLevel() == 0)
|
||||
return frame.getObject(getFramePointer().frameSlotIdx());
|
||||
MaterializedFrame currentFrame = getProperFrame(frame);
|
||||
return currentFrame.getObject(getFramePointer().getFrameSlotIdx());
|
||||
return currentFrame.getObject(getFramePointer().frameSlotIdx());
|
||||
}
|
||||
|
||||
@Specialization
|
||||
protected Object readGenericValue(VirtualFrame frame) {
|
||||
if (getFramePointer().getParentLevel() == 0)
|
||||
return frame.getValue(getFramePointer().getFrameSlotIdx());
|
||||
if (getFramePointer().parentLevel() == 0)
|
||||
return frame.getValue(getFramePointer().frameSlotIdx());
|
||||
MaterializedFrame currentFrame = getProperFrame(frame);
|
||||
return currentFrame.getValue(getFramePointer().getFrameSlotIdx());
|
||||
return currentFrame.getValue(getFramePointer().frameSlotIdx());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -97,7 +97,7 @@ public abstract class ReadLocalVariableNode extends ExpressionNode {
|
||||
@ExplodeLoop
|
||||
public MaterializedFrame getProperFrame(Frame frame) {
|
||||
MaterializedFrame currentFrame = getParentFrame(frame);
|
||||
for (int i = 1; i < getFramePointer().getParentLevel(); i++) {
|
||||
for (int i = 1; i < getFramePointer().parentLevel(); i++) {
|
||||
currentFrame = getParentFrame(currentFrame);
|
||||
}
|
||||
return currentFrame;
|
||||
|
@ -23,6 +23,7 @@ import java.util.UUID;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.logging.Level;
|
||||
import org.enso.compiler.context.CompilerContext;
|
||||
import org.enso.compiler.context.LocalScope;
|
||||
import org.enso.compiler.context.SimpleUpdate;
|
||||
import org.enso.compiler.core.IR;
|
||||
import org.enso.compiler.core.ir.Expression;
|
||||
@ -37,7 +38,6 @@ import org.enso.interpreter.runtime.data.EnsoObject;
|
||||
import org.enso.interpreter.runtime.data.Type;
|
||||
import org.enso.interpreter.runtime.data.text.Text;
|
||||
import org.enso.interpreter.runtime.data.vector.ArrayLikeHelpers;
|
||||
import org.enso.interpreter.runtime.scope.LocalScope;
|
||||
import org.enso.interpreter.runtime.scope.ModuleScope;
|
||||
import org.enso.interpreter.runtime.type.Types;
|
||||
import org.enso.pkg.Package;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package org.enso.interpreter.runtime.callable;
|
||||
|
||||
import com.oracle.truffle.api.frame.MaterializedFrame;
|
||||
import org.enso.interpreter.runtime.scope.LocalScope;
|
||||
import org.enso.compiler.context.LocalScope;
|
||||
import org.enso.interpreter.runtime.scope.ModuleScope;
|
||||
|
||||
/**
|
||||
|
@ -13,6 +13,7 @@ import com.oracle.truffle.api.nodes.RootNode;
|
||||
import com.oracle.truffle.api.source.SourceSection;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import org.enso.compiler.context.LocalScope;
|
||||
import org.enso.interpreter.EnsoLanguage;
|
||||
import org.enso.interpreter.node.ClosureRootNode;
|
||||
import org.enso.interpreter.node.ExpressionNode;
|
||||
@ -29,7 +30,6 @@ import org.enso.interpreter.runtime.callable.function.FunctionSchema;
|
||||
import org.enso.interpreter.runtime.data.EnsoObject;
|
||||
import org.enso.interpreter.runtime.data.Type;
|
||||
import org.enso.interpreter.runtime.library.dispatch.TypesLibrary;
|
||||
import org.enso.interpreter.runtime.scope.LocalScope;
|
||||
import org.enso.interpreter.runtime.scope.ModuleScope;
|
||||
import org.enso.pkg.QualifiedName;
|
||||
|
||||
|
@ -16,6 +16,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.stream.Collectors;
|
||||
import org.enso.compiler.context.FramePointer;
|
||||
import org.enso.interpreter.EnsoLanguage;
|
||||
import org.enso.interpreter.node.EnsoRootNode;
|
||||
import org.enso.interpreter.runtime.callable.function.Function;
|
||||
@ -100,9 +101,9 @@ public class DebugLocalScope implements EnsoObject {
|
||||
|
||||
int maxParentLevel =
|
||||
bindings.values().stream()
|
||||
.max(Comparator.comparingInt(FramePointer::getParentLevel))
|
||||
.max(Comparator.comparingInt(FramePointer::parentLevel))
|
||||
.orElseThrow()
|
||||
.getParentLevel();
|
||||
.parentLevel();
|
||||
|
||||
// Get all binding names for a particular parent level
|
||||
List<List<String>> bindingsByLevels = new ArrayList<>(maxParentLevel + 1);
|
||||
@ -110,7 +111,7 @@ public class DebugLocalScope implements EnsoObject {
|
||||
final int finalLevel = level;
|
||||
List<String> levelBindings =
|
||||
bindings.entrySet().stream()
|
||||
.filter(entry -> entry.getValue().getParentLevel() == finalLevel)
|
||||
.filter(entry -> entry.getValue().parentLevel() == finalLevel)
|
||||
.map(Entry::getKey)
|
||||
.collect(Collectors.toList());
|
||||
bindingsByLevels.add(levelBindings);
|
||||
@ -253,18 +254,18 @@ public class DebugLocalScope implements EnsoObject {
|
||||
}
|
||||
|
||||
private Object getValue(MaterializedFrame frame, FramePointer ptr) {
|
||||
return ptr == null ? null : getProperFrame(frame, ptr).getValue(ptr.getFrameSlotIdx());
|
||||
return ptr == null ? null : getProperFrame(frame, ptr).getValue(ptr.frameSlotIdx());
|
||||
}
|
||||
|
||||
private void setValue(MaterializedFrame frame, FramePointer ptr, Object value) {
|
||||
assert ptr != null;
|
||||
MaterializedFrame properFrame = getProperFrame(frame, ptr);
|
||||
properFrame.setObject(ptr.getFrameSlotIdx(), value);
|
||||
properFrame.setObject(ptr.frameSlotIdx(), value);
|
||||
}
|
||||
|
||||
private MaterializedFrame getProperFrame(MaterializedFrame frame, FramePointer ptr) {
|
||||
MaterializedFrame currentFrame = frame;
|
||||
for (int i = 0; i < ptr.getParentLevel(); i++) {
|
||||
for (int i = 0; i < ptr.parentLevel(); i++) {
|
||||
currentFrame = Function.ArgumentsHelper.getLocalScope(currentFrame.getArguments());
|
||||
}
|
||||
return currentFrame;
|
||||
|
@ -1,38 +0,0 @@
|
||||
package org.enso.interpreter.runtime.scope;
|
||||
|
||||
/**
|
||||
* A representation of a pointer into a stack frame at a given number of levels above the current.
|
||||
*/
|
||||
public class FramePointer {
|
||||
private final int parentLevel;
|
||||
private final int frameSlotIdx;
|
||||
|
||||
/**
|
||||
* A representation of a frame slot at a given level above the current frame.
|
||||
*
|
||||
* @param parentLevel the number of parents to move from the current frame to get here
|
||||
* @param frameSlotIdx the index of the slot in the n-th parent frame
|
||||
*/
|
||||
public FramePointer(int parentLevel, int frameSlotIdx) {
|
||||
this.parentLevel = parentLevel;
|
||||
this.frameSlotIdx = frameSlotIdx;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the parent level.
|
||||
*
|
||||
* @return the parent level represented by this {@code FramePointer}
|
||||
*/
|
||||
public int getParentLevel() {
|
||||
return parentLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the index of the frame slot.
|
||||
*
|
||||
* @return the frame slot index represented by this {@code FramePointer}
|
||||
*/
|
||||
public int getFrameSlotIdx() {
|
||||
return frameSlotIdx;
|
||||
}
|
||||
}
|
@ -3,6 +3,8 @@ package org.enso.interpreter.runtime
|
||||
import com.oracle.truffle.api.source.{Source, SourceSection}
|
||||
import com.oracle.truffle.api.interop.InteropLibrary
|
||||
import org.enso.compiler.context.CompilerContext
|
||||
import org.enso.compiler.context.FramePointer
|
||||
import org.enso.compiler.context.LocalScope
|
||||
import org.enso.compiler.core.CompilerError
|
||||
import org.enso.compiler.core.ConstantsNames
|
||||
import org.enso.compiler.core.Implicits.AsMetadata
|
||||
@ -104,11 +106,7 @@ import org.enso.interpreter.runtime.callable.{
|
||||
}
|
||||
import org.enso.interpreter.runtime.data.Type
|
||||
import org.enso.interpreter.runtime.data.text.Text
|
||||
import org.enso.interpreter.runtime.scope.{
|
||||
FramePointer,
|
||||
LocalScope,
|
||||
ModuleScope
|
||||
}
|
||||
import org.enso.interpreter.runtime.scope.{ModuleScope}
|
||||
import org.enso.interpreter.{Constants, EnsoLanguage}
|
||||
|
||||
import java.math.BigInteger
|
||||
|
@ -15,7 +15,7 @@ import org.scalatest.matchers.should.Matchers
|
||||
import org.scalatest.wordspec.AnyWordSpecLike
|
||||
import org.enso.interpreter.runtime
|
||||
import org.enso.interpreter.runtime.ModuleTestUtils
|
||||
import org.enso.interpreter.runtime.scope.LocalScope
|
||||
import org.enso.compiler.context.LocalScope
|
||||
import org.enso.pkg.QualifiedName
|
||||
import org.enso.polyglot.CompilationStage
|
||||
|
||||
|
@ -26,7 +26,7 @@ import org.enso.compiler.pass.analyse.DataflowAnalysis.{
|
||||
import org.enso.compiler.pass.analyse.{AliasAnalysis, DataflowAnalysis}
|
||||
import org.enso.compiler.pass.{PassConfiguration, PassGroup, PassManager}
|
||||
import org.enso.compiler.test.CompilerTest
|
||||
import org.enso.interpreter.runtime.scope.LocalScope
|
||||
import org.enso.compiler.context.LocalScope
|
||||
import org.enso.interpreter.test.Metadata
|
||||
import org.scalatest.Assertion
|
||||
|
||||
|
@ -15,7 +15,7 @@ import org.enso.compiler.pass.PassConfiguration._
|
||||
import org.enso.compiler.pass.analyse.{AliasAnalysis, DemandAnalysis}
|
||||
import org.enso.compiler.pass.{PassConfiguration, PassGroup, PassManager}
|
||||
import org.enso.compiler.test.CompilerTest
|
||||
import org.enso.interpreter.runtime.scope.LocalScope
|
||||
import org.enso.compiler.context.LocalScope
|
||||
|
||||
class DemandAnalysisTest extends CompilerTest {
|
||||
|
||||
|
@ -18,7 +18,7 @@ import org.enso.compiler.pass.analyse.TailCall.TailPosition
|
||||
import org.enso.compiler.pass.analyse.{AliasAnalysis, TailCall}
|
||||
import org.enso.compiler.pass.{PassConfiguration, PassGroup, PassManager}
|
||||
import org.enso.compiler.test.CompilerTest
|
||||
import org.enso.interpreter.runtime.scope.LocalScope
|
||||
import org.enso.compiler.context.LocalScope
|
||||
|
||||
class TailCallTest extends CompilerTest {
|
||||
|
||||
|
@ -10,7 +10,7 @@ import org.enso.compiler.pass.analyse._
|
||||
import org.enso.compiler.pass.lint.UnusedBindings
|
||||
import org.enso.compiler.pass.{PassConfiguration, PassGroup, PassManager}
|
||||
import org.enso.compiler.test.CompilerTest
|
||||
import org.enso.interpreter.runtime.scope.LocalScope
|
||||
import org.enso.compiler.context.LocalScope
|
||||
import org.scalatest.Inside
|
||||
|
||||
class UnusedBindingsTest extends CompilerTest with Inside {
|
||||
|
@ -17,7 +17,7 @@ import org.enso.compiler.pass.analyse.AliasAnalysis
|
||||
import org.enso.compiler.pass.optimise.LambdaConsolidate
|
||||
import org.enso.compiler.pass.{PassConfiguration, PassGroup, PassManager}
|
||||
import org.enso.compiler.test.CompilerTest
|
||||
import org.enso.interpreter.runtime.scope.LocalScope
|
||||
import org.enso.compiler.context.LocalScope
|
||||
|
||||
class LambdaConsolidateTest extends CompilerTest {
|
||||
|
||||
|
@ -12,7 +12,7 @@ import org.enso.compiler.pass.analyse.AliasAnalysis
|
||||
import org.enso.compiler.pass.resolve.SuspendedArguments
|
||||
import org.enso.compiler.pass.{PassConfiguration, PassGroup, PassManager}
|
||||
import org.enso.compiler.test.CompilerTest
|
||||
import org.enso.interpreter.runtime.scope.LocalScope
|
||||
import org.enso.compiler.context.LocalScope
|
||||
import org.enso.compiler.pass.PassConfiguration._
|
||||
|
||||
class SuspendedArgumentsTest extends CompilerTest {
|
||||
|
Loading…
Reference in New Issue
Block a user