terralang / terra

Terra is a low-level system programming language that is embedded in and meta-programmed by the Lua programming language.
terralang.org
Other
2.72k stars 201 forks source link

Terra support for MinGW and Tiny C compiler on Windows #449

Closed ghost closed 4 years ago

ghost commented 4 years ago

I opened this issue cause of a weird something i did but worked suddenly:

In fact when i downloaded Terra's Windows release I acknowledge that Lua made with C/C++ right? As a C programmer...

So...I found that Terra has missing headers I grabbed missing headers from a copy of MinGW compiler i have,Definitely from include folder And used it with terra tests

The results was shocking when all tests worked except few (7 or 8 tests) of them,By other means language can use MinGW compiler and it's headers instead of Clang or Visual C++

Even examples gives same output as what Visual Studio should outputs (I don't use Visual Studio) So...I used a library called raylib and it's for game programming

I tested a code with it,And it works so here is the code:

-- Load raylib libraries
local rl = terralib.includecstring([[
    #include "raylib.h"
    #include "physac.h"
    #include "raygui.h"
    #include "rlgl.h"
    #include "raymath.h"
]])

-- Load C libraries for use
local C = terralib.includecstring([[
    #include "_mingw.h"
    #include "stdio.h"
    #include "stdbool.h"
    #include "stdint.h"
    #include "stdlib.h"
    #include "time.h"
    #include "string.h"
    #include "strings.h"
    #include "unistd.h"
]])

function main()
    rl.InitWindow(0,0,"MadeWithTerra")
    rl.SetTargetFPS(60)
    while not rl.WindowShouldClose() do
        rl.BeginDrawing()
            rl.ClearBackground(rl.RAYWHITE)
            rl.DrawText("TERRA OR TERRABYTE?",10,10,32,rl.BLUE)
        rl.EndDrawing()
    end
    rl.CloseWindow()
    return 0
end
main()

But the output:

D:\terra\examples>..\bin\terra.exe core_basic_window.t
0   unknown                             0x0000000000000000
1   C                                   0x00007ff9c9519179 lua_yield + 62985
2   unknown                             0x0000000000010661
3   unknown                             0x0000000000000c01
4   unknown                             0x000001bd8c000c01
5   unknown                             0xffffffffff000c01
6   unknown                             0x000001bd8c000c01
7   unknown                             0x0000000000000c01
8   unknown                             0x0000000000000c01
9   unknown                             0x0000000000000c01
10  unknown                             0x0000000000000c01
11  unknown                             0x0000000000000c01
12  unknown                             0x0000000000000c01
13  unknown                             0x0000000000000c01
14  unknown                             0x0000000000000c01
15  unknown                             0x0000000000000c01
16  unknown                             0xfffd81bd8c000c01
17  unknown                             0xfffd81bd8c000c01
18  unknown                             0xfffd81bd8c000c01
19  unknown                             0xfffd81bd8c000c01
20  unknown                             0x000001bd8c000c01
21  unknown                             0x0000000000000c01
22  unknown                             0x0000000000000c01
23  unknown                             0x0000000000000c01
24  unknown                             0x0000000000000c01
25  unknown                             0x0000000000000c01
26  unknown                             0x0000000000000c01
27  unknown                             0xfffd81bd8c000c01
28  unknown                             0x000001bd8c000c01
29  unknown                             0x0000000000000c01
30  unknown                             0x0000000000000c01
31  unknown                             0x0000000000000c01
32  unknown                             0x000001bd8c000c01
33  unknown                             0x0000000000000c01
34  unknown                             0x0000000000000c01
35  unknown                             0x0000000000000c01
36  unknown                             0x0000000000000c01
37  unknown                             0x000001bd8c000c01
38  unknown                             0x0000000000020c01
39  unknown                             0x0000000000000c01
40  unknown                             0x0000000000000c01
41  unknown                             0x0000000000010c01
42  unknown                             0x0000000000010c01

In fact it's related to this issue Where who opened the related issue got same output i got,See here

Note that there is different output on Linux,You only get what i got if you use Microsoft Windows

And i even said that code works without errors in that issue,But i don't know what causes this Can someone believe me and believe that Terra works on MinGW?!! So if i'm right,That means i can also run it on Tiny C (If possible...)

Sorry for posting by this bad way... Thanks for support!!!

ghost commented 4 years ago

And to know where i placed headers,I placed them in include folder of Terra language compiler

I also copied them to beside test files,In fact you are not forced to place them in include folder as i did first cause tests worked just by placing headers beside them

Where you write a terra program,Place headers beside it Almost copy them from your copy of MinGW but not all cause few headers are just required See code example above for included headers,From line 12...

Hope someone respond,Thanks!!!

elliottslaughter commented 4 years ago

Hi there,

If you just want a way to add new include directories, you can do that with INCLUDE_PATH. That doesn't give you a way to set the linker though.

FYI, I do think we embed all/most of the headers that are bundled with Clang, but I don't think that actually gets us 100% of what we need, I think we still need the platform headers.

Just to set some expectations (also in reference to the other thread, which I skimmed briefly): This is an entirely volunteer project. No one on this project does it for their work (as far as I know) except in a very minimal way. We're happy to accept (reasonable) pull requests for new features and to provide some guidance on how to implement things, but in general people's time is limited. Therefore the best way to get things done is to push them forward on your own. For example, the reason why Terra's MSVC support is good is because of community effort. I'm sure we can add MinGW or tcc support as well but it will require some effort on your part.

Hope that helps.

ghost commented 4 years ago

About the way to include directories,Thank you!!! Terra compiler works so i don't need to push something to the repo,Just include headers But the problem of can't passing floats to C function is the problem

Every example i write it works,But the problem of can't passing floats to C function still happened If you can add this note below i'll be grateful

Terra also works with MinGW but you need to include MinGW include path