Jump to page: 1 2
Thread overview
Would appreciate some help porting Q3VM to D (mainly C macros and type conversions)
Oct 15
barbosso
Oct 15
drug007
5 days ago
Mai Lapyst
4 days ago
Jordan Wilson
4 days ago
matheus
October 15

For the past 2 days I've been trying to port the Q3VM (https://github.com/jnz/q3vm) to D.
While most of the code is converted, it's somewhat riddled with cast statements and I'm still having trouble getting it to compile without errors.

My conversion can be found here:

https://gist.github.com/markusbkk/442a571353a48c5377c503e7d02570fb

My main problem are the macro functions at line 398 in my code, as well as the compiler telling me that "static variable codeImage cannot be read at compile time".

Would really appreciate some help with this from the D Lords of this group.

October 15

Are you heard of https://github.com/dkorpel/ctod ?

October 15

On Tuesday, 15 October 2024 at 12:27:42 UTC, barbosso wrote:

>

Are you heard of https://github.com/dkorpel/ctod ?

I actually used CTOD for part of the translation but it wouldn't translate the macros correctly. It turned them into weird string mixins.

October 15

On Tuesday, 15 October 2024 at 13:30:03 UTC, Mark Bauermeister wrote:

>

On Tuesday, 15 October 2024 at 12:27:42 UTC, barbosso wrote:

>

Are you heard of https://github.com/dkorpel/ctod ?

I actually used CTOD for part of the translation but it wouldn't translate the macros correctly. It turned them into weird string mixins.

It's not as well known, but ImportC also converts C code to D: https://dlang.org/spec/importc.html#ctod It needs the -inline switch to output function bodies. The last time I used it, there were problems with generation of duplicate items, but it was able to handle most anything I threw at it. Would be worth a try.

October 15

On Tuesday, 15 October 2024 at 16:05:48 UTC, Lance Bachmeier wrote:

>

On Tuesday, 15 October 2024 at 13:30:03 UTC, Mark Bauermeister wrote:

>

On Tuesday, 15 October 2024 at 12:27:42 UTC, barbosso wrote:

>

Are you heard of https://github.com/dkorpel/ctod ?

I actually used CTOD for part of the translation but it wouldn't translate the macros correctly. It turned them into weird string mixins.

It's not as well known, but ImportC also converts C code to D: https://dlang.org/spec/importc.html#ctod It needs the -inline switch to output function bodies. The last time I used it, there were problems with generation of duplicate items, but it was able to handle most anything I threw at it. Would be worth a try.

Thanks! That helped me figure out some more macros.

Now if only I could figure out how to resolve "variable codeImage cannot be read at compile time". That's the last thing neither of those automation solutions can help me with.

October 15
On 15.10.2024 20:37, Mark Bauermeister wrote:
> On Tuesday, 15 October 2024 at 16:05:48 UTC, Lance Bachmeier wrote:
>> On Tuesday, 15 October 2024 at 13:30:03 UTC, Mark Bauermeister wrote:
>>> On Tuesday, 15 October 2024 at 12:27:42 UTC, barbosso wrote:
>>>> Are you heard of https://github.com/dkorpel/ctod ?
>>>
>>> I actually used CTOD for part of the translation but it wouldn't translate the macros correctly. It turned them into weird string mixins.
>>
>> It's not as well known, but ImportC also converts C code to D: https://dlang.org/spec/importc.html#ctod It needs the -inline switch to output function bodies. The last time I used it, there were problems with generation of duplicate items, but it was able to handle most anything I threw at it. Would be worth a try.
> 
> Thanks! That helped me figure out some more macros.
> 
> Now if only I could figure out how to resolve "variable `codeImage` cannot be read at compile time". That's the last thing neither of those automation solutions can help me with.

if you mean line 966 you need to replace `enum` by `const` or even `auto`. `enum` means the value should be available in compile time.
6 days ago
On Tuesday, 15 October 2024 at 17:50:54 UTC, drug007 wrote:
> On 15.10.2024 20:37, Mark Bauermeister wrote:
>> On Tuesday, 15 October 2024 at 16:05:48 UTC, Lance Bachmeier wrote:
>>> [...]
>> 
>> Thanks! That helped me figure out some more macros.
>> 
>> Now if only I could figure out how to resolve "variable `codeImage` cannot be read at compile time". That's the last thing neither of those automation solutions can help me with.
>
> if you mean line 966 you need to replace `enum` by `const` or even `auto`. `enum` means the value should be available in compile time.

Ah! Makes sense. I always forget about auto. Thanks!
6 days ago
On Wednesday, 16 October 2024 at 12:28:15 UTC, Mark Bauermeister wrote:
> On Tuesday, 15 October 2024 at 17:50:54 UTC, drug007 wrote:
>> On 15.10.2024 20:37, Mark Bauermeister wrote:
>>> On Tuesday, 15 October 2024 at 16:05:48 UTC, Lance Bachmeier wrote:
>>>> [...]
>>> 
>>> Thanks! That helped me figure out some more macros.
>>> 
>>> Now if only I could figure out how to resolve "variable `codeImage` cannot be read at compile time". That's the last thing neither of those automation solutions can help me with.
>>
>> if you mean line 966 you need to replace `enum` by `const` or even `auto`. `enum` means the value should be available in compile time.
>
> Ah! Makes sense. I always forget about auto. Thanks!

I think I got every compiler complaint fixed now. However, upon launch the program immediately quits with "Error Program exited with code -11". I assume that's a segfault, right?

https://gist.github.com/markusbkk/442a571353a48c5377c503e7d02570fb
5 days ago

On Wednesday, 16 October 2024 at 13:10:34 UTC, Mark Bauermeister wrote:

>

I think I got every compiler complaint fixed now. However, upon launch the program immediately quits with "Error Program exited with code -11". I assume that's a segfault, right?

https://gist.github.com/markusbkk/442a571353a48c5377c503e7d02570fb

Yes, an exitstatus of -11 is an SIGSEGV, like in any other unix/linux program.

One thing that you might wanna change is your ARRAY_LEN function: D already supports getting the length of an array with the .length property on arrays. Also the x.sizeof divided through itself will always only yield 1.

4 days ago

On Thursday, 17 October 2024 at 02:47:03 UTC, Mai Lapyst wrote:

>

On Wednesday, 16 October 2024 at 13:10:34 UTC, Mark Bauermeister wrote:

>

I think I got every compiler complaint fixed now. However, upon launch the program immediately quits with "Error Program exited with code -11". I assume that's a segfault, right?

https://gist.github.com/markusbkk/442a571353a48c5377c503e7d02570fb

Yes, an exitstatus of -11 is an SIGSEGV, like in any other unix/linux program.

One thing that you might wanna change is your ARRAY_LEN function: D already supports getting the length of an array with the .length property on arrays. Also the x.sizeof divided through itself will always only yield 1.

Yea. I forgot about the sizeof division being wrong. I replaced all calls to ARRAY_LEN with <array>.length.

No more segfaults thus far but strangely the proper switch case (https://gist.github.com/markusbkk/442a571353a48c5377c503e7d02570fb#file-dq3vm-d-L1200) is never hit. Instead, it goes straight to the default (https://gist.github.com/markusbkk/442a571353a48c5377c503e7d02570fb#file-dq3vm-d-L1055) even though there's a matching case.

When I printf("%i", opcode) inside the default case it correctly prints "3" which is goto_OP_ENTER, so I don't quite understand why it won't hit the correct branch.

I tried adding the default case to the very bottom of the switch/case chain too, thinking maybe this is somehow sequential. But to no avail.

« First   ‹ Prev
1 2