Skip to content

Commit

Permalink
fix(type_checker): always use i32,f32 for ints and floats
Browse files Browse the repository at this point in the history
  • Loading branch information
JaDogg committed Jul 24, 2024
1 parent 4a1c2f2 commit 6e44e68
Show file tree
Hide file tree
Showing 28 changed files with 112 additions and 104 deletions.
6 changes: 3 additions & 3 deletions compiler/carpntr/main.yaka.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct yy__pool_ThreadPool;
struct yy__raylib_support_BuildData;
struct yy__raylib_support_CObject;
typedef void (*yt_fn_in_any_ptr_out)(void*);
typedef int32_t (*yt_fn_in_any_ptr_out_int)(void*);
typedef int32_t (*yt_fn_in_any_ptr_out_i32)(void*);
struct yt_tuple_fn_in_any_ptr_out_any_ptr { yt_fn_in_any_ptr_out e1; void* e2; };
struct yy__building_BObject {
yk__sds* yy__building_args;
Expand Down Expand Up @@ -155,7 +155,7 @@ void yy__condition_destroy(yy__condition_Condition*);
int32_t yy__condition_signal(yy__condition_Condition*);
int32_t yy__condition_broadcast(yy__condition_Condition*);
int32_t yy__condition_wait(yy__condition_Condition*, yy__mutex_Mutex*);
int32_t yy__thread_create_with_data(yy__thread_Thread*, yt_fn_in_any_ptr_out_int, void*);
int32_t yy__thread_create_with_data(yy__thread_Thread*, yt_fn_in_any_ptr_out_i32, void*);
void yy__thread_exit(int32_t);
int32_t yy__thread_join(yy__thread_Thread);
struct yy__pool_ThreadPool* yy__pool_create(uint8_t, uint32_t);
Expand Down Expand Up @@ -723,7 +723,7 @@ void yy__condition_destroy(yy__condition_Condition* nn__cnd) { cnd_destroy(nn__c
int32_t yy__condition_signal(yy__condition_Condition* nn__cnd) { return cnd_signal(nn__cnd); }
int32_t yy__condition_broadcast(yy__condition_Condition* nn__cnd) { return cnd_broadcast(nn__cnd); }
int32_t yy__condition_wait(yy__condition_Condition* nn__cnd, yy__mutex_Mutex* nn__mtx) { return cnd_wait(nn__cnd, nn__mtx); }
int32_t yy__thread_create_with_data(yy__thread_Thread* nn__thr, yt_fn_in_any_ptr_out_int nn__func, void* nn__data) { return thrd_create(nn__thr, nn__func, nn__data); }
int32_t yy__thread_create_with_data(yy__thread_Thread* nn__thr, yt_fn_in_any_ptr_out_i32 nn__func, void* nn__data) { return thrd_create(nn__thr, nn__func, nn__data); }
void yy__thread_exit(int32_t nn__res) { thrd_exit(nn__res); }
int32_t yy__thread_join(yy__thread_Thread nn__thr)
{
Expand Down
2 changes: 1 addition & 1 deletion compiler/runtime/_include_mman_win.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ int munmap(void *addr, size_t len) {
}
int mprotect(void *addr, size_t len, int prot) {
uint32_t newProtect = __map_mmap_prot_page(prot);
uint32_t oldProtect = 0;
DWORD oldProtect = 0;
if (VirtualProtect(addr, len, newProtect, &oldProtect)) return 0;
errno = __map_mman_error(GetLastError(), EPERM);
return -1;
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/compiler/type_checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,7 @@ void type_checker::handle_assigns(token *oper, const yk_object &lhs,
error(oper, message.str());
}
if (lhs.datatype_->const_unwrap()->is_tuple()) {
if (safe_tuples(lhs, rhs) and !lhs.datatype_->is_const() and
if (safe_tuples(lhs, rhs) && !lhs.datatype_->is_const() &&
oper->type_ == token_type::EQ) {
// assigning simple tuples is allowed
return;
Expand Down
10 changes: 9 additions & 1 deletion compiler/src/utilities/ykdatatype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,15 @@ void yk_datatype::write_to_str(std::stringstream &s, bool write_mod) const {
if (!dt->module_.empty() && write_mod && !dt->is_dimension()) {
s << dt->module_ << ":::";
}
s << dt->token_->token_;
// i32 == int, f32 == float.
// so avoid writing the token for these 2 types
if (dt->is_i32()) {
s << "i32";
} else if (dt->is_f32()) {
s << "f32";
} else {
s << dt->token_->token_;
}
// arguments
if (!dt->args_.empty()) {
stack.emplace_back(
Expand Down
10 changes: 5 additions & 5 deletions compiler/test_data/compiler_tests/arrays/fixed_arr_loop.yaka.c
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
// YK
#include "yk__lib.h"
typedef int32_t yt_arr_int_3[3];
typedef int32_t yt_arr_int_4[4];
typedef int32_t yt_arr_i32_3[3];
typedef int32_t yt_arr_i32_4[4];
typedef struct yk__bstr yt_arr_sr_3[3];
int32_t yy__main();
int32_t yy__main()
{
yk__printlnstr("Fixed Array looping");
yt_arr_int_3 yy__a = {};
yt_arr_i32_3 yy__a = {};
yy__a[INT32_C(0)] = INT32_C(1);
yy__a[INT32_C(1)] = INT32_C(2);
yy__a[INT32_C(2)] = INT32_C(3);
yt_arr_sr_3 yy__b = {};
yy__b[INT32_C(0)] = yk__bstr_s("hello", 5);
yy__b[INT32_C(1)] = yk__bstr_s("world", 5);
yy__b[INT32_C(2)] = yk__bstr_s("!", 1);
yt_arr_int_3* yy__0t = (&(yy__a));
yt_arr_i32_3* yy__0t = (&(yy__a));
int32_t yy__1t = INT32_C(0);
while (true)
{
Expand All @@ -37,7 +37,7 @@ int32_t yy__main()
yk__printlnstr(yk__bstr_get_reference(((*yy__2t)[yy__3t])));
yy__3t += INT32_C(1);
}
yt_arr_int_4 yy__4t = {INT32_C(1), INT32_C(2), INT32_C(3), INT32_C(4)};
yt_arr_i32_4 yy__4t = {INT32_C(1), INT32_C(2), INT32_C(3), INT32_C(4)};
int32_t yy__5t = INT32_C(0);
while (true)
{
Expand Down
34 changes: 17 additions & 17 deletions compiler/test_data/compiler_tests/arrays/fixed_arr_structure.yaka.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@
#include "yk__lib.h"
struct yy__A;
struct yy__B;
typedef int32_t yt_arr_int_2[2];
typedef yt_arr_int_2 yt_arr_arr_int_2_2[2];
typedef int32_t* const yt_arr_const_ptr_int_2[2];
typedef int32_t (*yt_fn_in_int_out_int)(int32_t);
typedef yt_fn_in_int_out_int yt_arr_fn_in_int_out_int_2[2];
typedef int32_t yt_arr_int_3[3];
typedef int32_t* yt_arr_ptr_int_2[2];
typedef int32_t** yt_arr_ptr_ptr_int_2[2];
typedef int32_t yt_arr_i32_2[2];
typedef yt_arr_i32_2 yt_arr_arr_i32_2_2[2];
typedef int32_t* const yt_arr_const_ptr_i32_2[2];
typedef int32_t (*yt_fn_in_i32_out_i32)(int32_t);
typedef yt_fn_in_i32_out_i32 yt_arr_fn_in_i32_out_i32_2[2];
typedef int32_t yt_arr_i32_3[3];
typedef int32_t* yt_arr_ptr_i32_2[2];
typedef int32_t** yt_arr_ptr_ptr_i32_2[2];
struct yy__A {
int32_t yy__a;
yt_arr_int_3 yy__b;
yt_arr_int_3 yy__c;
yt_arr_i32_3 yy__b;
yt_arr_i32_3 yy__c;
};
struct yy__B {
yt_arr_arr_int_2_2 yy__nested;
yt_arr_int_2* yy__ptr_nested;
yt_arr_ptr_int_2 yy__nested_ptr;
yt_arr_ptr_int_2* yy__ptr_nested_ptr;
yt_arr_ptr_ptr_int_2 yy__nested_ptr_ptr;
yt_arr_fn_in_int_out_int_2 yy__nested_func;
yt_arr_const_ptr_int_2 yy__nested_const_ptr;
yt_arr_arr_i32_2_2 yy__nested;
yt_arr_i32_2* yy__ptr_nested;
yt_arr_ptr_i32_2 yy__nested_ptr;
yt_arr_ptr_i32_2* yy__ptr_nested_ptr;
yt_arr_ptr_ptr_i32_2 yy__nested_ptr_ptr;
yt_arr_fn_in_i32_out_i32_2 yy__nested_func;
yt_arr_const_ptr_i32_2 yy__nested_const_ptr;
};
int32_t yy__main();
int32_t yy__main()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// YK
#include "yk__lib.h"
typedef int32_t yt_arr_int_3[3];
typedef int32_t yt_arr_i32_3[3];
int32_t yy__main();
int32_t yy__main()
{
yt_arr_int_3 yy__a = {};
yt_arr_i32_3 yy__a = {};
yy__a[INT32_C(0)] = INT32_C(1);
yy__a[INT32_C(1)] = INT32_C(2);
yy__a[INT32_C(2)] = INT32_C(3);
yt_arr_int_3 yy__b = {};
yt_arr_i32_3 yy__b = {};
yy__b[INT32_C(0)] = yy__a[INT32_C(0)];
yy__b[INT32_C(1)] = yy__a[INT32_C(1)];
yy__b[INT32_C(2)] = yy__a[INT32_C(2)];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// YK
#include "yk__lib.h"
typedef int32_t yt_arr_int_3[3];
typedef int32_t yt_arr_i32_3[3];
int32_t yy__main();
int32_t yy__main()
{
yk__printlnstr("Creating a fixed array");
yt_arr_int_3 yy__a = {};
yt_arr_i32_3 yy__a = {};
yy__a[INT32_C(0)] = INT32_C(1);
yy__a[INT32_C(1)] = INT32_C(2);
yy__a[INT32_C(2)] = INT32_C(3);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// YK
#include "yk__lib.h"
typedef bool (*yt_fn_in_str_int_out_bool)(yk__sds, int32_t);
typedef bool (*yt_fn_in_str_i32_out_bool)(yk__sds, int32_t);
bool yy__keep_len_n(yk__sds, int32_t);
bool yy__keep_upto_n(int32_t, int32_t);
int32_t yy__main();
Expand All @@ -25,7 +25,7 @@ bool yy__keep_upto_n(int32_t yy__a, int32_t yy__n)
int32_t yy__main()
{
yk__printlnstr(">> countif str test <<");
yt_fn_in_str_int_out_bool yy__f = yy__keep_len_n;
yt_fn_in_str_i32_out_bool yy__f = yy__keep_len_n;
yk__sds* t__0 = NULL;
yk__arrsetcap(t__0, 5);
yk__arrput(t__0, yk__sdsnewlen("Hello", 5));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// YK
#include "yk__lib.h"
typedef bool (*yt_fn_in_int_int_out_bool)(int32_t, int32_t);
typedef bool (*yt_fn_in_str_int_out_bool)(yk__sds, int32_t);
typedef bool (*yt_fn_in_i32_i32_out_bool)(int32_t, int32_t);
typedef bool (*yt_fn_in_str_i32_out_bool)(yk__sds, int32_t);
bool yy__keep_len_n(yk__sds, int32_t);
bool yy__keep_all(yk__sds, int32_t);
bool yy__keep_upto(int32_t, int32_t);
Expand Down Expand Up @@ -47,7 +47,7 @@ bool yy__print_int(int32_t yy__a, int32_t yy__ignored)
int32_t yy__main()
{
yk__printlnstr(">> filter str test <<");
yt_fn_in_str_int_out_bool yy__f = yy__keep_len_n;
yt_fn_in_str_i32_out_bool yy__f = yy__keep_len_n;
yk__sds* t__2 = NULL;
yk__arrsetcap(t__2, 5);
yk__arrput(t__2, yk__sdsnewlen("Hello", 5));
Expand Down Expand Up @@ -109,7 +109,7 @@ int32_t yy__main()
}
t__36;
yk__printlnstr(">> filter int test <<");
yt_fn_in_int_int_out_bool yy__fi = yy__keep_upto;
yt_fn_in_i32_i32_out_bool yy__fi = yy__keep_upto;
int32_t* t__38 = NULL;
yk__arrsetcap(t__38, 10);
yk__arrput(t__38, INT32_C(1));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// YK
#include "yk__lib.h"
typedef bool (*yt_fn_in_int_int_out_bool)(int32_t, int32_t);
typedef bool (*yt_fn_in_str_int_out_bool)(yk__sds, int32_t);
typedef bool (*yt_fn_in_i32_i32_out_bool)(int32_t, int32_t);
typedef bool (*yt_fn_in_str_i32_out_bool)(yk__sds, int32_t);
bool yy__print_str(yk__sds, int32_t);
bool yy__print_add_n(int32_t, int32_t);
bool yy__print_upto_n(int32_t, int32_t);
Expand Down Expand Up @@ -31,7 +31,7 @@ bool yy__print_upto_n(int32_t yy__a, int32_t yy__n)
int32_t yy__main()
{
yk__printlnstr(">> foreach str test <<");
yt_fn_in_str_int_out_bool yy__f = yy__print_str;
yt_fn_in_str_i32_out_bool yy__f = yy__print_str;
yk__sds* t__0 = NULL;
yk__arrsetcap(t__0, 5);
yk__arrput(t__0, yk__sdsnewlen("Hello", 5));
Expand Down Expand Up @@ -61,7 +61,7 @@ int32_t yy__main()
}
t__13;
yk__printlnstr(">> foreach int test <<");
yt_fn_in_int_int_out_bool yy__fi = yy__print_add_n;
yt_fn_in_i32_i32_out_bool yy__fi = yy__print_add_n;
int32_t* t__15 = NULL;
yk__arrsetcap(t__15, 10);
yk__arrput(t__15, INT32_C(1));
Expand Down
4 changes: 2 additions & 2 deletions compiler/test_data/compiler_tests/nativefunc.yaka.ast.l
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(native_def readfile ( fname:str) (block (c "size_t ln;\n int err;\n char *out = yk__bhalib_read_file(nn__fname, &ln, &err);\n yk__sdsfree(nn__fname); // clean up filename as it will be copied\n if (err == 0) { return yk__sdsnewlen(out, ln); }\n return yk__sdsempty()")))
(native_def is_empty_str ( s:str) (block (c "bool x = yk__sdslen(nn__s) == 0;\n yk__sdsfree(nn__s);\n return x")))
(native_macro_def min_int ( a:int b:int) (block (c "((nn__a < nn__b) \? nn__a : nn__b)")))
(native_macro_def max_int ( a:int b:int) (block (nop)))
(native_macro_def min_int ( a:i32 b:i32) (block (c "((nn__a < nn__b) \? nn__a : nn__b)")))
(native_macro_def max_int ( a:i32 b:i32) (block (nop)))
(native_def leakme ( a:str b:str) (block (nop)))
(def main () (block (expression (call print "// ----->>> this is my code <<<<------\n")) (let a:str (call readfile "test.c")) (if (expr (call is_empty_str a)) then (block (expression (call print "test.c is empty or not found"))) else (block (expression (call print a)))) (return 0)))

4 changes: 2 additions & 2 deletions compiler/test_data/compiler_tests/normal_hash_map.yaka.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// YK
#include "yk__lib.h"
struct yt_pair_int_int { int32_t key; int32_t value; };
struct yt_pair_i32_i32 { int32_t key; int32_t value; };
int32_t yy__main();
int32_t yy__main()
{
struct yt_pair_int_int* yy__m = NULL;
struct yt_pair_i32_i32* yy__m = NULL;
;
yk__hmput(yy__m, INT32_C(1), INT32_C(42));
yk__hmput(yy__m, INT32_C(100), INT32_C(10000));
Expand Down
6 changes: 3 additions & 3 deletions compiler/test_data/compiler_tests/on_stack_test.yaka.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ struct yy__AnotherFriend;
struct yy__Enemy;
struct yy__Friend;
struct yy__class_stuff_C;
typedef int32_t (*yt_fn_in_out_int)(void);
typedef int32_t (*yt_fn_in_out_i32)(void);
struct yy__Enemy {
int32_t yy__x;
int32_t yy__y;
Expand All @@ -27,8 +27,8 @@ int32_t yy__a()
}
int32_t yy__main()
{
yt_fn_in_out_int yy__b = yy__a;
yt_fn_in_out_int yy__d = yy__a;
yt_fn_in_out_i32 yy__b = yy__a;
yt_fn_in_out_i32 yy__d = yy__a;
struct yk__bstr yy__e = yk__bstr_s("Hello world" , 11);
struct yy__Enemy* t__0 = NULL;
yk__arrsetlen(t__0, INT32_C(2));
Expand Down
10 changes: 5 additions & 5 deletions compiler/test_data/compiler_tests/string_hash.yaka.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// YK
#include "yk__lib.h"
struct yt_pair_str_float { yk__sds key; float value; };
struct yt_pair_str_int { yk__sds key; int32_t value; };
struct yt_pair_str_f32 { yk__sds key; float value; };
struct yt_pair_str_i32 { yk__sds key; int32_t value; };
int32_t yy__main();
int32_t yy__main()
{
struct yt_pair_str_int* yy__m = NULL;
struct yt_pair_str_i32* yy__m = NULL;
yk__sh_new_strdup(yy__m);
yk__shput(yy__m, yk__sdsnewlen("hello", 5), INT32_C(42));
yk__shput(yy__m, yk__sdsnewlen("world", 5), INT32_C(10000));
Expand All @@ -18,12 +18,12 @@ int32_t yy__main()
yk__printstr("\"unknown\" is located at = ");
yk__printlnint((intmax_t)yk__shgeti(yy__m, yk__sdsnewlen("unknown", 7)));
yk__shfree(yy__m);
struct yt_pair_str_float* yy__m2 = NULL;
struct yt_pair_str_f32* yy__m2 = NULL;
yk__sh_new_strdup(yy__m2);
yk__shput(yy__m2, yk__sdsnewlen("hello", 5), 42.0f);
yk__printstr("hello in m2 = ");
yk__printlndbl(yk__shget(yy__m2, yk__sdsnewlen("hello", 5)));
struct yt_pair_str_float* yy__m3 = NULL;
struct yt_pair_str_f32* yy__m3 = NULL;
yk__sh_new_strdup(yy__m3);
yk__shput(yy__m3, yk__sdsnewlen("hello", 5), 123.0f);
yk__printstr("hello in m3 = ");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// YK
#include "yk__lib.h"
typedef bool (*yt_fn_in_sr_int_out_bool)(struct yk__bstr, int32_t);
typedef bool (*yt_fn_in_sr_i32_out_bool)(struct yk__bstr, int32_t);
bool yy__keep_len_n(struct yk__bstr, int32_t);
bool yy__keep_upto_n(int32_t, int32_t);
int32_t yy__main();
Expand All @@ -23,7 +23,7 @@ bool yy__keep_upto_n(int32_t yy__a, int32_t yy__n)
int32_t yy__main()
{
yk__printlnstr(">> countif sr test <<");
yt_fn_in_sr_int_out_bool yy__f = yy__keep_len_n;
yt_fn_in_sr_i32_out_bool yy__f = yy__keep_len_n;
struct yk__bstr* t__0 = NULL;
yk__arrsetcap(t__0, 5);
yk__arrput(t__0, yk__bstr_s("Hello", 5));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// YK
#include "yk__lib.h"
typedef bool (*yt_fn_in_int_int_out_bool)(int32_t, int32_t);
typedef bool (*yt_fn_in_sr_int_out_bool)(struct yk__bstr, int32_t);
typedef bool (*yt_fn_in_i32_i32_out_bool)(int32_t, int32_t);
typedef bool (*yt_fn_in_sr_i32_out_bool)(struct yk__bstr, int32_t);
bool yy__keep_len_n(struct yk__bstr, int32_t);
bool yy__keep_all(struct yk__bstr, int32_t);
bool yy__keep_upto(int32_t, int32_t);
Expand Down Expand Up @@ -44,7 +44,7 @@ bool yy__print_int(int32_t yy__a, int32_t yy__ignored)
int32_t yy__main()
{
yk__printlnstr(">> filter sr test <<");
yt_fn_in_sr_int_out_bool yy__f = yy__keep_len_n;
yt_fn_in_sr_i32_out_bool yy__f = yy__keep_len_n;
struct yk__bstr* t__2 = NULL;
yk__arrsetcap(t__2, 5);
yk__arrput(t__2, yk__bstr_s("Hello", 5));
Expand Down Expand Up @@ -106,7 +106,7 @@ int32_t yy__main()
}
t__36;
yk__printlnstr(">> filter int test <<");
yt_fn_in_int_int_out_bool yy__fi = yy__keep_upto;
yt_fn_in_i32_i32_out_bool yy__fi = yy__keep_upto;
int32_t* t__38 = NULL;
yk__arrsetcap(t__38, 10);
yk__arrput(t__38, INT32_C(1));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// YK
#include "yk__lib.h"
typedef bool (*yt_fn_in_int_int_out_bool)(int32_t, int32_t);
typedef bool (*yt_fn_in_sr_int_out_bool)(struct yk__bstr, int32_t);
typedef bool (*yt_fn_in_i32_i32_out_bool)(int32_t, int32_t);
typedef bool (*yt_fn_in_sr_i32_out_bool)(struct yk__bstr, int32_t);
bool yy__print_sr(struct yk__bstr, int32_t);
bool yy__print_add_n(int32_t, int32_t);
bool yy__print_upto_n(int32_t, int32_t);
Expand Down Expand Up @@ -30,7 +30,7 @@ bool yy__print_upto_n(int32_t yy__a, int32_t yy__n)
int32_t yy__main()
{
yk__printlnstr(">> foreach sr test <<");
yt_fn_in_sr_int_out_bool yy__f = yy__print_sr;
yt_fn_in_sr_i32_out_bool yy__f = yy__print_sr;
struct yk__bstr* t__0 = NULL;
yk__arrsetcap(t__0, 5);
yk__arrput(t__0, yk__bstr_s("Hello", 5));
Expand Down Expand Up @@ -60,7 +60,7 @@ int32_t yy__main()
}
t__13;
yk__printlnstr(">> foreach int test <<");
yt_fn_in_int_int_out_bool yy__fi = yy__print_add_n;
yt_fn_in_i32_i32_out_bool yy__fi = yy__print_add_n;
int32_t* t__15 = NULL;
yk__arrsetcap(t__15, 10);
yk__arrput(t__15, INT32_C(1));
Expand Down
Loading

0 comments on commit 6e44e68

Please sign in to comment.