Skip to content

Commit

Permalink
More IR Work (#15)
Browse files Browse the repository at this point in the history
* Working towards making Module module match expected shape

* Re-organizing things to closer match morphir-elm

* Testing reorganization

* Added tests for Name

* Added PackageSpecFor and ModuleSpecFor

* Rename IR to MorphirIR

* Cleanup code organization of MorphirIR

* Added some additional things to the Type module

* Added transform operators.

Co-authored-by: Adam Fraser <[email protected]>

* Power up the Type

* Rename ir file

* formatting

* Unused import

* Fix tests

* Unused import

Co-authored-by: Adam Fraser <[email protected]>
  • Loading branch information
DamianReeves and adamgfraser authored Feb 5, 2022
1 parent 669ca2d commit 3f66737
Show file tree
Hide file tree
Showing 25 changed files with 1,081 additions and 631 deletions.
6 changes: 6 additions & 0 deletions morphir-ir/shared/src/main/scala/zio/morphir/IR.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package zio.morphir

import zio.morphir.ir._

final case class IR(valueSpecifications: Map[FQName, ???])
object IR {}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ final case class AccessControlled[+A](access: Access, value: A) { self =>
f(value)
}

def fold[B](ifPublic: A => B, ifPrivate: A => B): B =
access match {
case Access.Public => ifPublic(self.value)
case Access.Private => ifPrivate(self.value)
}

def withPublicAccess: Option[A] = self match {
case AccessControlled(Access.Public, a) => Some(a)
case _ => None
Expand Down
14 changes: 14 additions & 0 deletions morphir-ir/shared/src/main/scala/zio/morphir/ir/FQName.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package zio.morphir.ir

final case class FQName(packagePath: PackageName, modulePath: ModulePath, localName: Name)

object FQName {
def apply(packagePath: Path, modulePath: Path, localName: Name): FQName =
FQName(PackageName(packagePath), ModulePath(modulePath), localName)

val fqName: Path => Path => Name => FQName = packagePath =>
modulePath => localName => FQName(PackageName(packagePath), ModulePath(modulePath), localName)

/** Get the package path part of a fully-qualified name. */
def getPackagePath(fqName: FQName): Path = fqName.packagePath.toPath
}
12 changes: 12 additions & 0 deletions morphir-ir/shared/src/main/scala/zio/morphir/ir/Literal.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package zio.morphir.ir

sealed trait Literal[+A] {
def value: A
}
object Literal {
final case class Bool(value: scala.Boolean) extends Literal[scala.Boolean]
final case class Char(value: scala.Char) extends Literal[scala.Char]
final case class String(value: java.lang.String) extends Literal[java.lang.String]
final case class WholeNumber(value: java.math.BigInteger) extends Literal[java.math.BigInteger]
final case class Float(value: java.math.BigDecimal) extends Literal[java.math.BigDecimal]
}
45 changes: 45 additions & 0 deletions morphir-ir/shared/src/main/scala/zio/morphir/ir/Module.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package zio.morphir.ir

object Module {

type Definition[+Annotations] = MorphirIR.ModuleDefinition[Annotations]
val Definition = MorphirIR.ModuleDefinition

type Specification[+Annotations] = MorphirIR.ModuleSpecification[Annotations]
val Specification = MorphirIR.ModuleSpecification

lazy val emptyDefinition: Definition[Any] = Definition.empty

lazy val emptySpecification: Specification[Any] = Specification.empty

final case class ModuleName(namespace: Path, localName: Name) {
lazy val toPath = namespace / localName
}

final case class ModulePath(toPath: Path)

final case class QualifiedModuleName(packageName: Path, module: Path) {
lazy val toPath = packageName / module
}

}

trait ModuleSpecFor[A] {
import Module.*

def module: ModuleName
def spec: Specification[Any]
}

object ModuleSpecFor {
import Module.*

/** Summon the module specification for the given module/type. */
def apply[A](implicit specFor: ModuleSpecFor[A]): ModuleSpecFor[A] = specFor

def make[A](name: ModuleName)(moduleSpec: Specification[Any]): ModuleSpecFor[A] =
new ModuleSpecFor[A] {
val module = name
val spec = moduleSpec
}
}
Loading

0 comments on commit 3f66737

Please sign in to comment.