DEADSOFTWARE

fix pass record/array by value
[cpc.git] / src / cpfront / posix / generic / System / Mod / Kernel.cp
index 279fef9483a2960fa170d6ef66c71e7771eae372..bf9e33d9a4f94021cbdae310e7884ba6d5e9a673 100644 (file)
@@ -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;