Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
35 changes: 35 additions & 0 deletions software/luna/examples/file_example.luna
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const puts = fn@extern["puts"](fmt: *i8):i32;
const printf = fn@extern["printf"]@variadic(fmt: *i8): i32;
const malloc = fn@extern["malloc"](size:i32):*i8;

const file_open = fn@extern["fopen"](path: *i8, mode: *i8): *i8;
const file_seek = fn@extern["fseek"](file: *i8, loc: i32, v: i32);
const file_tell = fn@extern["ftell"](file: *i8, loc: i32, v: i32): i32;
const file_read = fn@extern["fread"](buffer: *i8, size: i32, count: i32, file: *i8): i32;
const file_close = fn@extern["fclose"](file: *i8);

const SEEK_END: i32 = 2;
const SEEK_SET: i32 = 0;

const main = fn() {
const file = file_open("Makefile", "rb");

printf("File: %d\n", file);

file_seek(file, 0, SEEK_END);
const size = file_tell(file);
file_seek(file, 0, SEEK_SET);

printf("size: %d\n", size);

const buffer = malloc(size);

const read = file_read(buffer, 1, size, file);

printf("read %d bytes\n", read);

printf("File: %s\n", buffer);

file_close(file);
return;
};
58 changes: 58 additions & 0 deletions software/luna/examples/raylib.luna
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const puts = fn@extern["puts"](str:*i8);
const printf = fn@extern["printf"]@variadic(fmt: *i8);

const init_window = fn@extern["InitWindow"](w: i32, h: i32, title: *i8);
const set_target_fps = fn@extern["SetTargetFPS"](fps: i32);
const window_should_close = fn@extern["WindowShouldClose"](): i8;
const begin_drawing = fn@extern["BeginDrawing"]();

const end_drawing = fn@extern["EndDrawing"]();

const clear_background = fn@extern["ClearBackground"](color: i32);
const draw_text = fn@extern["DrawText"](title: *i8, x: i32, y: i32, fs: i32, color: i32);
const draw_rect = fn@extern["DrawRectangle"](posX: i32, posY: i32, width: i32, height: i32, color: i32);
const close_window = fn@extern["CloseWindow"]();


const Color = struct {
r: i8,
g: i8,
b: i8,
a: i8
};

const main = fn() {
init_window(800, 450, "Hello Raylib from Luna");

set_target_fps(60);

let v: i8 = 1;

const white_color = .Color { r: 255, g: 255, b: 255, a: 255 };
const red_color = .Color { r: 0, g: 255, b: 0, a: 255 };

const white_color_int = @cast(i32,white_color);
const red_color_int = @cast(i32,red_color);

let x: i32 = 100;

while window_should_close() < v {
begin_drawing();

clear_background(white_color_int);
draw_text("Hello world from luna.", 190, 200, 20, red_color_int);
draw_rect(x, 50, 100, 200, red_color_int);

x = 1 + x;

if x > 500 {
x = 50;
};

end_drawing();
};

close_window();

return;
};
Binary file added software/luna/hello
Binary file not shown.
21 changes: 21 additions & 0 deletions software/luna/hello.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "raylib.h"

int main(void) {
// Initialize the window
InitWindow(800, 450, "Hello Raylib");

// Set target FPS for smoother visuals
SetTargetFPS(60);

// Main loop
while (!WindowShouldClose()) {
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText("Hello, world from Raylib!", 190, 200, 20, LIGHTGRAY);
EndDrawing();
}

// Clean up
CloseWindow();
return 0;
}
93 changes: 93 additions & 0 deletions software/luna/hello2
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
; ModuleID = 'hello.c'
source_filename = "hello.c"
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-n32:64-S128-Fn32"
target triple = "arm64-apple-macosx26.0.0"

%struct.Color = type { i8, i8, i8, i8 }

@.str = private unnamed_addr constant [13 x i8] c"Hello Raylib\00", align 1
@.str.1 = private unnamed_addr constant [26 x i8] c"Hello, world from Raylib!\00", align 1

; Function Attrs: noinline nounwind optnone ssp uwtable(sync)
define i32 @main() #0 {
%1 = alloca i32, align 4
%2 = alloca %struct.Color, align 1
%3 = alloca i64, align 8
%4 = alloca %struct.Color, align 1
%5 = alloca i64, align 8
store i32 0, ptr %1, align 4
call void @InitWindow(i32 noundef 800, i32 noundef 450, ptr noundef @.str)
call void @SetTargetFPS(i32 noundef 60)
br label %6

