This repository has been archived by the owner on Sep 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add scala Native support * scalafmt fixes * Provide support for Variable * Additional value constructor support * Provide support for Unit constructors * Added FieldFunction support in the recursive Value * Added support for Constructor * Added Reference Value support * Literal Value support * Added attributed Tuple construction support * Fix ambiguity in tuple call * Cleanup IsNotAValue to reduce allocations * Added attributed list constructors * Added list support * Support Apply * implement isData and uncurryApply * provide uncurryApply implementation * Provided record constructors * Completed valueToString and added Field constructors * Working on pattern * Adding Additional Pattern constructors * Adding Destructure constructors * Additional pattern constructors * lambda and destructure * IfThenElse constructors * UpdateRexord constructor support * Added patternMatch constructors * Added additional Pattern constructors * LetDefinition constructors * Let Recursion constructors * Apply Scalafix rules * Added testNative
- Loading branch information
1 parent
39df84d
commit e05d999
Showing
22 changed files
with
2,062 additions
and
151 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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
version = 3.5.0 | ||
version = 3.5.1 | ||
|
||
maxColumn = 120 | ||
runner.dialect = scala213source3 | ||
|
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
34 changes: 34 additions & 0 deletions
34
morphir-ir/shared/src/main/scala-2.12-2.13/zio/morphir/Not.scala
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,34 @@ | ||
package zio.morphir | ||
|
||
import scala.annotation.implicitAmbiguous | ||
|
||
/** | ||
* Provides implicit evidence that an instance of `A` is not in implicit scope. | ||
*/ | ||
@implicitAmbiguous("Implicit ${A} defined.") | ||
sealed trait Not[A] | ||
|
||
object Not { | ||
|
||
/** | ||
* Derives a `Not[A]` instance when an instance of `A` is not in implciit scope. | ||
*/ | ||
implicit def Not[A]: Not[A] = | ||
new Not[A] {} | ||
|
||
/** | ||
* Derives a `Not[A]` instance when an instance of `A` is in implicit scope. Together with the instance defined below | ||
* this will cause implicit search to fail due to ambiguous implicits, preventing an instance of `Not[A]` from being | ||
* in implicit scope when an instance of `A` is in implicit scope. | ||
*/ | ||
implicit def NotAmbiguous1[A](implicit ev: A): Not[A] = | ||
new Not[A] {} | ||
|
||
/** | ||
* Derives a `Not[A]` instance when an instance of `A` is in implicit scope. Together with the instance defined above | ||
* this will cause implicit search to fail due to ambiguous implicits, preventing an instance of `Not[A]` from being | ||
* in implicit scope when an instance of `A` is in implicit scope. | ||
*/ | ||
implicit def NotAmbiguous2[A](implicit ev: A): Not[A] = | ||
new Not[A] {} | ||
} |
30 changes: 30 additions & 0 deletions
30
morphir-ir/shared/src/main/scala-2.12-2.13/zio/morphir/ir/IsNotAValue.scala
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,30 @@ | ||
package zio.morphir.ir | ||
|
||
import scala.annotation.implicitAmbiguous | ||
|
||
sealed trait IsNotAValue[-A] | ||
|
||
object IsNotAValue extends IsNotAValue[Any] with IsNotAValueLowerPriority { | ||
|
||
implicit def isNotAValue[A]: IsNotAValue[A] = IsNotAValue | ||
|
||
@implicitAmbiguous( | ||
"This operation assumes that ${A} is not a morphir IR Value node. " + | ||
"However, ${A} is a Value." | ||
) | ||
implicit def isNotAValueAmbiguous1[A](implicit ev: A <:< value.recursive.Value[_, _]): IsNotAValue[A] = IsNotAValue | ||
|
||
implicit def isNotAValueAmbiguous2[A](implicit ev: A <:< value.recursive.Value[_, _]): IsNotAValue[A] = IsNotAValue | ||
|
||
} | ||
|
||
trait IsNotAValueLowerPriority { | ||
|
||
@implicitAmbiguous( | ||
"This operation assumes that ${A} is not a morphir IR Value node. " + | ||
"However, ${A} is a Value." | ||
) | ||
implicit def isNotAValueAmbiguousA[A](implicit ev: A <:< value.Value[_, _]): IsNotAValue[A] = IsNotAValue | ||
|
||
implicit def isNotAValueAmbiguousB[A](implicit ev: A <:< value.Value[_, _]): IsNotAValue[A] = IsNotAValue | ||
} |
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,17 @@ | ||
package zio.morphir | ||
import scala.annotation.implicitNotFound | ||
import scala.util.NotGiven | ||
|
||
/** | ||
* Provides implicit evidence that an instance of `A` is not in implicit scope. | ||
*/ | ||
@implicitNotFound("Implicit ${A} defined.") | ||
sealed trait Not[A] | ||
object Not { | ||
|
||
/** | ||
* Derives a `Not[A]` instance from a `NotGiven[A]` instance. | ||
*/ | ||
implicit def Not[A: NotGiven]: Not[A] = | ||
new Not[A] {} | ||
} |
15 changes: 15 additions & 0 deletions
15
morphir-ir/shared/src/main/scala-3/zio/morphir/ir/IsNotAValue.scala
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,15 @@ | ||
package zio.morphir.ir | ||
|
||
import scala.annotation.implicitNotFound | ||
import scala.util.NotGiven | ||
|
||
sealed abstract class IsNotAValue[-A] extends Serializable | ||
|
||
object IsNotAValue extends IsNotAValue[Any] with IsNotAValueLowerPriority { | ||
implicit def isNotAValue[A](using NotGiven[A <:< value.Value[_, _]]): IsNotAValue[A] = IsNotAValue | ||
|
||
} | ||
|
||
trait IsNotAValueLowerPriority { | ||
implicit def isNotARecursiveValue[A](using NotGiven[A <:< value.recursive.Value[_, _]]): IsNotAValue[A] = IsNotAValue | ||
} |
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
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
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
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
161 changes: 161 additions & 0 deletions
161
morphir-ir/shared/src/main/scala/zio/morphir/ir/value/PatternConstructors.scala
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,161 @@ | ||
package zio.morphir.ir.value | ||
|
||
import zio.Chunk | ||
import zio.morphir.Not | ||
import zio.morphir.ir.value.Pattern.DefaultAttributes | ||
import zio.morphir.ir.{FQName, Literal, Name} | ||
|
||
trait PatternConstructors { self => | ||
final def asAlias[A](attributes: A, alias: String): Pattern[A] = | ||
Pattern.AsPattern( | ||
attributes = attributes, | ||
pattern = Pattern.WildcardPattern(attributes), | ||
name = Name.fromString(alias) | ||
) | ||
|
||
final def asAlias[A](attributes: A, alias: Name): Pattern[A] = | ||
Pattern.AsPattern( | ||
attributes = attributes, | ||
pattern = Pattern.WildcardPattern(attributes), | ||
name = alias | ||
) | ||
|
||
final def asAlias(alias: String): UPattern = | ||
Pattern.AsPattern( | ||
attributes = DefaultAttributes, | ||
pattern = wildcardPattern, | ||
name = Name.fromString(alias) | ||
) | ||
|
||
final def asAlias(alias: Name): UPattern = | ||
Pattern.AsPattern( | ||
attributes = DefaultAttributes, | ||
pattern = wildcardPattern, | ||
name = alias | ||
) | ||
|
||
final def asPattern[A](attributes: A, pattern: Pattern[A], alias: Name): Pattern[A] = | ||
Pattern.AsPattern(attributes = attributes, pattern = pattern, name = alias) | ||
|
||
final def asPattern[A](attributes: A, pattern: Pattern[A], alias: String): Pattern[A] = | ||
Pattern.AsPattern(attributes = attributes, pattern = pattern, name = Name.fromString(alias)) | ||
|
||
final def asPattern(pattern: UPattern, alias: Name): UPattern = | ||
Pattern.AsPattern(attributes = DefaultAttributes, pattern = pattern, name = alias) | ||
|
||
final def asPattern(pattern: UPattern, alias: String): UPattern = | ||
Pattern.AsPattern(attributes = DefaultAttributes, pattern = pattern, name = Name.fromString(alias)) | ||
|
||
final def asPattern(alias: String): UPattern = | ||
Pattern.AsPattern( | ||
attributes = DefaultAttributes, | ||
pattern = wildcardPattern, | ||
name = Name.fromString(alias) | ||
) | ||
|
||
final def asPattern(alias: Name): UPattern = | ||
Pattern.AsPattern( | ||
attributes = DefaultAttributes, | ||
pattern = wildcardPattern, | ||
name = alias | ||
) | ||
|
||
final def booleanPattern[A](attributes: A, value: Boolean): Pattern[A] = | ||
Pattern.LiteralPattern(attributes = attributes, literal = Literal.boolean(value)) | ||
|
||
final def booleanPattern(value: Boolean): UPattern = | ||
Pattern.LiteralPattern(attributes = DefaultAttributes, literal = Literal.boolean(value)) | ||
|
||
final def constructorPattern[A]( | ||
attributes: A, | ||
constructorName: FQName, | ||
argumentPatterns: Chunk[Pattern[A]] | ||
): Pattern[A] = | ||
Pattern.ConstructorPattern( | ||
attributes = attributes, | ||
constructorName = constructorName, | ||
argumentPatterns = argumentPatterns | ||
) | ||
|
||
final def constructorPattern[A]( | ||
attributes: A, | ||
constructorName: String, | ||
argumentPatterns: Chunk[Pattern[A]] | ||
): Pattern[A] = | ||
Pattern.ConstructorPattern( | ||
attributes = attributes, | ||
constructorName = FQName.fromString(constructorName), | ||
argumentPatterns = argumentPatterns | ||
) | ||
|
||
final def decimalPattern[A](attributes: A, value: BigDecimal): Pattern[A] = | ||
Pattern.LiteralPattern(attributes = attributes, literal = Literal.decimal(value)) | ||
|
||
final def decimalPattern(value: BigDecimal): UPattern = | ||
Pattern.LiteralPattern(attributes = DefaultAttributes, literal = Literal.decimal(value)) | ||
|
||
final def emptyListPattern[A](attributes: A): Pattern[A] = | ||
Pattern.EmptyListPattern(attributes) | ||
|
||
final lazy val emptyListPattern: UPattern = | ||
Pattern.EmptyListPattern(DefaultAttributes) | ||
|
||
final def falsePattern[A](attributes: A): Pattern[A] = | ||
Pattern.LiteralPattern(attributes = attributes, literal = Literal.False) | ||
|
||
final def falsePattern: UPattern = | ||
Pattern.LiteralPattern(attributes = DefaultAttributes, literal = Literal.False) | ||
|
||
final def floatPattern[A](attributes: A, value: Float): Pattern[A] = | ||
Pattern.LiteralPattern(attributes = attributes, literal = Literal.float(value)) | ||
|
||
final def floatPattern(value: Float): UPattern = | ||
Pattern.LiteralPattern(attributes = DefaultAttributes, literal = Literal.float(value)) | ||
|
||
final def headTailPattern[A](attributes: A, head: Pattern[A], tail: Pattern[A]): Pattern[A] = | ||
Pattern.HeadTailPattern(attributes = attributes, headPattern = head, tailPattern = tail) | ||
|
||
final def headTailPattern(head: UPattern, tail: UPattern): UPattern = | ||
Pattern.HeadTailPattern(attributes = DefaultAttributes, headPattern = head, tailPattern = tail) | ||
|
||
final def intPattern[A](attributes: A, value: Int): Pattern[A] = | ||
Pattern.LiteralPattern(attributes = attributes, literal = Literal.int(value)) | ||
|
||
final def intPattern(value: Int): UPattern = | ||
Pattern.LiteralPattern(attributes = DefaultAttributes, literal = Literal.int(value)) | ||
|
||
final def literalPattern[A, T](attributes: A, value: Literal[T]): Pattern[A] = | ||
Pattern.LiteralPattern(attributes = attributes, literal = value) | ||
|
||
final def literalPattern[T](value: Literal[T]): UPattern = | ||
Pattern.LiteralPattern(attributes = DefaultAttributes, literal = value) | ||
|
||
final def stringPattern[A](attributes: A, value: String): Pattern[A] = | ||
Pattern.LiteralPattern(attributes = attributes, literal = Literal.string(value)) | ||
|
||
final def stringPattern(value: String): UPattern = | ||
Pattern.LiteralPattern(attributes = DefaultAttributes, literal = Literal.string(value)) | ||
|
||
final def truePattern[A](attributes: A): Pattern[A] = | ||
Pattern.LiteralPattern(attributes = attributes, literal = Literal.True) | ||
|
||
final def truePattern: UPattern = | ||
Pattern.LiteralPattern(attributes = DefaultAttributes, literal = Literal.True) | ||
|
||
final def tuplePattern[A](attributes: A, patterns: Chunk[Pattern[A]]): Pattern[A] = | ||
Pattern.TuplePattern(attributes = attributes, elementPatterns = patterns) | ||
|
||
final def tuplePattern[A](attributes: A, patterns: Pattern[A]*)(implicit ev: Not[A <:< Pattern[_]]): Pattern[A] = | ||
Pattern.TuplePattern(attributes = attributes, elementPatterns = Chunk.fromIterable(patterns)) | ||
|
||
final def tuplePattern(patterns: Chunk[UPattern]): UPattern = | ||
Pattern.TuplePattern(attributes = DefaultAttributes, elementPatterns = patterns) | ||
|
||
final def tuplePattern(patterns: UPattern*): UPattern = | ||
Pattern.TuplePattern(attributes = DefaultAttributes, elementPatterns = Chunk.fromIterable(patterns)) | ||
|
||
final def wildcardPattern[A](attributes: A): Pattern[A] = Pattern.WildcardPattern(attributes) | ||
|
||
final lazy val wildcardPattern: UPattern = Pattern.WildcardPattern(Pattern.DefaultAttributes) | ||
|
||
} |
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
Oops, something went wrong.