Ejemplo n.º 1
0
        // Emit code that saves the result of an expression to an array element.
        void GenerateSaveToArray(CodeGenerator cg)
        {
            Symbol sym = Identifier.Symbol;

            Debug.Assert(sym.IsArray);
            if (Identifier.IsArrayBase) {
                if (sym.IsParameter) {
                    GenerateStoreArgument(cg, sym);
                } else {
                    cg.GenerateExpression(SymType.NONE, ValueExpression);
                    cg.Emitter.StoreLocal(sym.Index);
                }
                return;
            }

            cg.GenerateLoadArrayAddress(Identifier);

            if (Identifier.HasSubstring) {
                cg.Emitter.LoadArrayElement(sym);
                cg.GenerateExpression(SymType.FIXEDCHAR, ValueExpression);
                GenerateSaveSubstring(cg, SymType.FIXEDCHAR);
                return;
            }

            if (sym.Type == SymType.FIXEDCHAR) {
                cg.Emitter.LoadArrayElement(sym);
                cg.GenerateExpression(SymType.NONE, ValueExpression);
                cg.Emitter.Call(cg.GetMethodForType(typeof(JComLib.FixedString), "Set", new[] { Symbol.SymTypeToSystemType(ValueExpression.Type) }));
                return;
            }

            cg.GenerateExpression(sym.Type, ValueExpression);
            cg.Emitter.StoreArrayElement(sym);
        }
Ejemplo n.º 2
0
        // Emit the code that loads part of an entire array by making a copy of
        // the array to the destination array dimensions and copying from the
        // given offset.
        void GenerateLoadSubArray(CodeGenerator cg, IdentifierParseNode identNode, Symbol symParam, Temporaries locals)
        {
            if (!identNode.HasIndexes) {
                cg.GenerateLoadArray(identNode, false);
                return;
            }

            LocalDescriptor index = locals.New(symParam.SystemType);

            cg.GenerateLoadArrayAddress(identNode);
            cg.Emitter.CreateSimpleArray(symParam.ArraySize, Symbol.SymTypeToSystemType(symParam.Type));
            cg.Emitter.Dup();
            cg.Emitter.StoreLocal(index);
            cg.Emitter.LoadInteger(0);
            cg.Emitter.LoadInteger(symParam.ArraySize);
            cg.Emitter.Call(typeof(Array).GetMethod("Copy", new [] { typeof(Array), typeof(int), typeof(Array), typeof(int), typeof(int) }));
            cg.Emitter.LoadLocal(index);
        }