Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: julianpeeters/dc10-scala
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.8.0
Choose a base ref
...
head repository: julianpeeters/dc10-scala
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.9.0
Choose a head ref
  • 4 commits
  • 40 files changed
  • 1 contributor

Commits on Nov 13, 2024

  1. Copy the full SHA
    5d1f56a View commit details

Commits on Nov 22, 2024

  1. Enhance metalang module

    julianpeeters committed Nov 22, 2024
    Copy the full SHA
    64b9c89 View commit details

Commits on Dec 19, 2024

  1. Major refactor

    julianpeeters committed Dec 19, 2024
    Copy the full SHA
    e70786f View commit details

Commits on Dec 26, 2024

  1. Major refactor

    Flatten ast and reorganize internal functions
    julianpeeters committed Dec 26, 2024
    Copy the full SHA
    ea29e3f View commit details
Showing with 2,062 additions and 1,410 deletions.
  1. +1 −1 README.md
  2. +1 −1 build.sbt
  3. +4 −4 docs/readme.md
  4. +128 −13 modules/metalang/shared/src/main/scala/dc10/scala/metalang/`dc10-scala`.scala
  5. +13 −16 modules/scala/jvm/src/test/scala/dc10/scala/predef/FunctionsSuite.scala
  6. +22 −23 modules/scala/jvm/src/test/scala/dc10/scala/predef/datatype/ComplexTypesSuite.scala
  7. +28 −28 modules/scala/jvm/src/test/scala/dc10/scala/predef/datatype/PrimitiveTypesSuite.scala
  8. +2 −2 modules/scala/jvm/src/test/scala/dc10/scala/predef/datatype/TemplateTypesSuite.scala
  9. +4 −4 modules/scala/jvm/src/test/scala/dc10/scala/predef/datatype/VariableTypesSuite.scala
  10. +1 −1 modules/scala/jvm/src/test/scala/dc10/scala/predef/file/FilesSuite.scala
  11. +3 −3 modules/scala/jvm/src/test/scala/dc10/scala/predef/namespace/ObjectSuite.scala
  12. +0 −5 modules/scala/shared/src/main/scala/dc10/scala/Error.scala
  13. +0 −3 modules/scala/shared/src/main/scala/dc10/scala/LibDep.scala
  14. +28 −146 modules/scala/shared/src/main/scala/dc10/scala/Statement.scala
  15. +0 −117 modules/scala/shared/src/main/scala/dc10/scala/Symbol.scala
  16. +36 −0 modules/scala/shared/src/main/scala/dc10/scala/Type.scala
  17. +48 −0 modules/scala/shared/src/main/scala/dc10/scala/Value.scala
  18. +5 −0 modules/scala/shared/src/main/scala/dc10/scala/compiler.scala
  19. +4 −1 modules/scala/shared/src/main/scala/dc10/scala/dsl.scala
  20. +64 −0 modules/scala/shared/src/main/scala/dc10/scala/internal/construct.scala
  21. +44 −0 modules/scala/shared/src/main/scala/dc10/scala/internal/extract.scala
  22. +159 −0 modules/scala/shared/src/main/scala/dc10/scala/internal/implement.scala
  23. +232 −0 modules/scala/shared/src/main/scala/dc10/scala/internal/indent.scala
  24. +88 −0 modules/scala/shared/src/main/scala/dc10/scala/internal/substitute.scala
  25. +0 −112 modules/scala/shared/src/main/scala/dc10/scala/predef/Applications.scala
  26. +0 −219 modules/scala/shared/src/main/scala/dc10/scala/predef/Functions.scala
  27. +0 −303 modules/scala/shared/src/main/scala/dc10/scala/predef/Variables.scala
  28. +85 −0 modules/scala/shared/src/main/scala/dc10/scala/predef/binding/Assignments.scala
  29. +30 −0 modules/scala/shared/src/main/scala/dc10/scala/predef/binding/References.scala
  30. +170 −0 modules/scala/shared/src/main/scala/dc10/scala/predef/calculus/Applications.scala
  31. +221 −0 modules/scala/shared/src/main/scala/dc10/scala/predef/calculus/Functions.scala
  32. +211 −0 modules/scala/shared/src/main/scala/dc10/scala/predef/calculus/Variables.scala
  33. +78 −77 modules/scala/shared/src/main/scala/dc10/scala/predef/datatype/ComplexTypes.scala
  34. +43 −59 modules/scala/shared/src/main/scala/dc10/scala/predef/datatype/PrimitiveTypes.scala
  35. +91 −95 modules/scala/shared/src/main/scala/dc10/scala/predef/datatype/TemplateTypes.scala
  36. +4 −6 modules/scala/shared/src/main/scala/dc10/scala/predef/file/Files.scala
  37. +29 −19 modules/scala/shared/src/main/scala/dc10/scala/predef/namespace/Objects.scala
  38. +2 −3 modules/scala/shared/src/main/scala/dc10/scala/predef/namespace/Packages.scala
  39. +182 −148 modules/scala/shared/src/main/scala/dc10/scala/version.scala
  40. +1 −1 project/build.properties
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ Use the `compiler` impl to check and render code `toString` or `virtualFile`:

