Skip to content

Commit

Permalink
Merge pull request #71 from objectionary/54-test-against-eo-compiler
Browse files Browse the repository at this point in the history
54 test against eo compiler
  • Loading branch information
fizruk authored Feb 2, 2024
2 parents 2f22e41 + d14f86c commit 68494bb
Show file tree
Hide file tree
Showing 8 changed files with 282 additions and 39 deletions.
31 changes: 26 additions & 5 deletions .github/workflows/ghc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,29 @@ jobs:
!eo-phi-normalizer/Setup.hs
- name: 🧰 Setup Stack
# FIXME use freckle/stack-action@v4 when https://github.com/freckle/stack-action/pull/31 is merged
uses: deemp/stack-action@main
# FIXME use freckle/stack-action@v5 when https://github.com/freckle/stack-action/pull/36 is merged
uses: deemp/stack-action@pb/v5
with:
fast: ${{ github.ref_name != 'master' }}
stack-build-arguments: --${{ github.ref_name != 'master' && 'fast' || '' }} --pedantic

pipeline:
name: "Run pipeline"
# TODO run on more runners on master
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
program: [1]

steps:
- name: 📥 Checkout repository
uses: actions/checkout@v4

- name: 🧰 Setup Stack
# FIXME use freckle/stack-action@v5 when https://github.com/freckle/stack-action/pull/36 is merged
uses: deemp/stack-action@pb/v5
with:
stack-build-arguments: --${{ github.ref_name != 'master' && 'fast' || '' }} --pedantic

- uses: actions/setup-node@v4
with:
Expand All @@ -52,9 +71,11 @@ jobs:

- name: Install EO
run: npm install -g [email protected]
- name: Run pipeline EO -> Phi -> Normalizer -> Phi -> EO

- name: Run pipeline
run: ./pipeline.sh
env:
PROGRAM: ${{ matrix.program }}

haddock:
needs: [build]
Expand Down
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# pipeline
.eoc
before.txt
after.txt
app.eo
.pipeline

*.bak
eo-phi-normalizer/src/Language/EO/Phi/Syntax/Lex.hs
eo-phi-normalizer/src/Language/EO/Phi/Syntax/Par.hs
Expand Down
14 changes: 10 additions & 4 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,16 @@
pkgs.maven
pkgs.perl
];
text = ''
export JAVA_HOME="${pkgs.jdk21.home}"
${builtins.readFile ./pipeline.sh}
'';
text =
let mkProgram = n: ''
export PROGRAM="${builtins.toString n}"
${builtins.readFile ./pipeline.sh}
''; in

''
export JAVA_HOME="${pkgs.jdk21.home}"
${lib.concatMapStringsSep "\n\n" mkProgram [ 2 ]}
'';
description = "Run pipeline";
excludeShellChecks = [ "SC2139" ];
};
Expand Down
90 changes: 63 additions & 27 deletions pipeline.sh
Original file line number Diff line number Diff line change
@@ -1,51 +1,84 @@
set -euo pipefail

mkdir -p pipeline
cd pipeline
ROOT_DIR="$PWD"

mkdir -p ".pipeline/$PROGRAM"
cd ".pipeline/$PROGRAM"

shopt -s expand_aliases

EO="0.34.3"
alias eo="eoc --parser=${EO}"

cat > app.eo <<EOT
[args] > app
QQ.io.stdout > @
"Hello, world!\n"
EOT
cp "$ROOT_DIR"/pipeline/programs/"$PROGRAM"/app.eo .

# Without normalizer

eo clean
eo link
eo --alone dataize app > before.txt
cp before.txt "$ROOT_DIR"/pipeline/programs/"$PROGRAM"/before.txt

# With normalizer

eo phi

# Now, you modify/normalize this file:
IO=".eoc/phi/app.phi"
I=".eoc/phi/app.bk.phi"
mv "$IO" "$I"

