Ignore:
Timestamp:
02/07/16 20:49:30 (8 years ago)
Author:
Maciej Komosinski
Message:
  • accessing a non-global variable that was declared outside of a function causes a compilation error
  • symbolic constant instead of a magic value
File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/vm/framscript.y

    r382 r466  
    155155{
    156156int offset;
    157 if (trctx.functionstackpos==999)
     157if (trctx.functionstackpos==TranslatorContext::NOT_IN_FUNCTION)
    158158        offset=-trstack.currentPos();
    159159else
     
    186186{
    187187int offset;
    188 if (trctx.functionstackpos==999)
     188if (trctx.functionstackpos==TranslatorContext::NOT_IN_FUNCTION)
    189189        offset=-trstack.currentPos();
    190190else
     
    231231int pos=trstack.currentPos();
    232232$$.setInt(pos);
    233 if (trctx.functionstackpos!=999)
     233if (trctx.functionstackpos!=TranslatorContext::NOT_IN_FUNCTION)
    234234        {trctx.err->printf("functions cannot be nested\n");return 1;}
     235trctx.beforefunctionstackpos=trstack.currentPos();
    235236}
    236237                            '(' paramlist ')'
     
    242243int pos=$3.getInt();
    243244trstack.dropToPos(pos);
    244 trctx.functionstackpos=999;
     245trctx.functionstackpos=TranslatorContext::NOT_IN_FUNCTION;
     246trctx.beforefunctionstackpos=TranslatorContext::NOT_IN_FUNCTION;
    245247trctx.out->printf(":_skipfun_%d\n",trctx.functiontmplabel);
    246248trctx.functiontmplabel=-1;
     
    14551457loc=trstack.getVariableLocation(var.getString());
    14561458if (loc != TranslatorStack::NOTFOUND)
    1457         {tok.setInt(loc); tok.constant=0;
    1458         return 1;}
     1459        {
     1460        if ((trctx.functionstackpos!=TranslatorContext::NOT_IN_FUNCTION)
     1461            && (loc>=trctx.beforefunctionstackpos))
     1462                return 0;
     1463        tok.setInt(loc); tok.constant=0;
     1464        return 1;
     1465        }
    14591466return 0;
    14601467}
Note: See TracChangeset for help on using the changeset viewer.