Compiling with MSVC, Using raylib! Cleanup
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -12,6 +12,7 @@
|
||||
*.10x
|
||||
*.obj
|
||||
*.exp
|
||||
*.dll
|
||||
|
||||
*.sublime-*
|
||||
tests/
|
||||
|
||||
@@ -2,9 +2,9 @@ constexpr size_t ARENA_BLOCK_SIZE = mib(4);
|
||||
constexpr size_t ARENA_ALIGNMENT = 8;
|
||||
|
||||
struct CRT_Heap : Allocator {};
|
||||
static void *crt_allocate(Allocator *allocator, size_t size) { return malloc(size); }
|
||||
static void crt_deallocate(Allocator *allocator, void *p) { return free(p); }
|
||||
static CRT_Heap make_crt_heap() {
|
||||
CORE_Static void *crt_allocate(Allocator *allocator, size_t size) { return malloc(size); }
|
||||
CORE_Static void crt_deallocate(Allocator *allocator, void *p) { return free(p); }
|
||||
CORE_Static CRT_Heap make_crt_heap() {
|
||||
CRT_Heap result = {};
|
||||
result.allocate = crt_allocate;
|
||||
result.deallocate = crt_deallocate;
|
||||
|
||||
14
build.bat
14
build.bat
@@ -1,9 +1,9 @@
|
||||
@echo off
|
||||
call "..\misc\compile_setup.bat"
|
||||
|
||||
bld --dont_compile_core
|
||||
rem if exist "..\misc\compile_setup.bat" call "..\misc\compile_setup.bat"
|
||||
|
||||
rem set clang-flags=-O0 -Wall -Wno-unused-function -fno-exceptions -fdiagnostics-absolute-paths -g -o main.exe -Wl,user32.lib
|
||||
|
||||
rem pushd %~dp0
|
||||
rem cl core_main.cpp -Zi -nologo -W3 -wd4200 -wd4267 -wd4244 -diagnostics:column -Fe:main.exe user32.lib
|
||||
rem popd
|
||||
cd build
|
||||
core_main.exe examples/game2d.core
|
||||
bld --dont_compile_core --link=vendor/raylib/windows/raylibdll.lib
|
||||
rem a.exe
|
||||
cd ..
|
||||
|
||||
93
build/examples/game2d.core
Normal file
93
build/examples/game2d.core
Normal file
@@ -0,0 +1,93 @@
|
||||
#import "LibC.core"
|
||||
#import "raylib.core"
|
||||
|
||||
/*@feature_idea: labeled block
|
||||
|
||||
It acts just like a scope in C.
|
||||
BUT it can be turned into a goto label by adding another semicolon
|
||||
at the end.
|
||||
|
||||
:block
|
||||
thing := 1
|
||||
thing2 := thing
|
||||
|
||||
:label_without_block
|
||||
thing := 1
|
||||
|
||||
|
||||
:goto_block:
|
||||
thing := 1
|
||||
thing2 := thing
|
||||
|
||||
:goto_block: for
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
@reproduction:
|
||||
This kills the compiler due to referencing slice data
|
||||
|
||||
Array :: struct($T: Type)
|
||||
slice: []T
|
||||
cap: S64
|
||||
|
||||
Guy :: struct
|
||||
pos: Vector2
|
||||
|
||||
Add :: (a: *Array($T), item: T)
|
||||
if a.cap == 0
|
||||
a.cap = 16
|
||||
a.slice.data = malloc(SizeOf(T) * a.cap)
|
||||
a.slice.data[a.slice.len++] = item
|
||||
|
||||
guys: Array(Guy)
|
||||
Add(&guys, {100, 100})
|
||||
*/
|
||||
Array :: struct($T: Type)
|
||||
data: *T
|
||||
len: S64
|
||||
cap: S64
|
||||
|
||||
Guy :: struct
|
||||
pos: Vector2
|
||||
|
||||
Add :: (a: *Array($T), item: T)
|
||||
if a.cap == 0
|
||||
a.cap = 16
|
||||
a.data = malloc(SizeOf(T) * a.cap->U64)
|
||||
if a.len + 1 > a.cap
|
||||
a.cap *= 2
|
||||
a.data = realloc(a.data, SizeOf(T) * a.cap->U64)
|
||||
a.data[a.len++] = item
|
||||
|
||||
main :: (): int
|
||||
guys: Array(Guy)
|
||||
Add(&guys, {pos = {100, 100}})
|
||||
|
||||
InitWindow(1280, 720, "Testing")
|
||||
SetTargetFPS(60)
|
||||
for !WindowShouldClose()
|
||||
|
||||
g := guys.data
|
||||
if IsKeyDown(KEY_W);; g.pos.y -= 2
|
||||
if IsKeyDown(KEY_S);; g.pos.y += 2
|
||||
if IsKeyDown(KEY_A);; g.pos.x -= 2
|
||||
if IsKeyDown(KEY_D);; g.pos.x += 2
|
||||
|
||||
|
||||
BeginDrawing()
|
||||
ClearBackground({100})
|
||||
DrawText("Testing and stuff", 100, 100, 20, RAYWHITE)
|
||||
for i := 0, i < guys.len, i += 1
|
||||
it := guys.data + i
|
||||
DrawCircleV(it.pos, 16, MAROON)
|
||||
EndDrawing()
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,16 +1,5 @@
|
||||
|
||||
/*
|
||||
PushStruct :: (a: *MA.Arena, $T: Type): *$T
|
||||
size := size_of(Type)
|
||||
result := PushSize(a, size)
|
||||
return result
|
||||
|
||||
Array(int)
|
||||
|
||||
QueueAddSLL(list: $List, node: $Node, first: #Identifier = first, last: #Identifier = last, next: #Identifier = next)
|
||||
|
||||
ArrayAdd(array: $Array, item: $Item, data: #Identifier = data, len: #Identifier = len, len: #Identifier = cap)
|
||||
|
||||
/* @todo
|
||||
QueueAddSLL(list: $List, node: $Node, $first = first, $last = last, $next = next)
|
||||
if list.first == 0
|
||||
list.first = list.last = node
|
||||
@@ -100,8 +89,7 @@ main :: (argc: int, argv: **char): int
|
||||
Add(&third_array, 32)
|
||||
Add(&fourth, 32)
|
||||
Add(&fifth, 32)
|
||||
Add(&sixth, {32})
|
||||
// Add(&seventh, {32, 32, 32})
|
||||
// Add(&sixth, {32}) // @todo this is possible !
|
||||
|
||||
// value := PolyLambda(**int)
|
||||
// PolyType_r1 := PolyType(10)
|
||||
230
build/modules/raylib.core
Normal file
230
build/modules/raylib.core
Normal file
@@ -0,0 +1,230 @@
|
||||
|
||||
InitWindow :: #foreign (width: int, height: int, title: *char)
|
||||
WindowShouldClose :: #foreign (): Bool
|
||||
|
||||
SetTargetFPS :: #foreign (fps: int)
|
||||
GetFPS :: #foreign (): int
|
||||
GetFrameTime :: #foreign (): F32
|
||||
GetTime :: #foreign (): F64
|
||||
|
||||
BeginDrawing :: #foreign ()
|
||||
EndDrawing :: #foreign ()
|
||||
ClearBackground :: #foreign (color: Color)
|
||||
|
||||
DrawCircle :: #foreign (centerX: int, centerY: int, radius: F32, color: Color)
|
||||
DrawCircleV :: #foreign (center: Vector2, radius: F32, color: Color)
|
||||
|
||||
DrawFPS :: #foreign (posX: int, posY: int)
|
||||
DrawText :: #foreign (text: *char, posX: int, posY: int, fontSize: int, color: Color)
|
||||
|
||||
|
||||
|
||||
IsKeyDown :: #foreign (key: int): Bool
|
||||
IsKeyPressed :: #foreign (key: int): Bool
|
||||
IsKeyReleased :: #foreign (key: int): Bool
|
||||
IsKeyUp :: #foreign (key: int): Bool
|
||||
|
||||
IsMouseButtonPressed :: #foreign (button: int): Bool
|
||||
IsMouseButtonDown :: #foreign (button: int): Bool
|
||||
IsMouseButtonReleased :: #foreign (button: int): Bool
|
||||
IsMouseButtonUp :: #foreign (button: int): Bool
|
||||
|
||||
CloseWindow :: #foreign ()
|
||||
IsWindowReady :: #foreign ()
|
||||
|
||||
Vector2 :: struct
|
||||
x: F32
|
||||
y: F32
|
||||
|
||||
Vector3 :: struct
|
||||
x: F32
|
||||
y: F32
|
||||
z: F32
|
||||
|
||||
Vector4 :: struct
|
||||
x: F32
|
||||
y: F32
|
||||
z: F32
|
||||
w: F32
|
||||
|
||||
Color :: struct
|
||||
r: U8 // @todo: Add C types
|
||||
g: U8
|
||||
b: U8
|
||||
a: U8
|
||||
|
||||
Rectangle :: struct
|
||||
x: F32
|
||||
y: F32
|
||||
width: F32
|
||||
height: F32
|
||||
|
||||
Image :: struct
|
||||
data: *void
|
||||
width: int
|
||||
height: int
|
||||
mipmaps: int
|
||||
format: int
|
||||
|
||||
Texture :: struct
|
||||
id: U32 // @todo: Add C types
|
||||
width: int
|
||||
height: int
|
||||
mipmaps: int
|
||||
format: int
|
||||
Texture2D :: Texture
|
||||
|
||||
|
||||
// Some Basic Colors
|
||||
// NOTE: Custom raylib color palette for amazing visuals on WHITE background
|
||||
LIGHTGRAY := Color{ 200, 200, 200, 255 } // Light Gray
|
||||
GRAY := Color{ 130, 130, 130, 255 } // Gray
|
||||
DARKGRAY := Color{ 80, 80, 80, 255 } // Dark Gray
|
||||
YELLOW := Color{ 253, 249, 0, 255 } // Yellow
|
||||
GOLD := Color{ 255, 203, 0, 255 } // Gold
|
||||
ORANGE := Color{ 255, 161, 0, 255 } // Orange
|
||||
PINK := Color{ 255, 109, 194, 255 } // Pink
|
||||
RED := Color{ 230, 41, 55, 255 } // Red
|
||||
MAROON := Color{ 190, 33, 55, 255 } // Maroon
|
||||
GREEN := Color{ 0, 228, 48, 255 } // Green
|
||||
LIME := Color{ 0, 158, 47, 255 } // Lime
|
||||
DARKGREEN := Color{ 0, 117, 44, 255 } // Dark Green
|
||||
SKYBLUE := Color{ 102, 191, 255, 255 } // Sky Blue
|
||||
BLUE := Color{ 0, 121, 241, 255 } // Blue
|
||||
DARKBLUE := Color{ 0, 82, 172, 255 } // Dark Blue
|
||||
PURPLE := Color{ 200, 122, 255, 255 } // Purple
|
||||
VIOLET := Color{ 135, 60, 190, 255 } // Violet
|
||||
DARKPURPLE := Color{ 112, 31, 126, 255 } // Dark Purple
|
||||
BEIGE := Color{ 211, 176, 131, 255 } // Beige
|
||||
BROWN := Color{ 127, 106, 79, 255 } // Brown
|
||||
DARKBROWN := Color{ 76, 63, 47, 255 } // Dark Brown
|
||||
WHITE := Color{ 255, 255, 255, 255 } // White
|
||||
BLACK := Color{ 0, 0, 0, 255 } // Black
|
||||
BLANK := Color{ 0, 0, 0, 0 } // Blank (Transparent)
|
||||
MAGENTA := Color{ 255, 0, 255, 255 } // Magenta
|
||||
RAYWHITE := Color{ 245, 245, 245, 255 } // My own White (raylib logo)
|
||||
|
||||
|
||||
KEY_NULL :: 0 // Key: NULL, used for no key pressed
|
||||
// Alphanumeric keys
|
||||
KEY_APOSTROPHE :: 39 // Key: '
|
||||
KEY_COMMA :: 44 // Key: ,
|
||||
KEY_MINUS :: 45 // Key: -
|
||||
KEY_PERIOD :: 46 // Key: .
|
||||
KEY_SLASH :: 47 // Key: /
|
||||
KEY_ZERO :: 48 // Key: 0
|
||||
KEY_ONE :: 49 // Key: 1
|
||||
KEY_TWO :: 50 // Key: 2
|
||||
KEY_THREE :: 51 // Key: 3
|
||||
KEY_FOUR :: 52 // Key: 4
|
||||
KEY_FIVE :: 53 // Key: 5
|
||||
KEY_SIX :: 54 // Key: 6
|
||||
KEY_SEVEN :: 55 // Key: 7
|
||||
KEY_EIGHT :: 56 // Key: 8
|
||||
KEY_NINE :: 57 // Key: 9
|
||||
KEY_SEMICOLON :: 59 // Key: ;
|
||||
KEY_EQUAL :: 61 // Key: ::
|
||||
KEY_A :: 65 // Key: A | a
|
||||
KEY_B :: 66 // Key: B | b
|
||||
KEY_C :: 67 // Key: C | c
|
||||
KEY_D :: 68 // Key: D | d
|
||||
KEY_E :: 69 // Key: E | e
|
||||
KEY_F :: 70 // Key: F | f
|
||||
KEY_G :: 71 // Key: G | g
|
||||
KEY_H :: 72 // Key: H | h
|
||||
KEY_I :: 73 // Key: I | i
|
||||
KEY_J :: 74 // Key: J | j
|
||||
KEY_K :: 75 // Key: K | k
|
||||
KEY_L :: 76 // Key: L | l
|
||||
KEY_M :: 77 // Key: M | m
|
||||
KEY_N :: 78 // Key: N | n
|
||||
KEY_O :: 79 // Key: O | o
|
||||
KEY_P :: 80 // Key: P | p
|
||||
KEY_Q :: 81 // Key: Q | q
|
||||
KEY_R :: 82 // Key: R | r
|
||||
KEY_S :: 83 // Key: S | s
|
||||
KEY_T :: 84 // Key: T | t
|
||||
KEY_U :: 85 // Key: U | u
|
||||
KEY_V :: 86 // Key: V | v
|
||||
KEY_W :: 87 // Key: W | w
|
||||
KEY_X :: 88 // Key: X | x
|
||||
KEY_Y :: 89 // Key: Y | y
|
||||
KEY_Z :: 90 // Key: Z | z
|
||||
KEY_LEFT_BRACKET :: 91 // Key: [
|
||||
KEY_BACKSLASH :: 92 // Key: '\'
|
||||
KEY_RIGHT_BRACKET :: 93 // Key: ]
|
||||
KEY_GRAVE :: 96 // Key: `
|
||||
// Function keys
|
||||
KEY_SPACE :: 32 // Key: Space
|
||||
KEY_ESCAPE :: 256 // Key: Esc
|
||||
KEY_ENTER :: 257 // Key: Enter
|
||||
KEY_TAB :: 258 // Key: Tab
|
||||
KEY_BACKSPACE :: 259 // Key: Backspace
|
||||
KEY_INSERT :: 260 // Key: Ins
|
||||
KEY_DELETE :: 261 // Key: Del
|
||||
KEY_RIGHT :: 262 // Key: Cursor right
|
||||
KEY_LEFT :: 263 // Key: Cursor left
|
||||
KEY_DOWN :: 264 // Key: Cursor down
|
||||
KEY_UP :: 265 // Key: Cursor up
|
||||
KEY_PAGE_UP :: 266 // Key: Page up
|
||||
KEY_PAGE_DOWN :: 267 // Key: Page down
|
||||
KEY_HOME :: 268 // Key: Home
|
||||
KEY_END :: 269 // Key: End
|
||||
KEY_CAPS_LOCK :: 280 // Key: Caps lock
|
||||
KEY_SCROLL_LOCK :: 281 // Key: Scroll down
|
||||
KEY_NUM_LOCK :: 282 // Key: Num lock
|
||||
KEY_PRINT_SCREEN :: 283 // Key: Print screen
|
||||
KEY_PAUSE :: 284 // Key: Pause
|
||||
KEY_F1 :: 290 // Key: F1
|
||||
KEY_F2 :: 291 // Key: F2
|
||||
KEY_F3 :: 292 // Key: F3
|
||||
KEY_F4 :: 293 // Key: F4
|
||||
KEY_F5 :: 294 // Key: F5
|
||||
KEY_F6 :: 295 // Key: F6
|
||||
KEY_F7 :: 296 // Key: F7
|
||||
KEY_F8 :: 297 // Key: F8
|
||||
KEY_F9 :: 298 // Key: F9
|
||||
KEY_F10 :: 299 // Key: F10
|
||||
KEY_F11 :: 300 // Key: F11
|
||||
KEY_F12 :: 301 // Key: F12
|
||||
KEY_LEFT_SHIFT :: 340 // Key: Shift left
|
||||
KEY_LEFT_CONTROL :: 341 // Key: Control left
|
||||
KEY_LEFT_ALT :: 342 // Key: Alt left
|
||||
KEY_LEFT_SUPER :: 343 // Key: Super left
|
||||
KEY_RIGHT_SHIFT :: 344 // Key: Shift right
|
||||
KEY_RIGHT_CONTROL :: 345 // Key: Control right
|
||||
KEY_RIGHT_ALT :: 346 // Key: Alt right
|
||||
KEY_RIGHT_SUPER :: 347 // Key: Super right
|
||||
KEY_KB_MENU :: 348 // Key: KB menu
|
||||
// Keypad keys
|
||||
KEY_KP_0 :: 320 // Key: Keypad 0
|
||||
KEY_KP_1 :: 321 // Key: Keypad 1
|
||||
KEY_KP_2 :: 322 // Key: Keypad 2
|
||||
KEY_KP_3 :: 323 // Key: Keypad 3
|
||||
KEY_KP_4 :: 324 // Key: Keypad 4
|
||||
KEY_KP_5 :: 325 // Key: Keypad 5
|
||||
KEY_KP_6 :: 326 // Key: Keypad 6
|
||||
KEY_KP_7 :: 327 // Key: Keypad 7
|
||||
KEY_KP_8 :: 328 // Key: Keypad 8
|
||||
KEY_KP_9 :: 329 // Key: Keypad 9
|
||||
KEY_KP_DECIMAL :: 330 // Key: Keypad .
|
||||
KEY_KP_DIVIDE :: 331 // Key: Keypad /
|
||||
KEY_KP_MULTIPLY :: 332 // Key: Keypad *
|
||||
KEY_KP_SUBTRACT :: 333 // Key: Keypad -
|
||||
KEY_KP_ADD :: 334 // Key: Keypad +
|
||||
KEY_KP_ENTER :: 335 // Key: Keypad Enter
|
||||
KEY_KP_EQUAL :: 336 // Key: Keypad ::
|
||||
// Android key buttons
|
||||
KEY_BACK :: 4 // Key: Android back button
|
||||
KEY_MENU :: 82 // Key: Android menu button
|
||||
KEY_VOLUME_UP :: 24 // Key: Android volume up button
|
||||
KEY_VOLUME_DOWN :: 25 // Key: Android volume down button
|
||||
|
||||
|
||||
MOUSE_BUTTON_LEFT :: 0 // Mouse button left
|
||||
MOUSE_BUTTON_RIGHT :: 1 // Mouse button right
|
||||
MOUSE_BUTTON_MIDDLE :: 2 // Mouse button middle (pressed wheel)
|
||||
MOUSE_BUTTON_SIDE :: 3 // Mouse button side (advanced mouse device)
|
||||
MOUSE_BUTTON_EXTRA :: 4 // Mouse button extra (advanced mouse device)
|
||||
MOUSE_BUTTON_FORWARD :: 5 // Mouse button forward (advanced mouse device)
|
||||
MOUSE_BUTTON_BACK :: 6 // Mouse button back (advanced mouse device)
|
||||
1588
build/vendor/raylib/raylib.h
vendored
Normal file
1588
build/vendor/raylib/raylib.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
2134
build/vendor/raylib/raymath.h
vendored
Normal file
2134
build/vendor/raylib/raymath.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
4740
build/vendor/raylib/rlgl.h
vendored
Normal file
4740
build/vendor/raylib/rlgl.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@@ -228,7 +228,7 @@ gen_value(Token *pos, Value a) {
|
||||
default: {
|
||||
if (is_string(type)) {
|
||||
int length = 0;
|
||||
gen("(%QString){(uint8_t *)\"", pctx->symbol_prefix);
|
||||
gen("{(uint8_t *)\"");
|
||||
for (int i = 0; i < a.intern_val.len; i++) {
|
||||
if (a.intern_val.str[i] == '\n') {
|
||||
length += 2;
|
||||
@@ -328,7 +328,7 @@ gen_var(Ast_Decl *decl, B32 emit_value, B32 scope_names) {
|
||||
gen(" = 0");
|
||||
}
|
||||
else {
|
||||
gen(" = {}");
|
||||
gen(" = {0}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -484,9 +484,12 @@ gen_expr(Ast_Expr *ast) {
|
||||
}
|
||||
|
||||
CASE(COMPOUND, Call) {
|
||||
gen("(");
|
||||
gen_simple_decl(node->resolved_type);
|
||||
gen(")");
|
||||
bool is_global_variable = node->parent_scope->kind == AST_FILE;
|
||||
if (!is_global_variable) {
|
||||
gen("(");
|
||||
gen_simple_decl(node->resolved_type);
|
||||
gen(")");
|
||||
}
|
||||
gen("{");
|
||||
|
||||
// We need to double wrap it because Any is a pointer
|
||||
@@ -530,8 +533,8 @@ gen_ast(Ast *ast) {
|
||||
switch (ast->kind) {
|
||||
|
||||
CASE(RUNTIME_ASSERT, Builtin) {
|
||||
if (node->assert_message.len == 0) gen("%QAssert", pctx->symbol_prefix);
|
||||
else gen("%QAssertMessage", pctx->symbol_prefix);
|
||||
if (node->assert_message.len == 0) gen("Assert");
|
||||
else gen("AssertMessage");
|
||||
gen("(");
|
||||
gen_expr(node->expr);
|
||||
if (node->assert_message.len) {
|
||||
@@ -554,7 +557,7 @@ gen_ast(Ast *ast) {
|
||||
|
||||
// We cant assign to array in C so we need a special case
|
||||
if (is_array(it->resolved_type)) {
|
||||
genln("%QMemoryCopy(&%Q.m%d, ", pctx->symbol_prefix, tuple_name, i);
|
||||
genln("MemoryCopy(&%Q.m%d, ", tuple_name, i);
|
||||
gen_expr(it);
|
||||
gen(", sizeof(%Q.m%d));", tuple_name, i);
|
||||
}
|
||||
@@ -650,12 +653,11 @@ gen_ast(Ast *ast) {
|
||||
}
|
||||
|
||||
CASE(FOR, For) {
|
||||
|
||||
// Array iter
|
||||
if (node->is_array_traversal) {
|
||||
gen("for(int64_t _i%d = 0; _i%d < ", node->pos->line, node->pos->line);
|
||||
if (is_array(node->cond->resolved_type)) {
|
||||
gen("%QBufferSize(", pctx->symbol_prefix);
|
||||
gen("BufferSize(");
|
||||
gen_expr(node->cond);
|
||||
gen(")");
|
||||
}
|
||||
@@ -792,7 +794,7 @@ gen_ast(Ast *ast) {
|
||||
|
||||
int i = 0;
|
||||
For(node->vars) {
|
||||
gen("%QMemoryCopy((void *)&%Q, (void *)&%Q.m%d, sizeof(%Q));", pctx->symbol_prefix, it->name, var_name, i++, it->name);
|
||||
gen("MemoryCopy((void *)&%Q, (void *)&%Q.m%d, sizeof(%Q));", it->name, var_name, i++, it->name);
|
||||
}
|
||||
BREAK();
|
||||
}
|
||||
@@ -812,78 +814,7 @@ CORE_Static String
|
||||
compile_to_c_code() {
|
||||
pctx->time.code_generation = os_time();
|
||||
|
||||
#if 0
|
||||
String core_stringify(Ast *);
|
||||
For(pctx->ordered_decls) {
|
||||
Ast *copy = ast_copy(it, 0);
|
||||
String r = core_stringify(it);
|
||||
printf("\n-----REAL!!!------\n");
|
||||
printf("%s\n", r.str);
|
||||
r = core_stringify(copy);
|
||||
printf("\n-----COPY!!!------\n");
|
||||
printf("%s\n", r.str);
|
||||
}
|
||||
pctx->gen.reset();
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
int di = 0;
|
||||
For(pctx->ordered_decls) {
|
||||
for (Ast_Iter iter = iterate_depth_first(pctx->heap, it); iter.ast; next(&iter)) {
|
||||
Ast_Decl *decl = (Ast_Decl *)iter.ast;
|
||||
Ast *ast = iter.ast;
|
||||
Ast_Atom *atom = (Ast_Atom *)iter.ast;
|
||||
|
||||
switch (iter.kind) {
|
||||
case AST_STRUCT: {
|
||||
genln("%Q :: struct", decl->name);
|
||||
global_indent += 1;
|
||||
} break;
|
||||
case AST_STRUCT + AST_NODE_END: {
|
||||
global_indent -= 1;
|
||||
} break;
|
||||
case AST_LAMBDA: {
|
||||
Ast_Lambda *lambda = decl->lambda;
|
||||
genln("%Q :: (", decl->name);
|
||||
For(lambda->args) {
|
||||
gen("%Q: %Q, ", it->name, core_type_to_string(it->type));
|
||||
}
|
||||
gen(")");
|
||||
|
||||
// @cleanup @refactor: return value shouldn't be a array of expressions.
|
||||
// It should be a single expression. So probably need a special type
|
||||
// for that.
|
||||
if (lambda->args.len) {
|
||||
gen(": ");
|
||||
For(lambda->args) {
|
||||
gen("%Q ", core_type_to_string(it->type));
|
||||
}
|
||||
}
|
||||
|
||||
iter.skip_children = true;
|
||||
iter.stack.add(decl);
|
||||
if (lambda->scope) iter.stack.add(lambda->scope);
|
||||
global_indent += 1;
|
||||
} break;
|
||||
case AST_LAMBDA + AST_NODE_END: {
|
||||
global_indent -= 1;
|
||||
} break;
|
||||
case AST_VAR: {
|
||||
genln("%Q: %Q", decl->name, core_type_to_string(decl->type));
|
||||
} break;
|
||||
case AST_VAR + AST_NODE_END: {
|
||||
} break;
|
||||
}
|
||||
}
|
||||
String str = string_flatten(pctx->perm, &pctx->gen);
|
||||
printf("%s", str.str);
|
||||
pctx->gen.reset();
|
||||
di += 1;
|
||||
}
|
||||
printf("\n");
|
||||
#endif
|
||||
|
||||
prefixed_string_type = string_fmt(pctx->perm, "%QString", pctx->symbol_prefix);
|
||||
prefixed_string_type = string_fmt(pctx->perm, "String");
|
||||
if (pctx->single_header_library_mode) {
|
||||
gen(R"(
|
||||
/*
|
||||
@@ -898,13 +829,12 @@ compile_to_c_code() {
|
||||
#define %Q_IMPLEMENTATION
|
||||
#include "%Q.h"
|
||||
|
||||
You can #define %QAssert(x) to avoid using default assert
|
||||
You can #define %QAssertMessage(x) to get more comprehensive error info
|
||||
You can #define %QMemoryCopy(x) to avoid using default memory copy
|
||||
You can #define Assert(x) to avoid using default assert
|
||||
You can #define AssertMessage(x) to get more comprehensive error info
|
||||
You can #define MemoryCopy(x) to avoid using default memory copy
|
||||
*/
|
||||
)",
|
||||
pctx->single_header_library_name, pctx->single_header_library_name, pctx->single_header_library_name,
|
||||
pctx->symbol_prefix, pctx->symbol_prefix, pctx->symbol_prefix);
|
||||
pctx->single_header_library_name, pctx->single_header_library_name, pctx->single_header_library_name);
|
||||
genln("#ifndef %Q_LIBRARY_HEADER ", pctx->single_header_library_name);
|
||||
genln("#define %Q_LIBRARY_HEADER ", pctx->single_header_library_name);
|
||||
}
|
||||
@@ -1023,43 +953,58 @@ compile_to_c_code() {
|
||||
global_indent++;
|
||||
For2(pctx->all_types, t) {
|
||||
if (t->kind == TYPE_POLYMORPH) continue;
|
||||
genln("{/*%Q*/.kind = %d, .size = %d, .align = %d, .is_unsigned = %s, .type = %d, ", typestring(t),
|
||||
(S32)t->kind, (S32)t->size, (S32)t->align, t->is_unsigned ? "true" : "false", t->type_id);
|
||||
|
||||
genln("{/*%Q*/", typestring(t));
|
||||
global_indent += 1;
|
||||
genln(".kind = %d, ", (S32)t->kind);
|
||||
genln(".size = %d, ", (S32)t->size);
|
||||
genln(".align = %d, ", (S32)t->align);
|
||||
genln(".is_unsigned = %s, ", t->is_unsigned ? "true" : "false");
|
||||
genln(".type = %d, ", t->type_id);
|
||||
|
||||
switch (t->kind) {
|
||||
case TYPE_POINTER:
|
||||
case TYPE_SLICE: {
|
||||
gen(".base_type = %d", t->base->type_id);
|
||||
genln(".base_type = %d", t->base->type_id);
|
||||
} break;
|
||||
case TYPE_ARRAY: {
|
||||
gen(".base_type = %d, ", t->base->type_id);
|
||||
gen(".array_size = %d", t->arr.size);
|
||||
genln(".base_type = %d, ", t->base->type_id);
|
||||
genln(".array_size = %d", t->arr.size);
|
||||
} break;
|
||||
case TYPE_LAMBDA: {
|
||||
gen(".lambda_return = %d, ", t->func.ret->type_id);
|
||||
gen(".lambda_arguments.len = %d, ", t->func.args.len);
|
||||
gen(".lambda_arguments.data = (Type_Info[%d]){", t->func.args.len);
|
||||
if (t->func.args.len == 0) goto end_of_switch;
|
||||
genln(".lambda_return = %d, ", t->func.ret->type_id);
|
||||
genln(".lambda_arguments.len = %d, ", t->func.args.len);
|
||||
genln(".lambda_arguments.data = (Type_Info[%d]){", t->func.args.len);
|
||||
global_indent += 1;
|
||||
For2(t->func.args, arg) {
|
||||
gen("{.type = %d}, ", arg->type_id);
|
||||
genln("{.type = %d}, ", arg->type_id);
|
||||
}
|
||||
gen("}");
|
||||
global_indent -= 1;
|
||||
genln("}");
|
||||
} break;
|
||||
case TYPE_UNION:
|
||||
case TYPE_STRUCT: {
|
||||
gen(".struct_members.len = %d, ", t->agg.members.len);
|
||||
gen(".struct_members.data = (Type_Info_Struct_Member[]){");
|
||||
if (t->agg.members.len == 0) goto end_of_switch;
|
||||
genln(".struct_members.len = %d, ", t->agg.members.len);
|
||||
genln(".struct_members.data = (Type_Info_Struct_Member[%d]){", t->agg.members.len);
|
||||
global_indent += 1;
|
||||
For2(t->agg.members, m) {
|
||||
gen("{.name = (%Q){(uint8_t *)\"%Q\", %d}, .type = %d, .offset = %d}, ", prefixed_string_type, m.name, m.name.len, m.type->type_id, m.offset);
|
||||
genln("{.name = {(uint8_t *)\"%Q\", %d}, .type = %d, .offset = %d}, ", prefixed_string_type, m.name, m.name.len, m.type->type_id, m.offset);
|
||||
}
|
||||
gen("}");
|
||||
global_indent -= 1;
|
||||
genln("}");
|
||||
} break;
|
||||
default: {
|
||||
}
|
||||
// invalid_default_case;
|
||||
}
|
||||
gen("},");
|
||||
end_of_switch:;
|
||||
global_indent -= 1;
|
||||
genln("},");
|
||||
}
|
||||
global_indent--;
|
||||
gen("};");
|
||||
genln("};");
|
||||
}
|
||||
|
||||
if (pctx->single_header_library_mode) {
|
||||
|
||||
@@ -14,7 +14,7 @@ static void core_init_compiler(Core_Ctx *ctx, Allocator *allocator) {
|
||||
pctx = ctx;
|
||||
|
||||
ctx->emit_type_info = true;
|
||||
ctx->emit_line_directives = true;
|
||||
ctx->emit_line_directives = false;
|
||||
ctx->debugger_break_on_compiler_error = true;
|
||||
ctx->color_codes_enabled = true;
|
||||
ctx->same_scope_token = {SAME_SCOPE};
|
||||
|
||||
@@ -81,7 +81,6 @@ struct Core_Ctx {
|
||||
// Codegen stage configurables
|
||||
bool emit_line_directives;
|
||||
bool emit_type_info;
|
||||
String symbol_prefix;
|
||||
bool single_header_library_mode;
|
||||
String single_header_library_name;
|
||||
|
||||
|
||||
@@ -96,6 +96,7 @@ const U32 COMPILE_PRINT_STATS = 0x1;
|
||||
const U32 COMPILE_PRINT_ALLOCATOR_STATS_BEFORE_DESTROY = 0x2;
|
||||
const U32 COMPILE_AND_RUN = 0x4;
|
||||
const U32 COMPILE_TESTING = 0x8;
|
||||
const U32 DONT_USE_C_COMPILER = 0x10;
|
||||
|
||||
static void compile_file(Allocator *allocator, String filename, U32 compile_flags = COMPILE_NULL) {
|
||||
if (is_flag_set(compile_flags, COMPILE_AND_RUN)) {
|
||||
@@ -103,7 +104,7 @@ static void compile_file(Allocator *allocator, String filename, U32 compile_flag
|
||||
}
|
||||
String result = compile_file_to_string(allocator, filename);
|
||||
|
||||
B32 r = os_write_file("program.c"_s, result);
|
||||
B32 r = os_write_file("generated_main.c"_s, result);
|
||||
assert(r);
|
||||
F64 total_compiler_time = os_time() - pctx->time.start;
|
||||
printf("%f - ", total_compiler_time);
|
||||
@@ -112,20 +113,22 @@ static void compile_file(Allocator *allocator, String filename, U32 compile_flag
|
||||
Scoped_Arena _scope(scratch);
|
||||
|
||||
F64 begin = os_time();
|
||||
String_Builder builder = {scratch};
|
||||
builder.addf("clang program.c -Wall -Wno-unused-function -Wno-parentheses-equality -g -o a" OS_EXE " ");
|
||||
For(pctx->files_to_link) {
|
||||
builder.addf("-l%Q ", it->intern_val);
|
||||
if (!is_flag_set(compile_flags, DONT_USE_C_COMPILER)) {
|
||||
String_Builder builder = {scratch};
|
||||
builder.addf("clang generated_main.c vendor\\raylib\\windows\\raylibdll.lib -Wall -Wno-unused-function -Wno-parentheses-equality -g -o a" OS_EXE " ");
|
||||
For(pctx->files_to_link) {
|
||||
builder.addf("-l%Q ", it->intern_val);
|
||||
}
|
||||
String compiler_call = string_flatten(scratch, &builder);
|
||||
system((const char *)compiler_call.str);
|
||||
printf("%s\n", compiler_call.str);
|
||||
}
|
||||
String compiler_call = string_flatten(scratch, &builder);
|
||||
|
||||
system((const char *)compiler_call.str);
|
||||
F64 end = os_time();
|
||||
|
||||
if (is_flag_set(compile_flags, COMPILE_PRINT_STATS)) {
|
||||
printf("total = %f\n", os_time() - pctx->time.start);
|
||||
printf("core_total = %f\n", pctx->time.total);
|
||||
printf("clang = %f\n", end - begin);
|
||||
if (!is_flag_set(compile_flags, DONT_USE_C_COMPILER)) printf("clang = %f\n", end - begin);
|
||||
printf("parsing = %f\n", pctx->time.parsing);
|
||||
printf("typecheck = %f\n", pctx->time.typechecking);
|
||||
printf("generatin = %f\n", pctx->time.code_generation);
|
||||
@@ -192,11 +195,11 @@ int main(int argument_count, char **arguments) {
|
||||
|
||||
else {
|
||||
String program_name = string_from_cstring(arguments[1]);
|
||||
compile_file(&arena, program_name, COMPILE_PRINT_STATS | COMPILE_AND_RUN);
|
||||
compile_file(&arena, program_name, COMPILE_PRINT_STATS | DONT_USE_C_COMPILER);
|
||||
}
|
||||
}
|
||||
printf("End of program\n");
|
||||
#if OS_WINDOWS
|
||||
#if 0 // OS_WINDOWS
|
||||
if (IsDebuggerPresent()) {
|
||||
Breakpoint;
|
||||
}
|
||||
|
||||
@@ -1805,11 +1805,11 @@ resolve_decl(Ast_Decl *ast) {
|
||||
|
||||
node->unique_name = node->name;
|
||||
if (!is_flag_set(node->expr->flags, AST_FOREIGN)) {
|
||||
node->unique_name = pctx->internf("%Q%Q%d", pctx->symbol_prefix, node->name, pctx->lambda_ids++);
|
||||
node->unique_name = pctx->internf("%Q%d", node->name, pctx->lambda_ids++);
|
||||
}
|
||||
|
||||
if (is_flag_set(node->flags, AST_OPERATOR_OVERLOAD)) {
|
||||
node->unique_name = pctx->internf("%QOPERATOR_%Q%d", pctx->symbol_prefix, node->overload_op_info->name, pctx->lambda_ids++);
|
||||
node->unique_name = pctx->internf("OPERATOR_%Q%d", node->overload_op_info->name, pctx->lambda_ids++);
|
||||
}
|
||||
|
||||
BREAK();
|
||||
|
||||
Reference in New Issue
Block a user