aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--code/lib/io.felan6
-rw-r--r--code/main.felan69
-rw-r--r--code/main2.felan87
-rw-r--r--src/compiler/ast-tree.c17
4 files changed, 107 insertions, 72 deletions
diff --git a/code/lib/io.felan b/code/lib/io.felan
index 97be3b1..1fe7cf9 100644
--- a/code/lib/io.felan
+++ b/code/lib/io.felan
@@ -70,5 +70,11 @@ _print_unsigned :: (comptime t:type, value:t) -> void {
value != @cast(0,t);
} {}
+ while i < NUMBERS_SIZE - 1 {
+ @putc(numbers[i]);
+ i += 1;
+ }
+ return;
+
puts(&numbers[i]);
};
diff --git a/code/main.felan b/code/main.felan
index cdaeee8..90b1d08 100644
--- a/code/main.felan
+++ b/code/main.felan
@@ -1,73 +1,6 @@
@import("basic.felan");
-/*
-libc :: @c_library("/lib/libc.so.6");
-puts :: @c_function(libc,"puts",(*u8)->i32);
-sleep :: @c_function(libc,"sleep",(i32)->i32);
-*/
-
-raylib :: @c_library("/lib/libraylib.so.5.5.0");
-InitWindow :: @c_function(raylib,"InitWindow",(i32,i32,*u8)->void);
-WindowShouldClose :: @c_function(raylib,"WindowShouldClose",()->bool);
-BeginDrawing :: @c_function(raylib,"BeginDrawing",()->void);
-EndDrawing :: @c_function(raylib,"EndDrawing",()->void);
-CloseWindow :: @c_function(raylib,"CloseWindow",()->void);
-ClearBackground :: @c_function(raylib,"ClearBackground",(Color)->void);
-DrawText :: @c_function(raylib,"DrawText",(*u8,i32,i32,i32,Color)->void);
-// void DrawRectangle(int posX, int posY, int width, int height, Color color);
-DrawRectangle :: @c_function(raylib,"DrawRectangle",(posX:i32,posY:i32,width:i32,height:i32,color:Color)->void);
-
-Color :: struct {
- r:u8;
- g:u8;
- b:u8;
- a:u8;
-};
-
main :: ()->void{
- print("hello");
- return;
- b := "raylib [core] example - basic window\0";
- c := "Congrats! You created your first window!\0";
- str := &b[0];
- str2 := &c[0];
- screenWidth :i32: 800;
- screenHeight :i32: 450;
- a : u8 : 255;
- b : u8 : 0;
- WHITE :: color(a,a,a,a);
- BLACK :: color(@cast(0xff0000ff,u32));
- InitWindow(screenWidth,screenHeight,str);
- rect_posx :i32= 0;
- rect_posy :i32= 0;
- while !WindowShouldClose() {
- BeginDrawing();
- ClearBackground(WHITE);
- DrawRectangle(rect_posx,rect_posy,@cast(200,i32),@cast(40,i32),color(@cast(0x00ffff,u32)));
- DrawText(str2,@cast(190,i32),@cast(200,i32),@cast(20,i32),BLACK);
- EndDrawing();
- /*
- rect_posx += @cast(1,i32);
- rect_posy += @cast(1,i32);
- */
- }
- CloseWindow();
+ print(1234);
};
-color :: (a:u8,r:u8,g:u8,b:u8)->Color{
- c : Color = undefined;
- c.r = r;
- c.g = g;
- c.b = b;
- c.a = a;
- return c;
-};
-
-color :: (value:u32)->Color{
- c : Color = undefined;
- c.r = @cast((value&@cast(0xff000000,u32))>>@cast(6*4,u32),u8);
- c.g = @cast((value&@cast(0x00ff0000,u32))>>@cast(4*4,u32),u8);
- c.b = @cast((value&@cast(0x0000ff00,u32))>>@cast(2*4,u32),u8);
- c.a = @cast((value&@cast(0x000000ff,u32))>>@cast(0*4,u32),u8);
- return c;
-};
diff --git a/code/main2.felan b/code/main2.felan
new file mode 100644
index 0000000..ffa3a5b
--- /dev/null
+++ b/code/main2.felan
@@ -0,0 +1,87 @@
+@import("basic.felan");
+
+raylib :: @c_library("/lib/libraylib.so.5.5.0");
+InitWindow :: @c_function(raylib,"InitWindow",(i32,i32,*u8)->void);
+WindowShouldClose :: @c_function(raylib,"WindowShouldClose",()->bool);
+BeginDrawing :: @c_function(raylib,"BeginDrawing",()->void);
+EndDrawing :: @c_function(raylib,"EndDrawing",()->void);
+CloseWindow :: @c_function(raylib,"CloseWindow",()->void);
+ClearBackground :: @c_function(raylib,"ClearBackground",(Color)->void);
+DrawText :: @c_function(raylib,"DrawText",(*u8,i32,i32,i32,Color)->void);
+// void DrawRectangle(int posX, int posY, int width, int height, Color color);
+DrawRectangle :: @c_function(raylib,"DrawRectangle",(posX:i32,posY:i32,width:i32,height:i32,color:Color)->void);
+
+Color :: struct {
+ r:u8;
+ g:u8;
+ b:u8;
+ a:u8;
+};
+
+main :: ()->void{
+ b := "raylib [core] example - basic window\0";
+ c := "Congrats! You created your first window!\0";
+ str := &b[0];
+ str2 := &c[0];
+ screenWidth :i32: 800;
+ screenHeight :i32: 450;
+ a : u8 : 255;
+ b : u8 : 0;
+ WHITE :: color(a,a,a,a);
+ BLACK :: color(@cast(0xff0000ff,u32));
+ InitWindow(screenWidth,screenHeight,str);
+ rect_posx :i32= 0;
+ rect_posy :i32= 0;
+ dx : i32 = 1;
+ dy : i32 = 1;
+ while !WindowShouldClose() {
+ BeginDrawing();
+ ClearBackground(WHITE);
+ DrawRectangle(rect_posx,rect_posy,@cast(200,i32),@cast(40,i32),color(@cast(0x00ffff,u32)));
+ DrawText(str2,@cast(190,i32),@cast(200,i32),@cast(20,i32),BLACK);
+ EndDrawing();
+ rect_posx += dx;
+ rect_posy += dy;
+ /*
+ print(rect_posx);
+ print_char(' ');
+ print(rect_posy);
+ print_char('\n');
+ */
+ if rect_posx >= screenWidth {
+ print("hello");
+ print(dx);
+ print("\n");
+ dx = @cast(-1,i32);
+ }else if rect_posx < @cast(0,i32) {
+ dx = @cast(1,i32);
+ }
+ if rect_posy >= screenHeight {
+ print("hi");
+ print(dy);
+ print("\n");
+ dy = @cast(-@cast(1,i32),i32);
+ }else if rect_posy < @cast(0,i32) {
+ dy = @cast(1,i32);
+ }
+ }
+ CloseWindow();
+};
+
+color :: (a:u8,r:u8,g:u8,b:u8)->Color{
+ c : Color = undefined;
+ c.r = r;
+ c.g = g;
+ c.b = b;
+ c.a = a;
+ return c;
+};
+
+color :: (value:u32)->Color{
+ c : Color = undefined;
+ c.r = @cast((value&@cast(0xff000000,u32))>>@cast(6*4,u32),u8);
+ c.g = @cast((value&@cast(0x00ff0000,u32))>>@cast(4*4,u32),u8);
+ c.b = @cast((value&@cast(0x0000ff00,u32))>>@cast(2*4,u32),u8);
+ c.a = @cast((value&@cast(0x000000ff,u32))>>@cast(0*4,u32),u8);
+ return c;
+}
diff --git a/src/compiler/ast-tree.c b/src/compiler/ast-tree.c
index fc9217e..d89f816 100644
--- a/src/compiler/ast-tree.c
+++ b/src/compiler/ast-tree.c
@@ -3727,7 +3727,7 @@ bool isConst(AstTree *tree) {
return false;
}
}
- return isConst(metadata->operand);
+ return isConst(metadata->operand) && isConst(metadata->operand);
}
case AST_TREE_TOKEN_NONE:
}
@@ -7296,11 +7296,17 @@ bool setTypesTypeArray(AstTree *tree, AstTreeSetTypesHelper helper) {
AstTree *param = metadata->parameters.data[i];
if (!setAllTypes(param, newHelper, NULL, NULL)) {
return false;
- } else if (!isIntType(param->type)) {
+ } else if (!typeIsEqual(param->type, &AST_TREE_I64_TYPE) &&
+ !typeIsEqual(param->type, &AST_TREE_U64_TYPE)) {
printError(param->str_begin, param->str_end,
"Should only be int (for now)");
return false;
+ } else if (!isConst(param)) {
+ printError(param->str_begin, param->str_end,
+ "Should only be const (for now)");
+ return false;
}
+ metadata->parameters.data[i] = getValue(param, false);
}
} else {
printError(tree->str_begin, tree->str_end,
@@ -7822,8 +7828,11 @@ size_t getSizeOfType(AstTree *type) {
case AST_TREE_TOKEN_TYPE_ARRAY: {
AstTreeBracket *metadata = type->metadata;
if (metadata->parameters.size == 1 &&
- isIntType(metadata->parameters.data[0]->type)) {
- return *(AstTreeInt *)metadata->parameters.data[0]->metadata;
+ (typeIsEqual(metadata->parameters.data[0]->type, &AST_TREE_I64_TYPE) ||
+ typeIsEqual(metadata->parameters.data[0]->type, &AST_TREE_U64_TYPE))) {
+ const size_t itemSize = getSizeOfType(metadata->operand);
+ const size_t size = *(u64 *)metadata->parameters.data[0]->metadata;
+ return size * itemSize;
} else {
UNREACHABLE;
}