]> git.sur5r.net Git - cc65/blobdiff - src/ca65/expr.c
Finished implemenation of commands to delete macros. Added the new commands to
[cc65] / src / ca65 / expr.c
index f9258c5313ec3d4699e2f84a23a8c5b696970e4d..b8efe42b1448ca6ff3fc394ad18ac7f07ebc6a08 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2006 Ullrich von Bassewitz                                       */
-/*               Römerstraße 52                                              */
-/*               D-70794 Filderstadt                                         */
-/* EMail:        uz@cc65.org                                                 */
+/* (C) 1998-2011, Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
@@ -185,7 +185,7 @@ static int IsEasyConst (const ExprNode* E, long* Val)
     /* Symbols resolved, check for a literal */
     if (E->Op == EXPR_LITERAL) {
         if (Val) {
-            *Val = E->V.Val;
+            *Val = E->V.IVal;
         }
         return 1;
     }
@@ -319,7 +319,7 @@ static ExprNode* Symbol (SymEntry* S)
 
 
 
-static ExprNode* FuncBankByte (void)
+ExprNode* FuncBankByte (void)
 /* Handle the .BANKBYTE builtin function */
 {
     return BankByte (Expression ());
@@ -333,15 +333,15 @@ static ExprNode* FuncBlank (void)
     /* We have a list of tokens that ends with the closing paren. Skip
      * the tokens, and count them. Allow optionally curly braces.
      */
-    enum Token Term = GetTokListTerm (TOK_RPAREN);
+    token_t Term = GetTokListTerm (TOK_RPAREN);
     unsigned Count = 0;
-    while (Tok != Term) {
+    while (CurTok.Tok != Term) {
 
        /* Check for end of line or end of input. Since the calling function
         * will check for the closing paren, we don't need to print an error
         * here, just bail out.
         */
-       if (TokIsSep (Tok)) {
+       if (TokIsSep (CurTok.Tok)) {
            break;
        }
 
@@ -353,7 +353,7 @@ static ExprNode* FuncBlank (void)
     }
 
     /* If the list was enclosed in curly braces, skip the closing brace */
-    if (Term == TOK_RCURLY && Tok == TOK_RCURLY) {
+    if (Term == TOK_RCURLY && CurTok.Tok == TOK_RCURLY) {
         NextTok ();
     }
 
@@ -385,7 +385,7 @@ static ExprNode* FuncDefined (void)
 /* Handle the .DEFINED builtin function */
 {
     /* Parse the symbol name and search for the symbol */
-    SymEntry* Sym = ParseScopedSymName (SYM_FIND_EXISTING);
+    SymEntry* Sym = ParseAnySymName (SYM_FIND_EXISTING);
 
     /* Check if the symbol is defined */
     return GenLiteralExpr (Sym != 0 && SymIsDef (Sym));
@@ -393,7 +393,7 @@ static ExprNode* FuncDefined (void)
 
 
 
-static ExprNode* FuncHiByte (void)
+ExprNode* FuncHiByte (void)
 /* Handle the .HIBYTE builtin function */
 {
     return HiByte (Expression ());
@@ -409,7 +409,7 @@ static ExprNode* FuncHiWord (void)
 
 
 
-static ExprNode* FuncLoByte (void)
+ExprNode* FuncLoByte (void)
 /* Handle the .LOBYTE builtin function */
 {
     return LoByte (Expression ());
@@ -437,11 +437,11 @@ static ExprNode* DoMatch (enum TC EqualityLevel)
      * single linked list of tokens including attributes. The list is
      * either enclosed in curly braces, or terminated by a comma.
      */
-    enum Token Term = GetTokListTerm (TOK_COMMA);
-    while (Tok != Term) {
+    token_t Term = GetTokListTerm (TOK_COMMA);
+    while (CurTok.Tok != Term) {
 
        /* We may not end-of-line of end-of-file here */
-       if (TokIsSep (Tok)) {
+       if (TokIsSep (CurTok.Tok)) {
            Error ("Unexpected end of line");
            return GenLiteral0 ();
        }
@@ -476,10 +476,10 @@ static ExprNode* DoMatch (enum TC EqualityLevel)
     Term = GetTokListTerm (TOK_RPAREN);
     Result = 1;
     Node = Root;
-    while (Tok != Term) {
+    while (CurTok.Tok != Term) {
 
        /* We may not end-of-line of end-of-file here */
-       if (TokIsSep (Tok)) {
+       if (TokIsSep (CurTok.Tok)) {
            Error ("Unexpected end of line");
            return GenLiteral0 ();
        }
@@ -535,11 +535,69 @@ static ExprNode* FuncMatch (void)
 
 
 
+static ExprNode* FuncMax (void)
+/* Handle the .MAX function */
+{
+    ExprNode* Left;
+    ExprNode* Right;
+    ExprNode* Expr;
+    long LeftVal, RightVal;
+
+    /* Two arguments to the pseudo function */
+    Left = Expression ();
+    ConsumeComma ();
+    Right = Expression ();
+
+    /* Check if we can evaluate the value immediately */
+    if (IsEasyConst (Left, &LeftVal) && IsEasyConst (Right, &RightVal)) {
+        FreeExpr (Left);
+        FreeExpr (Right);
+        Expr = GenLiteralExpr ((LeftVal > RightVal)? LeftVal : RightVal);
+    } else {
+        /* Make an expression node */
+        Expr = NewExprNode (EXPR_MAX);
+        Expr->Left = Left;
+        Expr->Right = Right;
+    }
+    return Expr;
+}
+
+
+
+static ExprNode* FuncMin (void)
+/* Handle the .MIN function */
+{
+    ExprNode* Left;
+    ExprNode* Right;
+    ExprNode* Expr;
+    long LeftVal, RightVal;
+
+    /* Two arguments to the pseudo function */
+    Left = Expression ();
+    ConsumeComma ();
+    Right = Expression ();
+
+    /* Check if we can evaluate the value immediately */
+    if (IsEasyConst (Left, &LeftVal) && IsEasyConst (Right, &RightVal)) {
+        FreeExpr (Left);
+        FreeExpr (Right);
+        Expr = GenLiteralExpr ((LeftVal < RightVal)? LeftVal : RightVal);
+    } else {
+        /* Make an expression node */
+        Expr = NewExprNode (EXPR_MIN);
+        Expr->Left = Left;
+        Expr->Right = Right;
+    }
+    return Expr;
+}
+
+
+
 static ExprNode* FuncReferenced (void)
 /* Handle the .REFERENCED builtin function */
 {
     /* Parse the symbol name and search for the symbol */
-    SymEntry* Sym = ParseScopedSymName (SYM_FIND_EXISTING);
+    SymEntry* Sym = ParseAnySymName (SYM_FIND_EXISTING);
 
     /* Check if the symbol is referenced */
     return GenLiteralExpr (Sym != 0 && SymIsRef (Sym));
@@ -550,8 +608,8 @@ static ExprNode* FuncReferenced (void)
 static ExprNode* FuncSizeOf (void)
 /* Handle the .SIZEOF function */
 {
-    StrBuf    ScopeName = AUTO_STRBUF_INITIALIZER;
-    char      Name[sizeof (SVal)];
+    StrBuf    ScopeName = STATIC_STRBUF_INITIALIZER;
+    StrBuf    Name = STATIC_STRBUF_INITIALIZER;
     SymTable* Scope;
     SymEntry* Sym;
     SymEntry* SizeSym;
@@ -563,30 +621,31 @@ static ExprNode* FuncSizeOf (void)
     SizeSym = 0;
 
     /* Check for a cheap local which needs special handling */
-    if (Tok == TOK_LOCAL_IDENT) {
+    if (CurTok.Tok == TOK_LOCAL_IDENT) {
 
         /* Cheap local symbol */
-        Sym = SymFindLocal (SymLast, SVal, SYM_FIND_EXISTING);
+        Sym = SymFindLocal (SymLast, &CurTok.SVal, SYM_FIND_EXISTING);
         if (Sym == 0) {
-            Error ("Unknown symbol or scope: `%s'", SVal);
+            Error ("Unknown symbol or scope: `%m%p'", &CurTok.SVal);
         } else {
             SizeSym = GetSizeOfSymbol (Sym);
         }
 
         /* Remember and skip SVal, terminate ScopeName so it is empty */
-        strcpy (Name, SVal);
+        SB_Copy (&Name, &CurTok.SVal);
         NextTok ();
         SB_Terminate (&ScopeName);
 
     } else {
 
         /* Parse the scope and the name */
-        SymTable* ParentScope = ParseScopedIdent (Name, &ScopeName);
+        SymTable* ParentScope = ParseScopedIdent (&Name, &ScopeName);
 
         /* Check if the parent scope is valid */
         if (ParentScope == 0) {
             /* No such scope */
-            DoneStrBuf (&ScopeName);
+            SB_Done (&ScopeName);
+            SB_Done (&Name);
             return GenLiteral0 ();
         }
 
@@ -597,9 +656,9 @@ static ExprNode* FuncSizeOf (void)
 
         /* First search for a scope with the given name */
         if (NoScope) {
-            Scope = SymFindAnyScope (ParentScope, Name);
+            Scope = SymFindAnyScope (ParentScope, &Name);
         } else {
-            Scope = SymFindScope (ParentScope, Name, SYM_FIND_EXISTING);
+            Scope = SymFindScope (ParentScope, &Name, SYM_FIND_EXISTING);
         }
 
         /* If we did find a scope with the name, read the symbol defining the
@@ -610,29 +669,30 @@ static ExprNode* FuncSizeOf (void)
             SizeSym = GetSizeOfScope (Scope);
         } else {
             if (NoScope) {
-                Sym = SymFindAny (ParentScope, Name);
+                Sym = SymFindAny (ParentScope, &Name);
             } else {
-                Sym = SymFind (ParentScope, Name, SYM_FIND_EXISTING);
+                Sym = SymFind (ParentScope, &Name, SYM_FIND_EXISTING);
             }
 
             /* If we found the symbol retrieve the size, otherwise complain */
             if (Sym) {
                 SizeSym = GetSizeOfSymbol (Sym);
             } else {
-                Error ("Unknown symbol or scope: `%s%s'",
-                       SB_GetConstBuf (&ScopeName), Name);
+                Error ("Unknown symbol or scope: `%m%p%m%p'",
+                       &ScopeName, &Name);
             }
         }
     }
 
     /* Check if we have a size */
     if (SizeSym == 0 || !SymIsConst (SizeSym, &Size)) {
-        Error ("Size of `%s%s' is unknown", SB_GetConstBuf (&ScopeName), Name);
+        Error ("Size of `%m%p%m%p' is unknown", &ScopeName, &Name);
         Size = 0;
     }
 
-    /* Free the scope name */
-    DoneStrBuf (&ScopeName);
+    /* Free the string buffers */
+    SB_Done (&ScopeName);
+    SB_Done (&Name);
 
     /* Return the size */
     return GenLiteralExpr (Size);
@@ -643,19 +703,19 @@ static ExprNode* FuncSizeOf (void)
 static ExprNode* FuncStrAt (void)
 /* Handle the .STRAT function */
 {
-    char Str [sizeof(SVal)];
+    StrBuf Str = STATIC_STRBUF_INITIALIZER;
     long Index;
-    unsigned char C;
+    unsigned char C = 0;
 
     /* String constant expected */
-    if (Tok != TOK_STRCON) {
+    if (CurTok.Tok != TOK_STRCON) {
        Error ("String constant expected");
        NextTok ();
-               return GenLiteral0 ();
+               goto ExitPoint;
     }
 
     /* Remember the string and skip it */
-    strcpy (Str, SVal);
+    SB_Copy (&Str, &CurTok.SVal);
     NextTok ();
 
     /* Comma must follow */
@@ -665,15 +725,19 @@ static ExprNode* FuncStrAt (void)
     Index = ConstExpression ();
 
     /* Must be a valid index */
-    if (Index >= (long) strlen (Str)) {
+    if (Index >= (long) SB_GetLen (&Str)) {
        Error ("Range error");
-       return GenLiteral0 ();
+        goto ExitPoint;
     }
 
     /* Get the char, handle as unsigned. Be sure to translate it into
      * the target character set.
      */
-    C = TgtTranslateChar (Str [(size_t)Index]);
+    C = TgtTranslateChar (SB_At (&Str, (unsigned)Index));
+
+ExitPoint:
+    /* Free string buffer memory */
+    SB_Done (&Str);
 
     /* Return the char expression */
     return GenLiteralExpr (C);
@@ -687,11 +751,11 @@ static ExprNode* FuncStrLen (void)
     int Len;
 
     /* String constant expected */
-    if (Tok != TOK_STRCON) {
+    if (CurTok.Tok != TOK_STRCON) {
 
        Error ("String constant expected");
        /* Smart error recovery */
-       if (Tok != TOK_RPAREN) {
+       if (CurTok.Tok != TOK_RPAREN) {
            NextTok ();
        }
                Len = 0;
@@ -699,7 +763,7 @@ static ExprNode* FuncStrLen (void)
     } else {
 
         /* Get the length of the string */
-       Len = strlen (SVal);
+               Len = SB_GetLen (&CurTok.SVal);
 
        /* Skip the string */
        NextTok ();
@@ -717,15 +781,15 @@ static ExprNode* FuncTCount (void)
     /* We have a list of tokens that ends with the closing paren. Skip
      * the tokens, and count them. Allow optionally curly braces.
      */
-    enum Token Term = GetTokListTerm (TOK_RPAREN);
+    token_t Term = GetTokListTerm (TOK_RPAREN);
     int Count = 0;
-    while (Tok != Term) {
+    while (CurTok.Tok != Term) {
 
        /* Check for end of line or end of input. Since the calling function
         * will check for the closing paren, we don't need to print an error
         * here, just bail out.
         */
-       if (TokIsSep (Tok)) {
+       if (TokIsSep (CurTok.Tok)) {
            break;
        }
 
@@ -737,7 +801,7 @@ static ExprNode* FuncTCount (void)
     }
 
     /* If the list was enclosed in curly braces, skip the closing brace */
-    if (Term == TOK_RCURLY && Tok == TOK_RCURLY) {
+    if (Term == TOK_RCURLY && CurTok.Tok == TOK_RCURLY) {
         NextTok ();
     }
 
@@ -764,7 +828,7 @@ static ExprNode* Function (ExprNode* (*F) (void))
     NextTok ();
 
     /* Expression must be enclosed in braces */
-    if (Tok != TOK_LPAREN) {
+    if (CurTok.Tok != TOK_LPAREN) {
        Error ("'(' expected");
        SkipUntilSep ();
        return GenLiteral0 ();
@@ -789,30 +853,26 @@ static ExprNode* Factor (void)
     ExprNode* N;
     long      Val;
 
-    switch (Tok) {
+    switch (CurTok.Tok) {
 
        case TOK_INTCON:
-           N = GenLiteralExpr (IVal);
+           N = GenLiteralExpr (CurTok.IVal);
                    NextTok ();
            break;
 
        case TOK_CHARCON:
-           N = GenLiteralExpr (TgtTranslateChar (IVal));
+           N = GenLiteralExpr (TgtTranslateChar (CurTok.IVal));
                    NextTok ();
            break;
 
        case TOK_NAMESPACE:
        case TOK_IDENT:
-            N = Symbol (ParseScopedSymName (SYM_ALLOC_NEW));
-           break;
-
         case TOK_LOCAL_IDENT:
-            N = Symbol (SymFindLocal (SymLast, SVal, SYM_ALLOC_NEW));
-            NextTok ();
-            break;
+            N = Symbol (ParseAnySymName (SYM_ALLOC_NEW));
+           break;
 
        case TOK_ULABEL:
-           N = ULabRef (IVal);
+           N = ULabRef (CurTok.IVal);
            NextTok ();
            break;
 
@@ -913,6 +973,14 @@ static ExprNode* Factor (void)
            N = Function (FuncMatch);
            break;
 
+        case TOK_MAX:
+            N = Function (FuncMax);
+            break;
+
+        case TOK_MIN:
+            N = Function (FuncMin);
+            break;
+
         case TOK_REFERENCED:
            N = Function (FuncReferenced);
            break;
@@ -939,7 +1007,7 @@ static ExprNode* Factor (void)
            break;
 
         case TOK_VERSION:
-            N = GenLiteralExpr (VERSION);
+            N = GenLiteralExpr (GetVersionAsNumber ());
             NextTok ();
             break;
 
@@ -948,9 +1016,10 @@ static ExprNode* Factor (void)
            break;
 
        default:
-           if (LooseCharTerm && Tok == TOK_STRCON && strlen(SVal) == 1) {
+           if (LooseCharTerm && CurTok.Tok == TOK_STRCON && 
+                SB_GetLen (&CurTok.SVal) == 1) {
                /* A character constant */
-               N = GenLiteralExpr (TgtTranslateChar (SVal[0]));
+               N = GenLiteralExpr (TgtTranslateChar (SB_At (&CurTok.SVal, 0)));
            } else {
                N = GenLiteral0 ();     /* Dummy */
                Error ("Syntax error");
@@ -969,16 +1038,17 @@ static ExprNode* Term (void)
     ExprNode* Root = Factor ();
 
     /* Handle multiplicative operations */
-    while (Tok == TOK_MUL || Tok == TOK_DIV || Tok == TOK_MOD ||
-          Tok == TOK_AND || Tok == TOK_XOR || Tok == TOK_SHL ||
-          Tok == TOK_SHR) {
+    while (CurTok.Tok == TOK_MUL || CurTok.Tok == TOK_DIV ||
+           CurTok.Tok == TOK_MOD || CurTok.Tok == TOK_AND ||
+           CurTok.Tok == TOK_XOR || CurTok.Tok == TOK_SHL ||
+          CurTok.Tok == TOK_SHR) {
 
         long LVal, RVal, Val;
         ExprNode* Left;
         ExprNode* Right;
 
         /* Remember the token and skip it */
-        enum Token T = Tok;
+        token_t T = CurTok.Tok;
         NextTok ();
 
         /* Move root to left side and read the right side */
@@ -1072,14 +1142,16 @@ static ExprNode* SimpleExpr (void)
     ExprNode* Root = Term ();
 
     /* Handle additive operations */
-    while (Tok == TOK_PLUS || Tok == TOK_MINUS || Tok == TOK_OR) {
+    while (CurTok.Tok == TOK_PLUS  ||
+           CurTok.Tok == TOK_MINUS ||
+           CurTok.Tok == TOK_OR) {
 
         long LVal, RVal, Val;
         ExprNode* Left;
         ExprNode* Right;
 
         /* Remember the token and skip it */
-        enum Token T = Tok;
+        token_t T = CurTok.Tok;
         NextTok ();
 
         /* Move root to left side and read the right side */
@@ -1133,15 +1205,16 @@ static ExprNode* BoolExpr (void)
     ExprNode* Root = SimpleExpr ();
 
     /* Handle booleans */
-    while (Tok == TOK_EQ || Tok == TOK_NE || Tok == TOK_LT ||
-          Tok == TOK_GT || Tok == TOK_LE || Tok == TOK_GE) {
+    while (CurTok.Tok == TOK_EQ || CurTok.Tok == TOK_NE ||
+           CurTok.Tok == TOK_LT || CurTok.Tok == TOK_GT ||
+           CurTok.Tok == TOK_LE || CurTok.Tok == TOK_GE) {
 
         long LVal, RVal, Val;
         ExprNode* Left;
         ExprNode* Right;
 
         /* Remember the token and skip it */
-        enum Token T = Tok;
+        token_t T = CurTok.Tok;
         NextTok ();
 
         /* Move root to left side and read the right side */
@@ -1201,14 +1274,14 @@ static ExprNode* Expr2 (void)
     ExprNode* Root = BoolExpr ();
 
     /* Handle booleans */
-    while (Tok == TOK_BOOLAND || Tok == TOK_BOOLXOR) {
+    while (CurTok.Tok == TOK_BOOLAND || CurTok.Tok == TOK_BOOLXOR) {
 
         long LVal, RVal, Val;
         ExprNode* Left;
         ExprNode* Right;
 
         /* Remember the token and skip it */
-        enum Token T = Tok;
+        token_t T = CurTok.Tok;
         NextTok ();
 
         /* Move root to left side and read the right side */
@@ -1260,14 +1333,14 @@ static ExprNode* Expr1 (void)
     ExprNode* Root = Expr2 ();
 
     /* Handle booleans */
-    while (Tok == TOK_BOOLOR) {
+    while (CurTok.Tok == TOK_BOOLOR) {
 
         long LVal, RVal, Val;
         ExprNode* Left;
         ExprNode* Right;
 
         /* Remember the token and skip it */
-        enum Token T = Tok;
+        token_t T = CurTok.Tok;
         NextTok ();
 
         /* Move root to left side and read the right side */
@@ -1316,7 +1389,7 @@ static ExprNode* Expr0 (void)
     ExprNode* Root;
 
     /* Handle booleans */
-    if (Tok == TOK_BOOLNOT) {
+    if (CurTok.Tok == TOK_BOOLNOT) {
 
         long Val;
         ExprNode* Left;
@@ -1422,7 +1495,7 @@ ExprNode* GenLiteralExpr (long Val)
 /* Return an expression tree that encodes the given literal value */
 {
     ExprNode* Expr = NewExprNode (EXPR_LITERAL);
-    Expr->V.Val = Val;
+    Expr->V.IVal = Val;
     return Expr;
 }
 
@@ -1447,11 +1520,11 @@ ExprNode* GenSymExpr (SymEntry* Sym)
 
 
 
-static ExprNode* GenSectionExpr (unsigned SegNum)
+static ExprNode* GenSectionExpr (unsigned SecNum)
 /* Return an expression node for the given section */
 {
     ExprNode* Expr = NewExprNode (EXPR_SECTION);
-    Expr->V.SegNum = SegNum;
+    Expr->V.SecNum = SecNum;
     return Expr;
 }
 
@@ -1482,7 +1555,7 @@ ExprNode* GenCurrentPC (void)
 {
     ExprNode* Root;
 
-    if (RelocMode) {
+    if (GetRelocMode ()) {
        /* Create SegmentBase + Offset */
                Root = GenAddExpr (GenSectionExpr (GetCurrentSegNum ()),
                            GenLiteralExpr (GetPC ()));
@@ -1531,7 +1604,7 @@ ExprNode* GenBranchExpr (unsigned Offs)
          * (Val - PC - Offs) - Seg
          */
         Root = GenLiteralExpr (Val - GetPC () - Offs);
-        if (RelocMode) {
+        if (GetRelocMode ()) {
             N = Root;
             Root = NewExprNode (EXPR_MINUS);
             Root->Left  = N;
@@ -1549,7 +1622,7 @@ ExprNode* GenBranchExpr (unsigned Offs)
         Root = NewExprNode (EXPR_MINUS);
         Root->Left  = N;
         Root->Right = GenLiteralExpr (GetPC () + Offs);
-        if (RelocMode) {
+        if (GetRelocMode ()) {
             N = Root;
             Root = NewExprNode (EXPR_MINUS);
             Root->Left  = N;
@@ -1567,7 +1640,7 @@ ExprNode* GenULabelExpr (unsigned Num)
 /* Return an expression for an unnamed label with the given index */
 {
     ExprNode* Node = NewExprNode (EXPR_ULABEL);
-    Node->V.Val        = Num;
+    Node->V.IVal       = Num;
 
     /* Return the new node */
     return Node;
@@ -1649,11 +1722,11 @@ ExprNode* CloneExpr (ExprNode* Expr)
     switch (Expr->Op) {
 
        case EXPR_LITERAL:
-            Clone = GenLiteralExpr (Expr->V.Val);
+            Clone = GenLiteralExpr (Expr->V.IVal);
             break;
 
        case EXPR_ULABEL:
-           Clone = GenULabelExpr (Expr->V.Val);
+           Clone = GenULabelExpr (Expr->V.IVal);
            break;
 
        case EXPR_SYMBOL:
@@ -1661,7 +1734,7 @@ ExprNode* CloneExpr (ExprNode* Expr)
            break;
 
        case EXPR_SECTION:
-           Clone = GenSectionExpr (Expr->V.SegNum);
+           Clone = GenSectionExpr (Expr->V.SecNum);
            break;
 
         default:
@@ -1695,13 +1768,13 @@ void WriteExpr (ExprNode* Expr)
 
         case EXPR_LITERAL:
             ObjWrite8 (EXPR_LITERAL);
-           ObjWrite32 (Expr->V.Val);
+           ObjWrite32 (Expr->V.IVal);
            break;
 
         case EXPR_SYMBOL:
            if (SymIsImport (Expr->V.Sym)) {
                 ObjWrite8 (EXPR_SYMBOL);
-                ObjWriteVar (GetSymIndex (Expr->V.Sym));
+                ObjWriteVar (GetSymImportId (Expr->V.Sym));
             } else {
                 WriteExpr (GetSymExpr (Expr->V.Sym));
             }
@@ -1709,11 +1782,11 @@ void WriteExpr (ExprNode* Expr)
 
         case EXPR_SECTION:
             ObjWrite8 (EXPR_SECTION);
-           ObjWrite8 (Expr->V.SegNum);
+           ObjWrite8 (Expr->V.SecNum);
            break;
 
        case EXPR_ULABEL:
-            WriteExpr (ULabResolve (Expr->V.Val));
+            WriteExpr (ULabResolve (Expr->V.IVal));
            break;
 
         default: