Skip to content

Commit

Permalink
support the annotated-3.yaml test
Browse files Browse the repository at this point in the history
  • Loading branch information
dours committed Oct 4, 2022
1 parent b424c99 commit 1de4f85
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 8 deletions.
1 change: 1 addition & 0 deletions transpiler/src/main/eo/preface/xfakeclasses.eo
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
fakeclass 10 > pyListClass
fakeclass 13 > pyStringClass
fakeclass 17 > xpyTypeClass
fakeclass 18 > pyTupleClass

[typ1 typ2] > gt
seq > @
Expand Down
6 changes: 3 additions & 3 deletions transpiler/src/main/eo/preface/xmyArray.eo
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
+alias xAssertionError preface.xAssertionError

[] > xmyArray
[initValue] > ap
[is-list initValue] > ap
[stackUp] > @
cage result > pResult
[] > result
cage initValue > value
xfakeclasses.pyListClass > x__class__
is-list.if (xfakeclasses.pyListClass) (xfakeclasses.pyTupleClass) > x__class__
[] > to-my-array
pResult > @
[x] > with-value
Expand Down Expand Up @@ -77,7 +77,7 @@
memory TRUE > acc
memory 0 > pos
if. > res
((x.x__class__.eq (xfakeclasses.pyListClass)).value.and (value.length.eq (x.value.length)))
((x.x__class__.eq (is-list.if (xfakeclasses.pyListClass) (xfakeclasses.pyTupleClass))).value.and (value.length.eq (x.value.length)))
seq
(acc.and (pos.lt (value.length))).while
[unused]
Expand Down
6 changes: 6 additions & 0 deletions transpiler/src/main/eo/preface/xtuple.eo
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
+package preface
+alias xfakeclasses preface.xfakeclasses

[] > xtuple
xfakeclasses.pyTupleClass > @

Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package org.polystat.py2eo.transpiler

import org.polystat.py2eo.parser.Expression.{CallIndex, CollectionCons, CollectionKind, DictCons, Ident, T}
import org.polystat.py2eo.parser.Expression.{BoolLiteral, CallIndex, CollectionCons, CollectionKind, DictCons, Ident, T}

