compiler/libec: Fixed passing of typed objects in ellipsis functions; Fixed string...
[sdk] / compiler / libec / src / pass15.ec
index 217d97a..1d32137 100644 (file)
@@ -34,6 +34,8 @@ static char * thisNameSpace;
 /*static */Class containerClass;
 bool thisClassParams = true;
 
+uint internalValueCounter;
+
 #ifdef _DEBUG
 Time findSymbolTotalTime;
 #endif
@@ -56,117 +58,6 @@ Time findSymbolTotalTime;
    }
 }
 
-int64 _strtoi64(char * string, char ** endString, int base)
-{
-   int64 value = 0;
-   int sign = 1;
-   int c;
-   char ch;
-   for(c = 0; (ch = string[c]) && isspace(ch); c++);
-   if(ch =='+') c++;
-   else if(ch == '-') { sign = -1; c++; };
-   if(!base)
-   {
-      if(ch == 0 && string[c+1] == 'x')
-      {
-         base = 16;
-         c+=2;
-      }
-      else if(ch == '0')
-      {
-         base = 8;
-         c++;
-      }
-      else
-         base = 10;
-   }
-   for( ;(ch = string[c]); c++)
-   {
-      if(ch == '0')
-         ch = 0;
-      else if(ch >= '1' && ch <= '9')
-         ch -= '1';
-      else if(ch >= 'a' && ch <= 'z') 
-         ch -= 'a'; 
-      else if(ch >= 'A' && ch <= 'Z') 
-         ch -= 'A';
-      else
-      {
-         *endString = string + c;
-         // Invalid character
-         break;
-      }
-      if(ch < base)
-      {
-         value *= base;
-         value += ch;
-      }
-      else
-      {
-         *endString = string + c;
-         // Invalid character
-         break;
-      }
-   }
-   return sign*value;
-}
-
-uint64 _strtoui64(char * string, char ** endString, int base)
-{
-   uint64 value = 0;
-   int sign = 1;
-   int c;
-   char ch;
-   for(c = 0; (ch = string[c]) && isspace(ch); c++);
-   if(ch =='+') c++;
-   else if(ch == '-') { sign = -1; c++; };
-   if(!base)
-   {
-      if(ch == 0 && string[c+1] == 'x')
-      {
-         base = 16;
-         c+=2;
-      }
-      else if(ch == '0')
-      {
-         base = 8;
-         c++;
-      }
-      else
-         base = 10;
-   }
-   for( ;(ch = string[c]); c++)
-   {
-      if(ch == '0')
-         ch = 0;
-      else if(ch >= '1' && ch <= '9')
-         ch -= '1';
-      else if(ch >= 'a' && ch <= 'z') 
-         ch -= 'a'; 
-      else if(ch >= 'A' && ch <= 'Z') 
-         ch -= 'A';
-      else
-      {
-         if(endString) *endString = string + c;
-         // Invalid character
-         break;
-      }
-      if(ch < base)
-      {
-         value *= base;
-         value += ch;
-      }
-      else
-      {
-         if(endString)
-            *endString = string + c;
-         // Invalid character
-         break;
-      }
-   }
-   return sign*value;
-}
-
 Type ProcessTemplateParameterType(TemplateParameter param)
 {
    if(param && param.type == TemplateParameterType::type && (param.dataType || param.dataTypeString))
@@ -201,6 +92,8 @@ bool NeedCast(Type type1, Type type2)
          case shortType:
          case intType:
          case int64Type:
+         case intPtrType:
+         case intSizeType:
             if(type1.passAsTemplate && !type2.passAsTemplate)
                return true;
             return type1.isSigned != type2.isSigned;
@@ -238,7 +131,7 @@ static void ReplaceClassMembers(Expression exp, Class _class)
          Property prop = eClass_FindProperty(_class, id.string, privateModule);
          Method method = null;
          DataMember member = null;
-         ClassProperty classProp;
+         ClassProperty classProp = null;
          if(!prop)
          {
             method = eClass_FindMethod(_class, id.string, privateModule);
@@ -402,14 +295,14 @@ public char * PrintUChar(unsigned char result)
 
 public char * PrintFloat(float result)
 {
-   char temp[100];
+   char temp[350];
    sprintf(temp, "%.16ff", result);
    return CopyString(temp);
 }
 
 public char * PrintDouble(double result)
 {
-   char temp[100];
+   char temp[350];
    sprintf(temp, "%.16f", result);
    return CopyString(temp);
 }
@@ -425,30 +318,41 @@ public char * PrintDouble(double result)
       Operand op2 = GetOperand(exp);                        \
       if(op2.kind == intType && op2.type.isSigned) *value2 = (t) op2.i; \
       else if(op2.kind == intType) *value2 = (t) op2.ui;                 \
-      if(op2.kind == int64Type && op2.type.isSigned) *value2 = (t) op2.i64; \
+      else if(op2.kind == int64Type && op2.type.isSigned) *value2 = (t) op2.i64; \
       else if(op2.kind == int64Type) *value2 = (t) op2.ui64;                 \
+      else if(op2.kind == intSizeType && op2.type.isSigned) *value2 = (t) op2.i64; \
+      else if(op2.kind == intSizeType) *value2 = (t) op2.ui64; \
+      else if(op2.kind == intPtrType && op2.type.isSigned) *value2 = (t) op2.i64; \
+      else if(op2.kind == intPtrType) *value2 = (t) op2.ui64;                 \
       else if(op2.kind == shortType && op2.type.isSigned) *value2 = (t) op2.s;   \
       else if(op2.kind == shortType) *value2 = (t) op2.us;                        \
       else if(op2.kind == charType && op2.type.isSigned) *value2 = (t) op2.c;    \
       else if(op2.kind == charType) *value2 = (t) op2.uc;                         \
       else if(op2.kind == floatType) *value2 = (t) op2.f;                         \
       else if(op2.kind == doubleType) *value2 = (t) op2.d;                        \
-      else if(op2.kind == pointerType) *value2 = (t) op2.ui;                        \
+      else if(op2.kind == pointerType) *value2 = (t) op2.ui64;                    \
       else                                                                          \
          return false;                                                              \
       return true;                                                                  \
    }
 
-GETVALUE(Int, int);
-GETVALUE(UInt, unsigned int);
-GETVALUE(Int64, int64);
-GETVALUE(UInt64, uint64);
-GETVALUE(Short, short);
-GETVALUE(UShort, unsigned short);
-GETVALUE(Char, char);
-GETVALUE(UChar, unsigned char);
-GETVALUE(Float, float);
-GETVALUE(Double, double);
+// To help the deubugger currently not preprocessing...
+#define HELP(x) x
+
+GETVALUE(Int, HELP(int));
+GETVALUE(UInt, HELP(unsigned int));
+GETVALUE(Int64, HELP(int64));
+GETVALUE(UInt64, HELP(uint64));
+GETVALUE(IntPtr, HELP(intptr));
+GETVALUE(UIntPtr, HELP(uintptr));
+GETVALUE(IntSize, HELP(intsize));
+GETVALUE(UIntSize, HELP(uintsize));
+GETVALUE(Short, HELP(short));
+GETVALUE(UShort, HELP(unsigned short));
+GETVALUE(Char, HELP(char));
+GETVALUE(UChar, HELP(unsigned char));
+GETVALUE(Float, HELP(float));
+GETVALUE(Double, HELP(double));
 
 void ComputeExpression(Expression exp);
 
@@ -457,12 +361,30 @@ void ComputeClassMembers(Class _class, bool isMember)
    DataMember member = isMember ? (DataMember) _class : null;
    Context context = isMember ? null : SetupTemplatesContext(_class);
    if(member || ((_class.type == bitClass || _class.type == normalClass || _class.type == structClass || _class.type == noHeadClass) && 
-                 (_class.type == bitClass || _class.structSize == _class.offset) && _class.computeSize))
+                 (_class.type == bitClass || (!_class.structSize || _class.structSize == _class.offset)) && _class.computeSize))
    {
       int c;
       int unionMemberOffset = 0;
       int bitFields = 0;
 
+      /*
+      if(!member && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass) && _class.memberOffset && _class.memberOffset > _class.base.structSize)
+         _class.memberOffset = (_class.base && _class.base.type != systemClass) ? _class.base.structSize : 0;
+      */
+
+      if(member)
+      {
+         member.memberOffset = 0;
+         if(targetBits < sizeof(void *) * 8)
+            member.structAlignment = 0;
+      }
+      else if(targetBits < sizeof(void *) * 8)
+         _class.structAlignment = 0;
+
+      // Confusion here: non struct classes seem to have their memberOffset restart at 0 at each hierarchy level
+      if(!member && ((_class.type == normalClass || _class.type == noHeadClass) || (_class.type == structClass && _class.memberOffset && _class.memberOffset > _class.base.structSize)))
+         _class.memberOffset = (_class.base && _class.type == structClass) ? _class.base.structSize : 0;
+
       if(!member && _class.destructionWatchOffset)
          _class.memberOffset += sizeof(OldList);
 
@@ -477,8 +399,6 @@ void ComputeClassMembers(Class _class, bool isMember)
             {
                if(dataMember.type == normalMember && dataMember.dataTypeString && !dataMember.dataType)
                {
-                  /*if(dataMember.dataType)
-                     printf("");*/
                   dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
                   /*if(!dataMember.dataType)
                      dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
@@ -575,12 +495,6 @@ void ComputeClassMembers(Class _class, bool isMember)
                      alignment = dataMember.dataType.alignment;
                   }
 
-#ifdef _DEBUG
-                  if(!size)
-                  {
-                     // printf("");
-                  }
-#endif
                   if(isMember)
                   {
                      // TESTING THIS PADDING CODE
@@ -617,12 +531,20 @@ void ComputeClassMembers(Class _class, bool isMember)
                }
                else
                {
+                  int alignment;
+
                   ComputeClassMembers((Class)dataMember, true);
+                  alignment = dataMember.structAlignment;
 
                   if(isMember)
                   {
-                     // THERE WASN'T A MAX HERE ? member.structAlignment = dataMember.structAlignment;
-                     member.structAlignment = Max(member.structAlignment, dataMember.structAlignment);
+                     if(alignment)
+                     {
+                        if(member.memberOffset % alignment)
+                           member.memberOffset += alignment - (member.memberOffset % alignment);
+
+                        member.structAlignment = Max(member.structAlignment, alignment);
+                     }
                      dataMember.offset = member.memberOffset;
                      if(member.type == unionMember)
                         unionMemberOffset = Max(unionMemberOffset, dataMember.memberOffset);
@@ -631,7 +553,12 @@ void ComputeClassMembers(Class _class, bool isMember)
                   }
                   else
                   {
-                     _class.structAlignment = Max(_class.structAlignment, dataMember.structAlignment);
+                     if(alignment)
+                     {
+                        if(_class.memberOffset % alignment)
+                           _class.memberOffset += alignment - (_class.memberOffset % alignment);
+                        _class.structAlignment = Max(_class.structAlignment, alignment);
+                     }
                      dataMember.offset = _class.memberOffset;
                      _class.memberOffset += dataMember.memberOffset;
                   }
@@ -690,7 +617,13 @@ void ComputeClassMembers(Class _class, bool isMember)
 
          if(_class.type != bitClass)
          {
-            _class.structSize = (_class.base ? (_class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize) : 0) + _class.memberOffset;
+            int extra = 0;
+            if(_class.structAlignment)
+            {
+               if(_class.memberOffset % _class.structAlignment)
+                  extra += _class.structAlignment - (_class.memberOffset % _class.structAlignment);
+            }
+            _class.structSize = (_class.base ? (_class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize) : 0) + _class.memberOffset + extra;
             if(!member)
             {
                Property prop;
@@ -754,6 +687,8 @@ public int ComputeTypeSize(Type type)
          case charType: type.alignment = size = sizeof(char); break;
          case intType: type.alignment = size = sizeof(int); break;
          case int64Type: type.alignment = size = sizeof(int64); break;
+         case intPtrType: type.alignment = size = targetBits / 8; break;
+         case intSizeType: type.alignment = size = targetBits / 8; break;
          case longType: type.alignment = size = sizeof(long); break;
          case shortType: type.alignment = size = sizeof(short); break;
          case floatType: type.alignment = size = sizeof(float); break;
@@ -781,10 +716,10 @@ public int ComputeTypeSize(Type type)
                size = type.alignment = ComputeTypeSize(_class.dataType);
             }
             else
-               size = type.alignment = sizeof(Instance *);
+               size = type.alignment = targetBits / 8; // sizeof(Instance *);
             break;
          }
-         case pointerType: case subClassType: size = type.alignment = sizeof(void *); break;
+         case pointerType: case subClassType: size = type.alignment = targetBits / 8; /*sizeof(void *); */break;
          case arrayType: 
             if(type.arraySizeExp)
             {
@@ -805,18 +740,12 @@ public int ComputeTypeSize(Type type)
                   yylloc = oldLoc;
                }
                GetInt(type.arraySizeExp, &type.arraySize);
-#ifdef _DEBUG
-               if(!type.arraySize)
-               {
-                  printf("");
-               }
-#endif
             }
             else if(type.enumClass)
             {
                if(type.enumClass && type.enumClass.registered && type.enumClass.registered.type == enumClass)
                {
-                  type.arraySize = eClass_GetProperty(type.enumClass.registered, "enumSize");
+                  type.arraySize = (int)eClass_GetProperty(type.enumClass.registered, "enumSize");
                }
                else
                   type.arraySize = 0;
@@ -874,19 +803,22 @@ public int ComputeTypeSize(Type type)
             TemplateParameter param = type.templateParameter;
             Type baseType = ProcessTemplateParameterType(param);
             if(baseType)
+            {
                size = ComputeTypeSize(baseType);
+               type.alignment = baseType.alignment;
+            }
             else
-               size = sizeof(uint64);
+               type.alignment = size = sizeof(uint64);
             break;
          }
          case enumType:
          {
-            size = sizeof(enum { test });
+            type.alignment = size = sizeof(enum { test });
             break;
          }
          case thisClassType:
          {
-            size = sizeof(void *);
+            type.alignment = size = targetBits / 8; //sizeof(void *);
             break;
          }
       }
@@ -897,7 +829,7 @@ public int ComputeTypeSize(Type type)
 }
 
 
