From ae0d7ee632cc59f8104cfca565675d70eab76162 Mon Sep 17 00:00:00 2001 From: Mehmet Can <104527797+MehmetJohn@users.noreply.github.com> Date: Fri, 18 Apr 2025 13:08:26 +0300 Subject: [PATCH 01/12] shift Exp error message fix --- src/tile/AntlrToExpression.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tile/AntlrToExpression.java b/src/tile/AntlrToExpression.java index 5f84c1b..7d6741c 100644 --- a/src/tile/AntlrToExpression.java +++ b/src/tile/AntlrToExpression.java @@ -401,7 +401,7 @@ public Expression visitShiftExpression(ShiftExpressionContext ctx) { Expression left = visit(exprs.get(0)); Expression right = visit(exprs.get(1)); String operator = ctx.getChild(1).getText(); - return new ShiftExpression(left, operator, right, new TypeInfoBinopInt()); + return new ShiftExpression(left, operator, right, TypeResolver.resolveBinopShiftType(left.getType(), right.getType())); } else if (exprs.size() == 1) { return visit(exprs.get(0)); } From 3d99a2a0f458dd4ab4158282e306e5b551a8c823 Mon Sep 17 00:00:00 2001 From: Mehmet Can <104527797+MehmetJohn@users.noreply.github.com> Date: Sun, 20 Apr 2025 14:21:24 +0300 Subject: [PATCH 02/12] shift Exp error message fix --- examples/expression/shiftExpr.tile | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 examples/expression/shiftExpr.tile diff --git a/examples/expression/shiftExpr.tile b/examples/expression/shiftExpr.tile new file mode 100644 index 0000000..6014aaa --- /dev/null +++ b/examples/expression/shiftExpr.tile @@ -0,0 +1,3 @@ +x: int = 4; +y: int = 4 << 2; +z: int = 4 >> 1.2; \ No newline at end of file From af99be33d8ad3127bfa4866ae8d4a27734ed8638 Mon Sep 17 00:00:00 2001 From: Mehmet Can <104527797+MehmetJohn@users.noreply.github.com> Date: Sun, 20 Apr 2025 14:48:27 +0300 Subject: [PATCH 03/12] shift Exp error message fix --- examples/expression/shiftExpr.tile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/expression/shiftExpr.tile b/examples/expression/shiftExpr.tile index 6014aaa..e9a86ff 100644 --- a/examples/expression/shiftExpr.tile +++ b/examples/expression/shiftExpr.tile @@ -1,3 +1,5 @@ +func main(): void { x: int = 4; y: int = 4 << 2; -z: int = 4 >> 1.2; \ No newline at end of file +z: int = 4 >> 1.2; +} From f07655279b37a7e491b7c024a3505ec4aaf9df46 Mon Sep 17 00:00:00 2001 From: Mehmet Can <104527797+MehmetJohn@users.noreply.github.com> Date: Sun, 20 Apr 2025 14:49:36 +0300 Subject: [PATCH 04/12] Shift Exp test file modified --- examples/expression/shiftExpr.tile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/expression/shiftExpr.tile b/examples/expression/shiftExpr.tile index e9a86ff..da80457 100644 --- a/examples/expression/shiftExpr.tile +++ b/examples/expression/shiftExpr.tile @@ -1,5 +1,5 @@ func main(): void { -x: int = 4; -y: int = 4 << 2; -z: int = 4 >> 1.2; + x: int = 4; + y: int = 4 << 2; + z: int = 4 >> 1.2; } From 91dca20605aa4b45dfd4eab930b6950464bd9395 Mon Sep 17 00:00:00 2001 From: Mehmet Can <104527797+MehmetJohn@users.noreply.github.com> Date: Sun, 20 Apr 2025 19:33:32 +0300 Subject: [PATCH 05/12] Shift Exp test file modified --- examples/expression/shiftExpr.tile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/expression/shiftExpr.tile b/examples/expression/shiftExpr.tile index da80457..cd67e86 100644 --- a/examples/expression/shiftExpr.tile +++ b/examples/expression/shiftExpr.tile @@ -1,5 +1,5 @@ func main(): void { x: int = 4; y: int = 4 << 2; - z: int = 4 >> 1.2; + z: int = 4 >> 1; } From eccb16a6c52f05a20b5e761c3b9f40a58366bc89 Mon Sep 17 00:00:00 2001 From: Mehmet Can <104527797+MehmetJohn@users.noreply.github.com> Date: Sun, 27 Apr 2025 13:22:37 +0300 Subject: [PATCH 06/12] Shift Exp test file improved --- examples/expression/shiftExpr.tile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/expression/shiftExpr.tile b/examples/expression/shiftExpr.tile index cd67e86..3347020 100644 --- a/examples/expression/shiftExpr.tile +++ b/examples/expression/shiftExpr.tile @@ -1,5 +1,6 @@ -func main(): void { +func main(argc: int): void { x: int = 4; y: int = 4 << 2; - z: int = 4 >> 1; + z: int = 4 >> 1 + 2; + t: int = 4 << 2 * 2; } From c9a8d1a96306a3422ce130ad7b91b25649ae998b Mon Sep 17 00:00:00 2001 From: Mehmet Can <104527797+MehmetJohn@users.noreply.github.com> Date: Sun, 27 Apr 2025 18:02:02 +0300 Subject: [PATCH 07/12] fix #38 --- examples/expression/shiftExpr.tile | 66 +++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/examples/expression/shiftExpr.tile b/examples/expression/shiftExpr.tile index 3347020..c5ea627 100644 --- a/examples/expression/shiftExpr.tile +++ b/examples/expression/shiftExpr.tile @@ -1,6 +1,68 @@ + +func print(str: string): void { + + tasm { + + "load 0", + + "puts" } + +}func printchar(c: char): void { + + tasm { + + "load 0", + + "putc" } + +}func print_number(num: int): void { + + if (num == 0) { + + print("0\n"); + + return; + + } + + if (num < 0) { + + print("-"); + + num = -num; + + } + + buffer: char[] = char[10]; + + i: int = 0; + + while (num > 0) { + + buffer[i] = (num % 10) + (int)'0'; + + num = num / 10; + + i = i + 1; + + } + + for (j: int = i - 1; j >= 0; j--) { + + printchar(buffer[j]); + + } print("\n"); + +} + + func main(argc: int): void { x: int = 4; y: int = 4 << 2; - z: int = 4 >> 1 + 2; - t: int = 4 << 2 * 2; + z: int = 4.4 >> 1; + t: int = 4 << 2.2; + print_number(x); + print_number(y); + print_number(z); + print_number(t); } From a465448340ad76ae957adce58ca6001cfbdc2771 Mon Sep 17 00:00:00 2001 From: Mehmet Can <104527797+MehmetJohn@users.noreply.github.com> Date: Sun, 27 Apr 2025 18:03:43 +0300 Subject: [PATCH 08/12] fix #38 --- examples/expression/shiftExpr.tile | 66 +----------------------------- 1 file changed, 2 insertions(+), 64 deletions(-) diff --git a/examples/expression/shiftExpr.tile b/examples/expression/shiftExpr.tile index c5ea627..3347020 100644 --- a/examples/expression/shiftExpr.tile +++ b/examples/expression/shiftExpr.tile @@ -1,68 +1,6 @@ - -func print(str: string): void { - - tasm { - - "load 0", - - "puts" } - -}func printchar(c: char): void { - - tasm { - - "load 0", - - "putc" } - -}func print_number(num: int): void { - - if (num == 0) { - - print("0\n"); - - return; - - } - - if (num < 0) { - - print("-"); - - num = -num; - - } - - buffer: char[] = char[10]; - - i: int = 0; - - while (num > 0) { - - buffer[i] = (num % 10) + (int)'0'; - - num = num / 10; - - i = i + 1; - - } - - for (j: int = i - 1; j >= 0; j--) { - - printchar(buffer[j]); - - } print("\n"); - -} - - func main(argc: int): void { x: int = 4; y: int = 4 << 2; - z: int = 4.4 >> 1; - t: int = 4 << 2.2; - print_number(x); - print_number(y); - print_number(z); - print_number(t); + z: int = 4 >> 1 + 2; + t: int = 4 << 2 * 2; } From 8b72997e64f72dc3d14c30d6256d2a8d77dbbd5a Mon Sep 17 00:00:00 2001 From: Mehmet Can <104527797+MehmetJohn@users.noreply.github.com> Date: Sun, 27 Apr 2025 18:08:53 +0300 Subject: [PATCH 09/12] fix #38 --- src/tile/ast/expr/ShiftExpression.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tile/ast/expr/ShiftExpression.java b/src/tile/ast/expr/ShiftExpression.java index bd88776..6de9e3d 100644 --- a/src/tile/ast/expr/ShiftExpression.java +++ b/src/tile/ast/expr/ShiftExpression.java @@ -26,9 +26,9 @@ public String generateTasm(String generatedCode) { generatedCode = right.generateTasm(generatedCode); if (operator.equals("<<")) { - generatedCode += " shl\n"; + generatedCode += " lshft\n"; } else if (operator.equals(">>")) { - generatedCode += " shr\n"; + generatedCode += " rshft\n"; } else { System.err.println("Unknown shift operator: " + operator); } From ac21d2ea1659cf9ae9ff7231fd0cfba28233bfcc Mon Sep 17 00:00:00 2001 From: Mehmet Can <104527797+MehmetJohn@users.noreply.github.com> Date: Sat, 3 May 2025 18:28:07 +0300 Subject: [PATCH 10/12] Tic-tac-toe example --- examples/tic-tac-toe/tic-tac-toe.tile | 212 ++++++++++++++++++++++++++ 1 file changed, 212 insertions(+) create mode 100644 examples/tic-tac-toe/tic-tac-toe.tile diff --git a/examples/tic-tac-toe/tic-tac-toe.tile b/examples/tic-tac-toe/tic-tac-toe.tile new file mode 100644 index 0000000..ad41e80 --- /dev/null +++ b/examples/tic-tac-toe/tic-tac-toe.tile @@ -0,0 +1,212 @@ +/* + 03.05.2025 + Mehmet Can Özkuzukıran + make app ARGS=".\examples\tic-tac-toe\tic-tac-toe.tile -o .\examples\tic-tac-toe\tic-tac-toe.bin -gen-tasm -l raylib.dll" + tvm .\examples\tic-tac-toe\tic-tac-toe.bin +*/ + +native func InitWindow(width: ci32, height: ci32, title: cptr): cvoid; +native func WindowShouldClose(): ci8; +native func CloseWindow(): cvoid; +native func BeginDrawing(): cvoid; +native func EndDrawing(): cvoid; +native func ClearBackground(color: cu32): cvoid; +native func SetTargetFPS(fps: ci32): cvoid; +native func DrawRectangle(posX: ci32, posY: ci32, width: ci32, height: ci32, color: cu32): cvoid; +native func DrawLine(ci32, ci32, ci32, ci32, cu32): cvoid; +native func IsKeyDown(key: ci16): ci8; +native func DrawText(text: cptr, posX: ci32, posY: ci32, fontSize: ci32, color: cu32): cvoid; + + +func drawCharText(c: char, x: int, y: int): void { + buffer: char[] = char[2]; + buffer[0] = c; + buffer[1] = 0; // Null-terminate for C-strings + DrawText(buffer, x, y, 30, 0x000000FF); +} + +func drawGrid(grid: char[], square_colors: int[], selected: int, current_player: char): void { + cellSize: int = 80; + gap: int = 10; + offsetX: int = 30; + offsetY: int = 30; + + for (i: int = 0; i < 9; i++) { + x: int = offsetX + (i % 3) * (cellSize + gap); + y: int = offsetY + (i / 3) * (cellSize + gap); + + DrawRectangle(x, y, cellSize, cellSize, square_colors[i]); + + // Draw selection border + if (i == selected) { + DrawRectangle(x, y, cellSize, cellSize, 0xCCCC00FF); // Yellow border for selected + } + + // Draw X or O + // if (grid[i] == 'X' || grid[i] == 'O') { + // drawCharText(grid[i], x + cellSize / 3, y + cellSize / 4); + // } + } +} + + +func print(str: string): void { + tasm { + "load 0", + "puts" + } +} +func printChar(c: char): void { + tasm { + "load 0", + "putc" + } +} + +func printGrid(grid: char[], selected: int): void { + for (i: int = 0; i < 9; i++) { + if (i == selected) { + print("["); + } else { + print(" "); + } + + printChar(grid[i]); + + if (i == selected) { + print("]"); + } else { + print(" "); + } + + if (i % 3 != 2) { + print("|"); + } else if (i != 8) { + print("\n-+-+-\n"); + } else { + print("\n"); + } + } +} + + + +func checkWinnerByColor(square_colors: int[], color: int): bool { + // Row 1 + if (square_colors[0] == color && square_colors[1] == color && square_colors[2] == color) { return true; } + // Row 2 + if (square_colors[3] == color && square_colors[4] == color && square_colors[5] == color) { return true; } + // Row 3 + if (square_colors[6] == color && square_colors[7] == color && square_colors[8] == color) { return true; } + // Column 1 + if (square_colors[0] == color && square_colors[3] == color && square_colors[6] == color) { return true; } + // Column 2 + if (square_colors[1] == color && square_colors[4] == color && square_colors[7] == color) { return true; } + // Column 3 + if (square_colors[2] == color && square_colors[5] == color && square_colors[8] == color) { return true; } + // Cross 1 + if (square_colors[0] == color && square_colors[4] == color && square_colors[8] == color) { return true; } + // Cross 2 + if (square_colors[2] == color && square_colors[4] == color && square_colors[6] == color) { return true; } + + return false; +} + +func main(argc: int): void { + InitWindow(400, 400, "Tic Tac Toe"); + SetTargetFPS(10); + + EMPTY: char = ' '; + grid: char[] = char[9]; + square_colors: int[] = int[9]; + for (i: int = 0; i < 9; i++) { + square_colors[i] = 0xFFFFFFFF; // White by default + } + current_player: char = 'X'; + winner: char = ' '; + moves: int = 0; + selected: int = 0; + showError: bool = false; + keyProcessed: bool = false; + + for (i: int = 0; i < 9; i++) { + grid[i] = EMPTY; + } + + while ((bool)WindowShouldClose() == false && winner == ' ' && moves < 9) { + showError = false; + + if (!(bool)IsKeyDown('E')) { + if ((bool)IsKeyDown('W') && selected >= 3) { + selected = selected - 3; + } else if ((bool)IsKeyDown('S') && selected <= 5) { + selected = selected + 3; + } else if ((bool)IsKeyDown('A') && selected % 3 != 0) { + selected = selected - 1; + } else if ((bool)IsKeyDown('D') && selected % 3 != 2) { + selected = selected + 1; + } + } + + if ((bool)IsKeyDown('E')) { + if (keyProcessed == false ) { + keyProcessed = true; + if (square_colors[selected] == 0xFFFFFFFF) { + grid[selected] = current_player; + moves = moves + 1; + if (current_player == 'X') { + square_colors[selected] = 0x00FF00FF; + } else { + square_colors[selected] = 0xFF0000FF; + } + if (checkWinnerByColor(square_colors, 0x00FF00FF)) { + winner = 'X'; + } else if (checkWinnerByColor(square_colors, 0xFF0000FF)) { + winner = 'O'; + }else if (moves == 9) { + winner = 'D'; + } + if (winner == ' ') { + if (current_player == 'X') { + current_player = 'O'; + } else { + current_player = 'X'; + } + } + } else { + showError = true; + } + } + } else { + keyProcessed = false; + } + + BeginDrawing(); + ClearBackground(0x808080FF); + drawGrid(grid, square_colors, selected, current_player); + if (showError) { + DrawText("Invalid Move!", 100, 370, 20, 0xFF0000FF); + } + EndDrawing(); + } + + while ((bool)WindowShouldClose() == false) { + BeginDrawing(); + ClearBackground(0x808080FF); + drawGrid(grid, square_colors, selected, current_player); + + if (winner == 'X') { + DrawText("Winner: ", 100, 370, 20, 0x00FF00FF); + DrawText("Green", 220, 370, 20, 0x00FF00FF); + } + else if (winner == 'O') { + DrawText("Winner: ", 100, 370, 20, 0xFF0000FF); + DrawText("Red", 220, 370, 20, 0xFF0000FF); + } + else if (winner == 'D') { + DrawText("Draw!", 100, 370, 20, 0x00FF00FF); + } + EndDrawing(); + } + CloseWindow(); +} From b5132953f53887733987215270c7f7d763e9067c Mon Sep 17 00:00:00 2001 From: Mehmet Can <104527797+MehmetJohn@users.noreply.github.com> Date: Sat, 3 May 2025 18:28:53 +0300 Subject: [PATCH 11/12] Tic-tac-toe example --- examples/tic-tac-toe/tic-tac-toe.tile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/tic-tac-toe/tic-tac-toe.tile b/examples/tic-tac-toe/tic-tac-toe.tile index ad41e80..c3a46c9 100644 --- a/examples/tic-tac-toe/tic-tac-toe.tile +++ b/examples/tic-tac-toe/tic-tac-toe.tile @@ -39,7 +39,7 @@ func drawGrid(grid: char[], square_colors: int[], selected: int, current_player: // Draw selection border if (i == selected) { - DrawRectangle(x, y, cellSize, cellSize, 0xCCCC00FF); // Yellow border for selected + DrawRectangle(x, y, cellSize, cellSize, 0xCCCC00FF); } // Draw X or O From fbf387c461b681b65454200ceba9be6e6faa3f45 Mon Sep 17 00:00:00 2001 From: Mehmet Can <104527797+MehmetJohn@users.noreply.github.com> Date: Sat, 3 May 2025 18:52:21 +0300 Subject: [PATCH 12/12] Tic-tac-toe example --- examples/tic-tac-toe/tic-tac-toe.tile | 39 --------------------------- 1 file changed, 39 deletions(-) diff --git a/examples/tic-tac-toe/tic-tac-toe.tile b/examples/tic-tac-toe/tic-tac-toe.tile index c3a46c9..12226dd 100644 --- a/examples/tic-tac-toe/tic-tac-toe.tile +++ b/examples/tic-tac-toe/tic-tac-toe.tile @@ -18,13 +18,6 @@ native func IsKeyDown(key: ci16): ci8; native func DrawText(text: cptr, posX: ci32, posY: ci32, fontSize: ci32, color: cu32): cvoid; -func drawCharText(c: char, x: int, y: int): void { - buffer: char[] = char[2]; - buffer[0] = c; - buffer[1] = 0; // Null-terminate for C-strings - DrawText(buffer, x, y, 30, 0x000000FF); -} - func drawGrid(grid: char[], square_colors: int[], selected: int, current_player: char): void { cellSize: int = 80; gap: int = 10; @@ -41,11 +34,6 @@ func drawGrid(grid: char[], square_colors: int[], selected: int, current_player: if (i == selected) { DrawRectangle(x, y, cellSize, cellSize, 0xCCCC00FF); } - - // Draw X or O - // if (grid[i] == 'X' || grid[i] == 'O') { - // drawCharText(grid[i], x + cellSize / 3, y + cellSize / 4); - // } } } @@ -63,33 +51,6 @@ func printChar(c: char): void { } } -func printGrid(grid: char[], selected: int): void { - for (i: int = 0; i < 9; i++) { - if (i == selected) { - print("["); - } else { - print(" "); - } - - printChar(grid[i]); - - if (i == selected) { - print("]"); - } else { - print(" "); - } - - if (i % 3 != 2) { - print("|"); - } else if (i != 8) { - print("\n-+-+-\n"); - } else { - print("\n"); - } - } -} - - func checkWinnerByColor(square_colors: int[], color: int): bool { // Row 1