system/corennnnn
Revisión | 37c54bd22e2ac5ca8601416701e14b546ce5b6f1 (tree) |
---|---|
Tiempo | 2009-07-15 10:35:36 |
Autor | Jack Palevich <jackpal@goog...> |
Commiter | Jack Palevich |
Make forward declarations of external symbols really work.
Until now we had always been treating external variables as "int",
and external functions as int (...);
@@ -2610,7 +2610,7 @@ class Compiler : public ErrorSink { | ||
2610 | 2610 | } |
2611 | 2611 | |
2612 | 2612 | virtual void convertR0(Type* pType){ |
2613 | - fprintf(stderr, "convertR0(pType)\n"); | |
2613 | + fprintf(stderr, "convertR0(pType tag=%d)\n", pType->tag); | |
2614 | 2614 | mpBase->convertR0(pType); |
2615 | 2615 | } |
2616 | 2616 |
@@ -3672,7 +3672,7 @@ class Compiler : public ErrorSink { | ||
3672 | 3672 | #if 0 |
3673 | 3673 | { |
3674 | 3674 | String buf; |
3675 | - decodeToken(buf, tok); | |
3675 | + decodeToken(buf, tok, true); | |
3676 | 3676 | fprintf(stderr, "%s\n", buf.getUnwrapped()); |
3677 | 3677 | } |
3678 | 3678 | #endif |
@@ -3883,10 +3883,12 @@ class Compiler : public ErrorSink { | ||
3883 | 3883 | /* forward reference: try dlsym */ |
3884 | 3884 | if (!n) { |
3885 | 3885 | n = (intptr_t) dlsym(RTLD_DEFAULT, nameof(t)); |
3886 | - if (tok == '(') { | |
3887 | - pVI->pType = mkpIntFn; | |
3888 | - } else { | |
3889 | - pVI->pType = mkpInt; | |
3886 | + if (pVI->pType == NULL) { | |
3887 | + if (tok == '(') { | |
3888 | + pVI->pType = mkpIntFn; | |
3889 | + } else { | |
3890 | + pVI->pType = mkpInt; | |
3891 | + } | |
3890 | 3892 | } |
3891 | 3893 | pVI->pAddress = (void*) n; |
3892 | 3894 | } |
@@ -4156,7 +4158,7 @@ class Compiler : public ErrorSink { | ||
4156 | 4158 | |
4157 | 4159 | String temp; |
4158 | 4160 | if (pType->id != 0) { |
4159 | - decodeToken(temp, pType->id); | |
4161 | + decodeToken(temp, pType->id, false); | |
4160 | 4162 | buffer.append(temp); |
4161 | 4163 | } |
4162 | 4164 |
@@ -4166,7 +4168,7 @@ class Compiler : public ErrorSink { | ||
4166 | 4168 | void decodeTypeImpPrefix(String& buffer, Type* pType) { |
4167 | 4169 | TypeTag tag = pType->tag; |
4168 | 4170 | |
4169 | - if (tag >= TY_INT && tag <= TY_VOID) { | |
4171 | + if (tag >= TY_INT && tag <= TY_DOUBLE) { | |
4170 | 4172 | switch (tag) { |
4171 | 4173 | case TY_INT: |
4172 | 4174 | buffer.appendCStr("int"); |
@@ -4343,7 +4345,7 @@ class Compiler : public ErrorSink { | ||
4343 | 4345 | error("Symbol %s not allowed here", nameof(declName)); |
4344 | 4346 | } else if (nameRequired && ! declName) { |
4345 | 4347 | String temp; |
4346 | - decodeToken(temp, tok); | |
4348 | + decodeToken(temp, tok, true); | |
4347 | 4349 | error("Expected symbol. Got %s", temp.getUnwrapped()); |
4348 | 4350 | } |
4349 | 4351 | } |
@@ -4395,7 +4397,7 @@ class Compiler : public ErrorSink { | ||
4395 | 4397 | Type* pType = acceptPrimitiveType(arena); |
4396 | 4398 | if (!pType) { |
4397 | 4399 | String buf; |
4398 | - decodeToken(buf, tok); | |
4400 | + decodeToken(buf, tok, true); | |
4399 | 4401 | error("Expected a type, got %s", buf.getUnwrapped()); |
4400 | 4402 | } |
4401 | 4403 | return pType; |
@@ -4455,7 +4457,7 @@ class Compiler : public ErrorSink { | ||
4455 | 4457 | return checkSymbol(tok); |
4456 | 4458 | } |
4457 | 4459 | |
4458 | - void decodeToken(String& buffer, tokenid_t token) { | |
4460 | + void decodeToken(String& buffer, tokenid_t token, bool quote) { | |
4459 | 4461 | if (token == EOF ) { |
4460 | 4462 | buffer.printf("EOF"); |
4461 | 4463 | } else if (token == TOK_NUM) { |
@@ -4466,10 +4468,16 @@ class Compiler : public ErrorSink { | ||
4466 | 4468 | } else { |
4467 | 4469 | buffer.printf("'%c'", token); |
4468 | 4470 | } |
4469 | - } else if (token >= TOK_KEYWORD && token < TOK_SYMBOL) { | |
4470 | - buffer.printf("keyword \"%s\"", nameof(token)); | |
4471 | 4471 | } else { |
4472 | - buffer.printf("symbol \"%s\"", nameof(token)); | |
4472 | + if (quote) { | |
4473 | + if (token >= TOK_KEYWORD && token < TOK_SYMBOL) { | |
4474 | + buffer.printf("keyword \"%s\"", nameof(token)); | |
4475 | + } else { | |
4476 | + buffer.printf("symbol \"%s\"", nameof(token)); | |
4477 | + } | |
4478 | + } else { | |
4479 | + buffer.printf("%s", nameof(token)); | |
4480 | + } | |
4473 | 4481 | } |
4474 | 4482 | } |
4475 | 4483 |
@@ -4477,7 +4485,7 @@ class Compiler : public ErrorSink { | ||
4477 | 4485 | bool result = token >= TOK_SYMBOL; |
4478 | 4486 | if (!result) { |
4479 | 4487 | String temp; |
4480 | - decodeToken(temp, token); | |
4488 | + decodeToken(temp, token, true); | |
4481 | 4489 | error("Expected symbol. Got %s", temp.getUnwrapped()); |
4482 | 4490 | } |
4483 | 4491 | return result; |
@@ -0,0 +1,9 @@ | ||
1 | + | |
2 | +float fabsf(float); | |
3 | + | |
4 | +int main(void* con, int ft, int launchID) | |
5 | +{ | |
6 | + float f = fabsf(-10.0f); | |
7 | + return f; | |
8 | +} | |
9 | + |
@@ -262,6 +262,10 @@ Pointer addition: 2 | ||
262 | 262 | Pointer comparison to zero: 0 0 1 |
263 | 263 | Pointer comparison: 1 0 0 0 1 |
264 | 264 | """) |
265 | + def testRollo3(self): | |
266 | + self.compileCheck(["-R", "data/rollo3.c"], """Executing compiled code: | |
267 | +result: 10""", """""") | |
268 | + | |
265 | 269 | |
266 | 270 | |
267 | 271 | if __name__ == '__main__': |