Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 37c54bd2 authored by Jack Palevich's avatar Jack Palevich
Browse files

Make forward declarations of external symbols really work.

Until now we had always been treating external variables as "int",
and external functions as int (...);
parent 7ecc5556
Loading
Loading
Loading
Loading
+23 −15
Original line number Diff line number Diff line
@@ -2610,7 +2610,7 @@ class Compiler : public ErrorSink {
        }

        virtual void convertR0(Type* pType){
            fprintf(stderr, "convertR0(pType)\n");
            fprintf(stderr, "convertR0(pType tag=%d)\n",  pType->tag);
            mpBase->convertR0(pType);
        }

@@ -3672,7 +3672,7 @@ class Compiler : public ErrorSink {
#if 0
        {
            String buf;
            decodeToken(buf, tok);
            decodeToken(buf, tok, true);
            fprintf(stderr, "%s\n", buf.getUnwrapped());
        }
#endif
@@ -3883,11 +3883,13 @@ class Compiler : public ErrorSink {
                /* forward reference: try dlsym */
                if (!n) {
                    n = (intptr_t) dlsym(RTLD_DEFAULT, nameof(t));
                    if (pVI->pType == NULL) {
                        if (tok == '(') {
                            pVI->pType = mkpIntFn;
                        } else {
                            pVI->pType = mkpInt;
                        }
                    }
                    pVI->pAddress = (void*) n;
                }
                if ((tok == '=') & allowAssignment) {
@@ -4156,7 +4158,7 @@ class Compiler : public ErrorSink {

        String temp;
        if (pType->id != 0) {
            decodeToken(temp, pType->id);
            decodeToken(temp, pType->id, false);
            buffer.append(temp);
        }

@@ -4166,7 +4168,7 @@ class Compiler : public ErrorSink {
    void decodeTypeImpPrefix(String& buffer, Type* pType) {
        TypeTag tag = pType->tag;

        if (tag >= TY_INT && tag <= TY_VOID) {
        if (tag >= TY_INT && tag <= TY_DOUBLE) {
            switch (tag) {
                case TY_INT:
                    buffer.appendCStr("int");
@@ -4343,7 +4345,7 @@ class Compiler : public ErrorSink {
                error("Symbol %s not allowed here", nameof(declName));
            } else if (nameRequired && ! declName) {
                String temp;
                decodeToken(temp, tok);
                decodeToken(temp, tok, true);
                error("Expected symbol. Got %s", temp.getUnwrapped());
            }
        }
@@ -4395,7 +4397,7 @@ class Compiler : public ErrorSink {
        Type* pType = acceptPrimitiveType(arena);
        if (!pType) {
            String buf;
            decodeToken(buf, tok);
            decodeToken(buf, tok, true);
            error("Expected a type, got %s", buf.getUnwrapped());
        }
        return pType;
@@ -4455,7 +4457,7 @@ class Compiler : public ErrorSink {
        return checkSymbol(tok);
    }

    void decodeToken(String& buffer, tokenid_t token) {
    void decodeToken(String& buffer, tokenid_t token, bool quote) {
        if (token == EOF ) {
            buffer.printf("EOF");
        } else if (token == TOK_NUM) {
@@ -4466,18 +4468,24 @@ class Compiler : public ErrorSink {
            } else {
                buffer.printf("'%c'", token);
            }
        } else if (token >= TOK_KEYWORD && token < TOK_SYMBOL) {
        } else {
            if (quote) {
                if (token >= TOK_KEYWORD && token < TOK_SYMBOL) {
                    buffer.printf("keyword \"%s\"", nameof(token));
                } else {
                    buffer.printf("symbol \"%s\"", nameof(token));
                }
            } else {
                buffer.printf("%s", nameof(token));
            }
        }
    }

    bool checkSymbol(tokenid_t token) {
        bool result = token >= TOK_SYMBOL;
        if (!result) {
            String temp;
            decodeToken(temp, token);
            decodeToken(temp, token, true);
            error("Expected symbol. Got %s", temp.getUnwrapped());
        }
        return result;
+9 −0
Original line number Diff line number Diff line

float fabsf(float);

int main(void* con, int ft, int launchID)
{
   float f =  fabsf(-10.0f);
   return f;
}
+4 −0
Original line number Diff line number Diff line
@@ -262,6 +262,10 @@ Pointer addition: 2
Pointer comparison to zero: 0 0 1
Pointer comparison: 1 0 0 0 1
""")
    def testRollo3(self):
        self.compileCheck(["-R", "data/rollo3.c"], """Executing compiled code:
result: 10""", """""")



if __name__ == '__main__':