From 9aad5a3f3a8db21eb22f2eb95d63799c1b9c1cbd Mon Sep 17 00:00:00 2001 From: tDwtp Date: Sat, 5 Aug 2023 09:44:07 +0200 Subject: [PATCH 1/5] add tcc support for compilation `make CC=tcc` will now work requires propper _WIN32 usage (always prefer _WIN32 over WIN32) --- Makefile | 29 +++-- gravity.def | 212 +++++++++++++++++++++++++++++++ src/cli/gravity.c | 2 +- src/compiler/gravity_codegen.c | 52 ++++---- src/optionals/gravity_opt_file.c | 6 +- src/shared/gravity_config.h | 4 +- src/utils/gravity_utils.c | 34 ++--- 7 files changed, 284 insertions(+), 55 deletions(-) create mode 100644 gravity.def diff --git a/Makefile b/Makefile index 6de946d..96d794c 100644 --- a/Makefile +++ b/Makefile @@ -14,13 +14,24 @@ SRC = $(wildcard $(COMPILER_DIR)*.c) \ $(wildcard $(OPT_DIR)*.c) INCLUDE = -I$(COMPILER_DIR) -I$(RUNTIME_DIR) -I$(SHARED_DIR) -I$(UTILS_DIR) -I$(OPT_DIR) -CFLAGS = $(INCLUDE) -std=gnu99 -fgnu89-inline -fPIC -DBUILD_GRAVITY_API OBJ = $(SRC:.c=.o) +CFLAGS = $(INCLUDE) -fPIC -DBUILD_GRAVITY_API +ifneq ($(CC),tcc) + CFLAGS += -std=gnu99 -fgnu89-inline +endif + + ifeq ($(OS),Windows_NT) # Windows LIBTARGET = gravity.dll - LDFLAGS = -lm -lShlwapi + LDFLAGS = -lShlwapi + ifeq ($(CC),tcc) + LDFLAGS += -lucrtbase + EXEXT = .exe + else + LDFLAGS += -lm + endif else UNAME_S := $(shell uname -s) ifeq ($(UNAME_S),Darwin) @@ -56,18 +67,18 @@ else CFLAGS += -O2 endif -all: gravity +all: gravity$(EXEXT) -gravity: $(OBJ) $(GRAVITY_SRC) +gravity$(EXEXT): $(OBJ) $(GRAVITY_SRC) $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) - -example: $(OBJ) $(EXAMPLE_SRC) + +example$(EXEXT): $(OBJ) $(EXAMPLE_SRC) $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) -lib: gravity +lib: gravity$(EXEXT) $(CC) -shared -o $(LIBTARGET) $(OBJ) $(LDFLAGS) clean: - rm -f $(OBJ) gravity example libgravity.so gravity.dll + rm -f $(OBJ) gravity gravity$(EXEXT) example example$(EXEXT) libgravity.so gravity.dll -.PHONY: all clean gravity example +.PHONY: all clean gravity$(EXEXT) example$(EXEXT) diff --git a/gravity.def b/gravity.def new file mode 100644 index 0000000..e290dbf --- /dev/null +++ b/gravity.def @@ -0,0 +1,212 @@ +LIBRARY gravity.exe + +EXPORTS +gravity_bytecode_deserialize +gravity_class_add_ivar +gravity_class_bind +gravity_class_blacken +gravity_class_count_ivars +gravity_class_deserialize +gravity_class_dump +gravity_class_free +gravity_class_free_core +gravity_class_get_meta +gravity_class_getsuper +gravity_class_grow +gravity_class_is_anon +gravity_class_is_meta +gravity_class_lookup +gravity_class_lookup_class_identifier +gravity_class_lookup_closure +gravity_class_lookup_constructor +gravity_class_new_pair +gravity_class_new_single +gravity_class_serialize +gravity_class_setsuper +gravity_class_setsuper_extern +gravity_class_setxdata +gravity_class_size +gravity_closure_blacken +gravity_closure_dec_refcount +gravity_closure_free +gravity_closure_inc_refcount +gravity_closure_new +gravity_closure_size +gravity_compiler_ast +gravity_compiler_create +gravity_compiler_free +gravity_compiler_run +gravity_compiler_serialize +gravity_compiler_serialize_infile +gravity_compiler_transfer +gravity_core_class_from_name +gravity_core_free +gravity_core_identifiers +gravity_core_init +gravity_core_register +gravity_fiber_blacken +gravity_fiber_free +gravity_fiber_new +gravity_fiber_reassign +gravity_fiber_reset +gravity_fiber_seterror +gravity_fiber_size +gravity_function_blacken +gravity_function_cpool_add +gravity_function_cpool_get +gravity_function_deserialize +gravity_function_dump +gravity_function_free +gravity_function_new +gravity_function_new_bridged +gravity_function_new_internal +gravity_function_new_special +gravity_function_params_get +gravity_function_serialize +gravity_function_setxdata +gravity_function_size +gravity_gc_setenabled +gravity_gc_setvalues +gravity_gc_start +gravity_gc_tempnull +gravity_gc_temppop +gravity_gc_temppush +gravity_gray_object +gravity_gray_value +gravity_hash_append +gravity_hash_compare +gravity_hash_compute_buffer +gravity_hash_compute_float +gravity_hash_compute_int +gravity_hash_count +gravity_hash_create +gravity_hash_dump +gravity_hash_free +gravity_hash_insert +gravity_hash_interalfree +gravity_hash_isempty +gravity_hash_iterate +gravity_hash_iterate2 +gravity_hash_iterate3 +gravity_hash_keyfree +gravity_hash_keyvaluefree +gravity_hash_lookup +gravity_hash_lookup_cstring +gravity_hash_memsize +gravity_hash_remove +gravity_hash_resetfree +gravity_hash_stat +gravity_hash_transform +gravity_hash_valuefree +gravity_instance_blacken +gravity_instance_clone +gravity_instance_deinit +gravity_instance_free +gravity_instance_isstruct +gravity_instance_lookup_event +gravity_instance_lookup_property +gravity_instance_new +gravity_instance_serialize +gravity_instance_setivar +gravity_instance_setxdata +gravity_instance_size +gravity_iscore_class +gravity_isopt_class +gravity_list_append_list +gravity_list_blacken +gravity_list_free +gravity_list_from_array +gravity_list_new +gravity_list_size +gravity_map_append_map +gravity_map_blacken +gravity_map_free +gravity_map_insert +gravity_map_new +gravity_map_size +gravity_module_blacken +gravity_module_free +gravity_module_new +gravity_module_size +gravity_object_blacken +gravity_object_debug +gravity_object_deserialize +gravity_object_free +gravity_object_serialize +gravity_object_size +gravity_opt_free +gravity_opt_register +gravity_range_blacken +gravity_range_deserialize +gravity_range_free +gravity_range_new +gravity_range_serialize +gravity_range_size +gravity_string_blacken +gravity_string_free +gravity_string_new +gravity_string_set +gravity_string_size +gravity_string_to_value +gravity_upvalue_blacken +gravity_upvalue_free +gravity_upvalue_new +gravity_upvalue_size +gravity_value_dump +gravity_value_equals +gravity_value_free +gravity_value_from_bool +gravity_value_from_error +gravity_value_from_float +gravity_value_from_int +gravity_value_from_null +gravity_value_from_object +gravity_value_from_undefined +gravity_value_getclass +gravity_value_getsuper +gravity_value_hash +gravity_value_isobject +gravity_value_name +gravity_value_serialize +gravity_value_size +gravity_value_vm_equals +gravity_value_xdata +gravity_vm_anonymous +gravity_vm_cleanup +gravity_vm_delegate +gravity_vm_fastlookup +gravity_vm_fiber +gravity_vm_filter +gravity_vm_free +gravity_vm_get +gravity_vm_getclosure +gravity_vm_getdata +gravity_vm_getslot +gravity_vm_getvalue +gravity_vm_initmodule +gravity_vm_isaborted +gravity_vm_ismini +gravity_vm_keyindex +gravity_vm_loadbuffer +gravity_vm_loadclosure +gravity_vm_loadfile +gravity_vm_lookup +gravity_vm_maxmemblock +gravity_vm_memupdate +gravity_vm_new +gravity_vm_newmini +gravity_vm_reset +gravity_vm_result +gravity_vm_runclosure +gravity_vm_runmain +gravity_vm_set +gravity_vm_set_callbacks +gravity_vm_setaborted +gravity_vm_setdata +gravity_vm_seterror +gravity_vm_seterror_string +gravity_vm_setfiber +gravity_vm_setslot +gravity_vm_setvalue +gravity_vm_time +gravity_vm_transfer diff --git a/src/cli/gravity.c b/src/cli/gravity.c index 0f122fc..ec09cee 100644 --- a/src/cli/gravity.c +++ b/src/cli/gravity.c @@ -171,7 +171,7 @@ static const char *unittest_read (const char *path, size_t *size, uint32_t *file static void unittest_scan (const char *folder_path, unittest_data *data) { DIRREF dir = directory_init(folder_path); if (!dir) return; - #ifdef WIN32 + #ifdef _WIN32 char outbuffer[MAX_PATH]; #else char *outbuffer = NULL; diff --git a/src/compiler/gravity_codegen.c b/src/compiler/gravity_codegen.c index 3e9b48a..8e662ed 100644 --- a/src/compiler/gravity_codegen.c +++ b/src/compiler/gravity_codegen.c @@ -647,47 +647,47 @@ static void visit_loop_for_stmt (gvisitor_t *self, gnode_loop_stmt_t *node) { // // to: // { - // var $expr = expr; - // var $value = $expr.iterate(null); - // while ($value) { - // cond = $expr.next($value); + // var expr = expr; + // var value = expr.iterate(null); + // while (value) { + // cond = expr.next(value); // stmp; - // $value = $expr.iterate($value); + // value = expr.iterate(value); // } // } - // $expr and $value are temporary registers that must be protected, otherwise + // expr and value are temporary registers that must be protected, otherwise // in visit_compound_statement, all temp registers are released within ircode_register_temps_clear - uint32_t $expr = ircode_register_push_temp_protected(code); // ++TEMP => 1 - uint32_t $value = ircode_register_push_temp_protected(code); // ++TEMP => 2 + uint32_t expr = ircode_register_push_temp_protected(code); // ++TEMP => 1 + uint32_t value = ircode_register_push_temp_protected(code); // ++TEMP => 2 // get cpool index for the required methods uint16_t iterate_idx = gravity_function_cpool_add(GET_VM(), context_function, VALUE_FROM_CSTRING(NULL, ITERATOR_INIT_FUNCTION)); uint16_t next_idx = gravity_function_cpool_add(GET_VM(), context_function, VALUE_FROM_CSTRING(NULL, ITERATOR_NEXT_FUNCTION)); uint32_t cond_idx = node2index(node->cond); - // generate code for $expr = expr (so expr is only evaluated once) + // generate code for expr = expr (so expr is only evaluated once) visit(node->expr); uint32_t once_expr = ircode_register_pop(code); if (once_expr == REGISTER_ERROR) report_error(self, (gnode_t *)node, "Invalid for expression."); - ircode_add(code, MOVE, $expr, once_expr, 0, LINE_NUMBER(node)); + ircode_add(code, MOVE, expr, once_expr, 0, LINE_NUMBER(node)); - // generate code for $value = $expr.iterate(null); + // generate code for value = expr.iterate(null); uint32_t iterate_fn = ircode_register_push_temp_protected(code); // ++TEMP => 3 ircode_add(code, LOADK, iterate_fn, iterate_idx, 0, LINE_NUMBER(node)); - ircode_add(code, LOAD, iterate_fn, $expr, iterate_fn, LINE_NUMBER(node)); + ircode_add(code, LOAD, iterate_fn, expr, iterate_fn, LINE_NUMBER(node)); uint32_t next_fn = ircode_register_push_temp_protected(code); // ++TEMP => 4 ircode_add(code, LOADK, next_fn, next_idx, 0, LINE_NUMBER(node)); - ircode_add(code, LOAD, next_fn, $expr, next_fn, LINE_NUMBER(node)); + ircode_add(code, LOAD, next_fn, expr, next_fn, LINE_NUMBER(node)); uint32_t temp1 = ircode_register_push_temp(code); // ++TEMP => 5 ircode_add(code, MOVE, temp1, iterate_fn, 0, LINE_NUMBER(node)); uint32_t temp2 = ircode_register_push_temp(code); // ++TEMP => 6 - ircode_add(code, MOVE, temp2, $expr, 0, LINE_NUMBER(node)); + ircode_add(code, MOVE, temp2, expr, 0, LINE_NUMBER(node)); uint32_t temp3 = ircode_register_push_temp(code); // ++TEMP => 7 ircode_add(code, LOADK, temp3, CPOOL_VALUE_NULL, 0, LINE_NUMBER(node)); - ircode_add(code, CALL, $value, temp1, 2, LINE_NUMBER(node)); + ircode_add(code, CALL, value, temp1, 2, LINE_NUMBER(node)); uint32_t temp = ircode_register_pop(code); // --TEMP => 6 DEBUG_ASSERT(temp != REGISTER_ERROR, "Unexpected register error."); temp = ircode_register_pop(code); // --TEMP => 5 @@ -704,16 +704,16 @@ static void visit_loop_for_stmt (gvisitor_t *self, gnode_loop_stmt_t *node) { ircode_setlabel_check(code, labelCheck); ircode_marklabel(code, labelTrue, LINE_NUMBER(node)); - ircode_add(code, JUMPF, $value, labelFalse, 1, LINE_NUMBER(node)); // flag JUMPF instruction to check ONLY BOOL values + ircode_add(code, JUMPF, value, labelFalse, 1, LINE_NUMBER(node)); // flag JUMPF instruction to check ONLY BOOL values - // cond = $expr.next($value); + // cond = expr.next(value); // cond is a local variable temp1 = ircode_register_push_temp_protected(code); // ++TEMP => 5 ircode_add(code, MOVE, temp1, next_fn, 0, LINE_NUMBER(node)); temp2 = ircode_register_push_temp_protected(code); // ++TEMP => 6 - ircode_add(code, MOVE, temp2, $expr, 0, LINE_NUMBER(node)); + ircode_add(code, MOVE, temp2, expr, 0, LINE_NUMBER(node)); temp3 = ircode_register_push_temp_protected(code); // ++TEMP => 7 - ircode_add(code, MOVE, temp3, $value, 0, LINE_NUMBER(node)); + ircode_add(code, MOVE, temp3, value, 0, LINE_NUMBER(node)); ircode_add(code, CALL, cond_idx, temp1, 2, LINE_NUMBER(node)); // process statement @@ -733,15 +733,15 @@ static void visit_loop_for_stmt (gvisitor_t *self, gnode_loop_stmt_t *node) { DEBUG_ASSERT(temp != REGISTER_ERROR, "Unexpected register error."); ircode_marklabel(code, labelCheck, LINE_NUMBER(node)); - // update $value for the next check - // $value = $expr.iterate($value); + // update value for the next check + // value = expr.iterate(value); temp1 = ircode_register_push_temp(code); // ++TEMP => 5 ircode_add(code, MOVE, temp1, iterate_fn, 0, LINE_NUMBER(node)); temp2 = ircode_register_push_temp(code); // ++TEMP => 6 - ircode_add(code, MOVE, temp2, $expr, 0, LINE_NUMBER(node)); + ircode_add(code, MOVE, temp2, expr, 0, LINE_NUMBER(node)); temp2 = ircode_register_push_temp(code); // ++TEMP => 7 - ircode_add(code, MOVE, temp2, $value, 0, LINE_NUMBER(node)); - ircode_add(code, CALL, $value, temp1, 2, LINE_NUMBER(node)); + ircode_add(code, MOVE, temp2, value, 0, LINE_NUMBER(node)); + ircode_add(code, CALL, value, temp1, 2, LINE_NUMBER(node)); temp = ircode_register_pop(code); // --TEMP => 6 DEBUG_ASSERT(temp != REGISTER_ERROR, "Unexpected register error."); temp = ircode_register_pop(code); // --TEMP => 5 @@ -767,8 +767,8 @@ static void visit_loop_for_stmt (gvisitor_t *self, gnode_loop_stmt_t *node) { DEBUG_ASSERT(temp != REGISTER_ERROR, "Unexpected register error."); // mark main for registers as reusable - ircode_register_temp_unprotect(code, $expr); - ircode_register_temp_unprotect(code, $value); + ircode_register_temp_unprotect(code, expr); + ircode_register_temp_unprotect(code, value); ircode_register_temp_unprotect(code, iterate_fn); ircode_register_temp_unprotect(code, next_fn); diff --git a/src/optionals/gravity_opt_file.c b/src/optionals/gravity_opt_file.c index e060070..03f84b3 100644 --- a/src/optionals/gravity_opt_file.c +++ b/src/optionals/gravity_opt_file.c @@ -168,13 +168,13 @@ static void scan_directory (gravity_vm *vm, char *path, bool recursive, gravity_ mem_free(name); gravity_value_t p2 = VALUE_FROM_CSTRING(vm, path); gravity_value_t p3 = VALUE_FROM_BOOL(true); - gravity_value_t params[] = {p1, p2, p3}; + gravity_value_t params[3] = {p1, p2, p3}; gravity_vm_runclosure(vm, closure, VALUE_FROM_NULL, params, 3); if (n) *n = *n + 1; } - #ifdef WIN32 + #ifdef _WIN32 char buffer[MAX_PATH]; #else char *buffer = NULL; @@ -192,7 +192,7 @@ static void scan_directory (gravity_vm *vm, char *path, bool recursive, gravity_ gravity_value_t p1 = VALUE_FROM_CSTRING(vm, target_file); gravity_value_t p2 = VALUE_FROM_CSTRING(vm, full_path); gravity_value_t p3 = VALUE_FROM_BOOL(false); - gravity_value_t params[] = {p1, p2, p3}; + gravity_value_t params[3] = {p1, p2, p3}; mem_free(full_path); gravity_vm_runclosure(vm, closure, VALUE_FROM_NULL, params, 3); diff --git a/src/shared/gravity_config.h b/src/shared/gravity_config.h index b539ff6..8b99587 100644 --- a/src/shared/gravity_config.h +++ b/src/shared/gravity_config.h @@ -9,7 +9,7 @@ #ifndef __GRAVITY_CONFIG__ #define __GRAVITY_CONFIG__ -#ifdef _MSC_VER +#if defined(_MSC_VER) || ( defined(__TINYC__) && defined(_WIN32) ) #pragma comment(lib, "shlwapi") #include @@ -23,7 +23,9 @@ #endif typedef SSIZE_T ssize_t; +#ifndef __TINYC__ typedef int mode_t; +#endif #define open _open #define close _close diff --git a/src/utils/gravity_utils.c b/src/utils/gravity_utils.c index a35d197..3f77eba 100644 --- a/src/utils/gravity_utils.c +++ b/src/utils/gravity_utils.c @@ -25,6 +25,10 @@ #include #include #include +#ifdef __TINYC__ +#define _WIN32_FILE_ATTRIBUTE_DATA struct _WIN32_FILE_ATTRIBUTE_DATA +#define _WIN32_FIND_DATAA struct _WIN32_FIND_DATAA +#endif #endif #if defined(__EMSCRIPTEN__) #include @@ -95,8 +99,8 @@ double millitime (nanotime_t tstart, nanotime_t tend) { // MARK: - I/O Functions - int64_t file_size (const char *path) { - #ifdef WIN32 - WIN32_FILE_ATTRIBUTE_DATA fileInfo; + #ifdef _WIN32 + _WIN32_FILE_ATTRIBUTE_DATA fileInfo; if (GetFileAttributesExA(path, GetFileExInfoStandard, (void*)&fileInfo) == 0) return -1; return (int64_t)(((__int64)fileInfo.nFileSizeHigh) << 32 ) + fileInfo.nFileSizeLow; #else @@ -107,7 +111,7 @@ int64_t file_size (const char *path) { } bool file_exists (const char *path) { - #ifdef WIN32 + #ifdef _WIN32 if (GetFileAttributesA(path) != INVALID_FILE_ATTRIBUTES) return true; #else if (access(path, F_OK) == 0) return true; @@ -117,7 +121,7 @@ bool file_exists (const char *path) { } bool file_delete (const char *path) { - #ifdef WIN32 + #ifdef _WIN32 return DeleteFileA(path); #else if (unlink(path) == 0) return true; @@ -136,7 +140,7 @@ char *file_read(const char *path, size_t *len) { if (fsize < 0) goto abort_read; int oflags = O_RDONLY; - #ifdef WIN32 + #ifdef _WIN32 // Only Windows needs to understand the difference between text and binary, so only Windows defines O_BINARY oflags |= O_BINARY; #endif @@ -185,7 +189,7 @@ char *file_buildpath (const char *filename, const char *dirpath) { char *full_path = (char *)mem_alloc(NULL, len); if (!full_path) return NULL; - #ifdef WIN32 + #ifdef _WIN32 PathCombineA(full_path, filename, dirpath); #else // check if PATH_SEPARATOR exists in dirpath @@ -220,7 +224,7 @@ char *file_name_frompath (const char *path) { // MARK: - Directory Functions - bool is_directory (const char *path) { - #ifdef WIN32 + #ifdef _WIN32 DWORD dwAttrs = GetFileAttributesA(path); if (dwAttrs == INVALID_FILE_ATTRIBUTES) return false; if (dwAttrs & FILE_ATTRIBUTE_DIRECTORY) return true; @@ -235,7 +239,7 @@ bool is_directory (const char *path) { } bool directory_create (const char *path) { - #ifdef WIN32 + #ifdef _WIN32 CreateDirectoryA(path, NULL); #else mode_t saved = umask(0); @@ -247,7 +251,7 @@ bool directory_create (const char *path) { } DIRREF directory_init (const char *dirpath) { - #ifdef WIN32 + #ifdef _WIN32 WIN32_FIND_DATAW findData; WCHAR path[MAX_PATH]; WCHAR dirpathW[MAX_PATH]; @@ -258,7 +262,7 @@ DIRREF directory_init (const char *dirpath) { // in this way I can be sure that the first file returned (and lost) is . PathCombineW(path, dirpathW, L"*"); - // if the path points to a symbolic link, the WIN32_FIND_DATA buffer contains + // if the path points to a symbolic link, the _WIN32_FIND_DATA buffer contains // information about the symbolic link, not the target return FindFirstFileW(path, &findData); #else @@ -270,7 +274,7 @@ char *directory_read (DIRREF ref, char *win32buffer) { if (ref == NULL) return NULL; while (1) { - #ifdef WIN32 + #ifdef _WIN32 WIN32_FIND_DATAA findData; if (FindNextFileA(ref, &findData) == 0) { @@ -280,7 +284,7 @@ char *directory_read (DIRREF ref, char *win32buffer) { if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; if (findData.cFileName[0] == '\0') continue; if (findData.cFileName[0] == '.') continue; - // cFileName from WIN32_FIND_DATAA is a fixed size array, and findData is local + // cFileName from _WIN32_FIND_DATAA is a fixed size array, and findData is local // This line of code is under the assumption that `win32buffer` is at least MAX_PATH in size! return !win32buffer ? NULL : memcpy(win32buffer, findData.cFileName, sizeof(findData.cFileName)); #else @@ -302,8 +306,8 @@ char *directory_read_extend (DIRREF ref, char *win32buffer) { if (ref == NULL) return NULL; while (1) { - #ifdef WIN32 - WIN32_FIND_DATAA findData; + #ifdef _WIN32 + _WIN32_FIND_DATAA findData; if (FindNextFileA(ref, &findData) == 0) { FindClose(ref); @@ -312,7 +316,7 @@ char *directory_read_extend (DIRREF ref, char *win32buffer) { if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; if (findData.cFileName[0] == '\0') continue; if (findData.cFileName[0] == '.') continue; - // cFileName from WIN32_FIND_DATAA is a fixed size array, and findData is local + // cFileName from _WIN32_FIND_DATAA is a fixed size array, and findData is local // This line of code is under the assumption that `win32buffer` is at least MAX_PATH in size! return !win32buffer ? NULL : memcpy(win32buffer, findData.cFileName, sizeof(findData.cFileName)); #else From d5dcf073b0ccaba5377ef4bb0f3bb968c534db4a Mon Sep 17 00:00:00 2001 From: tDwtp Date: Sat, 5 Aug 2023 09:48:28 +0200 Subject: [PATCH 2/5] added .def file from tcc to .gitignore .gitignore now also lists *.def for the library definition automatically generated by tcc --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index de47c87..5f409c0 100644 --- a/.gitignore +++ b/.gitignore @@ -267,6 +267,7 @@ paket-files/ *.gch # Libraries +*.def *.lib *.a *.la From dc1c893726ab1f44cd014dfa3f8a2afb3097e97e Mon Sep 17 00:00:00 2001 From: tDwtp Date: Sat, 5 Aug 2023 09:50:12 +0200 Subject: [PATCH 3/5] removed gravity.def accidentally added gravity.def fixed gitignore already, but it did not automatically remove gravity.def --- gravity.def | 212 ---------------------------------------------------- 1 file changed, 212 deletions(-) delete mode 100644 gravity.def diff --git a/gravity.def b/gravity.def deleted file mode 100644 index e290dbf..0000000 --- a/gravity.def +++ /dev/null @@ -1,212 +0,0 @@ -LIBRARY gravity.exe - -EXPORTS -gravity_bytecode_deserialize -gravity_class_add_ivar -gravity_class_bind -gravity_class_blacken -gravity_class_count_ivars -gravity_class_deserialize -gravity_class_dump -gravity_class_free -gravity_class_free_core -gravity_class_get_meta -gravity_class_getsuper -gravity_class_grow -gravity_class_is_anon -gravity_class_is_meta -gravity_class_lookup -gravity_class_lookup_class_identifier -gravity_class_lookup_closure -gravity_class_lookup_constructor -gravity_class_new_pair -gravity_class_new_single -gravity_class_serialize -gravity_class_setsuper -gravity_class_setsuper_extern -gravity_class_setxdata -gravity_class_size -gravity_closure_blacken -gravity_closure_dec_refcount -gravity_closure_free -gravity_closure_inc_refcount -gravity_closure_new -gravity_closure_size -gravity_compiler_ast -gravity_compiler_create -gravity_compiler_free -gravity_compiler_run -gravity_compiler_serialize -gravity_compiler_serialize_infile -gravity_compiler_transfer -gravity_core_class_from_name -gravity_core_free -gravity_core_identifiers -gravity_core_init -gravity_core_register -gravity_fiber_blacken -gravity_fiber_free -gravity_fiber_new -gravity_fiber_reassign -gravity_fiber_reset -gravity_fiber_seterror -gravity_fiber_size -gravity_function_blacken -gravity_function_cpool_add -gravity_function_cpool_get -gravity_function_deserialize -gravity_function_dump -gravity_function_free -gravity_function_new -gravity_function_new_bridged -gravity_function_new_internal -gravity_function_new_special -gravity_function_params_get -gravity_function_serialize -gravity_function_setxdata -gravity_function_size -gravity_gc_setenabled -gravity_gc_setvalues -gravity_gc_start -gravity_gc_tempnull -gravity_gc_temppop -gravity_gc_temppush -gravity_gray_object -gravity_gray_value -gravity_hash_append -gravity_hash_compare -gravity_hash_compute_buffer -gravity_hash_compute_float -gravity_hash_compute_int -gravity_hash_count -gravity_hash_create -gravity_hash_dump -gravity_hash_free -gravity_hash_insert -gravity_hash_interalfree -gravity_hash_isempty -gravity_hash_iterate -gravity_hash_iterate2 -gravity_hash_iterate3 -gravity_hash_keyfree -gravity_hash_keyvaluefree -gravity_hash_lookup -gravity_hash_lookup_cstring -gravity_hash_memsize -gravity_hash_remove -gravity_hash_resetfree -gravity_hash_stat -gravity_hash_transform -gravity_hash_valuefree -gravity_instance_blacken -gravity_instance_clone -gravity_instance_deinit -gravity_instance_free -gravity_instance_isstruct -gravity_instance_lookup_event -gravity_instance_lookup_property -gravity_instance_new -gravity_instance_serialize -gravity_instance_setivar -gravity_instance_setxdata -gravity_instance_size -gravity_iscore_class -gravity_isopt_class -gravity_list_append_list -gravity_list_blacken -gravity_list_free -gravity_list_from_array -gravity_list_new -gravity_list_size -gravity_map_append_map -gravity_map_blacken -gravity_map_free -gravity_map_insert -gravity_map_new -gravity_map_size -gravity_module_blacken -gravity_module_free -gravity_module_new -gravity_module_size -gravity_object_blacken -gravity_object_debug -gravity_object_deserialize -gravity_object_free -gravity_object_serialize -gravity_object_size -gravity_opt_free -gravity_opt_register -gravity_range_blacken -gravity_range_deserialize -gravity_range_free -gravity_range_new -gravity_range_serialize -gravity_range_size -gravity_string_blacken -gravity_string_free -gravity_string_new -gravity_string_set -gravity_string_size -gravity_string_to_value -gravity_upvalue_blacken -gravity_upvalue_free -gravity_upvalue_new -gravity_upvalue_size -gravity_value_dump -gravity_value_equals -gravity_value_free -gravity_value_from_bool -gravity_value_from_error -gravity_value_from_float -gravity_value_from_int -gravity_value_from_null -gravity_value_from_object -gravity_value_from_undefined -gravity_value_getclass -gravity_value_getsuper -gravity_value_hash -gravity_value_isobject -gravity_value_name -gravity_value_serialize -gravity_value_size -gravity_value_vm_equals -gravity_value_xdata -gravity_vm_anonymous -gravity_vm_cleanup -gravity_vm_delegate -gravity_vm_fastlookup -gravity_vm_fiber -gravity_vm_filter -gravity_vm_free -gravity_vm_get -gravity_vm_getclosure -gravity_vm_getdata -gravity_vm_getslot -gravity_vm_getvalue -gravity_vm_initmodule -gravity_vm_isaborted -gravity_vm_ismini -gravity_vm_keyindex -gravity_vm_loadbuffer -gravity_vm_loadclosure -gravity_vm_loadfile -gravity_vm_lookup -gravity_vm_maxmemblock -gravity_vm_memupdate -gravity_vm_new -gravity_vm_newmini -gravity_vm_reset -gravity_vm_result -gravity_vm_runclosure -gravity_vm_runmain -gravity_vm_set -gravity_vm_set_callbacks -gravity_vm_setaborted -gravity_vm_setdata -gravity_vm_seterror -gravity_vm_seterror_string -gravity_vm_setfiber -gravity_vm_setslot -gravity_vm_setvalue -gravity_vm_time -gravity_vm_transfer From 096aa22e0bf6e7e5bdaac9ac968aa5858c6368f0 Mon Sep 17 00:00:00 2001 From: tDwtp Date: Sat, 5 Aug 2023 10:12:18 +0200 Subject: [PATCH 4/5] finalize minor changes This fixes compatibility with MSVC and tcc by some simplification and the usage of typedefs of `windows.h` additionallly for em to work i added a rm.bat so tcc builds will also clean properly --- Makefile | 2 +- rm.bat | 5 +++++ src/utils/gravity_utils.c | 10 +++------- 3 files changed, 9 insertions(+), 8 deletions(-) create mode 100644 rm.bat diff --git a/Makefile b/Makefile index 96d794c..a3a7ff9 100644 --- a/Makefile +++ b/Makefile @@ -79,6 +79,6 @@ lib: gravity$(EXEXT) $(CC) -shared -o $(LIBTARGET) $(OBJ) $(LDFLAGS) clean: - rm -f $(OBJ) gravity gravity$(EXEXT) example example$(EXEXT) libgravity.so gravity.dll + rm -f $(OBJ) gravity gravity.def gravity.exe example example.def example.exe libgravity.so gravity.dll .PHONY: all clean gravity$(EXEXT) example$(EXEXT) diff --git a/rm.bat b/rm.bat new file mode 100644 index 0000000..28c621b --- /dev/null +++ b/rm.bat @@ -0,0 +1,5 @@ + +@SET OPTS= %* +@SET OPTS=%OPTS:/=\% +@SET OPTS=%OPTS: -f = /F % +@DEL %OPTS% diff --git a/src/utils/gravity_utils.c b/src/utils/gravity_utils.c index 3f77eba..856ca51 100644 --- a/src/utils/gravity_utils.c +++ b/src/utils/gravity_utils.c @@ -25,10 +25,6 @@ #include #include #include -#ifdef __TINYC__ -#define _WIN32_FILE_ATTRIBUTE_DATA struct _WIN32_FILE_ATTRIBUTE_DATA -#define _WIN32_FIND_DATAA struct _WIN32_FIND_DATAA -#endif #endif #if defined(__EMSCRIPTEN__) #include @@ -100,7 +96,7 @@ double millitime (nanotime_t tstart, nanotime_t tend) { int64_t file_size (const char *path) { #ifdef _WIN32 - _WIN32_FILE_ATTRIBUTE_DATA fileInfo; + WIN32_FILE_ATTRIBUTE_DATA fileInfo; if (GetFileAttributesExA(path, GetFileExInfoStandard, (void*)&fileInfo) == 0) return -1; return (int64_t)(((__int64)fileInfo.nFileSizeHigh) << 32 ) + fileInfo.nFileSizeLow; #else @@ -175,7 +171,7 @@ bool file_write (const char *path, const char *buffer, size_t len) { int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, mode); if (fd < 0) return false; - ssize_t nwrite = (ssize_t)write(fd, buffer, len); + ssize_t nwrite = (ssize_t)write(fd, buffer, (unsigned int)len); close(fd); return (nwrite == len); @@ -307,7 +303,7 @@ char *directory_read_extend (DIRREF ref, char *win32buffer) { while (1) { #ifdef _WIN32 - _WIN32_FIND_DATAA findData; + WIN32_FIND_DATAA findData; if (FindNextFileA(ref, &findData) == 0) { FindClose(ref); From 80e797919736e957f468ecb76a28ef2a5cfeb481 Mon Sep 17 00:00:00 2001 From: tDwtp Date: Sat, 5 Aug 2023 10:20:38 +0200 Subject: [PATCH 5/5] semantic fix on makefile when not inside a recipie (command lines) use spaces to indent. This is to distinguish between a recipie (which does not allow spaces as indentation) and makefile setup (the ifeq platform stuff for example) --- Makefile | 83 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 43 insertions(+), 40 deletions(-) diff --git a/Makefile b/Makefile index a3a7ff9..6773307 100644 --- a/Makefile +++ b/Makefile @@ -23,62 +23,65 @@ endif ifeq ($(OS),Windows_NT) - # Windows - LIBTARGET = gravity.dll - LDFLAGS = -lShlwapi - ifeq ($(CC),tcc) - LDFLAGS += -lucrtbase - EXEXT = .exe - else - LDFLAGS += -lm - endif + # Windows + LIBTARGET = gravity.dll + LDFLAGS = -lShlwapi + ifeq ($(CC),tcc) + LDFLAGS += -lucrtbase + EXEXT = .exe + else + LDFLAGS += -lm + endif else - UNAME_S := $(shell uname -s) - ifeq ($(UNAME_S),Darwin) - # MacOS - LIBTARGET = libgravity.dylib - LDFLAGS = -lm - else ifeq ($(UNAME_S),OpenBSD) - # OpenBSD - LIBTARGET = libgravity.so - LDFLAGS = -lm - else ifeq ($(UNAME_S),FreeBSD) - # FreeBSD - LIBTARGET = libgravity.so - LDFLAGS = -lm - else ifeq ($(UNAME_S),NetBSD) - # NetBSD - LIBTARGET = libgravity.so - LDFLAGS = -lm - else ifeq ($(UNAME_S),DragonFly) - # DragonFly - LIBTARGET = libgravity.so - LDFLAGS = -lm - else - # Linux - LIBTARGET = libgravity.so - LDFLAGS = -lm -lrt - endif + UNAME_S := $(shell uname -s) + ifeq ($(UNAME_S),Darwin) + # MacOS + LIBTARGET = libgravity.dylib + LDFLAGS = -lm + else ifeq ($(UNAME_S),OpenBSD) + # OpenBSD + LIBTARGET = libgravity.so + LDFLAGS = -lm + else ifeq ($(UNAME_S),FreeBSD) + # FreeBSD + LIBTARGET = libgravity.so + LDFLAGS = -lm + else ifeq ($(UNAME_S),NetBSD) + # NetBSD + LIBTARGET = libgravity.so + LDFLAGS = -lm + else ifeq ($(UNAME_S),DragonFly) + # DragonFly + LIBTARGET = libgravity.so + LDFLAGS = -lm + else + # Linux + LIBTARGET = libgravity.so + LDFLAGS = -lm -lrt + endif endif ifeq ($(mode),debug) - CFLAGS += -g -O0 -DDEBUG + CFLAGS += -g -O0 -DDEBUG else - CFLAGS += -O2 + CFLAGS += -O2 endif all: gravity$(EXEXT) -gravity$(EXEXT): $(OBJ) $(GRAVITY_SRC) +gravity$(EXEXT): $(OBJ) $(GRAVITY_SRC) $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) -example$(EXEXT): $(OBJ) $(EXAMPLE_SRC) +example$(EXEXT): $(OBJ) $(EXAMPLE_SRC) $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) lib: gravity$(EXEXT) $(CC) -shared -o $(LIBTARGET) $(OBJ) $(LDFLAGS) +cleanobj: + rm -f $(OBJ) + clean: rm -f $(OBJ) gravity gravity.def gravity.exe example example.def example.exe libgravity.so gravity.dll - + .PHONY: all clean gravity$(EXEXT) example$(EXEXT)