-/*static */int AddMembers(OldList * declarations, Class _class, bool isMember, uint * retSize, Class topClass)
+/*static */int AddMembers(OldList * declarations, Class _class, bool isMember, uint * retSize, Class topClass, bool *addedPadding)
 {
    // This function is in need of a major review when implementing private members etc.
    DataMember topMember = isMember ? (DataMember) _class : null;
@@ -906,6 +838,8 @@ public int ComputeTypeSize(Type type)
    int alignment, size;
    DataMember member;
    Context context = isMember ? null : SetupTemplatesContext(_class);
+   if(addedPadding)
+      *addedPadding = false;
 
    if(!isMember && _class.base)
    {
@@ -914,7 +848,7 @@ public int ComputeTypeSize(Type type)
       {
          // DANGER: Testing this noHeadClass here...
          if(_class.type == structClass || _class.type == noHeadClass)
-            /*totalSize = */AddMembers(declarations, _class.base, false, &totalSize, topClass);
+            /*totalSize = */AddMembers(declarations, _class.base, false, &totalSize, topClass, null);
          else
             maxSize -= _class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize;
       }
@@ -973,7 +907,7 @@ public int ComputeTypeSize(Type type)
                OldList * specs = MkList(), * list = MkList();
                
                size = 0;
-               AddMembers(list, (Class)member, true, &size, topClass);
+               AddMembers(list, (Class)member, true, &size, topClass, null);
                ListAdd(specs, 
                   MkStructOrUnion((member.type == unionMember)?unionSpecifier:structSpecifier, null, list));
                ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, null, null)));