stack run normalize-phi < "$I" > "$IO" \
|| {
printf "\n\nNormalizer failed!"
printf "\n\n* EO expression:\n\n"
cat app.eo
printf "\n\n* Phi expression:\n\n"
cat "$I"
printf "\n\n* Error:\n\n"
cat "$IO"
cat <<EOF
Normalizer failed!
* EO expression:
$(cat app.eo)
* Phi expression:
$(cat "$I")
* Error:
$(cat "$IO")
EOF
mv "$I" "$IO"
exit 1
}
perl -i -pe 'chomp if eof' "$IO"

printf "\n\nNormalizer succeeded!"
printf "\n\n* EO expression:\n\n"
cat app.eo
printf "\n\n* Phi expression:\n\n"
cat "$I"
printf "\n\n* Normalized Phi expression:\n\n"
cat "$IO"
printf "\n\n* Diff:\n\n"
diff "$I" "$IO" || true

{
export LC_ALL="C"
perl -i -pe 'chomp if eof' "$IO"
}

cat <<EOF
Normalizer succeeded!
* EO expression:
$(cat app.eo)
* Phi expression:
$(cat "$I")
* Normalized Phi expression:
$(cat "$IO")
* Diff:
$(diff "$I" "$IO" || true)
EOF

eo unphi

Expand All @@ -59,9 +92,12 @@ eo clean
eo link
eo --alone dataize app > after.txt

# Check dataization with and without the normalizer
# produces the same results

if [ "$(cat before.txt)" == "$(cat after.txt)" ]; then
echo 'SUCCESS'
else
echo 'FAILURE'
exit 1
fi
fi
3 changes: 3 additions & 0 deletions pipeline/programs/1/app.eo
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[args] > app
QQ.io.stdout > @
"Hello, world!\n"
1 change: 1 addition & 0 deletions pipeline/programs/1/before.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello, world!
176 changes: 176 additions & 0 deletions pipeline/programs/2/app.eo
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
+alias org.eolang.io.stdout
+alias org.eolang.txt.sprintf
+alias org.eolang.txt.sscanf
+alias org.eolang.collections.list

[n1 n2 length] > graphedge

[node edges] > nodeInEdges
reduce. > @
list
edges
FALSE
[accum current]
or. > @
accum
or.
eq.
^.node
current.n1
eq.
^.node
current.n2

[node nArray] > nodeInArray
reduce. > @
list
nArray
FALSE
[accum current]
or. > @
accum
eq.
^.node
current

[edges] > nodes
reduce. > @
list
edges
*
[accum current]
not. > addN1!
nodeInArray
current.n1
accum
not. > addN2!
nodeInArray
current.n2
accum
if. > @
and.
addN1
addN2
with.
with.
accum
current.n1
current.n2
if.
and.
addN1
addN2.not
with.
accum
current.n1
if.
and.
addN1.not
addN2
with.
accum
current.n2
accum

[s1 s2] > join
s1.as-bytes > x1
s2.as-bytes > x2
x1.concat x2 > x3
x3.as-string > @

[args...] > app
[] > graph!
[i] > getEdges
if. > @
(i.plus 2).lt
^.^.args.length
with.
^.getEdges
i.plus 3
graphedge
(sscanf "%d" (^.^.args.at i)).at 0
(sscanf "%d" (^.^.args.at (i.plus 1))).at 0
(sscanf "%d" (^.^.args.at (i.plus 2))).at 0
*
if. > @
^.args.length.lt 3
*
getEdges 0

nodes > graphNodes!
graph

[mi id] > getMin
if. > @
not.
lt.
id
^.graph.length
mi
if.
lt.
(^.graph.at id).length
(^.graph.at mi).length
^.getMin id (id.plus 1)
^.getMin mi (id.plus 1)