```scala
import dc10.scala.compiler.{compile, string}
import dc10.scala.version.`3.3.4`
import dc10.scala.version.`3.5.2`

val result: String = snippet.compile.string
// result: String = """val str: String = "hello, world"
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
val Dc10V = "0.5.1"
val Dc10V = "0.6.0"
val MUnitV = "1.0.2"

inThisBuild(List(
8 changes: 4 additions & 4 deletions docs/readme.md
Original file line number Diff line number Diff line change
@@ -18,16 +18,16 @@ import scala.language.implicitConversions // for literals, e.g. "hello, world"

val snippet =
for
s <- VAL("str", STRING, "hello, world")
_ <- VAL("msg", STRING, s)
s <- VAL("str", STRING) := "hello, world"
_ <- VAL("msg", STRING) := s
yield ()
```

Use the `compiler` impl to check and render code `toString` or `virtualFile`:
Use the `compiler` impl to check and render code to `string` or `virtualFile`:

```scala mdoc
import dc10.scala.compiler.{compile, string}
import dc10.scala.version.`3.3.4`
import dc10.scala.version.`3.5.2`

val result: String = snippet.compile.string
```
Original file line number Diff line number Diff line change
@@ -1,29 +1,144 @@
package dc10.scala.metalang

import cats.data.StateT
import dc10.scala.{ErrorF, LibDep, Statement, compiler}
import dc10.scala.Statement.TypeExpr.`Type`
import dc10.scala.Symbol.Term
import dc10.scala.{*, given}
import dc10.scala.dsl.{*, given}
import scala.language.implicitConversions

trait `dc10-scala`[F[_]]:
def TYPEEXPR[G[_], A](targ: F[`Type`[A]]): F[`Type`[G[A]]]
def ERRORF: F[`Type.*->*`[ErrorF]]
def LIBDEP: F[`Type.*`[LibDep]]
def STATEMENT: F[`Type.*`[Statement]]
def `TYPEEXPR`[G[_], A](targ: F[`Type.*`[A]]): F[`Type.*`[G[A]]]
@scala.annotation.targetName("_[_[_], _]")
def `TYPEEXPR`[G[_[_[_], _]], H[_[_], _]](targ: F[`Type.(*->*)->*->*`[H]]): F[`Type.*`[G[H]]]
@scala.annotation.targetName("Type[_[_], _]")
def TYPEEXPR[T[_[_], _]](arg: F[`Value.*`[`Type.Var[_[_], _]`[T]]]): F[`Value.*`[`Type.(*->*)->*->*`[T]]]
def VALUEEXPR[T](arg: F[`Value.*`[T]]): F[`Value.*`[`Value.*`[T]]]
def `TYPEEXPR[_]`[G[_[_]], H[_]](targ: F[`Type.*->*`[H]]): F[`Type.*`[G[H]]]
def `Type.Var[_[_], _]`[G[_[_], _]](nme: String): F[`Value.*`[`Type.Var[_[_], _]`[G]]]
@scala.annotation.targetName("Value[_[_]]")
def VALUEEXPR[G[_], A](targ: F[`Type.*`[A]]): F[`Type.*`[G[A]]]
extension (ctx: `Value.*`[(Set[LibDep], List[Statement])])
def DEP(d: F[`Value.*`[LibDep]]): F[`Value.*`[ErrorF[(Set[LibDep], List[Statement])]]]

object `dc10-scala`:

val lib: LibDep = LibDep(BuildInfo.organization, BuildInfo.name, BuildInfo.version)

trait Mixins extends `dc10-scala`[StateT[ErrorF, (Set[LibDep], List[Statement]), _]]:

