Example #1
0
        public override void Compile(Emitter.Emitter emitter)
        {
            var leftType = Left.GetExpressionType(emitter);
              var rightType = Right.GetExpressionType(emitter);

              // an array of values
              if (rightType == leftType + "[]")
              {
            Right.Compile(emitter);
            Left.Compile(emitter);
            if (leftType.IsAnyOf("int", "bool", "float", "complex"))
              emitter.EmitBox(emitter.ResolveType(leftType));

            var method = typeof(MirelleStdlib.ArrayHelper).GetMethod("Has", new[] { typeof(object), typeof(object) });
            emitter.EmitCall(emitter.AssemblyImport(method));
              }

              // an object has a "has" method that accepts the lefthand expression
              else
              {
            try
            {
              Expr.IdentifierInvoke("has", Right, Left).Compile(emitter);
              return;
            }
            catch { }

            Error(String.Format(Resources.errOperatorTypesMismatch, "in", leftType, rightType));
              }
        }
Example #2
0
        public override void Compile(Emitter.Emitter emitter)
        {
            var args = new[] { Parameters.Count == 1 ? typeof(object) : typeof(IEnumerable<dynamic>), typeof(bool) };
              var printMethod = emitter.AssemblyImport(typeof(MirelleStdlib.Printer).GetMethod("Print", args));

              if (Parameters.Count == 1)
              {
            var currType = Parameters[0].GetExpressionType(emitter);
            Parameters[0].Compile(emitter);
            if (currType.IsAnyOf("int", "bool", "float", "complex"))
              emitter.EmitBox(emitter.ResolveType(currType));
              }
              else
              {
            var objType = emitter.AssemblyImport(typeof(object));
            var arrType = new ArrayType(objType);

            var tmpVariable = emitter.CurrentMethod.Scope.Introduce("object[]", arrType);

            // load count & create
            emitter.EmitLoadInt(Parameters.Count);
            emitter.EmitNewArray(objType);
            emitter.EmitSaveVariable(tmpVariable);

            int idx = 0;
            foreach (var curr in Parameters)
            {
              var currType = curr.GetExpressionType(emitter);
              emitter.EmitLoadVariable(tmpVariable);
              emitter.EmitLoadInt(idx);
              curr.Compile(emitter);

              if (currType.IsAnyOf("int", "bool", "float", "complex"))
            emitter.EmitBox(emitter.ResolveType(currType));

              emitter.EmitSaveIndex("object");

              idx++;
            }

            // return the created array
            emitter.EmitLoadVariable(tmpVariable);
              }

              emitter.EmitLoadBool(PrintLine);
              emitter.EmitCall(printMethod);
        }