From 4698f29af16739226d3987d1cfd4ce93c068d897 Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Sun, 28 Jul 2019 20:53:49 +0300 Subject: [PATCH] fix pass record/array by value --- .../posix/generic/System/Mod/Kernel.cp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/cpfront/posix/generic/System/Mod/Kernel.cp b/src/cpfront/posix/generic/System/Mod/Kernel.cp index 279fef9..bf9e33d 100644 --- a/src/cpfront/posix/generic/System/Mod/Kernel.cp +++ b/src/cpfront/posix/generic/System/Mod/Kernel.cp @@ -9,7 +9,6 @@ MODULE Kernel; (* init fpu? *) (* add signal blocking to avoid race conditions in Try/Trap/TrapHandler *) (* add BeepHook for Beep *) - (* implement Call using libffi *) CONST nameLen* = 256; @@ -961,17 +960,25 @@ MODULE Kernel; farg[cn] := S.VAL(Ptype, S.ADR(typ)); END SetType; - PROCEDURE PushVal (size: INTEGER); + PROCEDURE PushAdr (size: INTEGER); BEGIN ASSERT(size IN {1, 2, 4, 8}, 20); - ASSERT(littleEndian); (* !!! swap 64bit value *) + ASSERT(littleEndian OR (size <= 4), 100); (* !!! swap 64bit value *) varg[cn] := S.ADR(par[d]); INC(cn); INC(d, MAX(1, size DIV 4)) + END PushAdr; + + PROCEDURE PushVal (size: INTEGER); + BEGIN + ASSERT(size IN {1, 2, 4, 8}, 20); + ASSERT(littleEndian OR (size <= 4), 100); (* !!! swap 64bit value *) + varg[cn] := par[d]; + INC(cn); INC(d, MAX(1, size DIV 4)) END PushVal; PROCEDURE Push (IN typ: LibFFI.type); BEGIN - SetType(typ); PushVal(typ.size) + SetType(typ); PushAdr(typ.size) END Push; BEGIN @@ -1015,7 +1022,7 @@ MODULE Kernel; targ[ut].type := LibFFI.TYPE_STRUCT; targ[ut].elements := S.VAL(PPtype, S.ADR(earg[ue])); SetType(targ[ut]); INC(ut); - size := MIN(1, typ.size); + size := MAX(1, typ.size); (* !!! better to pass original layout *) WHILE size >= 8 DO earg[ue] := S.VAL(Ptype, S.ADR(LibFFI.type_uint64)); @@ -1050,6 +1057,8 @@ MODULE Kernel; FOR i := 0 TO typ.id DIV 16 - 1 DO Push(LibFFI.type_sint32) (* dim size *) END + ELSE (* fix array *) + INC(d) (* skip size *) END END END; -- 2.29.2