def TYPEEXPR[G[_], A](
targ: StateT[ErrorF, (Set[LibDep], List[Statement]), `Type`[A]]
): StateT[ErrorF, (Set[LibDep], List[Statement]), `Type`[G[A]]] =
def ERRORF: StateT[ErrorF, (Set[LibDep], List[Statement]), `Type.*->*`[ErrorF]] =
StateT.pure(`Type.Var[_]`[ErrorF](0, "dc10.scala.ErrorF", None))

def LIBDEP: StateT[ErrorF, (Set[LibDep], List[Statement]), `Type.*`[LibDep]] =
StateT.pure(`Type.Var`[LibDep](0, "dc10.scala.LibDep", None))

def LibDep(
org: StateT[ErrorF, (Set[LibDep], List[Statement]), `Value.*`[String]],
nme: StateT[ErrorF, (Set[LibDep], List[Statement]), `Value.*`[String]],
ver: StateT[ErrorF, (Set[LibDep], List[Statement]), `Value.*`[String]]
): StateT[ErrorF, (Set[LibDep], List[Statement]), `Value.*`[LibDep]] =
for
o <- org
n <- nme
v <- ver
t <- LIBDEP
f <- StateT.pure[ErrorF, (Set[LibDep], List[Statement]), (`Type.*`[String], `Type.*`[String], `Type.*`[String])]((o.tpe, n.tpe, v.tpe)) ==> t
yield `Value.App3`(0, `Value.VarA`[(String, String, String) => LibDep](0, "dc10.scala.LibDep", f), o, n, v, t)

def STATEMENT: StateT[ErrorF, (Set[LibDep], List[Statement]), `Type.*`[Statement]] =
StateT.pure(`Type.Var`[Statement](0, "dc10.scala.Statement", None))

