From c05cd1c69e95a808744f3bd9bdac06244ca834a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BE=AA?= Date: Fri, 25 Oct 2024 21:03:40 +1300 Subject: [PATCH] save --- build.sbt | 11 -------- .../scala/chester/truffle/ChesterContext.java | 16 ++++++++++++ .../scala/chester/truffle/ChesterLang.java | 11 ++++++-- .../main/scala/chester/truffle/index.scala | 6 ----- .../chester/truffle/node/BooleanNode.java | 25 +++++++++++++++++++ .../chester/truffle/node/ChesterNode.java | 16 ++++++++++++ .../chester/truffle/node/LiteralNode.java | 6 +++++ .../scala/chester/truffle/node/TermNode.java | 6 +++++ .../main/scala/chester/syntax/core/Term.scala | 6 ++--- 9 files changed, 81 insertions(+), 22 deletions(-) create mode 100644 interpreter/jvm/src/main/scala/chester/truffle/ChesterContext.java delete mode 100644 interpreter/jvm/src/main/scala/chester/truffle/index.scala create mode 100644 interpreter/jvm/src/main/scala/chester/truffle/node/BooleanNode.java create mode 100644 interpreter/jvm/src/main/scala/chester/truffle/node/ChesterNode.java create mode 100644 interpreter/jvm/src/main/scala/chester/truffle/node/LiteralNode.java create mode 100644 interpreter/jvm/src/main/scala/chester/truffle/node/TermNode.java diff --git a/build.sbt b/build.sbt index 206c6f58..357f4f7a 100644 --- a/build.sbt +++ b/build.sbt @@ -1201,9 +1201,6 @@ lazy val buildTool = crossProject(JVMPlatform) ) ) -// Define directories for generated sources and classes -val generatedSourcesDir = file("target") / "generated" / "truffle" - lazy val interpreter = crossProject(JSPlatform, JVMPlatform, NativePlatform) .withoutSuffixFor(JVMPlatform) .crossType(CrossType.Full) @@ -1246,23 +1243,15 @@ lazy val interpreter = crossProject(JSPlatform, JVMPlatform, NativePlatform) val processorJars = cp.filter(_.getName.contains("truffle-dsl-processor")) val processorPath = processorJars.map(_.getAbsolutePath).mkString(java.io.File.pathSeparator) - // Ensure the directories exist - IO.createDirectory(generatedSourcesDir) - Seq( "-processorpath", processorPath, - "-s", - generatedSourcesDir.getAbsolutePath, "-source", "17", "-target", "17" ) }, - - // Add the generated sources to the unmanaged source directories - Compile / unmanagedSourceDirectories += generatedSourcesDir ) lazy val root = crossProject(JSPlatform, JVMPlatform, NativePlatform) diff --git a/interpreter/jvm/src/main/scala/chester/truffle/ChesterContext.java b/interpreter/jvm/src/main/scala/chester/truffle/ChesterContext.java new file mode 100644 index 00000000..988515f2 --- /dev/null +++ b/interpreter/jvm/src/main/scala/chester/truffle/ChesterContext.java @@ -0,0 +1,16 @@ +package chester.truffle; + +import com.oracle.truffle.api.TruffleLanguage; +import com.oracle.truffle.api.nodes.Node; +import com.oracle.truffle.api.object.DynamicObject; + +public final class ChesterContext { + private static final TruffleLanguage.ContextReference REF = + TruffleLanguage.ContextReference.create(ChesterLang.class); + + /** Retrieve the current language context for the given {@link Node}. */ + public static ChesterContext get(Node node) { + return REF.get(node); + } + +} \ No newline at end of file diff --git a/interpreter/jvm/src/main/scala/chester/truffle/ChesterLang.java b/interpreter/jvm/src/main/scala/chester/truffle/ChesterLang.java index 7057391a..bff6f0be 100644 --- a/interpreter/jvm/src/main/scala/chester/truffle/ChesterLang.java +++ b/interpreter/jvm/src/main/scala/chester/truffle/ChesterLang.java @@ -4,9 +4,16 @@ import com.oracle.truffle.api.TruffleLanguage; import com.oracle.truffle.api.TruffleLanguage.Env; import com.oracle.truffle.api.TruffleLanguage.ParsingRequest; +import com.oracle.truffle.api.nodes.Node; @TruffleLanguage.Registration(id = "cst", name = "Chester") -public class ChesterLang extends TruffleLanguage { +public final class ChesterLang extends TruffleLanguage { + private static final LanguageReference REF = + LanguageReference.create(ChesterLang.class); + /** Retrieve the current language instance for the given {@link Node}. */ + public static ChesterLang get(Node node) { + return REF.get(node); + } @Override protected CallTarget parse(ParsingRequest request) throws Exception { throw new UnsupportedOperationException("Not implemented yet"); @@ -14,6 +21,6 @@ protected CallTarget parse(ParsingRequest request) throws Exception { @Override protected ChesterContext createContext(Env env) { - return null; + return new ChesterContext(); } } \ No newline at end of file diff --git a/interpreter/jvm/src/main/scala/chester/truffle/index.scala b/interpreter/jvm/src/main/scala/chester/truffle/index.scala deleted file mode 100644 index 32cac642..00000000 --- a/interpreter/jvm/src/main/scala/chester/truffle/index.scala +++ /dev/null @@ -1,6 +0,0 @@ -package chester.truffle - -import com.oracle.truffle.api.{CallTarget, TruffleLanguage} -import com.oracle.truffle.api.TruffleLanguage.{Env, ParsingRequest} - -trait ChesterContext diff --git a/interpreter/jvm/src/main/scala/chester/truffle/node/BooleanNode.java b/interpreter/jvm/src/main/scala/chester/truffle/node/BooleanNode.java new file mode 100644 index 00000000..0bda1364 --- /dev/null +++ b/interpreter/jvm/src/main/scala/chester/truffle/node/BooleanNode.java @@ -0,0 +1,25 @@ +package chester.truffle.node; + +import chester.syntax.core.BooleanTerm; +import chester.syntax.core.BooleanTermC; +import chester.syntax.core.TermMeta; +import scala.None; +import scala.None$; +import scala.Option; + +public final class BooleanNode extends LiteralNode implements BooleanTermC { + private final boolean value; + + public BooleanNode(boolean value) { + this.value = value; + } + @Override + public boolean value() { + return value; + } + + @Override + public Option meta() { + return (Option) None$.MODULE$; + } +} diff --git a/interpreter/jvm/src/main/scala/chester/truffle/node/ChesterNode.java b/interpreter/jvm/src/main/scala/chester/truffle/node/ChesterNode.java new file mode 100644 index 00000000..fb643795 --- /dev/null +++ b/interpreter/jvm/src/main/scala/chester/truffle/node/ChesterNode.java @@ -0,0 +1,16 @@ +package chester.truffle.node; + +import chester.truffle.ChesterContext; +import chester.truffle.ChesterLang; +import com.oracle.truffle.api.nodes.Node; + +public abstract class ChesterNode extends Node { + protected final ChesterLang currentTruffleLanguage() { + return ChesterLang.get(this); + } + + /** Allows retrieving the current Truffle language Context from within a Node. */ + protected final ChesterContext currentLanguageContext() { + return ChesterContext.get(this); + } +} diff --git a/interpreter/jvm/src/main/scala/chester/truffle/node/LiteralNode.java b/interpreter/jvm/src/main/scala/chester/truffle/node/LiteralNode.java new file mode 100644 index 00000000..ea834b55 --- /dev/null +++ b/interpreter/jvm/src/main/scala/chester/truffle/node/LiteralNode.java @@ -0,0 +1,6 @@ +package chester.truffle.node; + +import chester.syntax.core.LiteralTermT; + +public abstract class LiteralNode extends TermNode implements LiteralTermT { +} diff --git a/interpreter/jvm/src/main/scala/chester/truffle/node/TermNode.java b/interpreter/jvm/src/main/scala/chester/truffle/node/TermNode.java new file mode 100644 index 00000000..e967e3c9 --- /dev/null +++ b/interpreter/jvm/src/main/scala/chester/truffle/node/TermNode.java @@ -0,0 +1,6 @@ +package chester.truffle.node; + +import chester.syntax.core.TermT; + +public abstract class TermNode extends ChesterNode implements TermT { +} diff --git a/syntax/src/main/scala/chester/syntax/core/Term.scala b/syntax/src/main/scala/chester/syntax/core/Term.scala index 3fa21edb..dd67f14b 100644 --- a/syntax/src/main/scala/chester/syntax/core/Term.scala +++ b/syntax/src/main/scala/chester/syntax/core/Term.scala @@ -105,7 +105,7 @@ trait SpecialMap { implicit inline def convertSpecialMap[T <: Term](inline f: SpecialMap): T => T = x => f.use(x).asInstanceOf[T] /** more abstract Term. sealed trait *T corresponds to sealed trait in Term; trait *C corresponds to case class in Term */ -sealed trait TermT[+Rec <: TermT[Rec]] { +trait TermT[+Rec <: TermT[Rec]] { type ThisTree <: TermT[Rec] def meta: OptionTermMeta def whnf: Trilean @@ -421,11 +421,11 @@ case class FType(level: Term, meta: OptionTermMeta) extends Sort with FTypeC[Ter Doc.wrapperlist("FType" <> Docs.`(`, Docs.`)`)(Vector(level)) } -sealed trait LiteralTermT[+Rec <: TermT[Rec]] extends TermT[Rec] { +trait LiteralTermT[+Rec <: TermT[Rec]] extends TermT[Rec] with WHNFT[Rec] { override type ThisTree <: LiteralTermT[Rec] } -sealed trait LiteralTerm extends Term with LiteralTermT[Term] derives ReadWriter { +sealed trait LiteralTerm extends Term with LiteralTermT[Term] with WHNF derives ReadWriter { override type ThisTree <: LiteralTerm }