Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
mio-19 committed Oct 25, 2024
1 parent 99a2abd commit c05cd1c
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 22 deletions.
11 changes: 0 additions & 11 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions interpreter/jvm/src/main/scala/chester/truffle/ChesterContext.java
Original file line number Diff line number Diff line change
@@ -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<ChesterContext> 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);
}

}
11 changes: 9 additions & 2 deletions interpreter/jvm/src/main/scala/chester/truffle/ChesterLang.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@
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<ChesterContext> {
public final class ChesterLang extends TruffleLanguage<ChesterContext> {
private static final LanguageReference<ChesterLang> 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");
}

@Override
protected ChesterContext createContext(Env env) {
return null;
return new ChesterContext();
}
}
6 changes: 0 additions & 6 deletions interpreter/jvm/src/main/scala/chester/truffle/index.scala

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<TermNode> {
private final boolean value;

public BooleanNode(boolean value) {
this.value = value;
}
@Override
public boolean value() {
return value;
}

@Override
public Option<TermMeta> meta() {
return (Option) None$.MODULE$;
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package chester.truffle.node;

import chester.syntax.core.LiteralTermT;

public abstract class LiteralNode extends TermNode implements LiteralTermT<TermNode> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package chester.truffle.node;

import chester.syntax.core.TermT;

public abstract class TermNode extends ChesterNode implements TermT<TermNode> {
}
6 changes: 3 additions & 3 deletions syntax/src/main/scala/chester/syntax/core/Term.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit c05cd1c

Please sign in to comment.