graph.at (getMin 0 0) > firstEdge
[step] > findEdges
[min id] > findNext
if. > @
not.
lt.
id
^.^.graph.length
min
seq
nodeInEdges > n1InStep!
(^.^.graph.at id).n1
^.step
nodeInEdges > n2InStep!
(^.^.graph.at id).n2
^.step
if.
and.
or.
and.
n1InStep
n2InStep.not
and.
n1InStep.not
n2InStep
or.
min.eq -1
lt.
(^.^.graph.at id).length
(^.^.graph.at min).length
^.findNext id (id.plus 1)
^.findNext min (id.plus 1)
findNext -1 0 > res
if. > @
eq.
-1
res
step
^.findEdges
with.
step
(^.graph.at res)
findEdges (* firstEdge) > ans!
[i] > output
if. > @
i.eq
ans.length
""
join
sprintf
"(%d %d - %d) "
(^.ans.at i).n1
(^.ans.at i).n2
(^.ans.at i).length
^.output (i.plus 1)
join "MST: " (output 0) > ret
stdout > @
sprintf
"%s \n"
ret
Empty file added pipeline/programs/2/before.txt
Empty file.

1 comment on commit 68494bb

@0pdd
Copy link

@0pdd 0pdd commented on 68494bb Feb 2, 2024

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/0pdd20240202-14-j7xdlx/Z2l0QGdpdGh1Yi5jb206b2JqZWN0aW9uYXJ5L25vcm1hbGl6ZXIuZ2l0 && pdd -v -f /tmp/20240202-1999528-n2suua [1]: + set -e + set -o pipefail + cd /tmp/0pdd20240202-14-j7xdlx/Z2l0QGdpdGh1Yi5jb206b2JqZWN0aW9uYXJ5L25vcm1hbGl6ZXIuZ2l0 + pdd...

Please, copy and paste this stack trace to GitHub:

UserError
set -x && set -e && set -o pipefail && cd /tmp/0pdd20240202-14-j7xdlx/Z2l0QGdpdGh1Yi5jb206b2JqZWN0aW9uYXJ5L25vcm1hbGl6ZXIuZ2l0 && pdd -v -f /tmp/20240202-1999528-n2suua [1]:
+ set -e
+ set -o pipefail
+ cd /tmp/0pdd20240202-14-j7xdlx/Z2l0QGdpdGh1Yi5jb206b2JqZWN0aW9uYXJ5L25vcm1hbGl6ZXIuZ2l0
+ pdd -v -f /tmp/20240202-1999528-n2suua