6: ; preds = %9, %0
%7 = call zeroext i1 @WindowShouldClose()
%8 = xor i1 %7, true
br i1 %8, label %9, label %20

9: ; preds = %6
call void @BeginDrawing()
%10 = getelementptr inbounds nuw %struct.Color, ptr %2, i32 0, i32 0
store i8 -11, ptr %10, align 1
%11 = getelementptr inbounds nuw %struct.Color, ptr %2, i32 0, i32 1
store i8 -11, ptr %11, align 1
%12 = getelementptr inbounds nuw %struct.Color, ptr %2, i32 0, i32 2
store i8 -11, ptr %12, align 1
%13 = getelementptr inbounds nuw %struct.Color, ptr %2, i32 0, i32 3
store i8 -1, ptr %13, align 1
call void @llvm.memcpy.p0.p0.i64(ptr align 8 %3, ptr align 1 %2, i64 4, i1 false)
%14 = load i64, ptr %3, align 8
call void @ClearBackground(i64 %14)
%15 = getelementptr inbounds nuw %struct.Color, ptr %4, i32 0, i32 0
store i8 -56, ptr %15, align 1
%16 = getelementptr inbounds nuw %struct.Color, ptr %4, i32 0, i32 1
store i8 -56, ptr %16, align 1
%17 = getelementptr inbounds nuw %struct.Color, ptr %4, i32 0, i32 2
store i8 -56, ptr %17, align 1
%18 = getelementptr inbounds nuw %struct.Color, ptr %4, i32 0, i32 3
store i8 -1, ptr %18, align 1
call void @llvm.memcpy.p0.p0.i64(ptr align 8 %5, ptr align 1 %4, i64 4, i1 false)
%19 = load i64, ptr %5, align 8
call void @DrawText(ptr noundef @.str.1, i32 noundef 190, i32 noundef 200, i32 noundef 20, i64 %19)
call void @EndDrawing()
br label %6, !llvm.loop !6

20: ; preds = %6
call void @CloseWindow()
ret i32 0
}

declare void @InitWindow(i32 noundef, i32 noundef, ptr noundef) #1

declare void @SetTargetFPS(i32 noundef) #1

declare zeroext i1 @WindowShouldClose() #1

declare void @BeginDrawing() #1

declare void @ClearBackground(i64) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias writeonly captures(none), ptr noalias readonly captures(none), i64, i1 immarg) #2

declare void @DrawText(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i64) #1

declare void @EndDrawing() #1

declare void @CloseWindow() #1

attributes #0 = { noinline nounwind optnone ssp uwtable(sync) "frame-pointer"="non-leaf" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="apple-m1" "target-features"="+aes,+altnzcv,+ccdp,+ccidx,+ccpp,+complxnum,+crc,+dit,+dotprod,+flagm,+fp-armv8,+fp16fml,+fptoint,+fullfp16,+jsconv,+lse,+neon,+pauth,+perfmon,+predres,+ras,+rcpc,+rdm,+sb,+sha2,+sha3,+specrestrict,+ssbs,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8a" }
attributes #1 = { "frame-pointer"="non-leaf" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="apple-m1" "target-features"="+aes,+altnzcv,+ccdp,+ccidx,+ccpp,+complxnum,+crc,+dit,+dotprod,+flagm,+fp-armv8,+fp16fml,+fptoint,+fullfp16,+jsconv,+lse,+neon,+pauth,+perfmon,+predres,+ras,+rcpc,+rdm,+sb,+sha2,+sha3,+specrestrict,+ssbs,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8a" }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }

!llvm.module.flags = !{!0, !1, !2, !3, !4}
!llvm.ident = !{!5}

