Defect #763
closedExternal procedure returning REAL32 fails to compile
100%
Description
The following simplified code with is part of a SDL3 wrapper library:
libsdl3.cpp:
// SDL3 API wrapper for Linux #include <def/linuxlib> LIBRARY (sdl3, "libSDL3.so") #define SDL3FUNCTION(name, parameters) FUNCTION (sdl3, name, parameters) SDL3FUNCTION (SDL_rand, 1) SDL3FUNCTION (SDL_randf, 0)
SDL3.mod:
MODULE SDL3; IMPORT SYSTEM; TYPE PCHAR* = POINTER TO VAR- CHAR; TYPE STRING* = POINTER TO ARRAY OF CHAR; TYPE Sint32* = SIGNED32; TYPE Sint64* = SIGNED64; TYPE Uint8* = UNSIGNED8; TYPE Uint16* = UNSIGNED16; TYPE Uint32* = UNSIGNED32; TYPE Uint64* = UNSIGNED64; PROCEDURE ^ rand* ["SDL_rand"] (n : Sint32): Sint32; PROCEDURE ^ randf* ["SDL_randf"] (): REAL32; END SDL3.
Test.mod:
MODULE Test;
IMPORT SDL3;
PROCEDURE Test;
BEGIN
TRACE(SDL3.rand(100));
TRACE(SDL3.rand(100));
TRACE(SDL3.rand(100));
TRACE(SDL3.randf());
TRACE(SDL3.randf());
TRACE(SDL3.randf());
END Test;
BEGIN
Test;
END Test.
Commenting out the randf procedure this works, but
with randf this fails to compile with the following error:
obamd64: obemitter.cpp:1010: ECS::Oberon::Emitter::Context::Complex ECS::Oberon::Emitter::Context::EvaluateComplex(const ECS::Oberon::Expression&): Assertion `IsComplex (*expression.type)' failed. Aborted
This used to work with the previous release of ECS and I created these files to isolate this case.
Files
Updated by Florian Negele 21 days ago
- File trace.patch trace.patch added
- Status changed from New to Closed
- % Done changed from 0 to 100
Thank you for reporting and sorry for the inconveniences. Please apply the attached patch and note that wrappers for functions with floating-point types in their signature are not supported at the moment.
Updated by Runar Tenfjord 21 days ago
Excellent. Confirmed to work and also the library is working again.
For now I use hand created assembler wrappers:
; Call function/procedure : (arg1: LENGTH; arg2 : LENGTH; x : REAL32)[: ARG];
.code _system_call_variant_iif
.shared
pop rbx
mov rdi, [rsp + 0]
mov rsi, [rsp + 8]
movss xmm0, dword [rsp + 16]
mov r12, rsp
and rsp, ~1111b
call rax
mov rsp, r12
jmp rbx
This might be simplified by using C++ as for the runtime.
Updated by Florian Negele 21 days ago
I agree. It should even be possible to do it generically, see this experimental template class for the Windows x64 calling convention.