diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..b1d94ab --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 tile-lang + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/examples/Makefile b/examples/Makefile index 25f9024..c59fb50 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -4,7 +4,7 @@ # Explicitly list subdirs since wildcard */ is failing EXAMPLE_DIRS := snake/ string/ forloop/ -TILE_FILES := $(wildcard snake/*.tile string/*.tile forloop/*.tile) +TILE_FILES := $(wildcard snake/*.tile pong/*.tile forloop/*.tile tic-tac-toe/*.tile) TASM_FILES := $(TILE_FILES:.tile=.tasm) BIN_FILES := $(TASM_FILES:.tasm=.bin) @@ -14,7 +14,7 @@ $(info TILE_FILES: $(TILE_FILES)) $(info TASM_FILES: $(TASM_FILES)) $(info BIN_FILES: $(BIN_FILES)) $(info WILDCARD DIRS: $(wildcard */)) -$(info WILDCARD TILES: $(wildcard snake/*.tile string/*.tile forloop/*.tile)) +$(info WILDCARD TILES: $(wildcard snake/*.tile pong/*.tile forloop/*.tile tic-tac-toe/*.tile)) all: $(BIN_FILES) @echo "Done building: $(BIN_FILES)" diff --git a/examples/snake/snake.tile b/examples/snake/snake.tile index 5e8069f..2a1a454 100644 --- a/examples/snake/snake.tile +++ b/examples/snake/snake.tile @@ -1,23 +1,9 @@ /* - 01.14.2025 + 04.26.2025 Muhammed Yasinhan Yaşar */ -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 GetFrameTime(): cf32; -native func DrawRectangle(posX: ci32, posY: ci32, width: ci32, height: ci32, color: cu32): cvoid; -native func DrawCircle(posX: ci32, posY: ci32, radius: cf32, color: cu32): cvoid; -native func DrawLine(ci32, ci32, ci32, ci32, cu32): cvoid; -native func IsKeyDown(key: ci16): ci8; - -native func SetRandomSeed(seed: cu32): cvoid; -native func GetRandomValue(min: ci32, max: ci32): ci32; +import "../tileraylib.tile"; screenWidth: int = 400; screenHeight: int = screenWidth; diff --git a/examples/tileraylib.tile b/examples/tileraylib.tile new file mode 100644 index 0000000..8a34b8d --- /dev/null +++ b/examples/tileraylib.tile @@ -0,0 +1,20 @@ +/* + 04.26.2025 + Muhammed Yasinhan Yaşar +*/ + +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 GetFrameTime(): cf32; +native func DrawRectangle(posX: ci32, posY: ci32, width: ci32, height: ci32, color: cu32): cvoid; +native func DrawCircle(posX: ci32, posY: ci32, radius: cf32, color: cu32): cvoid; +native func DrawLine(ci32, ci32, ci32, ci32, cu32): cvoid; +native func IsKeyDown(key: ci16): ci8; + +native func SetRandomSeed(seed: cu32): cvoid; +native func GetRandomValue(min: ci32, max: ci32): ci32; diff --git a/src/tile/Program.java b/src/tile/Program.java index dbc68e5..ebe933d 100644 --- a/src/tile/Program.java +++ b/src/tile/Program.java @@ -27,6 +27,7 @@ public class Program extends Generator { public static List blockStack = new ArrayList<>(); private static int tasmGlobalVarIdx = 0; public static Map globalVariableSymbols = new HashMap<>(); + public static List globalVariables = new ArrayList(); public static Deque parentStack = new ArrayDeque<>(); public static List programPaths = new ArrayList<>(); private static boolean _err; @@ -65,8 +66,6 @@ public void addStatement(Statement stmt) { } private String generateProgram(String generatedCode) { - List globalVariables = new ArrayList(); - if (!isImportedFile) { generatedCode += "; program begins\n"; generatedCode += "jmp __start\n"; @@ -85,17 +84,15 @@ private String generateProgram(String generatedCode) { } if(!isImportedFile) { - generatedCode += "__start:\n"; - } - generatedCode += "; global variables\n"; - for (int i = 0; i < globalVariables.size(); i++) { - Statement stmt = globalVariables.get(i); - if (stmt != null) { - generatedCode = stmt.generateTasm(generatedCode); + generatedCode += "__start:\n"; + generatedCode += "; global variables\n"; + for (int i = 0; i < globalVariables.size(); i++) { + Statement stmt = globalVariables.get(i); + if (stmt != null) { + generatedCode = stmt.generateTasm(generatedCode); + } } - } - - if (!isImportedFile) { + generatedCode += "\n\n"; generatedCode += "push 0 ; argc\n"; // for simulating argc and argv for now // generatedCode += "push 0 ; argv\n"; diff --git a/src/tile/ast/expr/ArrayIndexAccessor.java b/src/tile/ast/expr/ArrayIndexAccessor.java index d5040a2..319c99d 100644 --- a/src/tile/ast/expr/ArrayIndexAccessor.java +++ b/src/tile/ast/expr/ArrayIndexAccessor.java @@ -32,16 +32,12 @@ private String genLoadCode(String generatedCode) { public String generateTasm(String generatedCode) { generatedCode = genLoadCode(generatedCode); generatedCode += " deref ; dereferance\n"; - generatedCode += " derefb " + typeInfo.element_size + " ; dereferance\n"; generatedCode = indicies.get(0).generateTasm(generatedCode); generatedCode += " push " + typeInfo.element_size + "\n"; generatedCode += " mult\n"; generatedCode += " add\n"; + generatedCode += " derefb " + typeInfo.element_size + " ; dereferance\n"; return generatedCode; - - - // generatedCode += " derefb " + typeInfo.element_size + " ; dereferance\n"; - // generatedCode += " deref ; dereferance\n"; } @Override