def `TYPEEXPR`[G[_], A](
targ: StateT[ErrorF, (Set[LibDep], List[Statement]), `Type.*`[A]]
): StateT[ErrorF, (Set[LibDep], List[Statement]), `Type.*`[G[A]]] =
for
a <- targ
_ <- StateT.modifyF[ErrorF, (Set[LibDep], List[Statement])](ctx => ctx.dep(`dc10-scala`.lib))
yield Type(
Term.TypeLevel.App.`App[_]`(
Term.TypeLevel.Var.`UserDefinedType[_]`("dc10.scala.Statement.TypeExpr.`Type`", None),
a.tpe
)
yield `Type.App[_]`(
0,
`Type.Var[_]`(0, "dc10.scala.`Type.*`", None),
a
)


@scala.annotation.targetName("_[_[_], _]")
def `TYPEEXPR`[G[_[_[_], _]], H[_[_], _]](
targ: StateT[ErrorF, (Set[LibDep], List[Statement]), `Type.(*->*)->*->*`[H]]
): StateT[ErrorF, (Set[LibDep], List[Statement]), `Type.*`[G[H]]] =
for
a <- targ
_ <- StateT.modifyF[ErrorF, (Set[LibDep], List[Statement])](ctx => ctx.dep(`dc10-scala`.lib))
yield `Type.App[_[_[_], _]]`(
0,
`Type.Var[_[_[_], _]]`(0, "dc10.scala.`Type.(*->*)->*->*`", None),
a
)

@scala.annotation.targetName("Type[_[_], _]")
def TYPEEXPR[T[_[_], _]](arg: StateT[ErrorF, (Set[LibDep], List[Statement]), `Value.*`[`Type.Var[_[_], _]`[T]]]): StateT[ErrorF, (Set[LibDep], List[Statement]), `Value.*`[`Type.(*->*)->*->*`[T]]] =
for
a <- arg
t <- StateT.pure(`Value.VarA`[`Type.(*->*)->*->*`[T]](0, "", `Type.Var`(0, "dc10.scala.`Type.Var[_[_], _]`", None)))
f <- StateT.pure[ErrorF, (Set[LibDep], List[Statement]), `Value.*`[`Type.Var[_[_], _]`[T]]](a) ==> (x => StateT.pure(t))
_ <- StateT.modifyF[ErrorF, (Set[LibDep], List[Statement])](ctx => ctx.dep(`dc10-scala`.lib))
yield
`Value.App1`(
0,
`Value.VarA`[`Type.Var[_[_], _]`[T] => `Type.(*->*)->*->*`[T]](0, "dc10.scala.`Type.Var[_[_], _]`", f.tpe),
a,
t.tpe
)

def `VALUEEXPR`[T](
arg: StateT[ErrorF, (Set[LibDep], List[Statement]), `Value.*`[T]]
): StateT[ErrorF, (Set[LibDep], List[Statement]), `Value.*`[`Value.*`[T]]] =
for
a <- arg
t <- StateT.pure(`Type.Var`[`Value.*`[T]](0, "dc10.scala.`Type.(*->*)->*->*`", None))
f <- arg ==> (x => StateT.pure[ErrorF, (Set[LibDep], List[Statement]), `Value.*`[`Value.*`[T]]](`Value.VarA`[`Value.*`[T]](0, "SDSD", t)))
_ <- StateT.modifyF[ErrorF, (Set[LibDep], List[Statement])](ctx => ctx.dep(`dc10-scala`.lib))
yield
`Value.App1`(0, f, a, t)

def `TYPEEXPR[_]`[G[_[_]], H[_]](
targ: StateT[ErrorF, (Set[LibDep], List[Statement]), `Type.*->*`[H]]
): StateT[ErrorF, (Set[LibDep], List[Statement]), `Type.*`[G[H]]] =
for
a <- targ
_ <- StateT.modifyF[ErrorF, (Set[LibDep], List[Statement])](ctx => ctx.dep(`dc10-scala`.lib))
yield `Type.App[_[_]]`(
0,
`Type.Var[_[_]]`(0, "dc10.scala.`Type.*->*`", None),
a
)

def `Type.Var[_[_], _]`[G[_[_], _]](nme: String): StateT[ErrorF, (Set[LibDep], List[Statement]), `Value.*`[`Type.Var[_[_], _]`[G]]] =
StateT.pure(
`Value.VarA`(
0,
"dc10.scala.`Type.Var[_[_], _]`",
`Type.Var`(0, s"$nme**", None)
)
)

@scala.annotation.targetName("Value[_[_]]")
def VALUEEXPR[G[_], A](
targ: StateT[ErrorF, (Set[LibDep], List[Statement]), `Type.*`[A]]
): StateT[ErrorF, (Set[LibDep], List[Statement]), `Type.*`[G[A]]] =
for
a <- targ
_ <- StateT.modifyF[ErrorF, (Set[LibDep], List[Statement])](ctx => ctx.dep(`dc10-scala`.lib))
yield `Type.App[_]`(
0,
`Type.Var[_]`(0, "dc10.scala.`Value.*`", None),
a
)

extension (ctx: `Value.*`[(Set[LibDep], List[Statement])])
def DEP(d: StateT[ErrorF, (Set[LibDep], List[Statement]), `Value.*`[LibDep]]): StateT[ErrorF, (Set[LibDep], List[Statement]), `Value.*`[ErrorF[(Set[LibDep], List[Statement])]]] =
for
f <- VAL("dep", ctx.tpe ==> ERRORF(TUPLE(SET(LIBDEP), LIST(STATEMENT))))
t <- ERRORF(TUPLE(SET(LIBDEP), LIST(STATEMENT)))
a <- d
yield `Value.AppDot1`(0, f, ctx, a, t)
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ import cats.implicits.given
import dc10.scala.compiler.{compile, string}
import dc10.scala.dsl.{*, given}
import dc10.scala.{LibDep, Statement}
import dc10.scala.version.`3.3.4`
import dc10.scala.version.`3.5.2`
import munit.FunSuite

class FunctionsSuite extends FunSuite:
@@ -29,11 +29,9 @@ class FunctionsSuite extends FunSuite:

def ast =
for
f <- VAL("f1", STRING ==> STRING,
VAL("input", STRING) ==> (s => s)
)
b <- VAL("b", STRING, f("hello"))
_ <- VAL("c", STRING, f(b))
f <- VAL("f1", STRING ==> STRING) := VAL("input", STRING) ==> (s => s)
b <- VAL("b", STRING) := f("hello")
_ <- VAL("c", STRING) := f(b)
yield ()

val obtained: String =
@@ -48,23 +46,22 @@ class FunctionsSuite extends FunSuite:

test("for"):

def ast = VAL("f1", OPTION(STRING),
FOR(
for
s <- "s" <-- Option("wowie")
t <- "t" <-- Option(s)
yield t
)
)
def ast = VAL("f1", OPTION(STRING)) :=
FOR(
for
s <- "s" <-- Option("wowie")
t <- "t" <-- Option(s)
yield t
)

val obtained: String =
ast.compile.string

val expected: String =
"""|val f1: Option[String] =
| for
| s <- Option("wowie")
| t <- Option(s)
| s <- Option[String]("wowie")
| t <- Option[String](s)
| yield t""".stripMargin

assertEquals(obtained, expected)
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package dc10.scala.predef.datatype

import _root_.scala.language.implicitConversions
import cats.data.StateT
import cats.implicits.given
import dc10.scala.compiler.{compile, string}
import dc10.scala.dsl.{*, given}
import dc10.scala.version.`3.3.4`
import dc10.scala.version.`3.5.2`
import munit.FunSuite

class ComplexTypesSuite extends FunSuite:
@@ -35,22 +34,22 @@ class ComplexTypesSuite extends FunSuite:

def ast =
for
_ <- VAL("l0", LIST(INT), List())
_ <- VAL("l1", LIST(INT), List(1, 2, 3))
a <- VAL("l2", LIST(STRING), List("1", "2", "3"))
l <- VAL("l3", LIST(LIST(STRING)), List(List("1", "2", "3"), List("4", "5", "6")))
_ <- VAL("l4", LIST(LIST(LIST(STRING))), List(l, l))
_ <- VAL("l0", LIST(INT)) := List()
_ <- VAL("l1", LIST(INT)) := List(1, 2, 3)
a <- VAL("l2", LIST(STRING)) := List("1", "2", "3")
l <- VAL("l3", LIST(LIST(STRING))) := List(List("1", "2", "3"), List("4", "5", "6"))
_ <- VAL("l4", LIST(LIST(LIST(STRING)))) := List(l, l)
yield ()

val obtained: String =
ast.compile.string

val expected: String =
"""|val l0: List[Int] = List()
|val l1: List[Int] = List(1, 2, 3)
|val l2: List[String] = List("1", "2", "3")
|val l3: List[List[String]] = List(List("1", "2", "3"), List("4", "5", "6"))
|val l4: List[List[List[String]]] = List(l3, l3)""".stripMargin
"""|val l0: List[Int] = List[Nothing]()
|val l1: List[Int] = List[Int](1, 2, 3)
|val l2: List[String] = List[String]("1", "2", "3")
|val l3: List[List[String]] = List[List[String]](List[String]("1", "2", "3"), List[String]("4", "5", "6"))
|val l4: List[List[List[String]]] = List[List[List[String]]](l3, l3)""".stripMargin

assertEquals(obtained, expected)

@@ -79,22 +78,22 @@ class ComplexTypesSuite extends FunSuite:

def ast =
for
s <- VAL("s1", OPTION(INT), Some(1))
_ <- VAL("l1", OPTION(INT), Option(1))
a <- VAL("l2", OPTION(STRING), Option("1"))
l <- VAL("l3", OPTION(OPTION(STRING)), Option(Option("1")))
_ <- VAL("l4", OPTION(OPTION(OPTION(STRING))), Option(l))
s <- VAL("s1", OPTION(INT)) := Some(1)
_ <- VAL("l1", OPTION(INT)) := Option(1)
a <- VAL("l2", OPTION(STRING)) := Option("1")
l <- VAL("l3", OPTION(OPTION(STRING))) := Option(Option("1"))
_ <- VAL("l4", OPTION(OPTION(OPTION(STRING)))) := Option(l)
yield ()

val obtained: String =
ast.compile.string

val expected: String =
"""|val s1: Option[Int] = Some(1)
|val l1: Option[Int] = Option(1)
|val l2: Option[String] = Option("1")
|val l3: Option[Option[String]] = Option(Option("1"))
|val l4: Option[Option[Option[String]]] = Option(l3)""".stripMargin
"""|val s1: Option[Int] = Some[Int](1)
|val l1: Option[Int] = Option[Int](1)
|val l2: Option[String] = Option[String]("1")
|val l3: Option[Option[String]] = Option[Option[String]](Option[String]("1"))
|val l4: Option[Option[Option[String]]] = Option[Option[Option[String]]](l3)""".stripMargin

assertEquals(obtained, expected)

@@ -103,7 +102,7 @@ class ComplexTypesSuite extends FunSuite:
def ast =
for
s <- VAL("s1", TUPLE(INT, STRING))
_ <- VAL("s2", TUPLE(INT, STRING), Tuple(1, "hello"))
_ <- VAL("s2", TUPLE(INT, STRING)) := Tuple(1, "hello")
yield ()

val obtained: String =
Loading