object AddExplicitConstructionOfCollection {
def apply(e : T) : T = {
e match {
case CollectionCons(kind, l, ann)
if kind == CollectionKind.List || kind == CollectionKind.Tuple =>
CallIndex(true, Ident("xmyArray", e.ann.pos), List((None, e)), e.ann.pos)
CallIndex(
true,
Ident("xmyArray", e.ann.pos),
List((None, BoolLiteral(kind == CollectionKind.List, e.ann.pos)), (None, e)),
e.ann.pos
)
case DictCons(_, _) | CollectionCons(CollectionKind.Set, _, _) =>
CallIndex(true, Ident("xmyMap", e.ann.pos), List((None, e)), e.ann.pos)
case _ => e
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ object PrintLinearizedMutableEOWithCage {
"+alias xstr preface.xstr",
"+alias xsum preface.xsum",
"+alias xlist preface.xlist",
"+alias xtuple preface.xtuple",
"+alias xint preface.xint",
"+alias xfloat preface.xfloat",
"+alias xiter preface.xiter",
Expand Down Expand Up @@ -369,6 +370,7 @@ object PrintLinearizedMutableEOWithCage {
"xstr > dummy-xstr",
"xsum > dummy-xsum",
"xlist > dummy-xlist",
"xtuple > dummy-xtuple",
"xint > dummy-xint",
"xfloat > dummy-xfloat",
"xStopIteration > dummy-stop-iteration",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.polystat.py2eo.transpiler

import org.polystat.py2eo.parser.Expression.{CallIndex, CollectionCons, Field, Ident}
import org.polystat.py2eo.parser.Statement
import org.polystat.py2eo.parser.Statement.{Assign, Suite}
import org.polystat.py2eo.transpiler.GenericStatementPasses.NamesU

object SimplifyAssignmentToCollectionCons {
def apply(s : Statement.T, ns : NamesU) : (Statement.T, NamesU) = s match {
case Assign(List(CollectionCons(_, lhs, _), rhs), ann) =>
val (iter, ns1) = ns("it")
val iterID = Ident(iter, ann.pos)
val extractIter = Assign(List(
iterID,
CallIndex(true, Field(rhs, "__iter__", ann.pos), List(), ann.pos)
), ann.pos)
val assignments = lhs.map(lhs =>
Assign(List(lhs, CallIndex(true, Field(iterID, "__next__", ann.pos), List(), ann.pos)), ann.pos)
)
(
Suite((extractIter :: assignments), ann.pos),
ns1
)
case _ => (s, ns)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ object Transpile {
debugPrinter(simAssList._1, "simplifyAssList")
val simAss2Index = GenericStatementPasses.procStatement(SimplifyAssigmentToIndex.simplify)(simAssList._1, simAssList._2)
debugPrinter(simAss2Index._1, "simplifyAss2Index")
val simCompr = GenericStatementPasses.procExprInStatement((SimplifyComprehension.apply))(simAss2Index._1, simAss2Index._2)
val simAss2Coll = GenericStatementPasses.procStatement(SimplifyAssignmentToCollectionCons.apply)(simAss2Index._1, simAss2Index._2)
debugPrinter(simAss2Coll._1, "simplifyAss2Collection")
val simCompr = GenericStatementPasses.procExprInStatement((SimplifyComprehension.apply))(simAss2Coll._1, simAss2Coll._2)
debugPrinter(simCompr._1, "afterSimplifyCollectionComprehension")
val rmImport = SubstituteExternalIdent(simCompr._1, simCompr._2)
val simForAgain = GenericStatementPasses.procStatement(SimplifyFor.apply)(rmImport._1, rmImport._2)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
enabled: False
enabled: True
python: |
def test():
a: int;b: int;c: int
a,b,c = range(3)
print(a,b,c) #As output 0 1 2
return len((a, b, c)) == 3 and (a, b, c).__class__ is tuple

1 comment on commit 1de4f85

@0pdd
Copy link
Member

@0pdd 0pdd commented on 1de4f85 Oct 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't able to retrieve PDD puzzles from the code base and submit them to github. If you think that it's a bug on our side, please submit it to yegor256/0pdd:

set -x && set -e && set -o pipefail && cd /tmp/0pdd20221004-13-1gnc9nw/Z2l0QGdpdGh1Yi5jb206cG9seXN0YXQvcHkyZW8uZ2l0 && pdd -v -f /tmp/20221004-17048-11lwn0n [1]: + set -e + set -o pipefail + cd /tmp/0pdd20221004-13-1gnc9nw/Z2l0QGdpdGh1Yi5jb206cG9seXN0YXQvcHkyZW8uZ2l0 + pdd -v -f...

Please, copy and paste this stack trace to GitHub:

UserError
set -x && set -e && set -o pipefail && cd /tmp/0pdd20221004-13-1gnc9nw/Z2l0QGdpdGh1Yi5jb206cG9seXN0YXQvcHkyZW8uZ2l0 && pdd -v -f /tmp/20221004-17048-11lwn0n [1]:
+ set -e
+ set -o pipefail
+ cd /tmp/0pdd20221004-13-1gnc9nw/Z2l0QGdpdGh1Yi5jb206cG9seXN0YXQvcHkyZW8uZ2l0
+ pdd -v -f /tmp/20221004-17048-11lwn0n

My version is 0.21.3
Ruby version is 2.7.5 at x86_64-linux
Reading from root dir /tmp/0pdd20221004-13-1gnc9nw/Z2l0QGdpdGh1Yi5jb206cG9seXN0YXQvcHkyZW8uZ2l0
Reading runEO/pom.xml ...
Reading .gitignore ...
Reading README.md ...
Reading Dockerfile ...
Reading transpiler/pom.xml ...
Reading transpiler/src/main/eo/xmodules/xmath.eo ...
Reading transpiler/src/main/eo/preface/xmyMap.eo ...
Reading transpiler/src/main/eo/preface/continue.eo ...
Reading transpiler/src/main/eo/preface/pair.eo ...
Reading transpiler/src/main/eo/preface/xfakeclasses.eo ...
Reading transpiler/src/main/eo/preface/xfloat.eo ...
Reading transpiler/src/main/eo/preface/xValueError.eo ...
Reading transpiler/src/main/eo/preface/xBaseException.eo ...
Reading transpiler/src/main/eo/preface/xmap.eo ...
Reading transpiler/src/main/eo/preface/xiter.eo ...
Reading transpiler/src/main/eo/preface/pyfloat.eo ...
Reading transpiler/src/main/eo/preface/xTypeError.eo ...
Reading transpiler/src/main/eo/preface/pyint.eo ...
Reading transpiler/src/main/eo/preface/xZeroDivisionError.eo ...
Reading transpiler/src/main/eo/preface/break.eo ...
Reading transpiler/src/main/eo/preface/xrange.eo ...
Reading transpiler/src/main/eo/preface/xAssertionError.eo ...
Reading transpiler/src/main/eo/preface/xsum.eo ...
Reading transpiler/src/main/eo/preface/pycomplex.eo ...
Reading transpiler/src/main/eo/preface/pybool.eo ...
Reading transpiler/src/main/eo/preface/raiseNothing.eo ...
Reading transpiler/src/main/eo/preface/xlist.eo ...
Reading transpiler/src/main/eo/preface/newUID.eo ...
Reading transpiler/src/main/eo/preface/xmyArray.eo ...
Reading transpiler/src/main/eo/preface/raiseEmpty.eo ...
Reading transpiler/src/main/eo/preface/mkCopy.eo ...
Reading transpiler/src/main/eo/preface/xlen.eo ...
Reading transpiler/src/main/eo/preface/xstr.eo ...
Reading transpiler/src/main/eo/preface/xint.eo ...
Reading transpiler/src/main/eo/preface/xStopIteration.eo ...
Reading transpiler/src/main/eo/preface/xfilter.eo ...
Reading transpiler/src/main/eo/preface/pystring.eo ...
Reading transpiler/src/main/eo/preface/return.eo ...
Reading transpiler/src/main/eo/my-array.eo ...
Reading transpiler/src/main/scala/org/polystat/py2eo/transpiler/PrintLinearizedMutableEOWithCage.scala ...
ERROR: transpiler/src/main/scala/org/polystat/py2eo/transpiler/PrintLinearizedMutableEOWithCage.scala; PDD::Error at transpiler/src/main/scala/org/polystat/py2eo/transpiler/PrintLinearizedMutableEOWithCage.scala:59: @todo found, but puzzle can't be parsed, most probably because @todo is not followed by a puzzle marker, as this page explains: https://github.com/cqfn/pdd#how-to-format
If you can't understand the cause of this issue or you don't know how to fix it, please submit a GitHub issue, we will try to help you: https://github.com/cqfn/pdd/issues. This tool is still in its beta version and we will appreciate your feedback. Here is where you can find more documentation: https://github.com/cqfn/pdd/blob/master/README.md.
Exit code is 1

/app/objects/git_repo.rb:73:in `rescue in block in xml'
/app/objects/git_repo.rb:70:in `block in xml'
/app/vendor/ruby-2.7.5/lib/ruby/2.7.0/tempfile.rb:291:in `open'
/app/objects/git_repo.rb:69:in `xml'
/app/objects/puzzles.rb:41:in `deploy'
/app/objects/jobs/job.rb:38:in `proceed'
/app/objects/jobs/job_starred.rb:32:in `proceed'
/app/objects/jobs/job_recorded.rb:31:in `proceed'
/app/objects/jobs/job_emailed.rb:33:in `proceed'
/app/objects/jobs/job_commiterrors.rb:33:in `proceed'
/app/objects/jobs/job_detached.rb:48:in `exclusive'
/app/objects/jobs/job_detached.rb:36:in `block in proceed'
/app/objects/jobs/job_detached.rb:36:in `fork'
/app/objects/jobs/job_detached.rb:36:in `proceed'
/app/0pdd.rb:518:in `process_request'
/app/0pdd.rb:355:in `block in <top (required)>'
/app/vendor/bundle/ruby/2.7.0/gems/sinatra-2.2.2/lib/sinatra/base.rb:1686:in `call'
/app/vendor/bundle/ruby/2.7.0/gems/sinatra-2.2.2/lib/sinatra/base.rb:1686:in `block in compile!'
/app/vendor/bundle/ruby/2.7.0/gems/sinatra-2.2.2/lib/sinatra/base.rb:1023:in `block (3 levels) in route!'
/app/vendor/bundle/ruby/2.7.0/gems/sinatra-2.2.2/lib/sinatra/base.rb:1042:in `route_eval'
/app/vendor/bundle/ruby/2.7.0/gems/sinatra-2.2.2/lib/sinatra/base.rb:1023:in `block (2 levels) in route!'
/app/vendor/bundle/ruby/2.7.0/gems/sinatra-2.2.2/lib/sinatra/base.rb:1071:in `block in process_route'
/app/vendor/bundle/ruby/2.7.0/gems/sinatra-2.2.2/lib/sinatra/base.rb:1069:in `catch'
/app/vendor/bundle/ruby/2.7.0/gems/sinatra-2.2.2/lib/sinatra/base.rb:1069:in `process_route'
/app/vendor/bundle/ruby/2.7.0/gems/sinatra-2.2.2/lib/sinatra/base.rb:1021:in `block in route!'
/app/vendor/bundle/ruby/2.7.0/gems/sinatra-2.2.2/lib/sinatra/base.rb:1018:in `each'
/app/vendor/bundle/ruby/2.7.0/gems/sinatra-2.2.2/lib/sinatra/base.rb:1018:in `route!'
/app/vendor/bundle/ruby/2.7.0/gems/sinatra-2.2.2/lib/sinatra/base.rb:1140:in `block in dispatch!'
/app/vendor/bundle/ruby/2.7.0/gems/sinatra-2.2.2/lib/sinatra/base.rb:1112:in `block in invoke'
/app/vendor/bundle/ruby/2.7.0/gems/sinatra-2.2.2/lib/sinatra/base.rb:1112:in `catch'
/app/vendor/bundle/ruby/2.7.0/gems/sinatra-2.2.2/lib/sinatra/base.rb:1112:in `invoke'
/app/vendor/bundle/ruby/2.7.0/gems/sinatra-2.2.2/lib/sinatra/base.rb:1135:in `dispatch!'
/app/vendor/bundle/ruby/2.7.0/gems/sinatra-2.2.2/lib/sinatra/base.rb:949:in `block in call!'
/app/vendor/bundle/ruby/2.7.0/gems/sinatra-2.2.2/lib/sinatra/base.rb:1112:in `block in invoke'
/app/vendor/bundle/ruby/2.7.0/gems/sinatra-2.2.2/lib/sinatra/base.rb:1112:in `catch'
/app/vendor/bundle/ruby/2.7.0/gems/sinatra-2.2.2/lib/sinatra/base.rb:1112:in `invoke'
/app/vendor/bundle/ruby/2.7.0/gems/sinatra-2.2.2/lib/sinatra/base.rb:949:in `call!'
/app/vendor/bundle/ruby/2.7.0/gems/sinatra-2.2.2/lib/sinatra/base.rb:938:in `call'
/app/vendor/bundle/ruby/2.7.0/gems/rack-protection-2.2.2/lib/rack/protection/xss_header.rb:18:in `call'
/app/vendor/bundle/ruby/2.7.0/gems/rack-protection-2.2.2/lib/rack/protection/path_traversal.rb:16:in `call'
/app/vendor/bundle/ruby/2.7.0/gems/rack-protection-2.2.2/lib/rack/protection/json_csrf.rb:26:in `call'
/app/vendor/bundle/ruby/2.7.0/gems/rack-protection-2.2.2/lib/rack/protection/base.rb:50:in `call'
/app/vendor/bundle/ruby/2.7.0/gems/rack-protection-2.2.2/lib/rack/protection/base.rb:50:in `call'
/app/vendor/bundle/ruby/2.7.0/gems/rack-protection-2.2.2/lib/rack/protection/frame_options.rb:31:in `call'
/app/vendor/bundle/ruby/2.7.0/gems/rack-2.2.4/lib/rack/logger.rb:17:in `call'
/app/vendor/bundle/ruby/2.7.0/gems/rack-2.2.4/lib/rack/common_logger.rb:38:in `call'
/app/vendor/bundle/ruby/2.7.0/gems/sinatra-2.2.2/lib/sinatra/base.rb:255:in `call'
/app/vendor/bundle/ruby/2.7.0/gems/sinatra-2.2.2/lib/sinatra/base.rb:248:in `call'
/app/vendor/bundle/ruby/2.7.0/gems/rack-2.2.4/lib/rack/head.rb:12:in `call'
/app/vendor/bundle/ruby/2.7.0/gems/rack-2.2.4/lib/rack/method_override.rb:24:in `call'
/app/vendor/bundle/ruby/2.7.0/gems/sinatra-2.2.2/lib/sinatra/base.rb:218:in `call'
/app/vendor/bundle/ruby/2.7.0/gems/sinatra-2.2.2/lib/sinatra/base.rb:1993:in `call'
/app/vendor/bundle/ruby/2.7.0/gems/sinatra-2.2.2/lib/sinatra/base.rb:1553:in `block in call'
/app/vendor/bundle/ruby/2.7.0/gems/sinatra-2.2.2/lib/sinatra/base.rb:1769:in `synchronize'
/app/vendor/bundle/ruby/2.7.0/gems/sinatra-2.2.2/lib/sinatra/base.rb:1553:in `call'
/app/vendor/bundle/ruby/2.7.0/gems/rack-2.2.4/lib/rack/handler/webrick.rb:95:in `service'
/app/vendor/ruby-2.7.5/lib/ruby/2.7.0/webrick/httpserver.rb:140:in `service'
/app/vendor/ruby-2.7.5/lib/ruby/2.7.0/webrick/httpserver.rb:96:in `run'
/app/vendor/ruby-2.7.5/lib/ruby/2.7.0/webrick/server.rb:307:in `block in start_thread'

Please sign in to comment.