Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Removed unused dependencies #59

Merged
merged 5 commits into from
May 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,11 @@ package object naive {
// so we try to find it for some self and record this fact in the
// method state
case EODot(EOSimpleApp(dotLeftName), attrName)
if args
.headOption
.exists(_.expr match {
case EOSimpleApp(firstArgName) => firstArgName == dotLeftName
case _ => false
}) =>
if (args.head.expr match {
case EOSimpleApp(firstArgName) =>
firstArgName == dotLeftName
case _ => false
}) =>
for {
referencedMethods <- objs.findMethodsWithParamsByName(attrName)
_ <- referencedMethods.traverse_ { refMeth =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package org.polystat.odin.analysis.utils

import cats.Applicative
import cats.Eval
import cats.Foldable
import cats.Id
import cats.Monoid
import cats.implicits.catsSyntaxSemigroup
import cats.implicits.toFoldableOps
import cats.implicits.toFunctorOps
import com.github.tarao.nonempty.collection.NonEmpty
import cats.syntax.foldable._
import cats.syntax.functor._
import cats.syntax.semigroup._
import higherkindness.droste.data.Fix
import org.polystat.odin.core.ast._
import org.polystat.odin.core.ast.astparams.EOExprOnly
Expand All @@ -17,23 +14,6 @@ import Optics.{lenses, traversals}

object Abstract {

private type NonEmptyVector[A] = NonEmpty[A, Vector[A]]

implicit private val nonEmptyFoldable: Foldable[NonEmptyVector] =
new Foldable[NonEmptyVector] {

override def foldLeft[A, B](fa: NonEmptyVector[A], b: B)(
f: (B, A) => B
): B =
fa.value.foldLeft(b)(f)

override def foldRight[A, B](fa: NonEmptyVector[A], lb: Eval[B])(
f: (A, Eval[B]) => Eval[B]
): Eval[B] =
f(fa.head, fa.tail.foldRightDefer(lb)(f))

}

def modifyExprWithState[F[_]: Applicative, S](
initialState: S,
initialDepth: BigInt = 0
Expand Down Expand Up @@ -89,7 +69,7 @@ object Abstract {
case EOObj(_, _, bndAttrs) => bndAttrs.foldMap(recurse)
case EOCopy(trg, args) =>
recurse(EOAnonExpr(trg)).combine(
Foldable[NonEmptyVector].foldMap(args)(recurse)
args.foldMap(recurse)
)
case EODot(trg, _) => recurse(EOAnonExpr(trg))
case EOArray(elems) => elems.foldMap(recurse)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package org.polystat.odin.analysis.utils

import cats.Applicative
import cats.implicits.catsSyntaxTuple2Semigroupal
import cats.implicits.toFunctorOps
import cats.implicits.toTraverseOps
import com.github.tarao.nonempty.collection.NonEmpty
import cats.data.NonEmptyVector
import cats.syntax.apply._
import cats.syntax.functor._
import higherkindness.droste.data.Fix
import monocle.Lens
import monocle.Optional
import monocle.Prism
import monocle.Traversal
import monocle.macros.GenLens
import org.polystat.odin.analysis.utils.inlining.types.CopyArgs
import org.polystat.odin.core.ast._
import org.polystat.odin.core.ast.astparams.EOExprOnly

Expand Down Expand Up @@ -87,7 +85,7 @@ object Optics {
val focusDotSrc: Lens[EODot[EOExprOnly], EOExprOnly] =
GenLens[EODot[EOExprOnly]](_.src)

val focusCopyArgs: Lens[EOCopy[EOExprOnly], CopyArgs] =
val focusCopyArgs: Lens[EOCopy[EOExprOnly], NonEmptyVector[EOBnd[EOExprOnly]]] =
GenLens[EOCopy[EOExprOnly]](_.args)

val focusArrayElems: Lens[EOArray[EOExprOnly], Vector[EOBnd[EOExprOnly]]] =
Expand Down Expand Up @@ -117,9 +115,9 @@ object Optics {

def nonEmptyVectorIndexOptional[A](
i: Int
): Optional[NonEmpty[A, Vector[A]], A] =
Optional[NonEmpty[A, Vector[A]], A](_.lift(i))(item =>
seq => if (seq.isDefinedAt(i)) seq.updated(i, item) else seq
): Optional[NonEmptyVector[A], A] =
Optional[NonEmptyVector[A], A](_.toVector.lift(i))(item =>
nev => nev.updated(i, item).getOrElse(nev)
)

def focusBndAttrWithName(
Expand All @@ -143,7 +141,7 @@ object Optics {
i: Int
): Optional[EOCopy[EOExprOnly], EOExprOnly] =
Optional[EOCopy[EOExprOnly], EOExprOnly](copy =>
copy.args.lift(i).map(_.expr)
copy.args.toVector.lift(i).map(_.expr)
)(expr =>
copy => {
lenses
Expand Down Expand Up @@ -183,19 +181,8 @@ object Optics {

object traversals {

def nonEmptyVectorTraversal[A]: Traversal[NonEmpty[A, Vector[A]], A] =
new Traversal[NonEmpty[A, Vector[A]], A] {

override def modifyA[F[_]: Applicative](f: A => F[A])(
s: NonEmpty[A, Vector[A]]
): F[NonEmpty[A, Vector[A]]] = {
(
f(s.head),
s.tail.traverse(f)
).mapN((head, tail) => NonEmpty[Vector[A]](head, tail: _*))
}

}
def nonEmptyVectorTraversal[A]: Traversal[NonEmptyVector[A], A] =
Traversal.fromTraverse

val eoProg: Traversal[EOProg[EOExprOnly], EOExprOnly] =
new Traversal[EOProg[EOExprOnly], EOExprOnly] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,8 @@ object Inliner {
methodInfo: MethodInfo,
call: Call,
): EOObj[EOExprOnly] = {
val argMap = methodInfo.body.freeAttrs.map(_.name).zip(call.args).toMap
val argMap =
methodInfo.body.freeAttrs.map(_.name).zip(call.args.toVector).toMap
val localNames = methodInfo
.body
.bndAttrs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,11 @@ object LocateCalls {
Fix(EODot(Fix(EOSimpleAppWithLocator("self", locator)), name)),
args
) if locator == depth =>
val firstArgIsValid: Boolean = args
.headOption
.exists {
case EOAnonExpr(EOSimpleAppWithLocator("self", locator))
if locator == depth => true
case _ => false
}
val firstArgIsValid: Boolean = args.head match {
case EOAnonExpr(EOSimpleAppWithLocator("self", locator))
if locator == depth => true
case _ => false
}
if (firstArgIsValid)
Vector(
inlining.Call(
Expand Down Expand Up @@ -91,7 +89,7 @@ object LocateCalls {
.andThen(prisms.fixToEOCopy)
.andThen(lenses.focusCopyTrg),
depth = depth
) ++ args.zipWithIndex.flatMap { case (arg, i) =>
) ++ args.zipWithIndex.toVector.flatMap { case (arg, i) =>
findCallsRec(
subExpr = arg.expr,
pathToCallSite = pathToCallSite,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.polystat.odin.analysis.utils.inlining

import cats.Applicative
import cats.data.NonEmptyVector
import cats.syntax.align._
import cats.syntax.apply._
import cats.syntax.foldable._
Expand All @@ -10,6 +11,7 @@ import monocle.Optional
import org.polystat.odin.analysis.ObjectName
import org.polystat.odin.backend.eolang.ToEO.instances._
import org.polystat.odin.backend.eolang.ToEO.ops._
import org.polystat.odin.core.ast.EOBnd
import org.polystat.odin.core.ast.EOBndExpr
import org.polystat.odin.core.ast.EONamedBnd
import org.polystat.odin.core.ast.EOObj
Expand Down Expand Up @@ -211,5 +213,5 @@ final case class Call(
methodName: String,
callSite: PathToCallSite,
callLocation: PathToCall,
args: CopyArgs
args: NonEmptyVector[EOBnd[EOExprOnly]]
)
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package org.polystat.odin.analysis.utils.inlining

import com.github.tarao.nonempty.collection.NonEmpty
import monocle.Optional
import org.polystat.odin.core.ast.EOBnd
import org.polystat.odin.core.ast.EOObj
import org.polystat.odin.core.ast.astparams.EOExprOnly

object types {

type CopyArgs = NonEmpty[EOBnd[EOExprOnly], Vector[EOBnd[EOExprOnly]]]

type PathToCallSite = Optional[
EOObj[EOExprOnly], // method body
EOObj[EOExprOnly], // call site object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.polystat.odin.analysis.utils.logicalextraction
import ap.SimpleAPI
import ap.SimpleAPI.FunctionalityMode
import cats.data.EitherNel
import cats.data.NonEmptyVector
import cats.data.{NonEmptyList => Nel}
import cats.syntax.either._
import cats.syntax.traverse._
Expand Down Expand Up @@ -129,9 +130,11 @@ object ExtractLogic {
),
args
) =>
args.value.toList.map(x => Fix.un(x.expr)) match {
case EOSimpleAppWithLocator("self", locator2) :: moreArgs
if locator == locator2 =>
args.map(x => Fix.un(x.expr)) match {
case NonEmptyVector(
EOSimpleAppWithLocator("self", locator2),
moreArgs
) if locator == locator2 =>
moreArgs
.traverse(expr =>
extractInfo(depth, Fix(expr), availableMethods)
Expand Down Expand Up @@ -169,13 +172,11 @@ object ExtractLogic {
}
case EOCopy(Fix(EOSimpleAppWithLocator(name, _)), args) => for { /*
* FIXME: check locators */
infoArgs <- args
.value
.traverse(arg => extractInfo(depth, arg.expr, availableMethods))
result <- (name, infoArgs.toList) match {
case ("seq", Nil) =>
Left(Nel.one("seq is expecting at least one term"))
case ("seq", arg :: Nil) =>
infoArgs <- args.traverse(arg =>
extractInfo(depth, arg.expr, availableMethods)
)
result <- (name, infoArgs) match {
case ("seq", NonEmptyVector(arg, Vector())) =>
Right(
Info(
List.empty,
Expand All @@ -190,12 +191,12 @@ object ExtractLogic {
List.empty,
args.last.exists,
args.last.value,
And(args.map(x => x.properties))
And(args.toVector.map(x => x.properties))
)
)
// Todo if possible check that assert content is a boolean
// assert (3.div 2) causes problems with type correspondance
case ("assert", arg :: Nil) =>
case ("assert", NonEmptyVector(arg, Vector())) =>
Right(
Info(
List.empty,
Expand All @@ -213,10 +214,10 @@ object ExtractLogic {
} yield result
case EOCopy(Fix(EODot(src, attr)), args) => for {
infoSrc <- extractInfo(depth, src, availableMethods)
infoArgs <- args
.value
.traverse(arg => extractInfo(depth, arg.expr, availableMethods))
result <- (attr, infoArgs.toList) match {
infoArgs <- args.traverse(arg =>
extractInfo(depth, arg.expr, availableMethods)
)
result <- (attr, infoArgs.toVector.toList) match {
case ("add", infoArg :: Nil) =>
Right(
Info(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ object ToEO {

def renderCopySingleLine(copy: EOCopy[EOExprOnly]): Inline = {
val trg: String = renderArgSingleLine(EOAnonExpr(copy.trg))
val args: String = copy.args.map(renderArgSingleLine).mkString(" ")
val args: String = copy.args.map(renderArgSingleLine).mkString_(" ")

Inline(List(trg, args).mkString(" "))
}
Expand All @@ -365,7 +365,7 @@ object ToEO {

override def toEO(node: EOCopy[EOExprOnly]): InlineOrLines = {
val outerArgsString =
node.args.flatMap(_.toEO.toIterable).map(indent)
node.args.toVector.flatMap(_.toEO.toIterable).map(indent)

Fix.un(node.trg) match {
case EOObj(_, _, _) => renderCopySingleLine(node)
Expand Down Expand Up @@ -408,7 +408,7 @@ object ToEO {
new ToEO[EOBytesData[EOExprOnly], Inline] {

override def toEO(node: EOBytesData[EOExprOnly]): Inline =
Inline(node.bytes.map(_.toEO).mkString("-"))
Inline(node.bytes.map(_.toEO).mkString_("-"))

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
package org.polystat.odin.backend.eolang

import cats.Show

object inlineorlines {
type InlineOrLines = Either[String, Iterable[String]]

type Inline = Left[String, Iterable[String]]

implicit val inlineShow: Show[Inline] = new Show[Inline] {

override def show(t: Inline): String = {
val Left(s) = t
s
}

}

val Inline: String => Left[String, Iterable[String]] =
Left[String, Iterable[String]]

Expand Down
6 changes: 3 additions & 3 deletions core/src/main/scala/org/polystat/odin/core/ast/ast.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.polystat.odin.core.ast

import cats.data.NonEmptyList
import com.github.tarao.nonempty.collection.NonEmpty
import cats.data.NonEmptyVector

import scala.util.matching.Regex

Expand Down Expand Up @@ -93,7 +93,7 @@ sealed case class EODot[+A](src: A, name: String) extends EOApp[A]

sealed case class EOCopy[+A](
trg: A,
args: NonEmpty[EOBnd[A], Vector[EOBnd[A]]]
args: NonEmptyVector[EOBnd[A]]
) extends EOApp[A]

// / Data ////////////////////////////////////////////////////////////////////
Expand All @@ -102,7 +102,7 @@ sealed trait EOData[+A] extends EOExpr[A]
sealed case class EOSingleByte(byte: Byte)

sealed case class EOBytesData[+A](
bytes: NonEmpty[EOSingleByte, Vector[EOSingleByte]]
bytes: NonEmptyVector[EOSingleByte]
) extends EOData[A]

sealed case class EOStrData[+A](str: String) extends EOData[A]
Expand Down
Loading