From 1415be119eac1c0f439ba34adedbc026a65227a8 Mon Sep 17 00:00:00 2001 From: dours Date: Mon, 22 Aug 2022 00:35:35 +0300 Subject: [PATCH 1/2] implement the `map` function, add a test for lambda --- transpiler/src/main/eo/preface/xmap.eo | 20 +++++++++++++++++++ transpiler/src/main/eo/preface/xmyArray.eo | 2 ++ .../PrintLinearizedMutableEOWithCage.scala | 2 ++ .../expressions/lambda/lambda3.yaml | 2 +- 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 transpiler/src/main/eo/preface/xmap.eo diff --git a/transpiler/src/main/eo/preface/xmap.eo b/transpiler/src/main/eo/preface/xmap.eo new file mode 100644 index 000000000..923950e26 --- /dev/null +++ b/transpiler/src/main/eo/preface/xmap.eo @@ -0,0 +1,20 @@ ++package preface ++alias return preface.return ++alias xmyArray preface.xmyArray + +[] > xmap + [f l] > apply + [stackUp] > @ + (goto ((xmyArray.apply (*)).@)).result > ans + memory 0 > i + seq > @ + (i.lt (l.value.length)).while + [unused] + (goto ((f.apply (l.value.get i)).@)).result > to-append + seq > @ + (goto ((ans.xappend.apply ans to-append).@)).result + i.write (i.plus 1) + 123 + stackUp.forward (return ans) + 123 + diff --git a/transpiler/src/main/eo/preface/xmyArray.eo b/transpiler/src/main/eo/preface/xmyArray.eo index 9bbde97f1..bf008c21c 100644 --- a/transpiler/src/main/eo/preface/xmyArray.eo +++ b/transpiler/src/main/eo/preface/xmyArray.eo @@ -17,6 +17,8 @@ [] > result cage initValue > value fakeclasses.pyListClass > x__class__ + [] > to-my-array + pResult > @ [x] > with-value (goto ((xmyArray.apply x).@)).result > @ [] > xlength diff --git a/transpiler/src/main/scala/org/polystat/py2eo/transpiler/PrintLinearizedMutableEOWithCage.scala b/transpiler/src/main/scala/org/polystat/py2eo/transpiler/PrintLinearizedMutableEOWithCage.scala index f532434e1..50f9716f1 100644 --- a/transpiler/src/main/scala/org/polystat/py2eo/transpiler/PrintLinearizedMutableEOWithCage.scala +++ b/transpiler/src/main/scala/org/polystat/py2eo/transpiler/PrintLinearizedMutableEOWithCage.scala @@ -41,6 +41,7 @@ object PrintLinearizedMutableEOWithCage { "+alias xmyArray preface.xmyArray", "+alias xmyMap preface.xmyMap", "+alias xlen preface.xlen", + "+alias xmap preface.xmap", "+alias xstr preface.xstr", "+alias xsum preface.xsum", "+alias xlist preface.xlist", @@ -361,6 +362,7 @@ object PrintLinearizedMutableEOWithCage { "xmyMap > dummy-xmyMap", "mkCopy > dummy-mkCopy", "xlen > dummy-xlen", + "xmap > dummy-xmap", "pair > dummy-pair", "xstr > dummy-xstr", "xsum > dummy-xsum", diff --git a/transpiler/src/test/resources/org/polystat/py2eo/transpiler/simple-tests/expressions/lambda/lambda3.yaml b/transpiler/src/test/resources/org/polystat/py2eo/transpiler/simple-tests/expressions/lambda/lambda3.yaml index ede71239e..7e3334266 100644 --- a/transpiler/src/test/resources/org/polystat/py2eo/transpiler/simple-tests/expressions/lambda/lambda3.yaml +++ b/transpiler/src/test/resources/org/polystat/py2eo/transpiler/simple-tests/expressions/lambda/lambda3.yaml @@ -1,4 +1,4 @@ -enabled: False +enabled: True python: | def lambda1(): my_list = [1, 5, 4, 6, 8, 11, 3, 12] From a0c7a3bd1bb9f3642d86ca7e8192aeea2ab43a7f Mon Sep 17 00:00:00 2001 From: dours Date: Mon, 22 Aug 2022 00:49:35 +0300 Subject: [PATCH 2/2] implement a `filter` fun and enable a lambda test --- transpiler/src/main/eo/preface/xfilter.eo | 22 +++++++++++++++++++ .../PrintLinearizedMutableEOWithCage.scala | 2 ++ .../expressions/lambda/lambda2.yaml | 2 +- 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 transpiler/src/main/eo/preface/xfilter.eo diff --git a/transpiler/src/main/eo/preface/xfilter.eo b/transpiler/src/main/eo/preface/xfilter.eo new file mode 100644 index 000000000..524bca50d --- /dev/null +++ b/transpiler/src/main/eo/preface/xfilter.eo @@ -0,0 +1,22 @@ ++package preface ++alias return preface.return ++alias xmyArray preface.xmyArray + +[] > xfilter + [f l] > apply + [stackUp] > @ + (goto ((xmyArray.apply (*)).@)).result > ans + memory 0 > i + seq > @ + (i.lt (l.value.length)).while + [unused] + (goto ((f.apply (l.value.get i)).@)).result > to-append + seq > @ + to-append.if + (goto ((ans.xappend.apply ans (l.value.get i)).@)).result + 0 + i.write (i.plus 1) + 123 + stackUp.forward (return ans) + 123 + diff --git a/transpiler/src/main/scala/org/polystat/py2eo/transpiler/PrintLinearizedMutableEOWithCage.scala b/transpiler/src/main/scala/org/polystat/py2eo/transpiler/PrintLinearizedMutableEOWithCage.scala index 50f9716f1..827e97f47 100644 --- a/transpiler/src/main/scala/org/polystat/py2eo/transpiler/PrintLinearizedMutableEOWithCage.scala +++ b/transpiler/src/main/scala/org/polystat/py2eo/transpiler/PrintLinearizedMutableEOWithCage.scala @@ -42,6 +42,7 @@ object PrintLinearizedMutableEOWithCage { "+alias xmyMap preface.xmyMap", "+alias xlen preface.xlen", "+alias xmap preface.xmap", + "+alias xfilter preface.xfilter", "+alias xstr preface.xstr", "+alias xsum preface.xsum", "+alias xlist preface.xlist", @@ -363,6 +364,7 @@ object PrintLinearizedMutableEOWithCage { "mkCopy > dummy-mkCopy", "xlen > dummy-xlen", "xmap > dummy-xmap", + "xfilter > dummy-xfilter", "pair > dummy-pair", "xstr > dummy-xstr", "xsum > dummy-xsum", diff --git a/transpiler/src/test/resources/org/polystat/py2eo/transpiler/simple-tests/expressions/lambda/lambda2.yaml b/transpiler/src/test/resources/org/polystat/py2eo/transpiler/simple-tests/expressions/lambda/lambda2.yaml index 6608db8cc..ace5eed26 100644 --- a/transpiler/src/test/resources/org/polystat/py2eo/transpiler/simple-tests/expressions/lambda/lambda2.yaml +++ b/transpiler/src/test/resources/org/polystat/py2eo/transpiler/simple-tests/expressions/lambda/lambda2.yaml @@ -1,4 +1,4 @@ -enabled: False +enabled: True python: | def lambda1(): my_list = [1, 5, 4, 6, 8, 11, 3, 12]