Exemple #1
0
        public void CompileArray(Emitter.Emitter emitter)
        {
            // make sure it's an array
              var type = emitter.GetArrayItemType(ExpressionPrefix.GetExpressionType(emitter));
              if (type == "")
            Error(Resources.errIndexingNotAnArray);

              // make sure expression type matches array type
              var exprType = Expression.GetExpressionType(emitter);
              if (!emitter.TypeIsParent(type, exprType))
            Error(String.Format(Resources.errAssignTypeMismatch, exprType, type));

              ExpressionPrefix.Compile(emitter);
              Index.Compile(emitter);

              if (type == "complex")
              {
            // special case of valuetypes
            var typeRef = emitter.ResolveType(type);
            emitter.EmitLoadIndexAddress(typeRef);
            Expression.Compile(emitter);
            emitter.EmitSaveObject(typeRef);
              }
              else
              {
            Expression.Compile(emitter);
            emitter.EmitSaveIndex(type);
              }
        }
Exemple #2
0
        public override void Compile(Emitter.Emitter emitter)
        {
            try
              {
            Resolve(emitter);

            if (!emitter.TypeIsParent(IdentifierType, Expression.GetExpressionType(emitter)))
              Error(String.Format(Resources.errAssignTypeMismatch, Expression.GetExpressionType(emitter), IdentifierType));
              }
              catch(CompilerException ex)
              {
            ex.AffixToLexem(Lexem);
            throw;
              }

              switch (Kind)
              {

            case IdentifierKind.StaticField:  Expression.Compile(emitter);
                                          emitter.EmitSaveField(emitter.FindField(OwnerType, Name)); break;

            case IdentifierKind.Field:        if (ExpressionPrefix != null)
                                            ExpressionPrefix.Compile(emitter);
                                          else
                                            emitter.EmitLoadThis();
                                          Expression.Compile(emitter);
                                          emitter.EmitSaveField(emitter.FindField(OwnerType, Name)); break;

            case IdentifierKind.Variable:     Expression.Compile(emitter);
                                          emitter.EmitSaveVariable(emitter.CurrentMethod.Scope.Find(Name)); break;

            case IdentifierKind.Parameter:    Expression.Compile(emitter);
                                          emitter.EmitSaveParameter(emitter.CurrentMethod.Parameters[Name].Id); break;
              }
        }
Exemple #3
0
        public override void Compile(Emitter.Emitter emitter)
        {
            var methodType = emitter.CurrentMethod.Type.Signature;
              var exprType = "void";
              if (Expression != null)
              {
            exprType = GetExpressionType(emitter);
            Expression.Compile(emitter);
              }

              if(!emitter.TypeIsParent(methodType, exprType))
            Error(String.Format(Resources.errReturnTypeMismatch, emitter.CurrentMethod.Name, emitter.CurrentMethod.Type.Signature, exprType));

              emitter.EmitReturn();
        }