Skip to content

Commit

Permalink
0.1.0-SNAPSHOT
Browse files Browse the repository at this point in the history
  • Loading branch information
dos65 committed Apr 9, 2021
1 parent 5fd30c7 commit dd8a5c9
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 151 deletions.
5 changes: 1 addition & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import xerial.sbt.Sonatype._
lazy val commonSettings = Seq(
scalaVersion := "2.12.12",
organization := "io.github.dos65",
version := "0.0.35-SNAPSHOT",
version := "0.1.0-SNAPSHOT",
crossScalaVersions := Seq("2.12.12", "2.13.3"),
libraryDependencies ++= {
if (is213(scalaVersion.value))
Expand Down Expand Up @@ -37,8 +37,6 @@ lazy val make = project.in(file("modules/core"))
name := "make",
scalacOptions ++= Seq(
"-language:experimental.macros",
//"-Xprint:all",
//"-Ydebug"
),
sourceGenerators in Compile += (sourceManaged in Compile).map(dir => Boilerplate.gen(dir)).taskValue,
libraryDependencies ++= Seq(
Expand All @@ -47,7 +45,6 @@ lazy val make = project.in(file("modules/core"))
"org.typelevel" %% "cats-core" % "2.1.1",
"com.chuusai" %% "shapeless" % "2.3.3" % "test",
"org.typelevel" %% "cats-effect" % "2.1.3" % "test",
"com.lihaoyi" %% "pprint" % "0.5.6"
),
)

Expand Down
53 changes: 26 additions & 27 deletions modules/core/src/main/scala/make/Graph.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@ final class Graph[F[_], A](
targetId: Graph.Id
)(implicit F: Monad[F]) {

def x: Map[Graph.Id, Graph.RawEntry[F]] = entries

def initEff: F[A] = {
val order = initOrder
val init = F.pure(Map.empty[Graph.Id, Any])
println(s"Enries: ${entries.mkString("\n")}")

val rs = order.foldLeft(init) { case (rs, id) =>
F.flatMap(rs)(depsMap => {
Expand Down Expand Up @@ -83,30 +80,32 @@ object Graph {

type HandleOut = (List[Any] => F[Any], List[Id], List[Make[F, Any]])

def handleNode(v: Make[F, Any]): HandleOut = v match {
case Make.Value(v, tag) =>
((_: List[Any]) => v(), List.empty, List.empty)
case Make.Bind(prev, f, tag) =>
val func = (in: List[Any]) => f(in(0))
val deps = List(Id.fromTag(prev.tag))
val other = List(prev)
(func, deps, other)
case Make.Ap(prev, op, tag) =>
val func =
(in: List[Any]) => {
val a = in(0)
val aToB = in(1).asInstanceOf[Any => Any]
Applicative[F].pure[Any](aToB(a))
}
val deps = List(
Id.fromTag(prev.tag),
Id.fromTag(op.tag)
)
val other = List(
prev,
op.asInstanceOf[Make[F, Any]]
)
(func, deps, other)
def handleNode(v: Make[F, Any]): HandleOut = {
v match {
case Make.Value(v, tag) =>
((_: List[Any]) => v(), List.empty, List.empty)
case x @ Make.Bind(prev, f, tag) =>
val func = (in: List[Any]) => f(in(0))
val deps = List(Id.fromTag(prev.tag))
val other = List(prev)
(func, deps, other)
case Make.Ap(prev, op, tag) =>
val func =
(in: List[Any]) => {
val a = in(0)
val aToB = in(1).asInstanceOf[Any => Any]
Applicative[F].pure[Any](aToB(a))
}
val deps = List(
Id.fromTag(prev.tag),
Id.fromTag(op.tag)
)
val other = List(
prev,
op.asInstanceOf[Make[F, Any]]
)
(func, deps, other)
}
}

def handleMake(make: Make[F, Any]): (RawEntry[F], List[Make[F, Any]]) = {
Expand Down
4 changes: 2 additions & 2 deletions modules/core/src/main/scala/make/Make.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ sealed abstract class Make[F[_], A] {

object Make extends ContraMakeInstances with MakeTupleInstances with LowPrioMake {

def of[F[_], A](implicit m: Dep[F, A]): Make[F, A] = m.value
def of[F[_], A](implicit m: Make[F, A]): Make[F, A] = m

final private[make] case class Value[F[_], A](
v: () => F[A],
Expand Down Expand Up @@ -57,4 +57,4 @@ trait ContraMakeInstances {

trait LowPrioMake {
implicit def debugInstance[F[_], A](implicit x: Debug[Make[F, A]]): Make[F, A] = x.v
}
}
2 changes: 0 additions & 2 deletions modules/core/src/main/scala/make/internal/DepMacro.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class DepMacro(val c: whitebox.Context) {
}

if (root) {
//println(state.cache.mkString("\n"))
c.internal.removeAttachment[State](c.macroApplication)

val clsName = TypeName(c.freshName("Dep"))
Expand Down Expand Up @@ -76,7 +75,6 @@ class DepMacro(val c: whitebox.Context) {
}
_root_.make.Dep.apply[${ftpe.tpe}, ${atpe.tpe}]((new $clsName).$primaryName)
"""
//pprint.pprintln(tree, 100, Int.MaxValue)
c.Expr[Dep[F, A]](tree)
} else {
out
Expand Down
6 changes: 1 addition & 5 deletions modules/core/src/main/scala/make/internal/MakeMacro.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import make.Make
import make.Debug
import scala.collection.mutable

class MakeMacro(val ctx: whitebox.Context) extends DebugStateMacro(ctx){
class MakeMacro(val ctx: whitebox.Context) extends DebugStateMacro(ctx) {

import c.universe._

Expand All @@ -23,15 +23,11 @@ class MakeMacro(val ctx: whitebox.Context) extends DebugStateMacro(ctx){
out match {
case EmptyTree =>
val st = extractInstanceSt(atpe.tpe, debugState.reverseTraces)
//println(s"ST: ${st}")
val message = renderInstanceSt(st)
c.abort(c.enclosingPosition, s"Make for ${atpe.tpe} not found\n" + message)
case tree =>
val message = s"Debug: OK!\n\tMake instance for ${atpe.tpe} exists.\n\nRemove debug usage."
c.info(c.enclosingPosition, message, true)
// println("---???? FROM DEBUG ---- ")
// println(tree.toString().size)
// println(tree.toString().grouped(300).mkString("\n\t"))
c.Expr[Make[F, A]](tree)
}
}
Expand Down
Loading

0 comments on commit dd8a5c9

Please sign in to comment.