[M3devel] zero sized structs?
Jay K
jay.krell at cornell.edu
Thu Oct 4 08:25:53 CEST 2012
declare_local noArgs 0 8 Struct -1522787086 T F 50 v.318
and here is some relevant M3x86 code:
IF u.in_proc THEN v := get_temp_var (u, type, s, a, n); ELSE v := create_temp_var (u, type, s, a, n); END;
PROCEDURE get_temp_var (u: U; type: Type; s: ByteSize; a: Alignment; n: Name := M3ID.NoID): x86Var = BEGIN
(* round size and alignment up to 4 *)
IF s < 4 THEN s := 4; END;
IF a < 4 THEN a := 4; END;
PROCEDURE create_temp_var (u: U; type: Type; s: ByteSize; a: Alignment; n: Name): x86Var = VAR v := NewVar(u, type, 0, s, a, n); BEGIN v.loc := VLoc.temp; v.parent := u.current_proc;
u.current_proc.framesize := Word.And(u.current_proc.framesize + a - 1, Alignmask[a]);
INC(u.current_proc.framesize, s);
v.offset := -u.current_proc.framesize;
RETURN v; END create_temp_var;
which isn't clear by inspection...it actually looks likezero size is allowed through commonly...in_proc is rare,so create is common...assuming the frame is already aligned,the size remains unchanged...
Relevant aside: I have been ignoring alignment.I'm inclined to go with something like:
<* ASSERT (size MOD alignment) = 0 *>
If that ever fails, then I will change it to:
FUNCTION RoundUp(a, b: INTEGER): INTEGER =BEGIN WITH c = a MOD b DO IF c # 0 THEN RETURN a + b - c; END; END; RETURN a;END;
size := RoundUp(size, alignment);
and then, more to the point, I'll go with:
IF size = 0 THEN size = 1;END;
I haven't dug into what the gcc backend would do here, too muchto dig through. :)
Thoughts?
I guess I should try both m3x86 and m3cc, and print the addressof these things????
- Jay
From: jay.krell at cornell.edu
To: m3devel at elegosoft.com
Date: Thu, 4 Oct 2012 06:13:28 +0000
Subject: [M3devel] zero sized structs?
Building obliqrt I get:
****** runtime error:*** <*ASSERT*> failed.*** file "../src/M3C.m3", line 1768***
PROCEDURE GetStructSizes_Declare(self: GetStructSizes_t; type: Type; byte_size: ByteSize): M3CG.Var =BEGIN IF type = Type.Struct THEN <* ASSERT byte_size > 0 *> self.sizes[self.count] := byte_size; INC(self.count); END; RETURN NIL;END GetStructSizes_Declare;
due to presumably:
PROCEDURE ApplyThreadClosure (self: ObliqThreadClosure): REFANY = VAR noArgs: ARRAY [0 .. -1] OF ObValue.Val;
...
PROCEDURE HandleWork (self: ObliqWork) = VAR noArgs: ARRAY [0 .. -1] OF ObValue.Val;
..PROCEDURE EvalThread ( self : PackageThread;...noArgs : ARRAY [0 .. -1] OF ObValue.Val;
What is the meaning of this?
- Jay
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20121004/e8c4959a/attachment-0002.html>
More information about the M3devel
mailing list