diff --git a/.github/workflows/ghc.yml b/.github/workflows/ghc.yml index 41bf38e36..fe5ff6eb8 100644 --- a/.github/workflows/ghc.yml +++ b/.github/workflows/ghc.yml @@ -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: @@ -52,9 +71,11 @@ jobs: - name: Install EO run: npm install -g eolang@0.15.1 - - - name: Run pipeline EO -> Phi -> Normalizer -> Phi -> EO + + - name: Run pipeline run: ./pipeline.sh + env: + PROGRAM: ${{ matrix.program }} haddock: needs: [build] diff --git a/.gitignore b/.gitignore index 8a188c2b8..f75f14925 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/flake.nix b/flake.nix index 5220dda72..03b4f8d99 100644 --- a/flake.nix +++ b/flake.nix @@ -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" ]; }; diff --git a/pipeline.sh b/pipeline.sh index c10e7546d..7dfabed09 100755 --- a/pipeline.sh +++ b/pipeline.sh @@ -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 < 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 < 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 \ No newline at end of file +fi diff --git a/pipeline/programs/1/app.eo b/pipeline/programs/1/app.eo new file mode 100644 index 000000000..9e43124e1 --- /dev/null +++ b/pipeline/programs/1/app.eo @@ -0,0 +1,3 @@ +[args] > app + QQ.io.stdout > @ + "Hello, world!\n" diff --git a/pipeline/programs/1/before.txt b/pipeline/programs/1/before.txt new file mode 100644 index 000000000..af5626b4a --- /dev/null +++ b/pipeline/programs/1/before.txt @@ -0,0 +1 @@ +Hello, world! diff --git a/pipeline/programs/2/app.eo b/pipeline/programs/2/app.eo new file mode 100644 index 000000000..81ab1538e --- /dev/null +++ b/pipeline/programs/2/app.eo @@ -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 diff --git a/pipeline/programs/2/before.txt b/pipeline/programs/2/before.txt new file mode 100644 index 000000000..e69de29bb