@@ -999,11 +933,19 @@ public int ComputeTypeSize(Type type)
    }
    else if(totalSize < maxSize && _class.type != systemClass)
    {
-      char sizeString[50];
-      sprintf(sizeString, "%d", maxSize - totalSize);
-      ListAdd(declarations, 
-         MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(CHAR)), 
-         MkListOne(MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__ecere_padding")), MkExpConstant(sizeString))), null)));
+      int autoPadding = 0;
+      if(!isMember && _class.structAlignment && totalSize % _class.structAlignment)
+         autoPadding = _class.structAlignment - (totalSize % _class.structAlignment);
+      if(totalSize + autoPadding < maxSize)
+      {
+         char sizeString[50];
+         sprintf(sizeString, "%d", maxSize - totalSize);
+         ListAdd(declarations, 
+            MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(CHAR)), 
+            MkListOne(MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__ecere_padding")), MkExpConstant(sizeString))), null)));
+         if(addedPadding)
+            *addedPadding = true;
+      }
    }
    if(context)
       FinishTemplatesContext(context);
@@ -1059,12 +1001,12 @@ void DeclareStruct(char * name, bool skipNoHead)
    External external = null;
    Symbol classSym = FindClass(name);
 
-   if(!inCompiler || !classSym) return null;
+   if(!inCompiler || !classSym) return;
 
    // We don't need any declaration for bit classes...
    if(classSym.registered && 
       (classSym.registered.type == bitClass || classSym.registered.type == unitClass || classSym.registered.type == enumClass))
-      return null;
+      return;
 
    /*if(classSym.registered.templateClass)
       return DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
@@ -1092,7 +1034,7 @@ void DeclareStruct(char * name, bool skipNoHead)
             DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
             classSym.declaring--;
          }
-         return null;
+         return;
       }
       
       //if(!skipNoHead)
@@ -1106,18 +1048,19 @@ void DeclareStruct(char * name, bool skipNoHead)
 
       if(!skipNoHead)
       {
+         bool addedPadding = false;
          classSym.declaredStructSym = true;
 
          declarations = MkList();
 
-         AddMembers(declarations, classSym.registered, false, null, classSym.registered);
+         AddMembers(declarations, classSym.registered, false, null, classSym.registered, &addedPadding);
 
          //ListAdd(specifiers, MkSpecifier(TYPEDEF));
          //ListAdd(specifiers, MkStructOrUnion(structSpecifier, null, declarations));
 
-         if(!declarations->count)
+         if(!declarations->count || (declarations->count == 1 && addedPadding))
          {
-            FreeList(declarations, null);
+            FreeList(declarations, FreeClassDef);
             declarations = null;
          }
       }
@@ -1694,7 +1637,7 @@ void ProcessMemberInitData(MemberInit member, Class _class, Class * curClass, Da
       if(type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type && _class.templateArgs /* TODO: Watch out for these _class.templateClass*/)
       {
          int id = 0;
-         ClassTemplateParameter curParam;
+         ClassTemplateParameter curParam = null;
          Class sClass;
          for(sClass = _class; sClass; sClass = sClass.base)
          {
@@ -2218,7 +2161,7 @@ ClassTemplateArgument * FindTemplateArg(Class _class, TemplateParameter param)
 {
    ClassTemplateArgument * arg = null;
    int id = 0;
-   ClassTemplateParameter curParam;
+   ClassTemplateParameter curParam = null;
    Class sClass;
    for(sClass = _class; sClass; sClass = sClass.base)
    {
@@ -2259,7 +2202,7 @@ public Context SetupTemplatesContext(Class _class)
       {
          if(param.type == type && param.identifier)
          {
-            TemplatedType type { key = (uint)param.identifier.string, param = param };
+            TemplatedType type { key = (uintptr)param.identifier.string, param = param };
             curContext.templateTypes.Add((BTNode)type);
          }
       }
@@ -2288,7 +2231,7 @@ public Context SetupTemplatesContext(Class _class)
                      dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
                   };
                }
-               type = TemplatedType { key = (uint)p.name, param = param };
+               type = TemplatedType { key = (uintptr)p.name, param = param };
                curContext.templateTypes.Add((BTNode)type);
             }
          }
@@ -2780,7 +2723,7 @@ bool DeclareFunction(GlobalFunction function, char * name)
             {
                Specifier spec;
                for(spec = specifiers->first; spec; spec = spec.next)
-                  if(spec.type == extendedSpecifier && !strcmp(spec.name, "dllexport"))
+                  if(spec.type == extendedSpecifier && spec.extDecl && spec.extDecl.type == extDeclString && !strcmp(spec.extDecl.s, "dllexport"))
                   {
                      specifiers->Remove(spec);
                      FreeSpecifier(spec);
@@ -2946,7 +2889,7 @@ public bool MatchTypes(Type source, Type dest, OldList conversions, Class owning
 
          /*source.kind != voidType && source.kind != structType && source.kind != unionType  */
       
-         /*&& (source.kind != classType /*|| source._class.registered.type != structClass)*/)
+         /*&& (source.kind != classType /-*|| source._class.registered.type != structClass)*/)
          return true;
       if(!isConversionExploration && source.kind == pointerType && source.type.kind == voidType &&
          ((dest.kind == classType && (!dest._class || !dest._class.registered || dest._class.registered.type == structClass || dest._class.registered.type == normalClass || dest._class.registered.type == noHeadClass || dest._class.registered.type == systemClass))
@@ -3170,15 +3113,19 @@ public bool MatchTypes(Type source, Type dest, OldList conversions, Class owning
          return true;
       else if(dest.kind == shortType && source.kind == charType)
          return true;
-      else if(dest.kind == intType && (source.kind == shortType || source.kind == charType))
+      else if(dest.kind == intType && (source.kind == shortType || source.kind == charType || source.kind == intSizeType /* Exception here for size_t */))
+         return true;
+      else if(dest.kind == int64Type && (source.kind == shortType || source.kind == charType || source.kind == intType || source.kind == intPtrType || source.kind == intSizeType))
+         return true;
+      else if(dest.kind == intPtrType && (source.kind == shortType || source.kind == charType || source.kind == intType || source.kind == intSizeType || source.kind == int64Type))
          return true;
-      else if(dest.kind == int64Type && (source.kind == shortType || source.kind == charType || source.kind == intType))
+      else if(dest.kind == intSizeType && (source.kind == shortType || source.kind == charType || source.kind == intType || source.kind == int64Type || source.kind == intPtrType))
          return true;
       else if(source.kind == enumType &&
-         (dest.kind == intType || dest.kind == shortType || dest.kind == charType || dest.kind == longType || dest.kind == int64Type))
+         (dest.kind == intType || dest.kind == shortType || dest.kind == charType || dest.kind == longType || dest.kind == int64Type || dest.kind == intPtrType || dest.kind == intSizeType))
           return true;
       else if(dest.kind == enumType &&
-         (source.kind == intType || source.kind == shortType || source.kind == charType || source.kind == longType || dest.kind == int64Type))
+         (source.kind == intType || source.kind == shortType || source.kind == charType || source.kind == longType || source.kind == int64Type || source.kind == intPtrType || source.kind == intSizeType))
           return true;
       else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) && 
               ((source.kind == functionType || (source.kind == pointerType && source.type.kind == functionType) || source.kind == methodType)))
@@ -3300,7 +3247,7 @@ public bool MatchTypes(Type source, Type dest, OldList conversions, Class owning
                   paramSource.kind != templateType)
                {
                   int id = 0;
-                  ClassTemplateParameter curParam;
+                  ClassTemplateParameter curParam = null;
                   Class sClass;
                   for(sClass = owningClassSource; sClass; sClass = sClass.base)
                   {
@@ -3491,6 +3438,7 @@ bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, b
 {
    Type source = sourceExp.expType;
    Type realDest = dest;
+   Type backupSourceExpType = null;
 
    if(dest.kind == pointerType && sourceExp.type == constantExp && !strtoul(sourceExp.constant, null, 0))
       return true;
@@ -3567,9 +3515,9 @@ bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, b
                if(tempType._class)
                   MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false);
 
-               FreeType(sourceExp.expType);
+               // NOTE: To handle bad warnings on int64 vs 32 bit eda::Id incompatibilities
+               backupSourceExpType = sourceExp.expType;
                sourceExp.expType = dest; dest.refCount++;
-
                //sourceExp.expType = MkClassType(_class.fullName);
                flag = true;            
 
@@ -3635,6 +3583,7 @@ bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, b
 
             FreeType(source);
             FreeType(dest);
+            if(backupSourceExpType) FreeType(backupSourceExpType);
             return true;
          }
       }
@@ -3771,6 +3720,7 @@ bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, b
                FreeType(source);
                if(inCompiler) FreeType(dest);
 
+               if(backupSourceExpType) FreeType(backupSourceExpType);
                return true;
             }
 
