-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move DecodedLibrary to its own file (#1373)
* Move DecodedLibrary to its own file * fix tests
- Loading branch information
Showing
10 changed files
with
99 additions
and
97 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
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
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
40 changes: 40 additions & 0 deletions
40
core/src/main/scala/org/bykn/bosatsu/library/DecodedLibrary.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,40 @@ | ||
package org.bykn.bosatsu.library | ||
|
||
import _root_.bosatsu.{TypedAst => proto} | ||
import cats.MonadError | ||
import cats.syntax.all._ | ||
import org.bykn.bosatsu.hashing.{Hashed, HashValue} | ||
import org.bykn.bosatsu.{Package, PackageName, PackageMap, ProtoConverter} | ||
import scala.collection.immutable.{SortedMap, SortedSet} | ||
|
||
case class DecodedLibrary[A]( | ||
hashValue: HashValue[A], | ||
protoLib: proto.Library, | ||
interfaces: List[Package.Interface], | ||
implementations: PackageMap.Typed[Unit] | ||
) { | ||
lazy val publicPackageNames: SortedSet[PackageName] = | ||
interfaces.iterator.map(_.name).to(SortedSet) | ||
} | ||
|
||
object DecodedLibrary { | ||
def decode[F[_], A]( | ||
protoLib: Hashed[A, proto.Library] | ||
)(implicit F: MonadError[F, Throwable]): F[DecodedLibrary[A]] = | ||
F.fromTry( | ||
ProtoConverter | ||
.packagesFromProto( | ||
protoLib.arg.exportedIfaces, | ||
protoLib.arg.internalPackages | ||
) | ||
).map { case (ifs, impls) => | ||
// TODO: should verify somewhere that all the package names are distinct, but since this is presumed to be | ||
// a good library maybe that's a waste | ||
DecodedLibrary[A]( | ||
protoLib.hash, | ||
protoLib.arg, | ||
ifs, | ||
PackageMap(impls.iterator.map(pack => (pack.name, pack)).to(SortedMap)) | ||
) | ||
} | ||
} |
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