gonzula / splash

Simple Programming LAnguage for SHortcuts
GNU General Public License v3.0
231 stars 16 forks source link

Windows tweaks #26

Open IngwiePhoenix opened 4 years ago

IngwiePhoenix commented 4 years ago

I wanted to fool around with this for a while, so I made adjustments to make this work on Windows.

To reproduce:

Add this makefile: Makefile.win32

splash: lexycal syntax compile
        @echo DONE

lexycal:
        win_flex.exe --wincompat -o compiler/lex.yy.c compiler/splash.lm
syntax:
        win_bison.exe -d compiler/splash.ym -o compiler/splash.tab.c

compile:
        cl.exe /nologo compiler\structures/*.c compiler\scope.c compiler\action.c compiler\output.c compiler\utils.c compiler\splash_helper.c compiler\interpolated.c compiler\lex.yy.c compiler\splash.tab.c compiler\main.c /Fe:splash

# Not implemented properly...
.PHONY : clean
clean:
        @rm \
                compiler/splash.tab.c \
                compiler/lex.yy.c \
                compiler/y.tab.c \
                splash \
                2> /dev/null || :

And apply this patch:

diff --git a/compiler/main.c b/compiler/main.c
index fd3bdb4..8b41cf3 100644
--- a/compiler/main.c
+++ b/compiler/main.c
@@ -8,5 +8,6 @@ main(int argc, char *argv[]) {
         fprintf(stderr, "usage: %s <input splash file> <output shortcut>\n", argv[0]);
         return EXIT_FAILURE;
     }
-    return parse(argv[1], argv[2]);
+    char* err_ptr;
+    return parse(argv[1], argv[2], &err_ptr);
 }
diff --git a/compiler/structures/refcnt.c b/compiler/structures/refcnt.c
index 28b0aa4..456f736 100755
--- a/compiler/structures/refcnt.c
+++ b/compiler/structures/refcnt.c
@@ -11,7 +11,12 @@ typedef struct {
 void *
 alloc(size_t size, refcnt_obj_free freeFunc) {
     _refcnt_objwrapper *ow;
+    #ifdef _WIN32
+    // Windows-specific fix regarding cl.exe: https://social.msdn.microsoft.com/Forums/vstudio/en-US/043c1583-cbf3-4402-93c2-efc55cd70892/error-c2036-void-unknown-size?forum=vcgeneral
+    char *ptr;
+    #else
     void *ptr;
+    #endif

     ow = (_refcnt_objwrapper *)calloc(1, sizeof(_refcnt_objwrapper) + size);
     ptr = ow;
@@ -27,7 +32,12 @@ void
 retain(void *ptr) {
     if (!ptr) return;
     _refcnt_objwrapper * ow;
+    #ifdef _WIN32
+    // Windows-specific fix regarding cl.exe: https://social.msdn.microsoft.com/Forums/vstudio/en-US/043c1583-cbf3-4402-93c2-efc55cd70892/error-c2036-void-unknown-size?forum=vcgeneral
+    char *cptr;
+    #else
     void *cptr;
+    #endif
     cptr  = ptr;
     cptr -= sizeof(_refcnt_objwrapper);
     ow = (_refcnt_objwrapper *)cptr;

Then: make -f Makefile.win32 splash Et voila, there is a splash.exe :) ... and a crapload of .obj files. I didn't go all the way to not make these go into temporary folders or something. Anyway, this got a seemingly working binary. Compiling the age example seemed to work - now all that is left is to make it run on my phone ^^

Enjoy!