@@ -3826,6 +3776,12 @@ bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, b
          {
             FreeType(source);
             FreeType(dest);
+            if(backupSourceExpType)
+            {
+               // Failed to convert: revert previous exp type
+               if(sourceExp.expType) FreeType(sourceExp.expType);
+               sourceExp.expType = backupSourceExpType;
+            }
             return false;
          }
       }
@@ -3875,6 +3831,12 @@ bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, b
       {
          FreeType(source);
          FreeType(dest);
+         if(backupSourceExpType)
+         {
+            // Failed to convert: revert previous exp type
+            if(sourceExp.expType) FreeType(sourceExp.expType);
+            sourceExp.expType = backupSourceExpType;
+         }
          return false;
       }
 
@@ -3911,6 +3873,8 @@ bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, b
 
       FreeType(dest);
       FreeType(source);
+      if(backupSourceExpType) FreeType(backupSourceExpType);
+
       return true;
    }
    else
@@ -4254,6 +4218,32 @@ public Operand GetOperand(Expression exp)
                }
                op.kind = intType;
                break;
+            case intPtrType:
+               if(type.isSigned)
+               {
+                  op.i64 = (int64)_strtoi64(exp.constant, null, 0);
+                  op.ops = intOps;
+               }
+               else
+               {
+                  op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
+                  op.ops = uintOps;
+               }
+               op.kind = intType;
+               break;
+            case intSizeType:
+               if(type.isSigned)
+               {
+                  op.i64 = (int64)_strtoi64(exp.constant, null, 0);
+                  op.ops = intOps;
+               }
+               else
+               {
+                  op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
+                  op.ops = uintOps;
+               }
+               op.kind = intType;
+               break;
             case floatType:
                op.f = (float)strtod(exp.constant, null);
                op.ops = floatOps;
@@ -4268,7 +4258,7 @@ public Operand GetOperand(Expression exp)
             case arrayType:
             case pointerType:
             case classType:
-               op.p = (unsigned char *)strtoul(exp.constant, null, 0);
+               op.ui64 = _strtoui64(exp.constant, null, 0);
                op.kind = pointerType;
                op.ops = uintOps;
                // op.ptrSize = 
@@ -4378,6 +4368,22 @@ static void PopulateInstanceProcessMember(Instantiation inst, OldList * memberLi
                   exp.type = constantExp;
                   break;
                }
+               case intPtrType:
+               {
+                  FreeExpContents(exp);
+                  // TODO: This should probably use proper type
+                  exp.constant = PrintInt64((int64)*(intptr*)ptr);
+                  exp.type = constantExp;
+                  break;
+               }
+               case intSizeType:
+               {
+                  FreeExpContents(exp);
+                  // TODO: This should probably use proper type
+                  exp.constant = PrintInt64((int64)*(intptr*)ptr);
+                  exp.type = constantExp;
+                  break;
+               }
                default:
                   Compiler_Error($"Unhandled type populating instance\n");
             }