!0 = !{i32 2, !"SDK Version", [2 x i32] [i32 26, i32 0]}
!1 = !{i32 1, !"wchar_size", i32 4}
!2 = !{i32 8, !"PIC Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 1}
!4 = !{i32 7, !"frame-pointer", i32 1}
!5 = !{!"Homebrew clang version 21.1.3"}
!6 = distinct !{!6, !7}
!7 = !{!"llvm.loop.mustprogress"}
93 changes: 93 additions & 0 deletions software/luna/hello2.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
; ModuleID = 'hello.c'
source_filename = "hello.c"
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-n32:64-S128-Fn32"
target triple = "arm64-apple-macosx26.0.0"

%struct.Color = type { i8, i8, i8, i8 }

@.str = private unnamed_addr constant [13 x i8] c"Hello Raylib\00", align 1
@.str.1 = private unnamed_addr constant [26 x i8] c"Hello, world from Raylib!\00", align 1

; Function Attrs: noinline nounwind optnone ssp uwtable(sync)
define i32 @main() #0 {
%1 = alloca i32, align 4
%2 = alloca %struct.Color, align 1
%3 = alloca i64, align 8
%4 = alloca %struct.Color, align 1
%5 = alloca i64, align 8
store i32 0, ptr %1, align 4
call void @InitWindow(i32 noundef 800, i32 noundef 450, ptr noundef @.str)
call void @SetTargetFPS(i32 noundef 60)
br label %6

6: ; preds = %9, %0
%7 = call zeroext i1 @WindowShouldClose()
%8 = xor i1 %7, true
br i1 %8, label %9, label %20

9: ; preds = %6
call void @BeginDrawing()
%10 = getelementptr inbounds nuw %struct.Color, ptr %2, i32 0, i32 0
store i8 -11, ptr %10, align 1
%11 = getelementptr inbounds nuw %struct.Color, ptr %2, i32 0, i32 1
store i8 -11, ptr %11, align 1
%12 = getelementptr inbounds nuw %struct.Color, ptr %2, i32 0, i32 2
store i8 -11, ptr %12, align 1
%13 = getelementptr inbounds nuw %struct.Color, ptr %2, i32 0, i32 3
store i8 -1, ptr %13, align 1
call void @llvm.memcpy.p0.p0.i64(ptr align 8 %3, ptr align 1 %2, i64 4, i1 false)
%14 = load i64, ptr %3, align 8
call void @ClearBackground(i64 %14)
%15 = getelementptr inbounds nuw %struct.Color, ptr %4, i32 0, i32 0
store i8 -56, ptr %15, align 1
%16 = getelementptr inbounds nuw %struct.Color, ptr %4, i32 0, i32 1
store i8 -56, ptr %16, align 1
%17 = getelementptr inbounds nuw %struct.Color, ptr %4, i32 0, i32 2
store i8 -56, ptr %17, align 1
%18 = getelementptr inbounds nuw %struct.Color, ptr %4, i32 0, i32 3
store i8 -1, ptr %18, align 1
call void @llvm.memcpy.p0.p0.i64(ptr align 8 %5, ptr align 1 %4, i64 4, i1 false)
%19 = load i64, ptr %5, align 8
call void @DrawText(ptr noundef @.str.1, i32 noundef 190, i32 noundef 200, i32 noundef 20, i64 %19)
call void @EndDrawing()
br label %6, !llvm.loop !6

20: ; preds = %6
call void @CloseWindow()
ret i32 0
}

declare void @InitWindow(i32 noundef, i32 noundef, ptr noundef) #1

declare void @SetTargetFPS(i32 noundef) #1

declare zeroext i1 @WindowShouldClose() #1

declare void @BeginDrawing() #1

declare void @ClearBackground(i64) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias writeonly captures(none), ptr noalias readonly captures(none), i64, i1 immarg) #2

declare void @DrawText(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i64) #1

declare void @EndDrawing() #1

declare void @CloseWindow() #1

attributes #0 = { noinline nounwind optnone ssp uwtable(sync) "frame-pointer"="non-leaf" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="apple-m1" "target-features"="+aes,+altnzcv,+ccdp,+ccidx,+ccpp,+complxnum,+crc,+dit,+dotprod,+flagm,+fp-armv8,+fp16fml,+fptoint,+fullfp16,+jsconv,+lse,+neon,+pauth,+perfmon,+predres,+ras,+rcpc,+rdm,+sb,+sha2,+sha3,+specrestrict,+ssbs,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8a" }
attributes #1 = { "frame-pointer"="non-leaf" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="apple-m1" "target-features"="+aes,+altnzcv,+ccdp,+ccidx,+ccpp,+complxnum,+crc,+dit,+dotprod,+flagm,+fp-armv8,+fp16fml,+fptoint,+fullfp16,+jsconv,+lse,+neon,+pauth,+perfmon,+predres,+ras,+rcpc,+rdm,+sb,+sha2,+sha3,+specrestrict,+ssbs,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8a" }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }

!llvm.module.flags = !{!0, !1, !2, !3, !4}
!llvm.ident = !{!5}

!0 = !{i32 2, !"SDK Version", [2 x i32] [i32 26, i32 0]}
!1 = !{i32 1, !"wchar_size", i32 4}
!2 = !{i32 8, !"PIC Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 1}
!4 = !{i32 7, !"frame-pointer", i32 1}
!5 = !{!"Homebrew clang version 21.1.3"}
!6 = distinct !{!6, !7}
!7 = !{!"llvm.loop.mustprogress"}
Binary file added software/luna/lib/libraylib.a
Binary file not shown.
Loading