Browse Source

Some Windows related fixes

Marco Bambini 4 years ago
parent
commit
a2b1c7e41c

+ 1 - 0
gravity_visualstudio/exports.def

@@ -8,6 +8,7 @@ EXPORTS
 	gravity_vm_set_callbacks
 	gravity_vm_free
 ;	gravity_vm_reset
+	gravity_vm_loadclosure
 	gravity_vm_runclosure
 	gravity_vm_runmain
 	gravity_vm_setvalue

+ 2 - 0
gravity_visualstudio/gravity.vcxproj

@@ -34,6 +34,7 @@
     <ClInclude Include="..\src\compiler\gravity_visitor.h" />
     <ClInclude Include="..\src\optionals\gravity_optionals.h" />
     <ClInclude Include="..\src\optionals\gravity_opt_env.h" />
+    <ClInclude Include="..\src\optionals\gravity_opt_file.h" />
     <ClInclude Include="..\src\optionals\gravity_opt_json.h" />
     <ClInclude Include="..\src\optionals\gravity_opt_math.h" />
     <ClInclude Include="..\src\runtime\gravity_core.h" />
@@ -65,6 +66,7 @@
     <ClCompile Include="..\src\compiler\gravity_token.c" />
     <ClCompile Include="..\src\compiler\gravity_visitor.c" />
     <ClCompile Include="..\src\optionals\gravity_opt_env.c" />
+    <ClCompile Include="..\src\optionals\gravity_opt_file.c" />
     <ClCompile Include="..\src\optionals\gravity_opt_json.c" />
     <ClCompile Include="..\src\optionals\gravity_opt_math.c" />
     <ClCompile Include="..\src\runtime\gravity_core.c" />

+ 6 - 0
gravity_visualstudio/gravity.vcxproj.filters

@@ -129,6 +129,9 @@
     <ClInclude Include="..\src\optionals\gravity_opt_math.h">
       <Filter>src\opt</Filter>
     </ClInclude>
+    <ClInclude Include="..\src\optionals\gravity_opt_file.h">
+      <Filter>src\opt</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="..\src\compiler\gravity_codegen.c">
@@ -200,5 +203,8 @@
     <ClCompile Include="..\src\optionals\gravity_opt_math.c">
       <Filter>src\opt</Filter>
     </ClCompile>
+    <ClCompile Include="..\src\optionals\gravity_opt_file.c">
+      <Filter>src\opt</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>

+ 1 - 1
src/compiler/gravity_parser.c

@@ -639,7 +639,7 @@ static gnode_t *parse_identifier_or_keyword_expression (gravity_parser_t *parser
     token_keywords_indexes(&idx_start, &idx_end);
 
     gtoken_t peek = gravity_lexer_peek(lexer);
-    if ((peek >= idx_start) && (peek <= idx_end)) {
+    if (((uint32_t)peek >= idx_start) && ((uint32_t)peek <= idx_end)) {
 
         // consume token keyword
         gtoken_t keyword = gravity_lexer_next(lexer);

+ 7 - 6
src/utils/gravity_utils.c

@@ -24,6 +24,7 @@
 #include <windows.h>
 #include <Shlwapi.h>
 #include <tchar.h>
+#include <io.h>
 #endif
 
 #include "gravity_utils.h"
@@ -193,7 +194,7 @@ char *file_name_frompath (const char *path) {
     if (!path || (path[0] == 0)) return NULL;
     
     // must be sure to have a read-write memory address
-    char *buffer = strdup(path);
+	char *buffer = string_dup(path);
     if (!buffer) return false;
     
     char *name = NULL;
@@ -201,7 +202,7 @@ char *file_name_frompath (const char *path) {
     for (size_t i=len-1; i>0; --i) {
         if (buffer[i] == PATH_SEPARATOR) {
             buffer[i] = 0;
-            name = strdup(&buffer[i+1]);
+			name = string_dup(&buffer[i + 1]);
             break;
         }
     }
@@ -353,15 +354,15 @@ int string_cmp (const char *s1, const char *s2) {
     return strcmp(s1, s2);
 }
 
-const char *string_dup (const char *s1) {
-    size_t    len = (size_t)strlen(s1);
-    char    *s = (char *)mem_alloc(NULL, len + 1);
+char *string_dup (const char *s1) {
+    size_t len = (size_t)strlen(s1);
+    char*s = (char *)mem_alloc(NULL, len + 1);
     if (!s) return NULL;
     memcpy(s, s1, len);
     return s;
 }
 
-const char *string_ndup (const char *s1, size_t n) {
+char *string_ndup (const char *s1, size_t n) {
     char *s = (char *)mem_alloc(NULL, n + 1);
     if (!s) return NULL;
     memcpy(s, s1, n);

+ 2 - 2
src/utils/gravity_utils.h

@@ -48,8 +48,8 @@ char        *directory_read_extend (DIRREF ref, char *win32buffer);
 int         string_nocasencmp (const char *s1, const char *s2, size_t n);
 int         string_casencmp (const char *s1, const char *s2, size_t n);
 int         string_cmp (const char *s1, const char *s2);
-const char  *string_dup (const char *s1);
-const char  *string_ndup (const char *s1, size_t n);
+char		*string_dup (const char *s1);
+char		*string_ndup (const char *s1, size_t n);
 void        string_reverse (char *p);
 uint32_t    string_size (const char *p);
 char        *string_strnstr(const char *s, const char *find, size_t slen);