Skip to content

Commit

Permalink
Addressed concern around ScalarType constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
michel-steuwer committed Oct 7, 2020
1 parent 6df93e8 commit d04a352
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
6 changes: 6 additions & 0 deletions src/main/scala/rise/core/TypeLevelDSL.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ object TypeLevelDSL {
case class DataTypeFunctionWrapper[A](f: DataType => A)
implicit def toDataTypeFunctionWrapper[A](f: DataType => A): DataTypeFunctionWrapper[A] =
DataTypeFunctionWrapper(f)
implicit def toScalarTypeFunctionWrapper[A](f: ScalarType => A): DataTypeFunctionWrapper[A] =
DataTypeFunctionWrapper {
case st: ScalarType => f(st)
// TODO: see https://github.com/rise-lang/rise/issues/11
case _ => throw new Exception("Excepted a ScalarType")
}

case class NatToDataFunctionWrapper[A](f: NatToData => A)
implicit def toNatToDataFunctionWrapper[A](f: NatToData => A): NatToDataFunctionWrapper[A] =
Expand Down
24 changes: 12 additions & 12 deletions src/main/scala/rise/core/primitives.scala
Original file line number Diff line number Diff line change
Expand Up @@ -268,31 +268,31 @@ object primitives {
bool ->: bool
}

@primitive object add extends Primitive with Builder { impl{ t: DataType => t ->: t ->: t } }
@primitive object sub extends Primitive with Builder { impl{ t: DataType => t ->: t ->: t } }
@primitive object mul extends Primitive with Builder { impl{ t: DataType => t ->: t ->: t } }
@primitive object div extends Primitive with Builder { impl{ t: DataType => t ->: t ->: t } }
@primitive object mod extends Primitive with Builder { impl{ t: DataType => t ->: t ->: t } }

@primitive object gt extends Primitive with Builder { impl{ t: DataType => t ->: t ->: bool } }
@primitive object lt extends Primitive with Builder { impl{ t: DataType => t ->: t ->: bool } }
@primitive object add extends Primitive with Builder { impl{ t: ScalarType => t ->: t ->: t } }
@primitive object sub extends Primitive with Builder { impl{ t: ScalarType => t ->: t ->: t } }
@primitive object mul extends Primitive with Builder { impl{ t: ScalarType => t ->: t ->: t } }
@primitive object div extends Primitive with Builder { impl{ t: ScalarType => t ->: t ->: t } }
@primitive object mod extends Primitive with Builder { impl{ t: ScalarType => t ->: t ->: t } }

@primitive object gt extends Primitive with Builder { impl{ t: ScalarType => t ->: t ->: bool } }
@primitive object lt extends Primitive with Builder { impl{ t: ScalarType => t ->: t ->: bool } }
@primitive object equal extends Primitive with Builder { impl{ t: DataType => t ->: t ->: bool } }

// TODO: should vectorisation be in the core or not?

// TODO: track alignment in type system?
@primitive object asVectorAligned extends Primitive with Builder {
expl((n: Nat) => impl{ m: Nat => impl{ a: DataType =>
((m * n)`.`a) ->: (m`.`vec(n, a)) }})
expl((n: Nat) => impl{ m: Nat => impl{ t: ScalarType =>
((m * n)`.`t) ->: (m`.`vec(n, t)) }})
}

@primitive object asVector extends Primitive with Builder {
expl((n: Nat) => impl{ m: Nat => impl{ t: DataType =>
expl((n: Nat) => impl{ m: Nat => impl{ t: ScalarType =>
((m * n)`.`t) ->: (m`.`vec(n, t)) }})
}

@primitive object asScalar extends Primitive with Builder {
impl{ n: Nat => impl{ m: Nat => impl{ t: DataType =>
impl{ n: Nat => impl{ m: Nat => impl{ t: ScalarType =>
(m`.`vec(n, t)) ->: ((m * n)`.`t) }}}
}

Expand Down

0 comments on commit d04a352

Please sign in to comment.