]> git.sur5r.net Git - cc65/blobdiff - src/cc65/stdfunc.c
Just comment and formatting changes.
[cc65] / src / cc65 / stdfunc.c
index 820f4d75cea5ecb4dd03cd271610f33d269d0593..b41210f4461d3e50687960f1366b3a759a0d37d7 100644 (file)
@@ -6,7 +6,7 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2004 Ullrich von Bassewitz                                       */
+/* (C) 1998-2006 Ullrich von Bassewitz                                       */
 /*               Römerstrasse 52                                             */
 /*               D-70794 Filderstadt                                         */
 /* EMail:        uz@cc65.org                                                 */
@@ -48,6 +48,7 @@
 #include "funcdesc.h"
 #include "global.h"
 #include "litpool.h"
+#include "loadexpr.h"
 #include "scanner.h"
 #include "stackptr.h"
 #include "stdfunc.h"
@@ -92,9 +93,9 @@ static struct StdFuncDesc {
 
 typedef struct ArgDesc ArgDesc;
 struct ArgDesc {
-    const type* ArgType;        /* Required argument type */
+    const Type* ArgType;        /* Required argument type */
     ExprDesc    Expr;           /* Argument expression */
-    const type* Type;           /* The original type before conversion */
+    const Type* Type;           /* The original type before conversion */
     CodeMark    Start;          /* Start of the code for calculation */
     CodeMark    Push;           /* Start of argument push code */
     CodeMark    End;            /* End of the code for calculation+push */
@@ -138,7 +139,7 @@ static long ArrayElementCount (const ArgDesc* Arg)
 
 
 
-static void ParseArg (ArgDesc* Arg, type* Type)
+static void ParseArg (ArgDesc* Arg, Type* Type)
 /* Parse one argument but do not push it onto the stack. Make all fields in
  * Arg valid.
  */
@@ -150,7 +151,7 @@ static void ParseArg (ArgDesc* Arg, type* Type)
     Arg->ArgType = Type;
 
     /* Remember the current code position */
-    Arg->Start = GetCodePos ();
+    GetCodePos (&Arg->Start);
 
     /* Read the expression we're going to pass to the function */
     ExprWithCheck (hie1, &Arg->Expr);
@@ -169,11 +170,12 @@ static void ParseArg (ArgDesc* Arg, type* Type)
         Arg->Flags |= CF_CONST;
     } else {
         /* Load into the primary */
-        ExprLoad (CF_NONE, &Arg->Expr);
+        LoadExpr (CF_NONE, &Arg->Expr);
     }
 
     /* Remember the following code position */
-    Arg->End = Arg->Push = GetCodePos ();
+    GetCodePos (&Arg->Push);
+    GetCodePos (&Arg->End);
 
     /* Use the type of the argument for the push */
     Arg->Flags |= TypeOf (Arg->Expr.Type);
@@ -190,10 +192,10 @@ static void ParseArg (ArgDesc* Arg, type* Type)
 static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
 /* Handle the memcpy function */
 {
-    /* Argument types */
-    static type Arg1Type[] = { T_PTR, T_VOID, T_END };              /* void* */
-    static type Arg2Type[] = { T_PTR, T_VOID|T_QUAL_CONST, T_END }; /* const void* */
-    static type Arg3Type[] = { T_SIZE_T, T_END };                   /* size_t */
+    /* Argument types: (void*, const void*, size_t) */
+    static Type Arg1Type[] = { TYPE(T_PTR), TYPE(T_VOID), TYPE(T_END) };
+    static Type Arg2Type[] = { TYPE(T_PTR), TYPE(T_VOID|T_QUAL_CONST), TYPE(T_END) };
+    static Type Arg3Type[] = { TYPE(T_SIZE_T), TYPE(T_END) };
 
     CodeMark Start;
     ArgDesc  Arg1, Arg2, Arg3;
@@ -201,19 +203,19 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
     unsigned Label;
 
     /* Remember where we are now */
-    Start = GetCodePos ();
+    GetCodePos (&Start);
 
     /* Argument #1 */
     ParseArg (&Arg1, Arg1Type);
-    g_push (Arg1.Flags, Arg1.Expr.Val);
-    Arg1.End = GetCodePos ();
+    g_push (Arg1.Flags, Arg1.Expr.IVal);
+    GetCodePos (&Arg1.End);
     ParamSize += SizeOf (Arg1Type);
     ConsumeComma ();
 
     /* Argument #2 */
     ParseArg (&Arg2, Arg2Type);
-    g_push (Arg2.Flags, Arg2.Expr.Val);
-    Arg2.End = GetCodePos ();
+    g_push (Arg2.Flags, Arg2.Expr.IVal);
+    GetCodePos (&Arg2.End);
     ParamSize += SizeOf (Arg2Type);
     ConsumeComma ();
 
@@ -224,13 +226,13 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
      */
     ParseArg (&Arg3, Arg3Type);
     if (Arg3.Flags & CF_CONST) {
-        ExprLoad (CF_FORCECHAR, &Arg3.Expr);
+        LoadExpr (CF_NONE, &Arg3.Expr);
     }
 
     /* Emit the actual function call. This will also cleanup the stack. */
     g_call (CF_FIXARGC, Func_memcpy, ParamSize);
 
-    if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.Val == 0) {
+    if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.IVal == 0) {
 
         /* memcpy has been called with a count argument of zero */
         Warning ("Call to memcpy has no effect");
@@ -238,7 +240,7 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
         /* Remove all of the generated code but the load of the first
          * argument, which is what memcpy returns.
          */
-        RemoveCode (Arg1.Push);
+        RemoveCode (&Arg1.Push);
 
         /* Set the function result to the first argument */
         *Expr = Arg1.Expr;
@@ -252,7 +254,7 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
      * be generated. If such a situation is detected, throw away the
      * generated, and emit better code.
      */
-    if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.Val <= 256 &&
+    if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.IVal <= 256 &&
         ((ED_IsRVal (&Arg2.Expr) && ED_IsLocConst (&Arg2.Expr)) ||
          (ED_IsLVal (&Arg2.Expr) && ED_IsLocRegister (&Arg2.Expr))) &&
         ((ED_IsRVal (&Arg1.Expr) && ED_IsLocConst (&Arg1.Expr)) ||
@@ -262,16 +264,16 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
         int Reg2 = ED_IsLVal (&Arg2.Expr) && ED_IsLocRegister (&Arg2.Expr);
 
         /* Drop the generated code */
-        RemoveCode (Start);
+        RemoveCode (&Start);
 
         /* We need a label */
         Label = GetLocalLabel ();
 
         /* Generate memcpy code */
-        if (Arg3.Expr.Val <= 127) {
+        if (Arg3.Expr.IVal <= 127) {
 
-            AddCodeLine ("ldy #$%02X", (unsigned char) (Arg3.Expr.Val-1));
-            AddCodeLine ("lda #$%02X", (unsigned char) Arg2.Expr.Val);
+            AddCodeLine ("ldy #$%02X", (unsigned char) (Arg3.Expr.IVal-1));
+            AddCodeLine ("lda #$%02X", (unsigned char) Arg2.Expr.IVal);
             g_defcodelabel (Label);
             if (Reg2) {
                 AddCodeLine ("lda (%s),y", ED_GetLabelName (&Arg2.Expr, 0));
@@ -289,7 +291,7 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
         } else {
 
             AddCodeLine ("ldy #$00");
-            AddCodeLine ("lda #$%02X", (unsigned char) Arg2.Expr.Val);
+            AddCodeLine ("lda #$%02X", (unsigned char) Arg2.Expr.IVal);
             g_defcodelabel (Label);
             if (Reg2) {
                 AddCodeLine ("lda (%s),y", ED_GetLabelName (&Arg2.Expr, 0));
@@ -302,7 +304,7 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
                 AddCodeLine ("sta %s,y", ED_GetLabelName (&Arg1.Expr, 0));
             }
             AddCodeLine ("iny");
-            AddCodeLine ("cpy #$%02X", (unsigned char) Arg3.Expr.Val);
+            AddCodeLine ("cpy #$%02X", (unsigned char) Arg3.Expr.IVal);
             AddCodeLine ("bne %s", LocalLabelName (Label));
 
         }
@@ -312,10 +314,10 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
          */
         *Expr = Arg1.Expr;
 
-    } else if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.Val <= 256 &&
+    } else if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.IVal <= 256 &&
                ED_IsRVal (&Arg2.Expr) && ED_IsLocConst (&Arg2.Expr) &&
                ED_IsRVal (&Arg1.Expr) && ED_IsLocStack (&Arg1.Expr) &&
-               (Arg1.Expr.Val - StackPtr) + Arg3.Expr.Val < 256) {
+               (Arg1.Expr.IVal - StackPtr) + Arg3.Expr.IVal < 256) {
 
         /* It is possible to just use one index register even if the stack
          * offset is not zero, by adjusting the offset to the constant
@@ -325,30 +327,30 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
          * address calculation could overflow in the linker.
          */
         int AllowOneIndex = !ED_IsLocRegister (&Arg2.Expr) &&
-                            !(ED_IsLocAbs (&Arg2.Expr) && Arg2.Expr.Val < 256);
+                            !(ED_IsLocAbs (&Arg2.Expr) && Arg2.Expr.IVal < 256);
 
         /* Calculate the real stack offset */
         int Offs = ED_GetStackOffs (&Arg1.Expr, 0);
 
         /* Drop the generated code */
-        RemoveCode (Start);
+        RemoveCode (&Start);
 
         /* We need a label */
         Label = GetLocalLabel ();
 
         /* Generate memcpy code */
-        if (Arg3.Expr.Val <= 127) {
+        if (Arg3.Expr.IVal <= 127 && !AllowOneIndex) {
 
-            if (Offs == 0 || AllowOneIndex) {
-                AddCodeLine ("ldy #$%02X", (unsigned char) (Offs + Arg3.Expr.Val - 1));
+            if (Offs == 0) {
+                AddCodeLine ("ldy #$%02X", (unsigned char) (Offs + Arg3.Expr.IVal - 1));
                 g_defcodelabel (Label);
                 AddCodeLine ("lda %s,y", ED_GetLabelName (&Arg2.Expr, -Offs));
                 AddCodeLine ("sta (sp),y");
                 AddCodeLine ("dey");
                 AddCodeLine ("bpl %s", LocalLabelName (Label));
             } else {
-                AddCodeLine ("ldx #$%02X", (unsigned char) (Arg3.Expr.Val-1));
-                AddCodeLine ("ldy #$%02X", (unsigned char) (Offs + Arg3.Expr.Val - 1));
+                AddCodeLine ("ldx #$%02X", (unsigned char) (Arg3.Expr.IVal-1));
+                AddCodeLine ("ldy #$%02X", (unsigned char) (Offs + Arg3.Expr.IVal - 1));
                 g_defcodelabel (Label);
                 AddCodeLine ("lda %s,x", ED_GetLabelName (&Arg2.Expr, 0));
                 AddCodeLine ("sta (sp),y");
@@ -365,7 +367,7 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
                 AddCodeLine ("lda %s,y", ED_GetLabelName (&Arg2.Expr, -Offs));
                 AddCodeLine ("sta (sp),y");
                 AddCodeLine ("iny");
-                AddCodeLine ("cpy #$%02X", (unsigned char) (Offs + Arg3.Expr.Val));
+                AddCodeLine ("cpy #$%02X", (unsigned char) (Offs + Arg3.Expr.IVal));
                 AddCodeLine ("bne %s", LocalLabelName (Label));
             } else {
                 AddCodeLine ("ldx #$00");
@@ -375,7 +377,7 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
                 AddCodeLine ("sta (sp),y");
                 AddCodeLine ("iny");
                 AddCodeLine ("inx");
-                AddCodeLine ("cpx #$%02X", (unsigned char) Arg3.Expr.Val);
+                AddCodeLine ("cpx #$%02X", (unsigned char) Arg3.Expr.IVal);
                 AddCodeLine ("bne %s", LocalLabelName (Label));
             }
 
@@ -386,9 +388,9 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
          */
         *Expr = Arg1.Expr;
 
-    } else if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.Val <= 256 &&
+    } else if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.IVal <= 256 &&
                ED_IsRVal (&Arg2.Expr) && ED_IsLocStack (&Arg2.Expr) &&
-               (Arg2.Expr.Val - StackPtr) + Arg3.Expr.Val < 256 &&
+               (Arg2.Expr.IVal - StackPtr) + Arg3.Expr.IVal < 256 &&
                ED_IsRVal (&Arg1.Expr) && ED_IsLocConst (&Arg1.Expr)) {
 
         /* It is possible to just use one index register even if the stack
@@ -399,30 +401,30 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
          * address calculation could overflow in the linker.
          */
         int AllowOneIndex = !ED_IsLocRegister (&Arg1.Expr) &&
-                            !(ED_IsLocAbs (&Arg1.Expr) && Arg1.Expr.Val < 256);
+                            !(ED_IsLocAbs (&Arg1.Expr) && Arg1.Expr.IVal < 256);
 
         /* Calculate the real stack offset */
         int Offs = ED_GetStackOffs (&Arg2.Expr, 0);
 
         /* Drop the generated code */
-        RemoveCode (Start);
+        RemoveCode (&Start);
 
         /* We need a label */
         Label = GetLocalLabel ();
 
         /* Generate memcpy code */
-        if (Arg3.Expr.Val <= 127) {
+        if (Arg3.Expr.IVal <= 127 && !AllowOneIndex) {
 
-            if (Offs == 0 || AllowOneIndex) {
-                AddCodeLine ("ldy #$%02X", (unsigned char) (Offs + Arg3.Expr.Val - 1));
+            if (Offs == 0) {
+                AddCodeLine ("ldy #$%02X", (unsigned char) (Arg3.Expr.IVal - 1));
                 g_defcodelabel (Label);
                 AddCodeLine ("lda (sp),y");
-                AddCodeLine ("sta %s,y", ED_GetLabelName (&Arg1.Expr, -Offs));
+                AddCodeLine ("sta %s,y", ED_GetLabelName (&Arg1.Expr, 0));
                 AddCodeLine ("dey");
                 AddCodeLine ("bpl %s", LocalLabelName (Label));
             } else {
-                AddCodeLine ("ldx #$%02X", (unsigned char) (Arg3.Expr.Val-1));
-                AddCodeLine ("ldy #$%02X", (unsigned char) (Offs + Arg3.Expr.Val - 1));
+                AddCodeLine ("ldx #$%02X", (unsigned char) (Arg3.Expr.IVal-1));
+                AddCodeLine ("ldy #$%02X", (unsigned char) (Offs + Arg3.Expr.IVal - 1));
                 g_defcodelabel (Label);
                 AddCodeLine ("lda (sp),y");
                 AddCodeLine ("sta %s,x", ED_GetLabelName (&Arg1.Expr, 0));
@@ -439,7 +441,7 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
                 AddCodeLine ("lda (sp),y");
                 AddCodeLine ("sta %s,y", ED_GetLabelName (&Arg1.Expr, -Offs));
                 AddCodeLine ("iny");
-                AddCodeLine ("cpy #$%02X", (unsigned char) (Offs + Arg3.Expr.Val));
+                AddCodeLine ("cpy #$%02X", (unsigned char) (Offs + Arg3.Expr.IVal));
                 AddCodeLine ("bne %s", LocalLabelName (Label));
             } else {
                 AddCodeLine ("ldx #$00");
@@ -449,7 +451,7 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
                 AddCodeLine ("sta %s,x", ED_GetLabelName (&Arg1.Expr, 0));
                 AddCodeLine ("iny");
                 AddCodeLine ("inx");
-                AddCodeLine ("cpx #$%02X", (unsigned char) Arg3.Expr.Val);
+                AddCodeLine ("cpx #$%02X", (unsigned char) Arg3.Expr.IVal);
                 AddCodeLine ("bne %s", LocalLabelName (Label));
             }
 
@@ -484,10 +486,10 @@ ExitPoint:
 static void StdFunc_memset (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
 /* Handle the memset function */
 {
-    /* Argument types */
-    static type Arg1Type[] = { T_PTR, T_VOID, T_END };  /* void* */
-    static type Arg2Type[] = { T_INT, T_END };          /* int */
-    static type Arg3Type[] = { T_SIZE_T, T_END };       /* size_t */
+    /* Argument types: (void*, int, size_t) */
+    static Type Arg1Type[] = { TYPE(T_PTR), TYPE(T_VOID), TYPE(T_END) };
+    static Type Arg2Type[] = { TYPE(T_INT), TYPE(T_END) };
+    static Type Arg3Type[] = { TYPE(T_SIZE_T), TYPE(T_END) };
 
     CodeMark Start;
     ArgDesc  Arg1, Arg2, Arg3;
@@ -496,12 +498,12 @@ static void StdFunc_memset (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
     unsigned Label;
 
     /* Remember where we are now */
-    Start = GetCodePos ();
+    GetCodePos (&Start);
 
     /* Argument #1 */
     ParseArg (&Arg1, Arg1Type);
-    g_push (Arg1.Flags, Arg1.Expr.Val);
-    Arg1.End = GetCodePos ();
+    g_push (Arg1.Flags, Arg1.Expr.IVal);
+    GetCodePos (&Arg1.End);
     ParamSize += SizeOf (Arg1Type);
     ConsumeComma ();
 
@@ -509,13 +511,13 @@ static void StdFunc_memset (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
      * function if it is a constant zero.
      */
     ParseArg (&Arg2, Arg2Type);
-    if ((Arg2.Flags & CF_CONST) != 0 && Arg2.Expr.Val == 0) {
+    if ((Arg2.Flags & CF_CONST) != 0 && Arg2.Expr.IVal == 0) {
         /* Don't call memset, call bzero instead */
         MemSet = 0;
     } else {
         /* Push the argument */
-        g_push (Arg2.Flags, Arg2.Expr.Val);
-        Arg2.End = GetCodePos ();
+        g_push (Arg2.Flags, Arg2.Expr.IVal);
+        GetCodePos (&Arg2.End);
         ParamSize += SizeOf (Arg2Type);
     }
     ConsumeComma ();
@@ -527,13 +529,13 @@ static void StdFunc_memset (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
      */
     ParseArg (&Arg3, Arg3Type);
     if (Arg3.Flags & CF_CONST) {
-        ExprLoad (CF_FORCECHAR, &Arg3.Expr);
+        LoadExpr (CF_NONE, &Arg3.Expr);
     }
 
     /* Emit the actual function call. This will also cleanup the stack. */
     g_call (CF_FIXARGC, MemSet? Func_memset : Func__bzero, ParamSize);
 
-    if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.Val == 0) {
+    if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.IVal == 0) {
 
         /* memset has been called with a count argument of zero */
         Warning ("Call to memset has no effect");
@@ -541,7 +543,7 @@ static void StdFunc_memset (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
         /* Remove all of the generated code but the load of the first
          * argument, which is what memset returns.
          */
-        RemoveCode (Arg1.Push);
+        RemoveCode (&Arg1.Push);
 
         /* Set the function result to the first argument */
         *Expr = Arg1.Expr;
@@ -559,7 +561,7 @@ static void StdFunc_memset (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
      * being constant numerical values. Some checks have shown that this
      * covers nearly 90% of all memset calls.
      */
-    if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.Val <= 256 &&
+    if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.IVal <= 256 &&
         ED_IsConstAbsInt (&Arg2.Expr) &&
         ((ED_IsRVal (&Arg1.Expr) && ED_IsLocConst (&Arg1.Expr)) ||
          (ED_IsLVal (&Arg1.Expr) && ED_IsLocRegister (&Arg1.Expr)))) {
@@ -567,16 +569,16 @@ static void StdFunc_memset (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
         int Reg = ED_IsLVal (&Arg1.Expr) && ED_IsLocRegister (&Arg1.Expr);
 
         /* Drop the generated code */
-        RemoveCode (Start);
+        RemoveCode (&Start);
 
         /* We need a label */
         Label = GetLocalLabel ();
 
         /* Generate memset code */
-        if (Arg3.Expr.Val <= 127) {
+        if (Arg3.Expr.IVal <= 127) {
 
-            AddCodeLine ("ldy #$%02X", (unsigned char) (Arg3.Expr.Val-1));
-            AddCodeLine ("lda #$%02X", (unsigned char) Arg2.Expr.Val);
+            AddCodeLine ("ldy #$%02X", (unsigned char) (Arg3.Expr.IVal-1));
+            AddCodeLine ("lda #$%02X", (unsigned char) Arg2.Expr.IVal);
             g_defcodelabel (Label);
             if (Reg) {
                 AddCodeLine ("sta (%s),y", ED_GetLabelName (&Arg1.Expr, 0));
@@ -589,7 +591,7 @@ static void StdFunc_memset (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
         } else {
 
             AddCodeLine ("ldy #$00");
-            AddCodeLine ("lda #$%02X", (unsigned char) Arg2.Expr.Val);
+            AddCodeLine ("lda #$%02X", (unsigned char) Arg2.Expr.IVal);
             g_defcodelabel (Label);
             if (Reg) {
                 AddCodeLine ("sta (%s),y", ED_GetLabelName (&Arg1.Expr, 0));
@@ -597,7 +599,7 @@ static void StdFunc_memset (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
                 AddCodeLine ("sta %s,y", ED_GetLabelName (&Arg1.Expr, 0));
             }
             AddCodeLine ("iny");
-            AddCodeLine ("cpy #$%02X", (unsigned char) Arg3.Expr.Val);
+            AddCodeLine ("cpy #$%02X", (unsigned char) Arg3.Expr.IVal);
             AddCodeLine ("bne %s", LocalLabelName (Label));
 
         }
@@ -607,27 +609,27 @@ static void StdFunc_memset (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
          */
         *Expr = Arg1.Expr;
 
-    } else if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.Val <= 256 &&
+    } else if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.IVal <= 256 &&
                ED_IsConstAbsInt (&Arg2.Expr) &&
                ED_IsRVal (&Arg1.Expr) && ED_IsLocStack (&Arg1.Expr) &&
-               (Arg1.Expr.Val - StackPtr) + Arg3.Expr.Val < 256) {
+               (Arg1.Expr.IVal - StackPtr) + Arg3.Expr.IVal < 256) {
 
         /* Calculate the real stack offset */
         int Offs = ED_GetStackOffs (&Arg1.Expr, 0);
 
         /* Drop the generated code */
-        RemoveCode (Start);
+        RemoveCode (&Start);
 
         /* We need a label */
         Label = GetLocalLabel ();
 
         /* Generate memset code */
         AddCodeLine ("ldy #$%02X", (unsigned char) Offs);
-        AddCodeLine ("lda #$%02X", (unsigned char) Arg2.Expr.Val);
+        AddCodeLine ("lda #$%02X", (unsigned char) Arg2.Expr.IVal);
         g_defcodelabel (Label);
         AddCodeLine ("sta (sp),y");
         AddCodeLine ("iny");
-        AddCodeLine ("cpy #$%02X", (unsigned char) (Offs + Arg3.Expr.Val));
+        AddCodeLine ("cpy #$%02X", (unsigned char) (Offs + Arg3.Expr.IVal));
         AddCodeLine ("bne %s", LocalLabelName (Label));
 
         /* memset returns the address, so the result is actually identical
@@ -635,14 +637,14 @@ static void StdFunc_memset (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
          */
         *Expr = Arg1.Expr;
 
-    } else if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.Val <= 256 &&
+    } else if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.IVal <= 256 &&
                ED_IsConstAbsInt (&Arg2.Expr) &&
-               (Arg2.Expr.Val != 0 || CodeSizeFactor > 200)) {
+               (Arg2.Expr.IVal != 0 || IS_Get (&CodeSizeFactor) > 200)) {
 
         /* Remove all of the generated code but the load of the first
          * argument.
          */
-        RemoveCode (Arg1.Push);
+        RemoveCode (&Arg1.Push);
 
         /* We need a label */
         Label = GetLocalLabel ();
@@ -650,20 +652,20 @@ static void StdFunc_memset (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
         /* Generate code */
         AddCodeLine ("sta ptr1");
         AddCodeLine ("stx ptr1+1");
-        if (Arg3.Expr.Val <= 127) {
-            AddCodeLine ("ldy #$%02X", (unsigned char) (Arg3.Expr.Val-1));
-            AddCodeLine ("lda #$%02X", (unsigned char) Arg2.Expr.Val);
+        if (Arg3.Expr.IVal <= 127) {
+            AddCodeLine ("ldy #$%02X", (unsigned char) (Arg3.Expr.IVal-1));
+            AddCodeLine ("lda #$%02X", (unsigned char) Arg2.Expr.IVal);
             g_defcodelabel (Label);
             AddCodeLine ("sta (ptr1),y");
             AddCodeLine ("dey");
             AddCodeLine ("bpl %s", LocalLabelName (Label));
         } else {
             AddCodeLine ("ldy #$00");
-            AddCodeLine ("lda #$%02X", (unsigned char) Arg2.Expr.Val);
+            AddCodeLine ("lda #$%02X", (unsigned char) Arg2.Expr.IVal);
             g_defcodelabel (Label);
             AddCodeLine ("sta (ptr1),y");
             AddCodeLine ("iny");
-            AddCodeLine ("cpy #$%02X", (unsigned char) Arg3.Expr.Val);
+            AddCodeLine ("cpy #$%02X", (unsigned char) Arg3.Expr.IVal);
             AddCodeLine ("bne %s", LocalLabelName (Label));
         }
 
@@ -700,9 +702,9 @@ ExitPoint:
 static void StdFunc_strcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
 /* Handle the strcpy function */
 {
-    /* Argument types */
-    static type Arg1Type[] = { T_PTR, T_CHAR, T_END };              /* char* */
-    static type Arg2Type[] = { T_PTR, T_CHAR|T_QUAL_CONST, T_END }; /* const char* */
+    /* Argument types: (char*, const char*) */
+    static Type Arg1Type[] = { TYPE(T_PTR), TYPE(T_CHAR), TYPE(T_END) };
+    static Type Arg2Type[] = { TYPE(T_PTR), TYPE(T_CHAR|T_QUAL_CONST), TYPE(T_END) };
 
     CodeMark Start;
     ArgDesc  Arg1, Arg2;
@@ -711,16 +713,16 @@ static void StdFunc_strcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
     unsigned L1;
 
     /* Setup the argument type string */
-    Arg1Type[1] = GetDefaultChar ();
-    Arg2Type[1] = GetDefaultChar () | T_QUAL_CONST;
+    Arg1Type[1].C = GetDefaultChar ();
+    Arg2Type[1].C = GetDefaultChar () | T_QUAL_CONST;
 
     /* Remember where we are now */
-    Start = GetCodePos ();
+    GetCodePos (&Start);
 
     /* Argument #1 */
     ParseArg (&Arg1, Arg1Type);
-    g_push (Arg1.Flags, Arg1.Expr.Val);
-    Arg1.End = GetCodePos ();
+    g_push (Arg1.Flags, Arg1.Expr.IVal);
+    GetCodePos (&Arg1.End);
     ParamSize += SizeOf (Arg1Type);
     ConsumeComma ();
 
@@ -731,7 +733,7 @@ static void StdFunc_strcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
      */
     ParseArg (&Arg2, Arg2Type);
     if (Arg2.Flags & CF_CONST) {
-        ExprLoad (CF_FORCECHAR, &Arg2.Expr);
+        LoadExpr (CF_NONE, &Arg2.Expr);
     }
 
     /* Emit the actual function call. This will also cleanup the stack. */
@@ -766,7 +768,7 @@ static void StdFunc_strcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
         }
 
         /* Drop the generated code */
-        RemoveCode (Start);
+        RemoveCode (&Start);
 
         /* We need labels */
         L1 = GetLocalLabel ();
@@ -794,13 +796,13 @@ static void StdFunc_strcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
          * address calculation could overflow in the linker.
          */
         int AllowOneIndex = !ED_IsLocRegister (&Arg1.Expr) &&
-                            !(ED_IsLocAbs (&Arg1.Expr) && Arg1.Expr.Val < 256);
+                            !(ED_IsLocAbs (&Arg1.Expr) && Arg1.Expr.IVal < 256);
 
         /* Calculate the real stack offset */
         int Offs = ED_GetStackOffs (&Arg2.Expr, 0);
 
         /* Drop the generated code */
-        RemoveCode (Start);
+        RemoveCode (&Start);
 
         /* We need labels */
         L1 = GetLocalLabel ();
@@ -837,13 +839,13 @@ static void StdFunc_strcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
          * address calculation could overflow in the linker.
          */
         int AllowOneIndex = !ED_IsLocRegister (&Arg2.Expr) &&
-                            !(ED_IsLocAbs (&Arg2.Expr) && Arg2.Expr.Val < 256);
+                            !(ED_IsLocAbs (&Arg2.Expr) && Arg2.Expr.IVal < 256);
 
         /* Calculate the real stack offset */
         int Offs = ED_GetStackOffs (&Arg1.Expr, 0);
 
         /* Drop the generated code */
-        RemoveCode (Start);
+        RemoveCode (&Start);
 
         /* We need labels */
         L1 = GetLocalLabel ();
@@ -891,7 +893,7 @@ static void StdFunc_strcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
 static void StdFunc_strlen (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
 /* Handle the strlen function */
 {
-    static type ArgType[] = { T_PTR, T_SCHAR, T_END };
+    static Type ArgType[] = { TYPE(T_PTR), TYPE(T_CHAR|T_QUAL_CONST), TYPE(T_END) };
     ExprDesc    Arg;
     int         IsArray;
     int         IsPtr;
@@ -902,7 +904,7 @@ static void StdFunc_strlen (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
 
 
     /* Setup the argument type string */
-    ArgType[1] = GetDefaultChar () | T_QUAL_CONST;
+    ArgType[1].C = GetDefaultChar () | T_QUAL_CONST;
 
     /* Evaluate the parameter */
     hie1 (&Arg);
@@ -940,8 +942,8 @@ static void StdFunc_strlen (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
     if (ED_IsLocLiteral (&Arg) && IS_Get (&WritableStrings) == 0) {
 
         /* Constant string literal */
-        ED_MakeConstAbs (Expr, strlen (GetLiteral (Arg.Val)), type_size_t);
-        ResetLiteralPoolOffs (Arg.Val);
+        ED_MakeConstAbs (Expr, strlen (GetLiteral (Arg.IVal)), type_size_t);
+        ResetLiteralPoolOffs (Arg.IVal);
 
     /* We will inline strlen for arrays with constant addresses, if either the
      * inlining was forced on the command line, or the array is smaller than
@@ -968,7 +970,7 @@ static void StdFunc_strlen (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
      * completely within the reach of a byte sized index register.
      */
     } else if (ED_IsLocStack (&Arg) && IsArray && IsByteIndex &&
-               (Arg.Val - StackPtr) + ECount < 256) {
+               (Arg.IVal - StackPtr) + ECount < 256) {
 
         /* Calculate the true stack offset */
         int Offs = ED_GetStackOffs (&Arg, 0);
@@ -1014,10 +1016,10 @@ static void StdFunc_strlen (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
      * requested on the command line, and the code size factor is more than
      * 400 (code is 13 bytes vs. 3 for a jsr call).
      */
-    } else if (CodeSizeFactor > 400 && IS_Get (&InlineStdFuncs)) {
+    } else if (IS_Get (&CodeSizeFactor) > 400 && IS_Get (&InlineStdFuncs)) {
 
         /* Load the expression into the primary */
-        ExprLoad (CF_NONE, &Arg);
+        LoadExpr (CF_NONE, &Arg);
 
         /* Inline the function */
         L = GetLocalLabel ();
@@ -1038,7 +1040,7 @@ static void StdFunc_strlen (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
     } else {
 
         /* Load the expression into the primary */
-        ExprLoad (CF_NONE, &Arg);
+        LoadExpr (CF_NONE, &Arg);
 
         /* Call the strlen function */
         AddCodeLine ("jsr _%s", Func_strlen);
@@ -1056,7 +1058,7 @@ static void StdFunc_strlen (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
 
 
 /*****************************************************************************/
-/*                                  Code                                    */
+/*                                  Code                                    */
 /*****************************************************************************/