Esempio n. 1
0
 private RuntimeError CreateError(RuntimeOutputCode code, FlashElementInstruction instruction)
 {
     return(new RuntimeError(code, instruction.Line));
 }
Esempio n. 2
0
 private RuntimeError CreateError(RuntimeOutputCode code, Function function)
 {
     return(new RuntimeError(code, function.Directive));
 }
Esempio n. 3
0
        internal RuntimeError CallFunction(Function function)
        {
            Integer       localVarCounter = (Integer)1;
            CallStackItem csi             = new CallStackItem(function, (Integer)0);

            if (!function.IsStatic && !function.IsEntryPoint)
            {
                csi.Locals.Add(new Variable(_source.Machine.MemZone.ObjectStackItem, localVarCounter));
                localVarCounter += (Integer)1;
            }

            foreach (var parameter in function.Parameters)
            {
                if (_machine.MemZone.ParamStack.Count == 0)
                {
                    return(CreateError(RuntimeOutputCode.ArgumentsAreExpected, function));
                }

                Structures.Object value = _machine.MemZone.ParamStack.Pop();
                TypeReference     type  = parameter.Type;

                if (value.Type != type)
                {
                    return(CreateError(RuntimeOutputCode.ExpectedOtherType, function));
                }

                csi.Locals.Add(new Variable(value, localVarCounter));
                localVarCounter += (Integer)1;
            }

            RuntimeDataPackage package = new RuntimeDataPackage()
            {
                Constants      = function.RuntimeCache.Constants,
                Expressions    = function.RuntimeCache.Expressions,
                MemZone        = _machine.MemZone,
                RuntimeMachine = this,
                Assembly       = _source.Assembly,
                CallStackItem  = csi
            };

            _callStack.Push(csi);

            //foreach (var variable in function.RuntimeCache.Variables)
            //{
            //_machine.MemZone.Globals.Add(new Variable(variable.VariableType, variable.Index));
            //}

            for (; (int)csi.ProgramCounter < function.RuntimeCache.Instructions.Count; csi.ProgramCounter += (Integer)1)
            {
                Ticks++;

                var instruction = function.RuntimeCache.Instructions[(int)csi.ProgramCounter];

                if (Ticks == int.MaxValue)
                {
                    return(new RuntimeError(RuntimeOutputCode.StackOverFlow));
                }

                //Если все ОК, то запускаем нашу инструкцию
                RuntimeOutputCode output = SourceLineInstruction.Instructions[(int)instruction.InstructionNumber].Apply(package, instruction.Parameters);

                if (output != RuntimeOutputCode.OK)
                {
                    return(CreateError(output, instruction));
                }

                if (_funcReturned)
                {
                    _funcReturned = false;
                    _callStack.Pop();
                    return(null);
                }
            }

            return(null);
        }
Esempio n. 4
0
 public RuntimeError(RuntimeOutputCode code, SourceLine errorLine)
 {
     Code      = code;
     ErrorLine = errorLine;
 }
Esempio n. 5
0
 public RuntimeError(RuntimeOutputCode code)
 {
     Code = code;
 }
Esempio n. 6
0
        protected bool CheckObjectStackItem(RuntimeDataPackage package, Class baseClass, out RuntimeOutputCode error)
        {
            if (package.MemZone.ObjectStackItem == null)
            {
                error = RuntimeOutputCode.ObjectStackIsEmpty;
                return(false);
            }
            if (package.MemZone.ObjectStackItem.Type.Type != TypeReferenceType.Class)
            {
                error = RuntimeOutputCode.ClassTypeExpected;
                return(false);
            }

            if (package.MemZone.ObjectStackItem.Type.ClassType != baseClass)
            {
                error = RuntimeOutputCode.DifferentClasses;
                return(false);
            }

            error = RuntimeOutputCode.OK;
            return(true);
        }