@@ -4479,6 +4485,12 @@ void PopulateInstance(Instantiation inst)
                      exp.type = constantExp;
                      break;
                   }
+                  case intPtrType:
+                  {
+                     exp.constant = PrintInt64((int64)*(intptr*)ptr);
+                     exp.type = constantExp;
+                     break;
+                  }
                   default:
                      Compiler_Error($"Unhandled type populating instance\n");
                }
@@ -4675,6 +4687,16 @@ void ComputeInstantiation(Expression exp)
                                        GetInt64(value, (int64*)ptr);
                                        break;
                                     }
+                                    case intPtrType:
+                                    {
+                                       GetIntPtr(value, (intptr*)ptr);
+                                       break;
+                                    }
+                                    case intSizeType:
+                                    {
+                                       GetIntSize(value, (intsize*)ptr);
+                                       break;
+                                    }
                                     case floatType:
                                     {
                                        GetFloat(value, (float*)ptr);
@@ -4737,13 +4759,25 @@ void ComputeInstantiation(Expression exp)
                                        Set(inst.data, _strtoi64(value.constant, null, 0));
                                        break;
                                     }
+                                    case intPtrType:
+                                    {
+                                       void (*Set)(void *, intptr) = (void *)prop.Set;
+                                       Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
+                                       break;
+                                    }
+                                    case intSizeType:
+                                    {
+                                       void (*Set)(void *, intsize) = (void *)prop.Set;
+                                       Set(inst.data, (intsize)_strtoi64(value.constant, null, 0));
+                                       break;
+                                    }
                                  }
                               }
                               else if(value.type == stringExp)
                               {
                                  char temp[1024];
                                  ReadString(temp, value.string);
-                                 prop.Set(inst.data, temp);
+                                 ((void (*)(void *, void *))(void *)prop.Set)(inst.data, temp);
                               }
                            }
                         }
@@ -4848,6 +4882,26 @@ void ComputeInstantiation(Expression exp)
                                     else
                                        bits |= ((uint64)part << bitMember.pos);
                                     break;
+                                 case intPtrType:
+                                    if(type.isSigned)
+                                    {
+                                       bits |= ((intptr)part << bitMember.pos);
+                                    }
+                                    else
+                                    {
+                                       bits |= ((uintptr)part << bitMember.pos);
+                                    }
+                                    break;
+                                 case intSizeType:
+                                    if(type.isSigned)
+                                    {
+                                       bits |= ((ssize_t)(intsize)part << bitMember.pos);
+                                    }
+                                    else
+                                    {
+                                       bits |= ((size_t) (uintsize)part << bitMember.pos);
+                                    }
+                                    break;
                               }
                            }
                         }
@@ -5449,6 +5503,42 @@ void ComputeExpression(Expression exp)
                                  PopulateInstance(exp.instance);
                                  break;
                               }
+                              case intPtrType:
+                              {
+                                 // TOFIX:
+                                 intptr intValue;
+                                 void (*Set)(void *, intptr) = (void *)prop.Set;
+
+                                 exp.instance = Instantiation { };
+                                 exp.instance.data = new0 byte[_class.structSize];
+                                 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
+                                 exp.instance.loc = exp.loc;
+                                 exp.type = instanceExp;
+                              
+                                 GetIntPtr(value, &intValue);
+
+                                 Set(exp.instance.data, intValue);
+                                 PopulateInstance(exp.instance);
+                                 break;
+                              }
+                              case intSizeType:
+                              {
+                                 // TOFIX:
+                                 intsize intValue;
+                                 void (*Set)(void *, intsize) = (void *)prop.Set;
+
+                                 exp.instance = Instantiation { };
+                                 exp.instance.data = new0 byte[_class.structSize];
+                                 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
+                                 exp.instance.loc = exp.loc;
+                                 exp.type = instanceExp;
+
+                                 GetIntSize(value, &intValue);
+
+                                 Set(exp.instance.data, intValue);
+                                 PopulateInstance(exp.instance);
+                                 break;
+                              }
                               case doubleType:
                               {
                                  double doubleValue;
@@ -5738,6 +5828,42 @@ void ComputeExpression(Expression exp)
                      exp.type = constantExp;
                   }
                   break;
+               case intPtrType:
+                  if(type.isSigned)
+                  {
+                     intptr value;
+                     GetIntPtr(e, &value);
+                     FreeExpContents(exp);
+                     exp.constant = PrintInt64((int64)value);
+                     exp.type = constantExp;
+                  }
+                  else
+                  {
+                     uintptr value;
+                     GetUIntPtr(e, &value);
+                     FreeExpContents(exp);
+                     exp.constant = PrintUInt64((uint64)value);
+                     exp.type = constantExp;
+                  }
+                  break;
+               case intSizeType:
+                  if(type.isSigned)
+                  {
+                     intsize value;
+                     GetIntSize(e, &value);
+                     FreeExpContents(exp);
+                     exp.constant = PrintInt64((int64)value);
+                     exp.type = constantExp;
+                  }
+                  else
+                  {
+                     uintsize value;
+                     GetUIntSize(e, &value);
+                     FreeExpContents(exp);
+                     exp.constant = PrintUInt64((uint64)value);
+                     exp.type = constantExp;
+                  }
+                  break;
                case floatType:
                {
                   float value;
@@ -5941,17 +6067,31 @@ void CheckTemplateTypes(Expression exp)
       switch(exp.expType.kind)
       {
          case doubleType:
-            exp.type = opExp;
-            exp.op.exp1 = null;
-            context = PushContext();               
-            exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)), 
-               MkExpExtensionCompound(compound = MkCompoundStmt(
-                  MkListOne(MkDeclaration(MkListOne(MkSpecifier(DOUBLE)), 
-                     MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal")), MkInitializerAssignment(newExp))))),
-                  MkListOne(MkExpressionStmt(MkListOne(MkExpOp(null, '&', MkExpIdentifier(MkIdentifier("__internal")))))))));
-            compound.compound.context = context;
-            PopContext(context);
-            exp.op.op = '*';
+            if(exp.destType.classObjectType)
+            {
+               // We need to pass the address, just pass it along (Undo what was done above)
+               if(exp.destType) exp.destType.refCount--;
+               if(exp.expType)  exp.expType.refCount--;
+               delete newExp;
+            }
+            else
+            {
+               // If we're looking for value:
+               // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
+               OldList * specs;
+               OldList * unionDefs = MkList();
+               OldList * statements = MkList();
+               context = PushContext();
+               ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null))); 
+               ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
+               specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
+               exp.type = extensionCompoundExp;
+               exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
+               ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")), '=', newExp))));
+               ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")))));
+               exp.compound.compound.context = context;
+               PopContext(context);
+            }
             break;
          default:
             exp.type = castExp;
