add non-GCC support to compile.c and potion.c
This is generating lots of test fails, IDK why. "test/classes/sub.pn: expected <(7, 52, 9, 81)>, but got <(7, 52, nil, nil)>" is a known failure before this patch, but "expected <105>, but got <>" stuff is new. Cygwin make test example below
--------------------------------------------------------------------------------------------------------------
running potion VM tests
....
test/classes/sub.pn: expected <(7, 52, 9, 81)>, but got <(7, 52, nil, nil)>
..............
test/flow/except.pn: expected <TRY 1
TRY ERROR!
RESUMING
SUCCESS
TRY 2
SUCCESS
nil>, but got <TRY 1
TRY 2
SUCCESS
nil>
..............................................................
running potion compiler tests
test/classes/creature.pn: expected <((45, 65, 27, 89), (10, 44, 44, 4), 3)>, but got <>
test/classes/def.pn: expected <203>, but got <>
test/classes/meta.pn: expected <1677>, but got <>
test/classes/monkey.pn: expected <159>, but got <>
test/classes/sub.pn: expected <(7, 52, 9, 81)>, but got <>
test/closures/arg0.pn: expected <no arguments and highly sparse>, but got <>
test/closures/default.pn: expected <(1, 0, 1, 1, function(x:=0,y:=1), 2)>, but got <>
test/closures/inspect.pn: expected <function(x,y)>, but got <>
test/closures/long.pn: expected <105>, but got <>
test/closures/named.pn: expected <(1, -77, 97, XXX, Kiriku)>, but got <>
test/closures/nested.pn: expected <60>, but got <>
test/closures/passing.pn: expected <58>, but got <>
test/closures/upvals.pn: expected <(function(), 17, 45, 67, 23, true, 16, (nil, nil), (b=2))>, but got <>
test/data/grammar.pn: expected <[grammar [digit <- n:[0-9] { n number }, value <- d:digit+ | '(' e:expr ')' { d or e }, expr <- l:value op:[*/] r:value
{
if (op == '*'): l * r. else: l / r.
}, main <- expr]]>, but got <>
test/data/html.pn: expected <<html><body(margin=0)><p>SUPERIOR!</p><em></em><strong(padding=2)></strong></body></html>nil>, but got <>
test/data/string.pn: expected <([potion 0.0 (date=2009-06-16)], [app [stack [button Mice, button Eagles, button Quail]]])>, but got <>
test/flow/break.pn: expected <(10, 10, 10)>, but got <>
test/flow/callcc.pn: expected <Ringo
Max
Ron
nil>, but got <>
test/flow/continue.pn: expected <(0, (20, 10), (10, 10))>, but got <>
test/flow/except.pn: expected <TRY 1
TRY ERROR!
RESUMING
SUCCESS
TRY 2
SUCCESS
nil>, but got <>
test/flow/if.pn: expected <(14, 16, 12, Lobby, 10)>, but got <>
test/flow/mixed.pn: expected <Seth>, but got <>
test/flow/return.pn: expected <(1, 2, 3, nil, nil)>, but got <>
test/flow/while.pn: expected <4>, but got <>
test/lists/alloc.pn: expected <(nil, 1, nil)>, but got <>
test/lists/at.pn: expected <(germans, nil, bottles, exists, bottles)>, but got <>
test/lists/map.pn: expected <(1, 2, 3)>, but got <>
crash is C stack recursion/exhaustion, IDK why it doesn't happen in macro implementation (before this patch)
(gdb) bt
#0 0x6e89970f in __luaS_hash_string (s=0xfb5930ac "@\001") at core/khash.h:188
#1 0x6e899828 in kh_get_str (P=0xfff90038, h=0xfff9a778,
key=0xfb5930ac "@\001") at core/table.h:47
#2 0x6e89a18f in potion_lookup_str (P=0xfff90038, str=0xfb5930ac "@\001")
at core/string.c:28
#3 0x6e89a2cd in potion_str2 (P=0xfff90038, str=0xfff9c5c0 "@\001", len=19)
at core/string.c:55
#4 0x6e887857 in potion_read_const (P=0xfff90038, pn=4,
ptr=0xfff9c5c0 "@\001") at core/compile.c:934
#5 0x6e8878c8 in potion_read_values (P=0xfff90038, pn=4 '\004',
ptr=0xfff9c5c0 "@\001") at core/compile.c:947
#6 0x6e8879f7 in potion_proto_load (P=0xfff90038, up=4216913984, pn=4 '\004',
ptr=0x331bc) at core/compile.c:964
#7 0x6e88794e in potion_read_protos (P=0xfff90038, f=0xfb590040, pn=4 '\004',
ptr=0xfff9c5c0 "@\001") at core/compile.c:953
#8 0x6e887aca in potion_proto_load (P=0xfff90038, up=4216901976, pn=4 '\004',
ptr=0x3323c) at core/compile.c:970
#9 0x6e88794e in potion_read_protos (P=0xfff90038, f=0xfb58d158, pn=4 '\004',
ptr=0xfff9c5c0 "@\001") at core/compile.c:953
#10 0x6e887aca in potion_proto_load (P=0xfff90038, up=4216889968, pn=4 '\004',
ptr=0x332bc) at core/compile.c:970
#11 0x6e88794e in potion_read_protos (P=0xfff90038, f=0xfb58a270, pn=4 '\004',
ptr=0xfff9c5c0 "@\001") at core/compile.c:953
---Type <return> to continue, or q <return> to quit---
#12 0x6e887aca in potion_proto_load (P=0xfff90038, up=4216877960, pn=4 '\004',
ptr=0x3333c) at core/compile.c:970
#13 0x6e88794e in potion_read_protos (P=0xfff90038, f=0xfb587388, pn=4 '\004',
ptr=0xfff9c5c0 "@\001") at core/compile.c:953
#14 0x6e887aca in potion_proto_load (P=0xfff90038, up=4216865952, pn=4 '\004',
ptr=0x333bc) at core/compile.c:970
#15 0x6e88794e in potion_read_protos (P=0xfff90038, f=0xfb5844a0, pn=4 '\004',
ptr=0xfff9c5c0 "@\001") at core/compile.c:953
#16 0x6e887aca in potion_proto_load (P=0xfff90038, up=4216853944, pn=4 '\004',
ptr=0x3343c) at core/compile.c:970
#17 0x6e88794e in potion_read_protos (P=0xfff90038, f=0xfb5815b8, pn=4 '\004',
ptr=0xfff9c5c0 "@\001") at core/compile.c:953
#18 0x6e887aca in potion_proto_load (P=0xfff90038, up=4216841936, pn=4 '\004',
ptr=0x334bc) at core/compile.c:970
#19 0x6e88794e in potion_read_protos (P=0xfff90038, f=0xfb57e6d0, pn=4 '\004',
ptr=0xfff9c5c0 "@\001") at core/compile.c:953
#20 0x6e887aca in potion_proto_load (P=0xfff90038, up=4216829928, pn=4 '\004',
ptr=0x3353c) at core/compile.c:970
#21 0x6e88794e in potion_read_protos (P=0xfff90038, f=0xfb57b7e8, pn=4 '\004',
ptr=0xfff9c5c0 "@\001") at core/compile.c:953
#22 0x6e887aca in potion_proto_load (P=0xfff90038, up=4216817920, pn=4 '\004',
ptr=0x335bc) at core/compile.c:970
#23 0x6e88794e in potion_read_protos (P=0xfff90038, f=0xfb578900, pn=4 '\004',
(gdb) disas
Dump of assembler code for function __luaS_hash_string:
0x6e899706 <+0>: push %ebp
0x6e899707 <+1>: mov %esp,%ebp
0x6e899709 <+3>: sub $0x28,%esp
0x6e89970c <+6>: mov 0x8(%ebp),%eax
=> 0x6e89970f <+9>: mov %eax,(%esp)
0x6e899712 <+12>: call 0x6e8ba288
How should we name this branch? msvc or c89 or non-c99 maybe?
I'm aiming for C99-ish (ish because the Intel C uses the MS VC C89 headers atleast for me, language is C99, non constant length arrays are ok), so it is not MSVC compatiblity. I am getting rid of the GCC statement expressions which Win32 Intel C wont compile. But 2 of the inline funcs nee macros are causing c stack exhaustion (the GDB callstack went back 1000s of frames in the potion_read_protos/potion_proto_load combination ) on the GCC build .
Here is the preprocessed version of the 2 funcs.
inline static PN
potion_read_protos (Potion * P, struct PNProto *volatile f, u8 pn, u8 * ptr)
{
long i = 0, count = potion_read_u8 (ptr);
PN tup = potion_tuple_with_size (P, (PN_SIZE) count);
for (; i < count; i++)
((struct PNTuple *) potion_fwd ((PN) tup))->set[i] =
potion_proto_load (P, (PN) f, pn, &(ptr));
return tup;
}
PN
potion_proto_load (Potion * P, PN up, u8 pn, u8 ** ptr)
{
PN len = 0;
PNAsm *volatile asmb = ((void *) 0);
struct PNProto *volatile f =
(struct PNProto *) potion_gc_alloc (P, (13 + 0x250000),
sizeof (struct PNProto));
f->source = potion_read_const (P, pn, *ptr);
if (f->source == ((PN) 0))
f->source = up;
f->sig = potion_read_values (P, pn, *ptr);
f->stack = potion_read_const (P, pn, *ptr);
f->values = potion_read_values (P, pn, *ptr);
f->paths = potion_read_values (P, pn, *ptr);
f->locals = potion_read_values (P, pn, *ptr);
f->upvals = potion_read_values (P, pn, *ptr);
f->protos = potion_read_protos (P, f, pn, *ptr);
len = potion_read_pn (pn, (PN *) * ptr);
(asmb) =
(PNAsm *) potion_gc_alloc (P, (12 + 0x250000),
sizeof (PNAsm) +
(sizeof (*(asmb)->ptr) * len));
(asmb)->siz = sizeof (*(asmb)->ptr) * len;
(asmb)->len = 0;
memcpy ((void *) (asmb->ptr), (void *) (*ptr), sizeof (u8) * (len));
asmb->len = len;
f->asmb = (PN) asmb;
f->localsize = ((struct PNTuple *) potion_fwd ((PN) f->locals))->len;
f->upvalsize = ((struct PNTuple *) potion_fwd ((PN) f->upvals))->len;
f->pathsize = ((struct PNTuple *) potion_fwd ((PN) f->paths))->len;
*ptr += len;
return (PN) f;
}