-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 78b154f
Showing
18 changed files
with
227 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.idea | ||
/.bsp | ||
*.iml | ||
**/target | ||
*.sc | ||
|
||
.bloop/ | ||
/.metals/ | ||
metals.sbt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name := "IncRepro" | ||
|
||
//ThisBuild / logLevel := Level.Debug | ||
|
||
scalaVersion := "3.5.0" | ||
|
||
Compile / incOptions ~= ( _.withTransitiveStep(10) ) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sbt.version = 1.10.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package net.opengrabeso.engine | ||
|
||
trait MT { | ||
export MTOpaque.Vector3f | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package net.opengrabeso.engine | ||
|
||
import net.opengrabeso.p.OM | ||
|
||
import scala.language.implicitConversions | ||
|
||
object MTTx { | ||
class DirectSkeleton | ||
} | ||
|
||
import MTTx.* | ||
|
||
//noinspection ScalaRedundantConversion | ||
trait MTTx extends MT | ||
|
||
object MTOpaque { | ||
|
||
opaque type Vector3f = tx.Vector3 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package net.opengrabeso.engine | ||
|
||
object tx { | ||
|
||
case class Vector3(x: Double, y: Double, z: Double) | ||
|
||
type DirectSkeleton = MTTx.DirectSkeleton | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package net.opengrabeso.json | ||
|
||
import net.opengrabeso.engine.tx | ||
|
||
trait ASchema | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package net.opengrabeso.json | ||
|
||
import scala.quoted.* | ||
import scala.reflect.ClassTag | ||
|
||
/** Scala 3 specific implementation of ASchema */ | ||
object Schema extends ASchema with TypeAccessScala3 { | ||
|
||
def getSurface(quotes: Quotes)(classSymbol: quotes.reflect.Symbol): Option[Expr[ClassTag[?]]] = { | ||
given q: Quotes = quotes | ||
import quotes.reflect.* | ||
val subclassType = classSymbol.typeRef | ||
//println(s" Subclass ${subclassType.name} ${classSymbol.flags.is(Flags.Trait)} ${classSymbol.flags.is(Flags.Sealed)}") | ||
Option.when(!classSymbol.flags.is(Flags.Trait) || !classSymbol.flags.is(Flags.Sealed)) { // instead of sealed traits we will list their derived classes | ||
val expr = subclassType.asType match { | ||
case '[t] => | ||
Expr.summon[ClassTag[t]] match { | ||
case Some(classTagExpr) => classTagExpr.asExprOf[ClassTag[?]] | ||
case None => | ||
report.error(s"No ClassTag available for type ${Type.show[t]}") | ||
'{???} | ||
} | ||
} | ||
//println(s" Surface of ${subclassType.name} $expr") | ||
expr | ||
} | ||
} | ||
|
||
def enumerateSubclassesImpl[T: Type](using Quotes): Expr[List[ClassTag[?]]] = { | ||
import quotes.reflect.* | ||
|
||
// Get the symbol of the sealed trait T | ||
val traitSymbol = TypeRepr.of[T].typeSymbol | ||
if (traitSymbol.flags.is(Flags.Sealed)) { // Ensure T is a sealed trait and get its subclasses | ||
//println(s"Subclasses of ${traitSymbol.name}: ${traitSymbol.children.map(_.name).mkString(",")}") | ||
//val process = traitSymbol.children.drop(1).take(1) // good | ||
//val process = traitSymbol.children.take(3) // bad | ||
//val process = traitSymbol.children.take(3).drop(1) // bad | ||
//val process = traitSymbol.children.take(3).drop(2) // bad | ||
// Recursive function to get all subclasses, including indirect ones | ||
def getAllSubclasses(symbol: Symbol): List[Symbol] = { | ||
symbol.children.flatMap { child => | ||
child :: getAllSubclasses(child) | ||
} | ||
} | ||
|
||
// documentation seems unclear, it seems children already include indirect children, but not always (AB children missing) | ||
val process = getAllSubclasses(traitSymbol).distinct | ||
|
||
//println(s" processing ${process.map(_.name).mkString(",")}") | ||
val childrenExpr = process.flatMap(getSurface(summon[Quotes])) // 2 good, 3 bad | ||
Expr.ofList(childrenExpr) | ||
} else { | ||
report.error(s"${traitSymbol.fullName} is not a sealed trait") | ||
'{ List.empty[ClassTag[?]] } | ||
} | ||
} | ||
|
||
inline def enumerateSubclasses[T]: List[ClassTag[?]] = ${ enumerateSubclassesImpl[T] } | ||
/** helper call for schema derivation of polymorphic sealed trait and classes */ | ||
inline def listDerivedClasses[T]: List[TypeDesc] = enumerateSubclasses[T].map(TypeDesc.apply(_)) | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package net.opengrabeso.json | ||
|
||
import scala.reflect.ClassTag | ||
|
||
trait TypeAccessScala3 { | ||
case class TypeDesc(ct: ClassTag[?]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package net.opengrabeso | ||
|
||
package object json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package net.opengrabeso.p | ||
|
||
class OM extends OMShaders { | ||
|
||
override def clone(): OM = { | ||
new OM().copy(this) | ||
} | ||
|
||
def copy(source: OM): OM = { | ||
this | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package net.opengrabeso.p | ||
|
||
import net.opengrabeso.p.state.HM | ||
|
||
abstract class OMShaders |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package net.opengrabeso.p | ||
|
||
case class State(timeUs: Long) { | ||
|
||
def initFamily(s: State) = { | ||
val a: Any = 0 | ||
a match { | ||
case _: state.WC.SimClass.AB => | ||
None | ||
} | ||
|
||
??? | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package net.opengrabeso.p | ||
|
||
import net.opengrabeso.p.s.SLog | ||
|
||
object World { | ||
case class ItemPlacement(houseId: Option[Int], passable: Boolean) | ||
} | ||
|
||
case class World( | ||
houses: Map[Int, SLog.HDesc] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package net.opengrabeso.p | ||
package s | ||
|
||
import net.opengrabeso.p.state.PWD | ||
|
||
object SLog { | ||
|
||
case class HDesc() { | ||
def sp: PWD = PWD() | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package net.opengrabeso.p | ||
package state | ||
|
||
import World.ItemPlacement | ||
|
||
object HM { | ||
val HiddenColor = null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package net.opengrabeso.p | ||
package state | ||
|
||
import net.opengrabeso.json.Schema | ||
|
||
object WC { | ||
|
||
/** edit this comment HERE- to trigger compilation */ | ||
sealed trait SimClass { | ||
def name: String = this.toString | ||
} | ||
|
||
object SimClass { | ||
def derivedClasses = Schema.listDerivedClasses[SimClass] | ||
|
||
trait AB | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package net.opengrabeso.p | ||
|
||
package object state { | ||
|
||
extension (WI: WI) { | ||
def isFor(state: State): Boolean = { | ||
false | ||
} | ||
} | ||
|
||
case class WI() | ||
|
||
case class PWD() | ||
} |