@@ -5974,18 +6114,31 @@ void CheckTemplateTypes(Expression exp)
       switch(exp.expType.kind)
       {
          case doubleType:
-            exp.type = opExp;
-            exp.op.exp1 = null;
-            context = PushContext();               
-            exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifier(DOUBLE)), MkDeclaratorPointer(MkPointer(null, null), null)), 
-               MkExpExtensionCompound(compound = MkCompoundStmt(
-                  MkListOne(MkDeclaration(MkListOne(MkSpecifierName("uint64")), 
-                     MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal")), MkInitializerAssignment(newExp))))),
-                  MkListOne(MkExpressionStmt(MkListOne(MkExpOp(null, '&', MkExpIdentifier(MkIdentifier("__internal")))))))));
-            compound.compound.context = context;
-            PopContext(context);
-            exp.op.op = '*';
-            ProcessExpressionType(exp.op.exp2);
+            if(exp.destType.classObjectType)
+            {
+               // We need to pass the address, just pass it along (Undo what was done above)
+               if(exp.destType) exp.destType.refCount--;
+               if(exp.expType)  exp.expType.refCount--;
+               delete newExp;
+            }
+            else
+            {
+               // If we're looking for value:
+               // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
+               OldList * specs;
+               OldList * unionDefs = MkList();
+               OldList * statements = MkList();
+               context = PushContext();
+               ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null))); 
+               ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
+               specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
+               exp.type = extensionCompoundExp;
+               exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
+               ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")), '=', newExp))));
+               ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")))));
+               exp.compound.compound.context = context;
+               PopContext(context);
+            }
             break;
          case classType:
          {
@@ -6200,7 +6353,7 @@ static void ProcessDeclaration(Declaration decl);
 
 static void GetTypeSpecs(Type type, OldList * specs)
 {
-   if(!type.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
+   if(!type.isSigned && type.kind != intPtrType && type.kind != intSizeType) ListAdd(specs, MkSpecifier(UNSIGNED));
    switch(type.kind)
    {
       case classType: 
@@ -6218,6 +6371,8 @@ static void GetTypeSpecs(Type type, OldList * specs)
       case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
       case shortType: ListAdd(specs, MkSpecifier(SHORT)); break;
       case int64Type: ListAdd(specs, MkSpecifier(INT64)); break;
+      case intPtrType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intptr" : "uintptr")); break;
+      case intSizeType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intsize" : "uintsize")); break;
       case intType: 
       default:
          ListAdd(specs, MkSpecifier(INT)); break;
@@ -6287,6 +6442,8 @@ static void _PrintType(Type type, char * string, bool printName, bool printFunct
          case voidType: strcat(string, "void"); break;
          case intType:  strcat(string, type.isSigned ? "int" : "uint"); break;
          case int64Type:  strcat(string, type.isSigned ? "int64" : "uint64"); break;
+         case intPtrType:  strcat(string, type.isSigned ? "intptr" : "uintptr"); break;
+         case intSizeType:  strcat(string, type.isSigned ? "intsize" : "uintsize"); break;
          case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
          case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
          case floatType: strcat(string, "float"); break;
@@ -6370,12 +6527,6 @@ static void _PrintType(Type type, char * string, bool printName, bool printFunct
                      strcat(string, name);
                   }
                }
-#ifdef _DEBUG
-               else
-               {
-                  printf("");
-               }
-#endif
             }
 
             if(printFunction)
@@ -6479,10 +6630,6 @@ static void _PrintType(Type type, char * string, bool printName, bool printFunct
          case vaListType:
          strcat(string, "__builtin_va_list");
             break;
-#ifdef _DEBUG
-         default:
-            printf("");
-#endif
       }
       if(type.name && printName && type.kind != functionType && (type.kind != pointerType || type.type.kind != functionType))
       {
@@ -6492,6 +6639,9 @@ static void _PrintType(Type type, char * string, bool printName, bool printFunct
    }
 }
 
+// *****
+// TODO: Add a max buffer size to avoid overflows. This function is used with static size char arrays.
+// *****
 void PrintType(Type type, char * string, bool printName, bool fullName)
 {
    Type funcType;
@@ -6505,14 +6655,7 @@ void PrintType(Type type, char * string, bool printName, bool fullName)
       strcat(string, "(");
       _PrintType(type, string, printName, false, fullName);
       strcat(string, ")");
-      /*
-      if(type.name)
-         strcat(string, type.name);
-      else
-      {
-         printf("");
-      }
-      */
+
       strcat(string, "(");
       for(param = funcType.params.first; param; param = param.next)
       {
@@ -6683,7 +6826,7 @@ static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassChe
          {
             char constant[256];
             exp.type = constantExp;
-            sprintf(constant, "%d",classProp.Get(_class));
+            sprintf(constant, "%d", (int)classProp.Get(_class));
             exp.constant = CopyString(constant);
          }
       }
@@ -6874,11 +7017,30 @@ void ApplyAnyObjectLogic(Expression e)
 
                         curContext = context;
                         e.type = extensionCompoundExp;
+
+                        // We need a current compound for this
+                        if(curCompound)
+                        {
+                           char name[100];
+                           OldList * stmts = MkList();
+                           sprintf(name, "__internalValue%03X", internalValueCounter++);
+                           if(!curCompound.compound.declarations)
+                              curCompound.compound.declarations = MkList();
+                           curCompound.compound.declarations->Insert(null, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(name)), null))));
+                           ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', newExp))));
+                           ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier(name)))));
+                           e.compound = MkCompoundStmt(null, stmts);
+                        }
+                        else
+                           printf("libec: compiler error, curCompound is null in ApplyAnyObjectLogic\n");
+
+                        /*
                         e.compound = MkCompoundStmt(
                            MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(
                               MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))), 
 
                            MkListOne(MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier("__internalValue"))))));
+                        */
                         
                         {
                            Type type = e.destType;
@@ -7337,12 +7499,6 @@ void ProcessExpressionType(Expression exp)
             {
                exp.instance._class = MkSpecifierName(exp.destType._class.string);
             }
-#ifdef _DEBUG
-            else 
-            {
-               printf("");               
-            }
-#endif
          }
 
          //classSym = FindClass(exp.instance._class.fullName);
