Skip to content

Commit

Permalink
what is happening
Browse files Browse the repository at this point in the history
  • Loading branch information
mio-19 committed Dec 30, 2024
1 parent 30c940e commit 8728195
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 15 deletions.
16 changes: 8 additions & 8 deletions syntax/jvm/src/main/scala/chester/syntax/core/truffle.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import scala.collection.immutable.{ArraySeq, HashMap}
object truffle {
type ExecuteGeneric = (VirtualFrame, Term) => Object
val globalExecuteGeneric: Parameter[ExecuteGeneric] = new Parameter[ExecuteGeneric]
given rw: ReadWriter[Term] = implicitly[ReadWriter[simple.Term]].bimap(convertToTruffle, convertToSimple)
given rw: ReadWriter[Term] = implicitly[ReadWriter[simple.Term]].bimap(convertToSimple, convertToTruffle)
given rw1: ReadWriter[ReferenceCall] = rw.asInstanceOf[ReadWriter[ReferenceCall]]
given rw2: ReadWriter[Effects] = rw.asInstanceOf[ReadWriter[Effects]]
given rw3: ReadWriter[BlockTerm] = rw.asInstanceOf[ReadWriter[BlockTerm]]
Expand Down Expand Up @@ -58,7 +58,7 @@ object truffle {
) extends WHNF
with FCallTermC[Term] {
override type ThisTree = FCallTerm
override def cons: FCallTermF[Term, ThisTree] = this.copy
override def cons: FCallTermF[Term, ThisTree] = FCallTerm(_, _, _)
}
sealed abstract class Pat extends SpecialTerm with PatT[Term] {
override type ThisTree <: Pat
Expand All @@ -70,7 +70,7 @@ object truffle {
) extends Pat
with BindC[Term] {
override type ThisTree = Bind
override def cons: BindF[Term, ThisTree] = this.copy
override def cons: BindF[Term, ThisTree] = Bind(_,_,_)
}
sealed trait WHNF extends Term with WHNFT[Term] {
override type ThisTree <: WHNF
Expand Down Expand Up @@ -216,7 +216,7 @@ object truffle {
) extends TypeTerm
with LiteralTypeC[Term] {
override type ThisTree = LiteralType
override def cons: LiteralTypeF[Term, ThisTree] = this.copy
override def cons: LiteralTypeF[Term, ThisTree] = LiteralType(_,_)
}
case class ArgTerm(
@child var bind: LocalV,
Expand All @@ -236,7 +236,7 @@ object truffle {
) extends WHNF
with TelescopeTermC[Term] {
override type ThisTree = TelescopeTerm
override def cons: TelescopeTermF[Term, ThisTree] = this.copy
override def cons: TelescopeTermF[Term, ThisTree] = TelescopeTerm(_,_,_)
}
case class Function(
@child var ty: FunctionType,
Expand All @@ -245,7 +245,7 @@ object truffle {
) extends WHNF
with FunctionC[Term] {
override type ThisTree = Function
override def cons: FunctionF[Term, ThisTree] = this.copy
override def cons: FunctionF[Term, ThisTree] = Function(_,_,_)
}
case class FunctionType(
@const telescope: Vector[TelescopeTerm],
Expand All @@ -272,7 +272,7 @@ object truffle {
) extends WHNF
with ObjectTermC[Term] {
override type ThisTree = ObjectTerm
override def cons: ObjectTermF[Term, ThisTree] = this.copy
override def cons: ObjectTermF[Term, ThisTree] = ObjectTerm(_,_)
}
case class ObjectType(
@const fieldTypes: Vector[ObjectClauseValueTerm],
Expand Down Expand Up @@ -395,7 +395,7 @@ object truffle {
) extends Uneval
with BlockTermC[Term] {
override type ThisTree = BlockTerm
override def cons: BlockTermF[Term, ThisTree] = this.copy
override def cons: BlockTermF[Term, ThisTree] = BlockTerm(_,_,_)
}
case class Annotation(
@child var term: Term,
Expand Down
5 changes: 1 addition & 4 deletions syntax/shared/src/main/scala/chester/syntax/Tree.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,4 @@ trait TreeMap[Tre <: Tree[Tre]] {
final def apply[T <: Tre](x: T): T = use(x).asInstanceOf[T]
}

implicit def convertSpecialMap2[A <: Tree[A], T <: A](f: TreeMap[A]): Tree[A] => T = x => f.use(x.asInstanceOf[T]).asInstanceOf[T]
implicit def conversion1[A <: Tree[A], T <: Tree[A], U <: T](x: Vector[T]): Vector[U] = x.asInstanceOf[Vector[U]]
implicit def conversion11[A <: Tree[A], T <: Tree[A], U <: T](x: T): U = x.asInstanceOf[U]
//implicit def conversion2[A <: Tree[A], T <: Tree[A]](x:T): A&T = x.asInstanceOf[A&T]
implicit def convertSpecialMap2[A <: Tree[A], T <: A](f: TreeMap[A]): Tree[A] => T = x => f.use(x.asInstanceOf[T]).asInstanceOf[T]
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ object simple {
) extends WHNF
with FunctionTypeC[Term] {
override type ThisTree = FunctionType
override def cons: FunctionTypeF[Term, ThisTree] = this.copy
override def cons: FunctionTypeF[Term, ThisTree] = FunctionType(_,_,_,_)
}
case class ObjectClauseValueTerm(
key: Term,
Expand Down
32 changes: 31 additions & 1 deletion syntax/shared/src/main/scala/chester/syntax/core/spec/Term.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ object spec {
trait CallingArgTermF[Term <: TermT[Term], ThisTree <: CallingArgTermC[Term]] {
def newCallingArgTerm(value: Term, ty: Term, name: Option[Name], vararg: Boolean, meta: OptionTermMeta): ThisTree
}

implicit def convertArg[Term <: TermT[Term],CallingArgTerm <: CallingArgTermC[Term] ](x: CallingArgTermC[Term] ): CallingArgTerm = x.asInstanceOf[CallingArgTerm]
implicit def convertArg[Term <: TermT[Term],CallingArgTerm <: CallingArgTermC[Term] ](x: Seq[CallingArgTermC[Term]] ): Seq[CallingArgTerm] = x.asInstanceOf[Seq[CallingArgTerm] ]

trait CallingArgTermC[Term <: TermT[Term]] extends WHNFT[Term] {
override type ThisTree <: CallingArgTermC[Term]
Expand Down Expand Up @@ -86,7 +89,7 @@ object spec {
def newCalling(args: Seq[CallingArgTermC[Term]], implicitly: Boolean, meta: OptionTermMeta): ThisTree
}

implicit inline def convertaaa[Term <: TermT[Term], ThisTree <: CallingC[Term]](x: Seq[CallingArgTermC[Term]]): Seq[ThisTree] = x.asInstanceOf[Seq[ThisTree]]
implicit inline def convertbbb[Term <: TermT[Term], ThisTree <: CallingC[Term]](x: Vector[CallingC[Term]]): Vector[ThisTree] = x.asInstanceOf[Vector[ThisTree]]

trait CallingC[Term <: TermT[Term]] extends WHNFT[Term] {
override type ThisTree <: CallingC[Term]
Expand Down Expand Up @@ -167,6 +170,8 @@ object spec {
override def descent(f: Term => Term, g: TreeMap[Term]): Term = thisOr(cpy(bind = g(bind), ty = f(ty)))
}

implicit def convert [Term <: TermT[Term]](x: TermT[Term]): Term = x.asInstanceOf[Term]

/** more abstract Term. sealed trait *T corresponds to sealed trait in Term; trait *C corresponds to case class in Term */
trait TermT[Term <: TermT[Term]] extends Any with ToDoc with WithPos with ContainsUniqid with Tree[Term] {
override type ThisTree <: TermT[Term]
Expand Down Expand Up @@ -278,6 +283,8 @@ object spec {
override type ThisTree <: EffectsMT[Term]
}

implicit def convertEffectsM[Term <: TermT[Term], EffectsM <: EffectsMT[Term]](x: EffectsMT[Term]): EffectsM = x.asInstanceOf[EffectsM]

trait MetaTermC[Term <: TermT[Term]] extends TermT[Term] with EffectsMT[Term] with SpecialTermT[Term] {
override type ThisTree <: MetaTermC[Term]

Expand Down Expand Up @@ -448,6 +455,8 @@ object spec {
override type ThisTree <: LiteralTermT[Term]
}

implicit def conveL[Term <: TermT[Term], LiteralTerm <: LiteralTermT[Term]](x: LiteralTermT[Term]): LiteralTerm = x.asInstanceOf[LiteralTerm]

trait AbstractIntTermT[Term <: TermT[Term]] extends LiteralTermT[Term] {
override type ThisTree <: AbstractIntTermT[Term]
}
Expand Down Expand Up @@ -778,6 +787,10 @@ object spec {
def newArgTerm(bind: LocalVC[Term], ty: Term, default: Option[Term], vararg: Boolean, meta: OptionTermMeta): ThisTree
}

implicit def convertA[Term <: TermT[Term], ArgTerm <: ArgTermC[Term]](x: ArgTermC[Term]): ArgTerm = x.asInstanceOf[ArgTerm]

implicit def convertA[Term <: TermT[Term], ArgTerm <: ArgTermC[Term]](x: Vector[ArgTermC[Term]]): Vector[ArgTerm] = x.asInstanceOf[Vector[ArgTerm]]

trait ArgTermC[Term <: TermT[Term]] extends WHNFT[Term] {
override type ThisTree <: ArgTermC[Term]

Expand Down Expand Up @@ -813,6 +826,9 @@ object spec {
def name = bind.name
}

implicit def convertTelescopeTerm[Term <: TermT[Term], TelescopeTerm <: TelescopeTermC[Term]](x: TelescopeTermC[Term]): TelescopeTerm = x.asInstanceOf[TelescopeTerm]
implicit def convertTelescopeTermVec[Term <: TermT[Term], TelescopeTerm <: TelescopeTermC[Term]](x: Vector[TelescopeTermC[Term]]): Vector[TelescopeTerm] = x.asInstanceOf[Vector[TelescopeTerm]]

trait TelescopeTermC[Term <: TermT[Term]] extends WHNFT[Term] {
override type ThisTree <: TelescopeTermC[Term]

Expand Down Expand Up @@ -884,6 +900,8 @@ object spec {
): ThisTree
}

implicit def convertFunctionTypeC[Term <: TermT[Term], FunctionType <: FunctionTypeC[Term]](x: FunctionTypeC[Term]): FunctionType = x.asInstanceOf[FunctionType]

trait FunctionTypeC[Term <: TermT[Term]] extends WHNFT[Term] {
override type ThisTree <: FunctionTypeC[Term]

Expand Down Expand Up @@ -927,6 +945,9 @@ object spec {
def newObjectClauseValueTerm(key: Term, value: Term, meta: OptionTermMeta): ThisTree
}

implicit def convertObjectClauseValueTermC[Term <: TermT[Term], ObjectClauseValueTerm <: ObjectClauseValueTermC[Term]](x: ObjectClauseValueTermC[Term]): ObjectClauseValueTerm = x.asInstanceOf[ObjectClauseValueTerm]
implicit def convertObjectClauseValueTermCB[Term <: TermT[Term], ObjectClauseValueTerm <: ObjectClauseValueTermC[Term]](x: Vector[ObjectClauseValueTermC[Term]]): Vector[ObjectClauseValueTerm] = x.asInstanceOf[Vector[ObjectClauseValueTerm]]

trait ObjectClauseValueTermC[Term <: TermT[Term]] extends WHNFT[Term] {
override type ThisTree <: ObjectClauseValueTermC[Term]

Expand Down Expand Up @@ -1174,6 +1195,8 @@ object spec {
implicit def conversionTop[Term <: TermT[Term], ToplevelV <: ToplevelVC[Term]](x: UniqidOf[ToplevelVC[Term]]): UniqidOf[ToplevelV] =
x.asInstanceOf[UniqidOf[ToplevelV]]

implicit def converLocalV[Term <: TermT[Term], LocalV <: LocalVC[Term]](x: LocalVC[Term]): LocalV =
x.asInstanceOf[LocalV]
trait LocalVC[Term <: TermT[Term]] extends ReferenceCallC[Term] {
override type ThisTree <: LocalVC[Term]

Expand Down Expand Up @@ -1239,6 +1262,9 @@ object spec {
override type ThisTree <: StmtTermT[Term]
}

implicit def convertStmtTermT[Term <: TermT[Term], StmtTerm <: StmtTermT[Term]](x: StmtTermT[Term]): StmtTerm = x.asInstanceOf[StmtTerm]
implicit def convertStmtTermT2[Term <: TermT[Term], StmtTerm <: StmtTermT[Term]](x: Vector[StmtTermT[Term]]): Vector[StmtTerm] = x.asInstanceOf[Vector[StmtTerm]]

@FunctionalInterface
trait LetStmtTermF[Term <: TermT[Term], ThisTree <: LetStmtTermC[Term]] {
def newLetStmt(localv: LocalVC[Term], value: Term, ty: Term, meta: OptionTermMeta): ThisTree
Expand Down Expand Up @@ -1464,6 +1490,10 @@ object spec {
)
}


implicit def convertFieldTerm[Term <: TermT[Term], FieldTerm <: FieldTermC[Term]](x: FieldTermC[Term]): FieldTerm = x.asInstanceOf[FieldTerm]
implicit def convertFieldTermVec[Term <: TermT[Term], FieldTerm <: FieldTermC[Term]](x: Vector[FieldTermC[Term]]): Vector[FieldTerm] = x.asInstanceOf[Vector[FieldTerm]]

trait FieldTermC[Term <: TermT[Term]] extends WHNFT[Term] {
override type ThisTree <: FieldTermC[Term]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ trait ElaboraterCommon extends ProvideCtx with ElaboraterBase with CommonPropaga
with NoFill[Effects] {
override def add(key: LocalV, value: Term): DynamicEffectsCell = {
require(!effects.contains(key))
copy(effects = effects + (key -> value))
copy(effects = effects.updated(key, value))
}

override def readUnstable: Option[Effects] = Some(Effects(effects, None))
Expand Down

0 comments on commit 8728195

Please sign in to comment.