On 18/02/24 21:33, Malcolm McLean wrote:
> Meeting with the boss the other day, and the upshot is that I've got
> three months to do exactly as I like. It doesn't have to be anything of
> any commercial value to the company. Part of the idea is to give me a
> bit of a rest, so nothing too ambitious.
>
> Anyone any suggestions?
Can you help with SubC?
I'm not good with complex algorithms, so there are
bugs that I can't fix.
E.g. I have this code:
D:\devel\subc\src>type foo.c
typedef int xxx;
int foo(void)
{
xxx yyy;
yyy = 4;
return (xxx)3;
}
D:\devel\subc\src>
and (with debug) it is giving this error:
D:\devel\subc\src>scc -S foo.c
hit here
p is 2
three
four
p is 7
three
error: foo.c: 8: void value in expression
D:\devel\subc\src>
Those "p" values are
2 - PINT
7 - PVOID
The code that is failing is here:
expr.c:
static node *exprlist(int *lv, int ckvoid) {
node *n, *n2;
int p;
n2 = NULL;
n = asgmnt(lv);
p = lv[LVPRIM];
printf("p is %d\n", p);
if (COMMA == Token) n = rvalue(n, lv);
while (COMMA == Token) {
Token = scan();
n2 = asgmnt(lv);
n2 = rvalue(n2, lv);
p = lv[LVPRIM];
printf("p is %d\n", p);
n = mkbinop(OP_COMMA, n, n2);
}
printf("three\n");
/* return not working here */
if (ckvoid) notvoid(p);
printf("four\n");
return n;
}
And at this point I don't know what to do.
I looked in decl.c and I thought this might be the right track:
void typedecl(void) {
int utype, prim;
Token = scan();
if (STRUCT == Token || UNION == Token) {
structdecl(CTYPE, UNION == Token);
}
else if (ENUM == Token) {
enumdecl(1);
}
else if ((utype = usertype(Text)) != 0) {
Token = scan();
decl(CTYPE, Prims[utype], utype);
}
else {
prim = primtype(Token, NULL);
printf("hit here\n");
Token = scan();
decl(CTYPE, prim, 0);
ie the decl call (below "hit here") may need to do something
more to set the primary type to int. ie that CTYPE needs to
be converted into a variable name in the "lv" array.
But it's beyond my current ability to solve.
If you can suggest something to try, I can
give that a go.
Note that if you are on the company time, I don't
want you to make any code changes, as they could
potentially claim copyright over it.
However, if you can simply give me advice, I can
try to make the code change myself.
The latest code is on the PDOS/386 disk (\devel\subc\src
in pdos.vhd in pdos.zip at
http://pdos.org), but I can make
it available standalone or email if you are interested.
BFN. Paul.