@@ -7703,7 +7859,7 @@ void ProcessExpressionType(Expression exp)
 
             if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
             {
-               if(exp.op.exp2.expType.kind == int64Type || exp.op.exp2.expType.kind == intType || exp.op.exp2.expType.kind == shortType || exp.op.exp2.expType.kind == charType)
+               if(exp.op.exp2.expType.kind == intSizeType || exp.op.exp2.expType.kind == intPtrType || exp.op.exp2.expType.kind == int64Type || exp.op.exp2.expType.kind == intType || exp.op.exp2.expType.kind == shortType || exp.op.exp2.expType.kind == charType)
                {
                   if(exp.op.op != '=' && type1.type.kind == voidType) 
                      Compiler_Error($"void *: unknown size\n");
@@ -7807,7 +7963,7 @@ void ProcessExpressionType(Expression exp)
             {
                if(type1 && type2 &&
                   // If either both are class or both are not class
-                  ((type1.kind == classType && strcmp(type1._class.string, "String")) == (type2.kind == classType && strcmp(type2._class.string, "String"))))
+                  ((type1.kind == classType && type1._class && strcmp(type1._class.string, "String")) == (type2.kind == classType && type2._class && strcmp(type2._class.string, "String"))))
                {
                   if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
                   exp.op.exp2.destType = type1;
@@ -7860,14 +8016,14 @@ void ProcessExpressionType(Expression exp)
                      }
                   }
                   
-                  if(!boolResult && ((type1.kind == pointerType || type1.kind == arrayType || (type1.kind == classType && !strcmp(type1._class.string, "String"))) && (type2.kind == int64Type || type2.kind == intType || type2.kind == shortType || type2.kind == charType)))
+                  if(!boolResult && ((type1.kind == pointerType || type1.kind == arrayType || (type1.kind == classType && !strcmp(type1._class.string, "String"))) && (type2.kind == intSizeType || type2.kind == intPtrType || type2.kind == int64Type || type2.kind == intType || type2.kind == shortType || type2.kind == charType)))
                   {
                      if(type1.kind != classType && type1.type.kind == voidType) 
                         Compiler_Error($"void *: unknown size\n");
                      exp.expType = type1;
                      if(type1) type1.refCount++;
                   }
-                  else if(!boolResult && ((type2.kind == pointerType || type2.kind == arrayType || (type2.kind == classType && !strcmp(type2._class.string, "String"))) && (type1.kind == int64Type || type1.kind == intType || type1.kind == shortType || type1.kind == charType)))
+                  else if(!boolResult && ((type2.kind == pointerType || type2.kind == arrayType || (type2.kind == classType && !strcmp(type2._class.string, "String"))) && (type1.kind == intSizeType || type1.kind == intPtrType || type1.kind == int64Type || type1.kind == intType || type1.kind == shortType || type1.kind == charType)))
                   {
                      if(type2.kind != classType && type2.type.kind == voidType) 
                         Compiler_Error($"void *: unknown size\n");
@@ -8416,7 +8572,14 @@ void ProcessExpressionType(Expression exp)
          {
             Expression idExp = exp.call.exp;
             Identifier id = idExp.identifier;
-            if(!strcmp(id.string, "__ENDIAN_PAD"))
+            if(!strcmp(id.string, "__builtin_frame_address"))
+            {
+               exp.expType = ProcessTypeString("void *", true);
+               if(exp.call.arguments && exp.call.arguments->first)
+                  ProcessExpressionType(exp.call.arguments->first);
+               break;
+            }
+            else if(!strcmp(id.string, "__ENDIAN_PAD"))
             {
                exp.expType = ProcessTypeString("int", true);
                if(exp.call.arguments && exp.call.arguments->first)
@@ -8640,7 +8803,7 @@ void ProcessExpressionType(Expression exp)
             if(!type) emptyParams = true;
 
             // WORKING ON THIS:
-            if(functionType.extraParam && e)
+            if(functionType.extraParam && e && functionType.thisClass)
             {
                e.destType = MkClassType(functionType.thisClass.string);
                e = e.next;
@@ -8756,8 +8919,16 @@ void ProcessExpressionType(Expression exp)
                }
                else
                {
-                  e.destType = type;
-                  if(type) type.refCount++;
+                  if(type && type.kind == ellipsisType && type.prev && type.prev.kind == classType && type.prev.classObjectType)
+                  {
+                     e.destType = type.prev;
+                     e.destType.refCount++;
+                  }
+                  else
+                  {
+                     e.destType = type;
+                     if(type) type.refCount++;
+                  }
                }
                // Don't reach the end for the ellipsis
                if(type && type.kind != ellipsisType)
@@ -9296,7 +9467,7 @@ void ProcessExpressionType(Expression exp)
                   if(tClass && exp.expType.kind == templateType && exp.expType.templateParameter.type == TemplateParameterType::type)
                   {
                      int id = 0;
-                     ClassTemplateParameter curParam;
+                     ClassTemplateParameter curParam = null;
                      Class sClass;
 
                      for(sClass = tClass; sClass; sClass = sClass.base)
@@ -9354,7 +9525,7 @@ void ProcessExpressionType(Expression exp)
                   else if(tClass && exp.expType.kind == pointerType && exp.expType.type && exp.expType.type.kind == templateType && exp.expType.type.templateParameter.type == TemplateParameterType::type)
                   {
                      int id = 0;
-                     ClassTemplateParameter curParam;
+                     ClassTemplateParameter curParam = null;
                      Class sClass;
 
                      for(sClass = tClass; sClass; sClass = sClass.base)
@@ -9723,6 +9894,8 @@ void ProcessExpressionType(Expression exp)
       {
          Type type = ProcessType(exp.initializer.typeName.qualifiers, exp.initializer.typeName.declarator);
          type.refCount++;
+
+         // We have yet to support this... ( { } initializers are currently processed inside ProcessDeclaration()'s initDeclaration case statement
          // ProcessInitializer(exp.initializer.initializer, type);
          exp.expType = type;
          break;
@@ -9909,49 +10082,27 @@ void ProcessExpressionType(Expression exp)
          if(typeString)
          {
             /*
-            (Container)(__extension__( { 
-               int __arrayMembers[] = { 1, 7, 3, 4, 5 };
-               BuiltInContainer __baseContainer
-               {
-                  data = __arrayMembers,
-                  count = 5,
-                  type = class(int),
-                  _vTbl = class(BuiltInContainer)._vTbl,
-                  _class = class(BuiltInContainer) };
-               &__baseContainer;
-             }))
+            (Container)& (struct BuiltInContainer)
+            {
+               ._vTbl = class(BuiltInContainer)._vTbl,
+               ._class = class(BuiltInContainer),
+               .refCount = 0,
+               .data = (int[]){ 1, 7, 3, 4, 5 },
+               .count = 5,
+               .type = class(int),
+            }
             */
-            
             char templateString[1024];
-            OldList * declarations = MkList();
-            OldList * instMembers = MkList();
-            OldList * specs = MkList();
             OldList * initializers = MkList();
-            char count[128];
-            Expression e;
+            OldList * structInitializers = MkList();
+            OldList * specs = MkList();
             Expression expExt;
             Declarator decl = SpecDeclFromString(typeString, specs, null);
-            Context context = PushContext();
-
-            // sprintf(templateString, "Container<%s >", typeString);
             sprintf(templateString, "Container<%s>", typeString);
-   
-            ListAdd(instMembers, MkMemberInit(MkListOne(MkIdentifier("data")), MkInitializerAssignment(MkExpIdentifier(MkIdentifier("__internalList")))));
-
-            sprintf(count, "%d", exp.list->count);
-            ListAdd(instMembers, MkMemberInit(MkListOne(MkIdentifier("count")), MkInitializerAssignment(MkExpConstant(count))));
-
-            ListAdd(instMembers, MkMemberInit(MkListOne(MkIdentifier("type")), MkInitializerAssignment(MkExpClass(CopyList(specs, CopySpecifier), 
-               CopyDeclarator(decl)))));
-
-            ListAdd(instMembers, MkMemberInit(MkListOne(MkIdentifier("_vTbl")), MkInitializerAssignment(MkExpMember(
-               MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl")))));
-
-            ListAdd(instMembers, MkMemberInit(MkListOne(MkIdentifier("_class")), MkInitializerAssignment(
-               MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null))));
 
             if(exp.list)
             {
+               Expression e;
                type = ProcessTypeString(typeString, false);
                while(e = exp.list->first)
                {
@@ -9965,19 +10116,28 @@ void ProcessExpressionType(Expression exp)
                delete exp.list;
             }
             
-            ListAdd(declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorArray(PlugDeclarator(decl, 
-               MkDeclaratorIdentifier(MkIdentifier("__internalList"))), null),
-               MkInitializerList(initializers)))));
-            ListAdd(declarations, MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName("BuiltInContainer")),
-               MkExpIdentifier(MkIdentifier("__internalContainer")), MkListOne(MkMembersInitList(instMembers)))));
-
+            DeclareStruct("ecere::com::BuiltInContainer", false);
+
+            ListAdd(structInitializers, /*MkIdentifier("_vTbl")*/    MkInitializerAssignment(MkExpMember(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl"))));
+               ProcessExpressionType(((Initializer)structInitializers->last).exp);
+            ListAdd(structInitializers, /*MkIdentifier("_class")*/   MkInitializerAssignment(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null)));
+               ProcessExpressionType(((Initializer)structInitializers->last).exp);
+            ListAdd(structInitializers, /*MkIdentifier("_refCount")*/MkInitializerAssignment(MkExpConstant("0")));
+               ProcessExpressionType(((Initializer)structInitializers->last).exp);
+            ListAdd(structInitializers, /*MkIdentifier("data")*/     MkInitializerAssignment(MkExpExtensionInitializer(
+               MkTypeName(specs, MkDeclaratorArray(decl, null)),
+               MkInitializerList(initializers))));
+               ProcessExpressionType(((Initializer)structInitializers->last).exp);
+            ListAdd(structInitializers, /*MkIdentifier("count")*/    MkInitializerAssignment({ type = constantExp, constant = PrintString(initializers->count) }));
+               ProcessExpressionType(((Initializer)structInitializers->last).exp);
+            ListAdd(structInitializers, /*MkIdentifier("type")*/     MkInitializerAssignment(MkExpClass(CopyList(specs, CopySpecifier), CopyDeclarator(decl))));
+               ProcessExpressionType(((Initializer)structInitializers->last).exp);
             exp.expType = ProcessTypeString(templateString, false);
             exp.type = bracketsExp;
             exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(templateString)), null),
-               (expExt = MkExpExtensionCompound(MkCompoundStmt(
-                  declarations, MkListOne(MkExpressionStmt(MkListOne(MkExpOp(null, '&', MkExpIdentifier(MkIdentifier("__internalContainer")))))))))));
-            expExt.compound.compound.context = context;
-            PopContext(context);
+               MkExpOp(null, '&',
+               expExt = MkExpExtensionInitializer(MkTypeName(MkListOne(MkSpecifierName("BuiltInContainer")), null),
+                  MkInitializerList(structInitializers)))));
             ProcessExpressionType(expExt);
          }
          else
@@ -10099,7 +10259,9 @@ void ProcessExpressionType(Expression exp)
 #ifdef _DEBUG
                   CheckExpressionType(exp, exp.destType, false);
 #endif
-                  Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
+                  // Flex & Bison generate code that triggers this, so we ignore it for a quiet sdk build:
+                  if(!sourceFile || (strcmp(sourceFile, "src\\lexer.ec") && strcmp(sourceFile, "src/lexer.ec") && strcmp(sourceFile, "src\\grammar.ec") && strcmp(sourceFile, "src/grammar.ec")))
+                     Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
 
                   // TO CHECK: FORCING HERE TO HELP DEBUGGER
                   FreeType(exp.expType);
@@ -12017,22 +12179,72 @@ static void ProcessClass(OldList definitions, Symbol symbol)
    }
 }
 
