From 0dba42ce5368a5e3fd2964ae48ec57754b6397a8 Mon Sep 17 00:00:00 2001 From: Xavier Mitault Date: Tue, 19 Dec 2023 21:08:46 +0100 Subject: [PATCH 01/54] Fix CICD --- .github/workflows/documentation.yml | 19 ---------- .github/workflows/release.yml | 56 +++++++++++++++++++++-------- .github/workflows/tests.yml | 2 +- .gitignore | 3 ++ Makefile | 36 ++++++++----------- docs/Coverage.md | 1 - docs/SUMMARY.md | 2 -- docs/Tests.md | 1 - lvtc/stack.yaml.lock | 13 +++++++ lvtrun/stack.yaml.lock | 13 +++++++ 10 files changed, 87 insertions(+), 59 deletions(-) delete mode 100644 docs/Coverage.md delete mode 100644 docs/Tests.md create mode 100644 lvtc/stack.yaml.lock create mode 100644 lvtrun/stack.yaml.lock diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index ee2702f..af808f7 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -61,25 +61,6 @@ jobs: exit 0 fi - - name: Tests - if: steps.filter.outputs.docs == 'true' || steps.filter.outputs.docs2 == 'true' || steps.filter.outputs.workflow == 'true' || github.ref == 'refs/heads/main' - run: | - if ! stack test --test-arguments "--html book/Tests.html"; then - exit 0 - fi - - - name: Coverage - if: steps.filter.outputs.docs == 'true' || steps.filter.outputs.docs2 == 'true' || steps.filter.outputs.workflow == 'true' || github.ref == 'refs/heads/main' - run: | - if ! make tests-coverage; then - exit 0 - else - PATH_HTML=$(make tests-coverage-html-path) - cp -r "$PATH_HTML/koaky" book/ - cp -r "$PATH_HTML/combined" book/ - cp "$PATH_HTML/index.html" book/Coverage.html - fi - - name: Setup Pages if: github.ref == 'refs/heads/main' uses: actions/configure-pages@v3 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index df632a1..86779f2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -59,14 +59,22 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - gh release upload ${{ needs.release-create.outputs.release }} "./koaky-exe.exe#koaky-windows.exe" + gh release upload ${{ needs.release-create.outputs.release }} "./lvtc/lvtc-exe.exe#lvtc-windows.exe" + gh release upload ${{ needs.release-create.outputs.release }} "./lvtrun/lvtrun-exe.exe#lvtrun-windows.exe" - - name: Upload To Artifact + - name: Upload To Artifact lvtc if: github.ref != 'refs/heads/main' uses: actions/upload-artifact@v3 with: - name: koaky.exe - path: ./koaky.exe + name: lvtc-windows.exe + path: ./lvtc/lvtc-exe.exe + + - name: Upload To Artifact lvtrun + if: github.ref != 'refs/heads/main' + uses: actions/upload-artifact@v3 + with: + name: lvtrun-windows.exe + path: ./lvtrun/lvtrun-exe.exe release-linux: runs-on: ubuntu-latest @@ -89,21 +97,31 @@ jobs: run: make - name: Rename - run: mv koaky-exe koaky-linux + run: | + mv lvtc/lvtc-exe lvtc-linux + mv lvtrun/lvtrun-exe lvtrun-linux - name: Upload To Release if: github.ref == 'refs/heads/main' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - gh release upload ${{ needs.release-create.outputs.release }} "./koaky-linux" + gh release upload ${{ needs.release-create.outputs.release }} "./lvtc-linux" + gh release upload ${{ needs.release-create.outputs.release }} "./lvtrun-linux" + + - name: Upload To Artifact lvtc + if: github.ref != 'refs/heads/main' + uses: actions/upload-artifact@v3 + with: + name: lvtc-linux + path: ./lvtc-linux - - name: Upload To Artifact + - name: Upload To Artifact lvtrun if: github.ref != 'refs/heads/main' uses: actions/upload-artifact@v3 with: - name: koaky-linux - path: ./koaky-linux + name: lvtrun-linux + path: ./lvtrun-linux release-macos: runs-on: macos-latest @@ -126,18 +144,28 @@ jobs: run: make - name: Rename - run: mv koaky-exe koaky-macos + run: | + mv lvtc/lvtc-exe lvtc-macos + mv lvtrun/lvtrun-exe lvtrun-macos - name: Upload To Release if: github.ref == 'refs/heads/main' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - gh release upload ${{ needs.release-create.outputs.release }} "./koaky-macos" + gh release upload ${{ needs.release-create.outputs.release }} "./lvtc-macos" + gh release upload ${{ needs.release-create.outputs.release }} "./lvtrun-macos" + + - name: Upload To Artifact lvtc + if: github.ref != 'refs/heads/main' + uses: actions/upload-artifact@v3 + with: + name: lvtc-macos + path: ./lvtc-macos - - name: Upload To Artifact + - name: Upload To Artifact lvtrun if: github.ref != 'refs/heads/main' uses: actions/upload-artifact@v3 with: - name: koaky-macos - path: ./koaky-macos + name: lvtrun-macos + path: ./lvtrun-macos diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index dd66015..93b97d4 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -58,7 +58,7 @@ jobs: - name: Tests id: failedTest run: | - if ! stack test &> tests.log; then + if ! make tests &> tests.log; then echo "failedTest=true" >> $GITHUB_OUTPUT else echo "failedTest=false" >> $GITHUB_OUTPUT diff --git a/.gitignore b/.gitignore index ac73cc9..f61f7ff 100644 --- a/.gitignore +++ b/.gitignore @@ -169,6 +169,9 @@ tags /koaky-exe /glados +lvtc-exe +lvtrun-exe + *.log *.exe diff --git a/Makefile b/Makefile index 294c12a..ee3e8f1 100644 --- a/Makefile +++ b/Makefile @@ -5,41 +5,35 @@ ## makefile that stack ## -TARGET = koaky -MARVIN_TARGET = glados +TARGET = leviator -CP = cp -RM = rm -rf - -ifeq ($(OS),Windows_NT) - BIN_STACK = $(TARGET)-exe.exe -else - BIN_STACK = $(TARGET)-exe -endif - -all: $(TARGET) +LVT_COMPILER = lvtc +LVT_RUNER = lvtrun $(TARGET): - stack build --copy-bins --local-bin-path . - $(CP) "$(BIN_STACK)" "$(MARVIN_TARGET)" + "$(MAKE)" -C "$(LVT_COMPILER)" + "$(MAKE)" -C "$(LVT_RUNER)" clean: - stack clean + "$(MAKE)" -C "$(LVT_COMPILER)" clean + "$(MAKE)" -C "$(LVT_RUNER)" clean fclean: clean - stack purge - $(RM) "$(BIN_STACK)" - $(RM) "$(MARVIN_TARGET)" + "$(MAKE)" -C "$(LVT_COMPILER)" fclean + "$(MAKE)" -C "$(LVT_RUNER)" fclean re: fclean $(TARGET) tests: - stack test + "$(MAKE)" -C "$(LVT_COMPILER)" tests + "$(MAKE)" -C "$(LVT_RUNER)" tests tests-coverage: - stack test --coverage + "$(MAKE)" -C "$(LVT_COMPILER)" tests-coverage + "$(MAKE)" -C "$(LVT_RUNER)" tests-coverage tests-coverage-html-path: - @stack path --local-hpc-root + @"$(MAKE)" -C "$(LVT_COMPILER)" tests-coverage-html-path + @"$(MAKE)" -C "$(LVT_RUNER)" tests-coverage-html-path .PHONY: $(TARGET) fclean re clean all diff --git a/docs/Coverage.md b/docs/Coverage.md deleted file mode 100644 index 3bccffe..0000000 --- a/docs/Coverage.md +++ /dev/null @@ -1 +0,0 @@ -# this will be overwiten by the tests ... diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index d4fe094..8168fc0 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -4,5 +4,3 @@ This is a new amazing programming language made in Haskell. [README](README.md) -[:link: Tests](Tests.md) -[:link: Coverage](Coverage.md) diff --git a/docs/Tests.md b/docs/Tests.md deleted file mode 100644 index 3bccffe..0000000 --- a/docs/Tests.md +++ /dev/null @@ -1 +0,0 @@ -# this will be overwiten by the tests ... diff --git a/lvtc/stack.yaml.lock b/lvtc/stack.yaml.lock new file mode 100644 index 0000000..a39a124 --- /dev/null +++ b/lvtc/stack.yaml.lock @@ -0,0 +1,13 @@ +# This file was autogenerated by Stack. +# You should not edit this file by hand. +# For more information, please see the documentation at: +# https://docs.haskellstack.org/en/stable/lock_files + +packages: [] +snapshots: +- completed: + sha256: e176944bc843f740e05242fa7a66ca1f440c127e425254f7f1257f9b19add23f + size: 712153 + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/22/0.yaml + original: + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/22/0.yaml diff --git a/lvtrun/stack.yaml.lock b/lvtrun/stack.yaml.lock new file mode 100644 index 0000000..a39a124 --- /dev/null +++ b/lvtrun/stack.yaml.lock @@ -0,0 +1,13 @@ +# This file was autogenerated by Stack. +# You should not edit this file by hand. +# For more information, please see the documentation at: +# https://docs.haskellstack.org/en/stable/lock_files + +packages: [] +snapshots: +- completed: + sha256: e176944bc843f740e05242fa7a66ca1f440c127e425254f7f1257f9b19add23f + size: 712153 + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/22/0.yaml + original: + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/22/0.yaml From a9ad01b4be614730ab082809b94b3205b9be8138 Mon Sep 17 00:00:00 2001 From: guillaume abel Date: Tue, 19 Dec 2023 22:27:23 +0100 Subject: [PATCH 02/54] Enhance Readme --- README.md | 26 ++++++++++++- spec.md | 114 ++++++++++++++++++++++++++++++++++++------------------ 2 files changed, 101 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index f3650f1..5193874 100644 --- a/README.md +++ b/README.md @@ -180,15 +180,37 @@ a / b ```c struct Point { - a: Int, + x: Int, + y: Int, }; ``` +- **Structs Initialization** +``` +@Point p = {1, 2}; +``` + +- **Structs Access** +``` +p:x +``` + +- **Nested Structs** +``` +struct Rect +{ + Point size; + Point pos; +}; +@Rect r = {{1, 2}, {3, 4}}; +r:size:x +``` + - **Generic Structs** ```c struct Rect[A] { - a: A, + attribute: A, }; ``` diff --git a/spec.md b/spec.md index 15b2793..f9ee5ea 100644 --- a/spec.md +++ b/spec.md @@ -2,17 +2,12 @@ :: All value starting with `0x` are hexadecimal -|-----------------------------------------------------------------------------| -| Header | -|-----------------------------------------------------------------------------| -| Struct registration | -|-----------------------------------------------------------------------------| -| Global variable registration | -|-----------------------------------------------------------------------------| -| Function registration | -|-----------------------------------------------------------------------------| -| Start function | -|-----------------------------------------------------------------------------| +| Summary | +|------------------------------| +| Header | +| Struct registration | +| Function registration | +| Start function | ## Header @@ -24,9 +19,6 @@ ## Struct registration -|-----------------------------------------------------------------------------| -| 0x01 0xZZZZZZZZ 0x | -|-----------------------------------------------------------------------------| Struct ID for: - __Int__: `0x00000001` @@ -37,41 +29,89 @@ Struct ID for: 1. The section starts with: -``` -0x00 0x06 0x07 0x00 -``` + ``` + 0x00 0x06 0x07 0x00 + ``` + - Each struct type `ID` is an (Int32) followed by its name in multiple (Char8), until `0x00` + ``` + 0x00000006MyStruct0x000x00000007SndStruct0x00 + ``` 2. Struct are a list of other struct of built-in types -- Struct start + - Struct start -``` -0x01 -``` + ``` + 0x01 + ``` -- Struct name (Int32) is an `ID` of the struct name. + - Struct name (Int32) is an `ID` of the struct name. -All reference to this struct will be with the `ID`. + All reference to this struct will be with the `ID`. -- Number of fields (Int16) + - Number of fields (Int16) -- Each fild is a `ID` of the field type + - Each field is an `ID` of the field type -- Struct end + - Struct end -``` -0x00 -``` + ``` + 0x00 + ``` +## Function registration -``` -struct a { - int -} +Struct ID for: +- __print__: `0x00000001` +- __printErr__: `0x00000002` +- __getLine__: `0x00000003` +- __str__: `0x00000004` +- __type__: `0x00000005` +- __call__: `0x00000006` -struct b { - a -} -``` +1. The section starts with: + + ``` + 0x00 0x06 0x07 0x00 + ``` + + - Each function `ID` is an (Int32) followed by its name in multiple (Char8), until `0x00` + + ``` + 0x00000006myFunc0x000x00000007sndFunc0x00 + ``` + +2. Struct are a list of other struct of built-in types + + - Struct start + + ``` + 0x01 + ``` + + - Struct name (Int32) is an `ID` of the struct name. + + +1. The section starts with: + + ``` + 0x00 0x06 0x07 0x00 + ``` + +2. Each function is: + + - Function start + + ``` + 0x01 + ``` + + - Function name (Int32) is an `ID` of the function name. + + All reference to this function will be with the `ID`. + + - Function name (Char8) is the name of the function and finish with `0x00` + + - \ No newline at end of file From a1b08d206390ae731e253d2eabbc178e40f83fad Mon Sep 17 00:00:00 2001 From: Xavier Mitault Date: Wed, 20 Dec 2023 09:20:38 +0100 Subject: [PATCH 03/54] Move file in docs --- spec.md => docs/ByteCodeSpec.md | 0 docs/SUMMARY.md | 1 + 2 files changed, 1 insertion(+) rename spec.md => docs/ByteCodeSpec.md (100%) diff --git a/spec.md b/docs/ByteCodeSpec.md similarity index 100% rename from spec.md rename to docs/ByteCodeSpec.md diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 8168fc0..72e6716 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -4,3 +4,4 @@ This is a new amazing programming language made in Haskell. [README](README.md) +[Byte Code Spec](ByteCodeSpec.md) From 2ae306f71217a2aec57e2a82d4c0d4dd59d5a3fd Mon Sep 17 00:00:00 2001 From: Xavier Mitault Date: Wed, 20 Dec 2023 09:21:48 +0100 Subject: [PATCH 04/54] Remove compil haskell in the doc --- .github/workflows/documentation.yml | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index af808f7..017b93a 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -48,19 +48,6 @@ jobs: if: steps.filter.outputs.docs == 'true' || steps.filter.outputs.docs2 == 'true' || steps.filter.outputs.workflow == 'true' || github.ref == 'refs/heads/main' run: mdbook build - - name: Install Haskell - uses: haskell-actions/setup@v2 - with: - enable-stack: true - stack-version: 'latest' - - - name: Compil - if: steps.filter.outputs.docs == 'true' || steps.filter.outputs.docs2 == 'true' || steps.filter.outputs.workflow == 'true' || github.ref == 'refs/heads/main' - run: | - if ! stack build; then - exit 0 - fi - - name: Setup Pages if: github.ref == 'refs/heads/main' uses: actions/configure-pages@v3 From 3424b98d80f71444405c5316a213601e5a1818ff Mon Sep 17 00:00:00 2001 From: Xavier Mitault Date: Wed, 20 Dec 2023 11:53:31 +0100 Subject: [PATCH 05/54] Add current spec --- docs/ByteCodeSpec.md | 191 ++++++++++++++++++++++++++++--------------- 1 file changed, 126 insertions(+), 65 deletions(-) diff --git a/docs/ByteCodeSpec.md b/docs/ByteCodeSpec.md index f9ee5ea..067fff6 100644 --- a/docs/ByteCodeSpec.md +++ b/docs/ByteCodeSpec.md @@ -2,116 +2,177 @@ :: All value starting with `0x` are hexadecimal -| Summary | -|------------------------------| -| Header | -| Struct registration | -| Function registration | -| Start function | - ## Header 1. The file starts with: ``` -0x55 0x1E 0x53 0x0A +0x00 0x61 0x73 0x6D +0x01 0x00 0x00 0x00 ``` -## Struct registration +## Function Section +``` +0x03 +``` -Struct ID for: -- __Int__: `0x00000001` -- __String__: `0x00000002` -- __Bool__: `0x00000003` -- __Void__: `0x00000004` -- __Char__: `0x00000005` +## Export Section -1. The section starts with: +``` +0x07 +``` - ``` - 0x00 0x06 0x07 0x00 - ``` +Instructions +------------ - - Each struct type `ID` is an (Int32) followed by its name in multiple (Char8), until `0x00` +## Instructions - ``` - 0x00000006MyStruct0x000x00000007SndStruct0x00 - ``` +### Stack -2. Struct are a list of other struct of built-in types +#### local - - Struct start +##### local.get - ``` - 0x01 - ``` +``` +0x20 +``` - - Struct name (Int32) is an `ID` of the struct name. +Get a local variable by its index and add it to the stack. - All reference to this struct will be with the `ID`. +##### local.set - - Number of fields (Int16) +``` +0x21 +``` - - Each field is an `ID` of the field type +Get the top of the stack and set a local variable by its index. - - Struct end +#### global - ``` - 0x00 - ``` +##### global.get + +``` +0x23 +``` + +Get a global variable by its index and add it to the stack. + +##### global.set + +``` +0x24 +``` + +Get the top of the stack and set a global variable by its index. + +#### i32 + +##### i32.const + +``` +0x41 +``` + +Push an `Int32` to the stack. -## Function registration +### Memory -Struct ID for: -- __print__: `0x00000001` -- __printErr__: `0x00000002` -- __getLine__: `0x00000003` -- __str__: `0x00000004` -- __type__: `0x00000005` -- __call__: `0x00000006` +#### i32 -1. The section starts with: +##### i32.store + +``` +0x36 +``` + +Take the top of the stack. This will be the value stored in memory. +Take the top of the stack. This will be the index in memory. + +Store the value in memory at the index. + +##### i32.load + +``` +0x28 +``` + +Take the top of the stack. This will be the index in memory. + +Push an `Int32` to the stack with the value at address in memory. + +### Condition + +#### i32 + +##### i32.gt_s + +``` +0x4a +``` + +Compare the 2 values on the top of the stack. + +If the first value is greater than the second value, push `1` to the stack. +else, push `0` + +##### i32.eq + +``` +0x46 +``` + +Compare the 2 values on the top of the stack. + +If the first value is equal to the second value, push `1` to the stack. +else, push `0` + +#### control + +##### if...else...end + +- if ``` - 0x00 0x06 0x07 0x00 + 0x04 ``` - - Each function `ID` is an (Int32) followed by its name in multiple (Char8), until `0x00` + Enter in the first branch if the top of the stack is 1. + +- else ``` - 0x00000006myFunc0x000x00000007sndFunc0x00 + 0x05 ``` -2. Struct are a list of other struct of built-in types + Enter in the second branch if the top of the stack is 0. - - Struct start +- end ``` - 0x01 + 0x0b ``` - - Struct name (Int32) is an `ID` of the struct name. + Exit from the if/else block. +##### loop