Loading libacc/acc.cpp +63 −47 Original line number Diff line number Diff line Loading @@ -1854,11 +1854,6 @@ class Compiler : public ErrorSink { Vector<Mark> mLevelStack; }; struct Value { Type* pType; bool mLValue; // This is the L-value (true means the lvalue) }; int ch; // Current input character, or EOF tokenid_t tok; // token intptr_t tokc; // token extra info Loading @@ -1884,13 +1879,12 @@ class Compiler : public ErrorSink { Type* mkpInt; Type* mkpChar; Type* mkpVoid; Type* mkpFloat; Type* mkpDouble; Type* mkpIntPtr; Type* mkpCharPtr; Type* mkpPtrIntFn; // Track what's on the expression stack Vector<Value> mValueStack; InputStream* file; CodeBuf codeBuf; Loading Loading @@ -2014,7 +2008,7 @@ class Compiler : public ErrorSink { bool isSymbolOrKeyword(tokenid_t t) { return t >= TOK_KEYWORD && ((size_t) (t-TOK_SYMBOL)) < mTokenTable.size(); ((size_t) (t-TOK_KEYWORD)) < mTokenTable.size(); } VariableInfo* VI(tokenid_t t) { Loading Loading @@ -2418,8 +2412,7 @@ class Compiler : public ErrorSink { } skip(')'); unary(false); if (tok == '=') { next(); if (accept('=')) { pGen->pushR0(); expr(); pGen->popR1(); Loading Loading @@ -2479,9 +2472,12 @@ class Compiler : public ErrorSink { while (tok != ')' && tok != EOF) { expr(); pGen->storeR0ToArg(l); if (tok == ',') next(); l = l + 4; if (accept(',')) { // fine } else if ( tok != ')') { error("Expected ',' or ')'"); } } pGen->endFunctionCallArguments(a, l); skip(')'); Loading Loading @@ -2551,9 +2547,10 @@ class Compiler : public ErrorSink { void block(intptr_t l, bool outermostFunctionBlock) { intptr_t a, n, t; if (tok == TOK_INT || tok == TOK_CHAR) { Type* pBaseType; if ((pBaseType = acceptPrimitiveType(mLocalArena))) { /* declarations */ localDeclarations(); localDeclarations(pBaseType); } else if (tok == TOK_IF) { next(); skip('('); Loading Loading @@ -2609,13 +2606,11 @@ class Compiler : public ErrorSink { mLocals.popLevel(); } } else { if (tok == TOK_RETURN) { next(); if (accept(TOK_RETURN)) { if (tok != ';') expr(); rsym = pGen->gjmp(rsym); /* jmp */ } else if (tok == TOK_BREAK) { next(); } else if (accept(TOK_BREAK)) { *(int *) l = pGen->gjmp(*(int *) l); } else if (tok != ';') expr(); Loading @@ -2624,7 +2619,8 @@ class Compiler : public ErrorSink { } enum TypeTag { TY_INT, TY_CHAR, TY_VOID, TY_POINTER, TY_FUNC, TY_PARAM TY_INT, TY_CHAR, TY_VOID, TY_FLOAT, TY_DOUBLE, TY_POINTER, TY_FUNC, TY_PARAM }; struct Type { Loading Loading @@ -2706,6 +2702,12 @@ class Compiler : public ErrorSink { case TY_VOID: buffer.appendCStr("void"); break; case TY_FLOAT: buffer.appendCStr("float"); break; case TY_DOUBLE: buffer.appendCStr("double"); break; default: break; } Loading @@ -2719,6 +2721,10 @@ class Compiler : public ErrorSink { break; case TY_VOID: break; case TY_FLOAT: break; case TY_DOUBLE: break; case TY_POINTER: decodeTypeImpPrefix(buffer, pType->pHead); if(pType->pHead && pType->pHead->tag == TY_FUNC) { Loading Loading @@ -2779,6 +2785,10 @@ class Compiler : public ErrorSink { pType = mkpChar; } else if (tok == TOK_VOID) { pType = mkpVoid; } else if (tok == TOK_FLOAT) { pType = mkpFloat; } else if (tok == TOK_DOUBLE) { pType = mkpDouble; } else { return NULL; } Loading Loading @@ -2937,11 +2947,10 @@ class Compiler : public ErrorSink { mLocals.add(pDecl); } void localDeclarations() { void localDeclarations(Type* pBaseType) { intptr_t a; Type* pBaseType; while ((pBaseType = acceptPrimitiveType(mLocalArena)) != NULL) { while (pBaseType) { while (tok != ';' && tok != EOF) { Type* pDecl = expectDeclaration(pBaseType, mLocalArena); if (!pDecl) { Loading @@ -2961,6 +2970,7 @@ class Compiler : public ErrorSink { next(); } skip(';'); pBaseType = acceptPrimitiveType(mLocalArena); } } Loading Loading @@ -3053,6 +3063,9 @@ class Compiler : public ErrorSink { skip(';'); } else { // Function declaration if (accept(';')) { // forward declaration. } else { if (name) { /* patch forward references (XXX: does not work for function pointers) */ Loading Loading @@ -3081,6 +3094,7 @@ class Compiler : public ErrorSink { } } } } char* allocGlobalSpace(int bytes) { if (glo - pGlobalBase + bytes > ALLOC_SIZE) { Loading Loading @@ -3216,6 +3230,8 @@ public: mkpInt = createType(TY_INT, NULL, NULL, mGlobalArena); mkpChar = createType(TY_CHAR, NULL, NULL, mGlobalArena); mkpVoid = createType(TY_VOID, NULL, NULL, mGlobalArena); mkpFloat = createType(TY_FLOAT, NULL, NULL, mGlobalArena); mkpDouble = createType(TY_DOUBLE, NULL, NULL, mGlobalArena); mkpIntPtr = createPtrType(mkpInt, mGlobalArena); mkpCharPtr = createPtrType(mkpChar, mGlobalArena); mkpPtrIntFn = createPtrType( Loading libacc/tests/data/double.c 0 → 100644 +7 −0 Original line number Diff line number Diff line double atof(char *nptr); int main() { printf("Value = %g\n", atof("10.42")); return 0; } Loading
libacc/acc.cpp +63 −47 Original line number Diff line number Diff line Loading @@ -1854,11 +1854,6 @@ class Compiler : public ErrorSink { Vector<Mark> mLevelStack; }; struct Value { Type* pType; bool mLValue; // This is the L-value (true means the lvalue) }; int ch; // Current input character, or EOF tokenid_t tok; // token intptr_t tokc; // token extra info Loading @@ -1884,13 +1879,12 @@ class Compiler : public ErrorSink { Type* mkpInt; Type* mkpChar; Type* mkpVoid; Type* mkpFloat; Type* mkpDouble; Type* mkpIntPtr; Type* mkpCharPtr; Type* mkpPtrIntFn; // Track what's on the expression stack Vector<Value> mValueStack; InputStream* file; CodeBuf codeBuf; Loading Loading @@ -2014,7 +2008,7 @@ class Compiler : public ErrorSink { bool isSymbolOrKeyword(tokenid_t t) { return t >= TOK_KEYWORD && ((size_t) (t-TOK_SYMBOL)) < mTokenTable.size(); ((size_t) (t-TOK_KEYWORD)) < mTokenTable.size(); } VariableInfo* VI(tokenid_t t) { Loading Loading @@ -2418,8 +2412,7 @@ class Compiler : public ErrorSink { } skip(')'); unary(false); if (tok == '=') { next(); if (accept('=')) { pGen->pushR0(); expr(); pGen->popR1(); Loading Loading @@ -2479,9 +2472,12 @@ class Compiler : public ErrorSink { while (tok != ')' && tok != EOF) { expr(); pGen->storeR0ToArg(l); if (tok == ',') next(); l = l + 4; if (accept(',')) { // fine } else if ( tok != ')') { error("Expected ',' or ')'"); } } pGen->endFunctionCallArguments(a, l); skip(')'); Loading Loading @@ -2551,9 +2547,10 @@ class Compiler : public ErrorSink { void block(intptr_t l, bool outermostFunctionBlock) { intptr_t a, n, t; if (tok == TOK_INT || tok == TOK_CHAR) { Type* pBaseType; if ((pBaseType = acceptPrimitiveType(mLocalArena))) { /* declarations */ localDeclarations(); localDeclarations(pBaseType); } else if (tok == TOK_IF) { next(); skip('('); Loading Loading @@ -2609,13 +2606,11 @@ class Compiler : public ErrorSink { mLocals.popLevel(); } } else { if (tok == TOK_RETURN) { next(); if (accept(TOK_RETURN)) { if (tok != ';') expr(); rsym = pGen->gjmp(rsym); /* jmp */ } else if (tok == TOK_BREAK) { next(); } else if (accept(TOK_BREAK)) { *(int *) l = pGen->gjmp(*(int *) l); } else if (tok != ';') expr(); Loading @@ -2624,7 +2619,8 @@ class Compiler : public ErrorSink { } enum TypeTag { TY_INT, TY_CHAR, TY_VOID, TY_POINTER, TY_FUNC, TY_PARAM TY_INT, TY_CHAR, TY_VOID, TY_FLOAT, TY_DOUBLE, TY_POINTER, TY_FUNC, TY_PARAM }; struct Type { Loading Loading @@ -2706,6 +2702,12 @@ class Compiler : public ErrorSink { case TY_VOID: buffer.appendCStr("void"); break; case TY_FLOAT: buffer.appendCStr("float"); break; case TY_DOUBLE: buffer.appendCStr("double"); break; default: break; } Loading @@ -2719,6 +2721,10 @@ class Compiler : public ErrorSink { break; case TY_VOID: break; case TY_FLOAT: break; case TY_DOUBLE: break; case TY_POINTER: decodeTypeImpPrefix(buffer, pType->pHead); if(pType->pHead && pType->pHead->tag == TY_FUNC) { Loading Loading @@ -2779,6 +2785,10 @@ class Compiler : public ErrorSink { pType = mkpChar; } else if (tok == TOK_VOID) { pType = mkpVoid; } else if (tok == TOK_FLOAT) { pType = mkpFloat; } else if (tok == TOK_DOUBLE) { pType = mkpDouble; } else { return NULL; } Loading Loading @@ -2937,11 +2947,10 @@ class Compiler : public ErrorSink { mLocals.add(pDecl); } void localDeclarations() { void localDeclarations(Type* pBaseType) { intptr_t a; Type* pBaseType; while ((pBaseType = acceptPrimitiveType(mLocalArena)) != NULL) { while (pBaseType) { while (tok != ';' && tok != EOF) { Type* pDecl = expectDeclaration(pBaseType, mLocalArena); if (!pDecl) { Loading @@ -2961,6 +2970,7 @@ class Compiler : public ErrorSink { next(); } skip(';'); pBaseType = acceptPrimitiveType(mLocalArena); } } Loading Loading @@ -3053,6 +3063,9 @@ class Compiler : public ErrorSink { skip(';'); } else { // Function declaration if (accept(';')) { // forward declaration. } else { if (name) { /* patch forward references (XXX: does not work for function pointers) */ Loading Loading @@ -3081,6 +3094,7 @@ class Compiler : public ErrorSink { } } } } char* allocGlobalSpace(int bytes) { if (glo - pGlobalBase + bytes > ALLOC_SIZE) { Loading Loading @@ -3216,6 +3230,8 @@ public: mkpInt = createType(TY_INT, NULL, NULL, mGlobalArena); mkpChar = createType(TY_CHAR, NULL, NULL, mGlobalArena); mkpVoid = createType(TY_VOID, NULL, NULL, mGlobalArena); mkpFloat = createType(TY_FLOAT, NULL, NULL, mGlobalArena); mkpDouble = createType(TY_DOUBLE, NULL, NULL, mGlobalArena); mkpIntPtr = createPtrType(mkpInt, mGlobalArena); mkpCharPtr = createPtrType(mkpChar, mGlobalArena); mkpPtrIntFn = createPtrType( Loading
libacc/tests/data/double.c 0 → 100644 +7 −0 Original line number Diff line number Diff line double atof(char *nptr); int main() { printf("Value = %g\n", atof("10.42")); return 0; }