+void DeclareFunctionUtil(String s)
+{
+   GlobalFunction function = eSystem_FindFunction(privateModule, s);
+   if(function)
+   {
+      char name[1024];
+      name[0] = 0;
+      if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
+         strcpy(name, "__ecereFunction_");
+      FullClassNameCat(name, s, false); // Why is this using FullClassNameCat ?
+      DeclareFunction(function, name);
+   }
+}
+
 void ComputeDataTypes()
 {
    External external;
    External temp { };
+   External after = null;
+
    currentClass = null;
 
    containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
 
-   temp.symbol = Symbol { id = -1000, idCode = -1000 };
-
-   // WHERE SHOULD THIS GO?
-   // curExternal = ast->first;
-   ast->Insert(null, temp);
+   for(external = ast->first; external; external = external.next)
+   {
+      if(external.type == declarationExternal)
+      {
+         Declaration decl = external.declaration;
+         if(decl)
+         {
+            OldList * decls = decl.declarators;
+            if(decls)
+            {
+               InitDeclarator initDecl = decls->first;
+               if(initDecl)
+               {
+                  Declarator declarator = initDecl.declarator;
+                  if(declarator && declarator.type == identifierDeclarator)
+                  {
+                     Identifier id = declarator.identifier;
+                     if(id && id.string)
+                     {
+                        if(!strcmp(id.string, "uintptr_t") || !strcmp(id.string, "intptr_t") || !strcmp(id.string, "size_t") || !strcmp(id.string, "ssize_t"))
+                        {
+                           external.symbol.id = -1001, external.symbol.idCode = -1001;
+                           after = external;
+                        }
+                     }
+                  }
+               }
+            }
+         }
+       }
+   }
 
+   temp.symbol = Symbol { id = -1000, idCode = -1000 };
+   ast->Insert(after, temp);
    curExternal = temp;
 
+   DeclareFunctionUtil("eSystem_New");
+   DeclareFunctionUtil("eSystem_New0");
+   DeclareFunctionUtil("eSystem_Renew");
+   DeclareFunctionUtil("eSystem_Renew0");
+   DeclareFunctionUtil("eClass_GetProperty");
+
    DeclareStruct("ecere::com::Class", false);
    DeclareStruct("ecere::com::Instance", false);
    DeclareStruct("ecere::com::Property", false);