Core: Conditional compound to fix Msvc, better assert but printf based, Fix tests
This commit is contained in:
@@ -17,31 +17,31 @@ and make a pointer out of it. Have to be mindful of the lifetime.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
storage: [32]S64
|
storage: [32]int
|
||||||
len : S64
|
len : int
|
||||||
|
|
||||||
"+" :: (a: Any, b: Any): Any
|
"+" :: (a: Any, b: Any): Any
|
||||||
result: Any = storage[len++]
|
result: Any = storage[len++]
|
||||||
if a.type == S64 && b.type == S64
|
if a.type == int && b.type == int
|
||||||
*(result.data->*S64) = *(a.data->*S64) + *(b.data->*S64)
|
*(result.data->*int) = *(a.data->*int) + *(b.data->*int)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
"+" :: (a: Any, b: S64): Any
|
"+" :: (a: Any, b: int): Any
|
||||||
result: Any = storage[len++]
|
result: Any = storage[len++]
|
||||||
if a.type == S64
|
if a.type == int
|
||||||
*(result.data->*S64) = *(a.data->*S64) + b
|
*(result.data->*int) = *(a.data->*int) + b
|
||||||
return result
|
return result
|
||||||
|
|
||||||
"==" :: (a: Any, b: S64): bool
|
"==" :: (a: Any, b: int): bool
|
||||||
result := false
|
result := false
|
||||||
if a.type == S64
|
if a.type == int
|
||||||
result = *(a.data->*S64) == b
|
result = *(a.data->*int) == b
|
||||||
return result
|
return result
|
||||||
|
|
||||||
"==" :: (a: Any, b: Any): bool
|
"==" :: (a: Any, b: Any): bool
|
||||||
result := false
|
result := false
|
||||||
if a.type == S64 && b.type == S64
|
if a.type == int && b.type == int
|
||||||
result = *(a.data->*S64) == *(b.data->*S64)
|
result = *(a.data->*int) == *(b.data->*int)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
main :: (): int
|
main :: (): int
|
||||||
@@ -49,7 +49,7 @@ main :: (): int
|
|||||||
b: Any = 20
|
b: Any = 20
|
||||||
c := a + b
|
c := a + b
|
||||||
|
|
||||||
Assert(c.type == S64 && c == 30)
|
Assert(c.type == int && c == 30)
|
||||||
Assert(a+b+a==c+(5+5))
|
Assert(a+b+a==c+(5+5))
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
@@ -16,6 +16,12 @@ Tuple :: struct($A: Type, $B: Type)
|
|||||||
a: A
|
a: A
|
||||||
b: B
|
b: B
|
||||||
|
|
||||||
|
Triple :: struct($A: Type, $B: Type, $C: Type)
|
||||||
|
a: A
|
||||||
|
b: B
|
||||||
|
c: C
|
||||||
|
|
||||||
|
|
||||||
Variant :: union($A: Type, $B: Type, $C: Type)
|
Variant :: union($A: Type, $B: Type, $C: Type)
|
||||||
a: A
|
a: A
|
||||||
b: B
|
b: B
|
||||||
@@ -49,9 +55,6 @@ GetCount :: (a: int): int
|
|||||||
// @todo: this is allowed, shouldn't be
|
// @todo: this is allowed, shouldn't be
|
||||||
// Test :: (a: int, b: int = 10, c: int???)
|
// Test :: (a: int, b: int = 10, c: int???)
|
||||||
|
|
||||||
Test :: (a: C.Triple(int, int, int))
|
|
||||||
pass
|
|
||||||
|
|
||||||
// @todo:
|
// @todo:
|
||||||
// Add :: (arr: *Array($T), item: T)
|
// Add :: (arr: *Array($T), item: T)
|
||||||
// return
|
// return
|
||||||
@@ -74,7 +77,6 @@ main :: (argc: int, argv: **char): int
|
|||||||
sixth: Array(Array(F32))
|
sixth: Array(Array(F32))
|
||||||
seventh: Variant(int, F32, S64)
|
seventh: Variant(int, F32, S64)
|
||||||
|
|
||||||
Test({1,2,3})
|
|
||||||
test_a := int
|
test_a := int
|
||||||
test := *int
|
test := *int
|
||||||
Assert(test_a != test)
|
Assert(test_a != test)
|
||||||
|
|||||||
@@ -10,6 +10,6 @@ main :: (argc: int, argv: **char): int
|
|||||||
a: *int = PushStruct(&arena, int, int)
|
a: *int = PushStruct(&arena, int, int)
|
||||||
b: *F32 = PushStruct(&arena, int, F32)
|
b: *F32 = PushStruct(&arena, int, F32)
|
||||||
padding := sizeof(int)
|
padding := sizeof(int)
|
||||||
Assert(arena.len->S64 == (sizeof(int) + sizeof(F32) + padding))
|
Assert(arena.len->int == (sizeof(int) + sizeof(F32) + padding))
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
@@ -4,8 +4,8 @@ V2 :: #import "MathVec2.core"; Vec2 :: V2.Vec2
|
|||||||
|
|
||||||
Epsilon :: 0.00001
|
Epsilon :: 0.00001
|
||||||
Screen : *U32
|
Screen : *U32
|
||||||
X : S64
|
X : int
|
||||||
Y : S64
|
Y : int
|
||||||
TotalTime: F64
|
TotalTime: F64
|
||||||
LightPos := Vec3{2,4,2}
|
LightPos := Vec3{2,4,2}
|
||||||
|
|
||||||
@@ -143,7 +143,7 @@ WinMain :: (hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: LPSTR, nS
|
|||||||
|
|
||||||
requested_time_per_frame: F64 = 1.0 / 60.0
|
requested_time_per_frame: F64 = 1.0 / 60.0
|
||||||
frame_start_time := Time()
|
frame_start_time := Time()
|
||||||
frame_number: S64
|
frame_number: int
|
||||||
for AppIsRunning
|
for AppIsRunning
|
||||||
msg: MSG
|
msg: MSG
|
||||||
for PeekMessageW(&msg, window, 0, 0, PM_REMOVE) > 0
|
for PeekMessageW(&msg, window, 0, 0, PM_REMOVE) > 0
|
||||||
|
|||||||
@@ -34,15 +34,11 @@ main :: (): int
|
|||||||
value_to_be_wrapped := 10
|
value_to_be_wrapped := 10
|
||||||
any_value: Any = value_to_be_wrapped
|
any_value: Any = value_to_be_wrapped
|
||||||
|
|
||||||
if any_value.type == S64
|
if any_value.type == int
|
||||||
*(any_value.data->*S64) = 20
|
*(any_value.data->*int) = 20
|
||||||
elif any_value.type == int
|
else ;; Assert(false, "No bueno")
|
||||||
// Void pointers get implicitly cast
|
|
||||||
value: *int = any_value.data
|
|
||||||
*value = 30
|
|
||||||
elif any_value.type == char;; Assert(false, "No bueno")
|
|
||||||
|
|
||||||
Assert(*(any_value.data->*S64) == 20)
|
Assert(*(any_value.data->*int) == 20)
|
||||||
|
|
||||||
letter := GetFirstLetterOfType(value_to_be_wrapped)
|
letter := GetFirstLetterOfType(value_to_be_wrapped)
|
||||||
Assert(letter == 'I')
|
Assert(letter == 'I')
|
||||||
|
|||||||
@@ -27,12 +27,12 @@ ZeroMemory :: (p: *void, size: SizeU)
|
|||||||
// Unicode
|
// Unicode
|
||||||
//
|
//
|
||||||
QuestionMark16 :: 0x003f
|
QuestionMark16 :: 0x003f
|
||||||
String32 :: struct;; str: *U32; len: S64
|
String32 :: struct;; str: *U32; len: int
|
||||||
String16 :: struct;; str: *U16; len: S64
|
String16 :: struct;; str: *U16; len: int
|
||||||
|
|
||||||
Utf8ToUtf32 :: (c: *U8, max_advance: S64): U32, S64
|
Utf8ToUtf32 :: (c: *U8, max_advance: int): U32, int
|
||||||
out_str: U32
|
out_str: U32
|
||||||
advance: S64
|
advance: int
|
||||||
if (c[0] & 0b10000000) == 0
|
if (c[0] & 0b10000000) == 0
|
||||||
if max_advance >= 1
|
if max_advance >= 1
|
||||||
c0 := c[0]->U32
|
c0 := c[0]->U32
|
||||||
@@ -62,7 +62,7 @@ Utf8ToUtf32 :: (c: *U8, max_advance: S64): U32, S64
|
|||||||
|
|
||||||
return out_str, advance
|
return out_str, advance
|
||||||
|
|
||||||
Utf32ToUtf16 :: (codepoint: U32): [2]U16, S64
|
Utf32ToUtf16 :: (codepoint: U32): [2]U16, int
|
||||||
str: [2]U16
|
str: [2]U16
|
||||||
len := 0
|
len := 0
|
||||||
if codepoint < 0x10000
|
if codepoint < 0x10000
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
Vec2I :: struct;; x: S64; y: S64
|
Vec2I :: struct;; x: int; y: int
|
||||||
Vec2 :: struct;; x: F32; y: F32
|
Vec2 :: struct;; x: F32; y: F32
|
||||||
|
|
||||||
"*" :: (a: Vec2, b: Vec2): Vec2 ;; return {a.x*b.x, a.y*b.y}
|
"*" :: (a: Vec2, b: Vec2): Vec2 ;; return {a.x*b.x, a.y*b.y}
|
||||||
@@ -16,17 +16,17 @@ Vec2 :: struct;; x: F32; y: F32
|
|||||||
"/" :: (a: F32, b: Vec2) : Vec2 ;; return {a/b.x, a/b.y}
|
"/" :: (a: F32, b: Vec2) : Vec2 ;; return {a/b.x, a/b.y}
|
||||||
|
|
||||||
"*" :: (a: Vec2I, b: Vec2I): Vec2I ;; return {a.x*b.x, a.y*b.y}
|
"*" :: (a: Vec2I, b: Vec2I): Vec2I ;; return {a.x*b.x, a.y*b.y}
|
||||||
"*" :: (a: Vec2I, b: S64) : Vec2I ;; return {a.x*b, a.y*b}
|
"*" :: (a: Vec2I, b: int) : Vec2I ;; return {a.x*b, a.y*b}
|
||||||
"*" :: (a: S64, b: Vec2I) : Vec2I ;; return {a*b.x, a*b.y}
|
"*" :: (a: int, b: Vec2I) : Vec2I ;; return {a*b.x, a*b.y}
|
||||||
"-" :: (a: Vec2I, b: Vec2I): Vec2I ;; return {a.x-b.x, a.y-b.y}
|
"-" :: (a: Vec2I, b: Vec2I): Vec2I ;; return {a.x-b.x, a.y-b.y}
|
||||||
"-" :: (a: Vec2I, b: S64) : Vec2I ;; return {a.x-b, a.y-b}
|
"-" :: (a: Vec2I, b: int) : Vec2I ;; return {a.x-b, a.y-b}
|
||||||
"-" :: (a: S64, b: Vec2I) : Vec2I ;; return {a-b.x, a-b.y}
|
"-" :: (a: int, b: Vec2I) : Vec2I ;; return {a-b.x, a-b.y}
|
||||||
"+" :: (a: Vec2I, b: Vec2I): Vec2I ;; return {a.x+b.x, a.y+b.y}
|
"+" :: (a: Vec2I, b: Vec2I): Vec2I ;; return {a.x+b.x, a.y+b.y}
|
||||||
"+" :: (a: Vec2I, b: S64) : Vec2I ;; return {a.x+b, a.y+b}
|
"+" :: (a: Vec2I, b: int) : Vec2I ;; return {a.x+b, a.y+b}
|
||||||
"+" :: (a: S64, b: Vec2I) : Vec2I ;; return {a+b.x, a+b.y}
|
"+" :: (a: int, b: Vec2I) : Vec2I ;; return {a+b.x, a+b.y}
|
||||||
"/" :: (a: Vec2I, b: Vec2I): Vec2I ;; return {a.x/b.x, a.y/b.y}
|
"/" :: (a: Vec2I, b: Vec2I): Vec2I ;; return {a.x/b.x, a.y/b.y}
|
||||||
"/" :: (a: Vec2I, b: S64) : Vec2I ;; return {a.x/b, a.y/b}
|
"/" :: (a: Vec2I, b: int) : Vec2I ;; return {a.x/b, a.y/b}
|
||||||
"/" :: (a: S64, b: Vec2I) : Vec2I ;; return {a/b.x, a/b.y}
|
"/" :: (a: int, b: Vec2I) : Vec2I ;; return {a/b.x, a/b.y}
|
||||||
|
|
||||||
FloorVec2ToVec2I :: (a: Vec2): Vec2I ;; return {floorf(a.x)->S64, floorf(a.y)->S64}
|
FloorVec2ToVec2I :: (a: Vec2): Vec2I ;; return {floorf(a.x)->int, floorf(a.y)->int}
|
||||||
CastVec2ToVec2I :: (a: Vec2): Vec2I ;; return {a.x->S64, a.y->S64}
|
CastVec2ToVec2I :: (a: Vec2): Vec2I ;; return {a.x->int, a.y->int}
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ MU :: struct
|
|||||||
os: Platform
|
os: Platform
|
||||||
|
|
||||||
MUWindow :: struct
|
MUWindow :: struct
|
||||||
x: S64
|
x: int
|
||||||
y: S64
|
y: int
|
||||||
sizef: Vec2
|
sizef: Vec2
|
||||||
size: Vec2I
|
size: Vec2I
|
||||||
resizable: bool
|
resizable: bool
|
||||||
@@ -55,7 +55,7 @@ Mouse :: struct
|
|||||||
left: KeyState
|
left: KeyState
|
||||||
right: KeyState
|
right: KeyState
|
||||||
middle: KeyState
|
middle: KeyState
|
||||||
wheel: S64
|
wheel: int
|
||||||
|
|
||||||
#import "Base.core"
|
#import "Base.core"
|
||||||
#import "MathF32.core"
|
#import "MathF32.core"
|
||||||
|
|||||||
@@ -66,8 +66,8 @@ GetWindowSize :: (window: HWND): Vec2I
|
|||||||
result: Vec2I
|
result: Vec2I
|
||||||
window_rect: RECT
|
window_rect: RECT
|
||||||
GetClientRect(window, &window_rect)
|
GetClientRect(window, &window_rect)
|
||||||
result.x = (window_rect.right - window_rect.left)->S64
|
result.x = (window_rect.right - window_rect.left)->int
|
||||||
result.y = (window_rect.bottom - window_rect.top)->S64
|
result.y = (window_rect.bottom - window_rect.top)->int
|
||||||
return result
|
return result
|
||||||
|
|
||||||
GetWindowPos :: (window: HWND): Vec2I
|
GetWindowPos :: (window: HWND): Vec2I
|
||||||
@@ -94,7 +94,7 @@ SetWindowPosition :: (window: HWND, style: DWORD, pos: Vec2I): void
|
|||||||
SetWindowPos(window, 0, rect.left, rect.top, 0, 0, SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE)
|
SetWindowPos(window, 0, rect.left, rect.top, 0, 0, SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE)
|
||||||
|
|
||||||
StartMultimedia :: (
|
StartMultimedia :: (
|
||||||
x: S64 = 1280, y: S64 = 720,
|
x: int = 1280, y: int = 720,
|
||||||
title: String = "Hello people!",
|
title: String = "Hello people!",
|
||||||
window_resizable: bool = false,
|
window_resizable: bool = false,
|
||||||
target_ms: F64 = 0.0166666
|
target_ms: F64 = 0.0166666
|
||||||
|
|||||||
@@ -243,7 +243,7 @@ gen_value(Token *pos, Value a) {
|
|||||||
default: {
|
default: {
|
||||||
if (is_string(type)) {
|
if (is_string(type)) {
|
||||||
int length = 0;
|
int length = 0;
|
||||||
gen("{(uint8_t *)\"");
|
gen("CORE_ConditionalCompound(String){(uint8_t *)\"");
|
||||||
for (int i = 0; i < a.intern_val.len; i++) {
|
for (int i = 0; i < a.intern_val.len; i++) {
|
||||||
if (a.intern_val.str[i] == '\n') {
|
if (a.intern_val.str[i] == '\n') {
|
||||||
length += 2;
|
length += 2;
|
||||||
@@ -845,8 +845,14 @@ compile_to_c_code() {
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
int printf(const char *format, ...);
|
||||||
#ifndef Assert
|
#ifndef Assert
|
||||||
#define Assert(x) do{if(!(x))(*(volatile int *)0 = 0);}while(0)
|
#define Assert(x) do{ \
|
||||||
|
if(!(x)) { \
|
||||||
|
printf("Assertion failed! %%s(%%d): %%s\n", __FILE__, __LINE__, #x); \
|
||||||
|
*(volatile int *)0 = 0; \
|
||||||
|
} \
|
||||||
|
}while(0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef AssertMessage
|
#ifndef AssertMessage
|
||||||
@@ -866,7 +872,15 @@ compile_to_c_code() {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define BufferSize(x) (sizeof(x)/sizeof((x)[0]))
|
#define BufferSize(x) ((int)(sizeof(x)/sizeof((x)[0])))
|
||||||
|
|
||||||
|
#ifdef __clang__
|
||||||
|
#define CORE_ConditionalCompound(x) (x)
|
||||||
|
#elif _MSC_VER
|
||||||
|
#define CORE_ConditionalCompound(x)
|
||||||
|
#else
|
||||||
|
#define CORE_ConditionalCompound(x) (x)
|
||||||
|
#endif
|
||||||
|
|
||||||
)");
|
)");
|
||||||
|
|
||||||
|
|||||||
@@ -311,7 +311,8 @@ resolve_everything_in_module(Ast_Module *module) {
|
|||||||
if (decl->flags & AST_POLYMORPH) continue;
|
if (decl->flags & AST_POLYMORPH) continue;
|
||||||
|
|
||||||
// @cleanup: Why I'm not calling resolve_decl here?
|
// @cleanup: Why I'm not calling resolve_decl here?
|
||||||
resolve_name(file, decl->pos, decl->name);
|
// resolve_name(file, decl->pos, decl->name);
|
||||||
|
resolve_decl(decl);
|
||||||
if (decl->kind == AST_STRUCT || decl->kind == AST_UNION) type_complete(decl->type_val);
|
if (decl->kind == AST_STRUCT || decl->kind == AST_UNION) type_complete(decl->type_val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ static void compile_file(Allocator *allocator, String filename, U32 compile_flag
|
|||||||
F64 begin = os_time();
|
F64 begin = os_time();
|
||||||
if (!is_flag_set(compile_flags, DONT_USE_C_COMPILER)) {
|
if (!is_flag_set(compile_flags, DONT_USE_C_COMPILER)) {
|
||||||
String_Builder builder = {scratch};
|
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 " ");
|
builder.addf("clang generated_main.c -Wall -Wno-unused-function -Wno-parentheses-equality -g -o a" OS_EXE " ");
|
||||||
For(pctx->files_to_link) {
|
For(pctx->files_to_link) {
|
||||||
builder.addf("-l%Q ", it->intern_val);
|
builder.addf("-l%Q ", it->intern_val);
|
||||||
}
|
}
|
||||||
@@ -170,7 +170,6 @@ int main(int argument_count, char **arguments) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
For(args) {
|
For(args) {
|
||||||
|
|
||||||
if (it == "-testing"_s) {
|
if (it == "-testing"_s) {
|
||||||
Scoped_Arena _scope(&scratch);
|
Scoped_Arena _scope(&scratch);
|
||||||
Array<OS_File_Info> examples = os_list_dir(&scratch, &scratch, "examples"_s);
|
Array<OS_File_Info> examples = os_list_dir(&scratch, &scratch, "examples"_s);
|
||||||
@@ -193,7 +192,7 @@ int main(int argument_count, char **arguments) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("End of program\n");
|
printf("End of program\n");
|
||||||
#if 0 // OS_WINDOWS
|
#if 1
|
||||||
if (IsDebuggerPresent()) {
|
if (IsDebuggerPresent()) {
|
||||||
Breakpoint;
|
Breakpoint;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -612,7 +612,7 @@ insert_into_scope(Ast_Scope *scope, Ast_Decl *decl) {
|
|||||||
// as such we probably don't want to call any resolve stuff here
|
// as such we probably don't want to call any resolve stuff here
|
||||||
Scoped_Arena scratch(pctx->scratch);
|
Scoped_Arena scratch(pctx->scratch);
|
||||||
Scope_Search search = make_scope_search(scratch.arena, scope, decl->name);
|
Scope_Search search = make_scope_search(scratch.arena, scope, decl->name);
|
||||||
// search.search_only_current_scope = true;
|
search.search_only_current_scope = true;
|
||||||
scope_search(&search);
|
scope_search(&search);
|
||||||
if (search.results.len != 0) {
|
if (search.results.len != 0) {
|
||||||
if (!is_flag_set(decl->flags, AST_OPERATOR_OVERLOAD)) {
|
if (!is_flag_set(decl->flags, AST_OPERATOR_OVERLOAD)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user