My version is 0.23.2
Ruby version is 3.1.4 at x86_64-linux
Reading from root dir /tmp/0pdd20240202-14-j7xdlx/Z2l0QGdpdGh1Yi5jb206b2JqZWN0aW9uYXJ5L25vcm1hbGl6ZXIuZ2l0
/tmp/0pdd20240202-14-j7xdlx/Z2l0QGdpdGh1Yi5jb206b2JqZWN0aW9uYXJ5L25vcm1hbGl6ZXIuZ2l0/.vscode/settings.json is a binary file (260 bytes)
/tmp/0pdd20240202-14-j7xdlx/Z2l0QGdpdGh1Yi5jb206b2JqZWN0aW9uYXJ5L25vcm1hbGl6ZXIuZ2l0/flake.lock is a binary file (1494 bytes)
/tmp/0pdd20240202-14-j7xdlx/Z2l0QGdpdGh1Yi5jb206b2JqZWN0aW9uYXJ5L25vcm1hbGl6ZXIuZ2l0/pipeline/programs/2/before.txt is a binary file (0 bytes)
/tmp/0pdd20240202-14-j7xdlx/Z2l0QGdpdGh1Yi5jb206b2JqZWN0aW9uYXJ5L25vcm1hbGl6ZXIuZ2l0/renovate.json is a binary file (114 bytes)
Reading .envrc ...
Reading .gitattributes ...
Reading .github/workflows/ghc.yml ...
ERROR: ERROR: .github/workflows/ghc.yml; PDD::Error at .github/workflows/ghc.yml:46: 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-3.1.4/lib/ruby/3.1.0/tempfile.rb:317: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:531:in `process_request'
/app/0pdd.rb:367:in `block in <top (required)>'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.6/lib/sinatra/base.rb:1706:in `call'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.6/lib/sinatra/base.rb:1706:in `block in compile!'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.6/lib/sinatra/base.rb:1019:in `block (3 levels) in route!'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.6/lib/sinatra/base.rb:1037:in `route_eval'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.6/lib/sinatra/base.rb:1019:in `block (2 levels) in route!'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.6/lib/sinatra/base.rb:1068:in `block in process_route'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.6/lib/sinatra/base.rb:1066:in `catch'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.6/lib/sinatra/base.rb:1066:in `process_route'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.6/lib/sinatra/base.rb:1017:in `block in route!'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.6/lib/sinatra/base.rb:1014:in `each'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.6/lib/sinatra/base.rb:1014:in `route!'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.6/lib/sinatra/base.rb:1138:in `block in dispatch!'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.6/lib/sinatra/base.rb:1109:in `catch'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.6/lib/sinatra/base.rb:1109:in `invoke'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.6/lib/sinatra/base.rb:1133:in `dispatch!'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.6/lib/sinatra/base.rb:949:in `block in call!'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.6/lib/sinatra/base.rb:1109:in `catch'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.6/lib/sinatra/base.rb:1109:in `invoke'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.6/lib/sinatra/base.rb:949:in `call!'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.6/lib/sinatra/base.rb:938:in `call'
/app/vendor/bundle/ruby/3.1.0/gems/rack-2.2.8/lib/rack/deflater.rb:44:in `call'
/app/vendor/bundle/ruby/3.1.0/gems/rack-protection-3.0.6/lib/rack/protection/xss_header.rb:20:in `call'
/app/vendor/bundle/ruby/3.1.0/gems/rack-protection-3.0.6/lib/rack/protection/path_traversal.rb:18:in `call'
/app/vendor/bundle/ruby/3.1.0/gems/rack-protection-3.0.6/lib/rack/protection/json_csrf.rb:28:in `call'
/app/vendor/bundle/ruby/3.1.0/gems/rack-protection-3.0.6/lib/rack/protection/base.rb:53:in `call'
/app/vendor/bundle/ruby/3.1.0/gems/rack-protection-3.0.6/lib/rack/protection/base.rb:53:in `call'
/app/vendor/bundle/ruby/3.1.0/gems/rack-protection-3.0.6/lib/rack/protection/frame_options.rb:33:in `call'
/app/vendor/bundle/ruby/3.1.0/gems/rack-2.2.8/lib/rack/logger.rb:17:in `call'
/app/vendor/bundle/ruby/3.1.0/gems/rack-2.2.8/lib/rack/common_logger.rb:38:in `call'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.6/lib/sinatra/base.rb:261:in `call'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.6/lib/sinatra/base.rb:254:in `call'
/app/vendor/bundle/ruby/3.1.0/gems/rack-2.2.8/lib/rack/head.rb:12:in `call'
/app/vendor/bundle/ruby/3.1.0/gems/rack-2.2.8/lib/rack/method_override.rb:24:in `call'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.6/lib/sinatra/base.rb:219:in `call'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.6/lib/sinatra/base.rb:2018:in `call'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.6/lib/sinatra/base.rb:1576:in `block in call'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.6/lib/sinatra/base.rb:1792:in `synchronize'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-3.0.6/lib/sinatra/base.rb:1576:in `call'
/app/vendor/bundle/ruby/3.1.0/gems/rack-2.2.8/lib/rack/handler/webrick.rb:95:in `service'
/app/vendor/bundle/ruby/3.1.0/gems/webrick-1.8.1/lib/webrick/httpserver.rb:140:in `service'
/app/vendor/bundle/ruby/3.1.0/gems/webrick-1.8.1/lib/webrick/httpserver.rb:96:in `run'
/app/vendor/bundle/ruby/3.1.0/gems/webrick-1.8.1/lib/webrick/server.rb:310:in `block in start_thread'

Please sign in to comment.