Ejemplo n.º 1
0
 /// <summary>
 /// Initialize a new instance of <see cref="BlockInterpreter"/>
 /// </summary>
 /// <param name="statements">the list of statements to interpret</param>
 /// <param name="debugMode">defines is the debug mode is enabled or not</param>
 /// <param name="parentProgramInterpreter">the parent program interpreter</param>
 /// <param name="parentMethodInterpreter">the parent method interpreter</param>
 /// <param name="parentBlockInterpreter">the parent block interpreter</param>
 /// <param name="parentClassInterpreter">the parent class interpreter</param>
 internal BlockInterpreter(AlgorithmStatementCollection statements, bool debugMode, ProgramInterpreter parentProgramInterpreter, MethodInterpreter parentMethodInterpreter, BlockInterpreter parentBlockInterpreter, ClassInterpreter parentClassInterpreter)
     : base(debugMode)
 {
     ParentProgramInterpreter = parentProgramInterpreter;
     ParentMethodInterpreter  = parentMethodInterpreter;
     ParentBlockInterpreter   = parentBlockInterpreter;
     ParentClassInterpreter   = parentClassInterpreter;
     Statements = statements;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Create a new instance of the current class interpreter.
        /// </summary>
        /// <returns>returns the new object</returns>
        internal ClassInterpreter CreateNewInstance()
        {
            var instance = new ClassInterpreter(ClassDeclaration, DebugMode);

            return(instance);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Start the program by finding the entry point and calling it
        /// </summary>
        internal void Start()
        {
            if (State != AlgorithmInterpreterState.Ready && State != AlgorithmInterpreterState.Stopped && State != AlgorithmInterpreterState.StoppedWithError)
            {
                throw new InvalidOperationException("Unable to start a algorithm interpreter which is not stopped.");
            }

            ChangeState(this, new AlgorithmInterpreterStateEventArgs(AlgorithmInterpreterState.Preparing));

            Initialize();

            var entryPointMethod = ProgramDeclaration.GetEntryPointMethod();
            var i = 0;
            ClassInterpreter entryPointClass = null;

            if (entryPointMethod == null)
            {
                ChangeState(this, new AlgorithmInterpreterStateEventArgs(new Error(new MissingEntryPointMethodException(ProgramDeclaration.EntryPointPath)), GetDebugInfo()));
                return;
            }

            ChangeState(this, new AlgorithmInterpreterStateEventArgs(AlgorithmInterpreterState.Running));

            while (i < Classes.Count && entryPointClass == null)
            {
                if (Classes[i].ClassDeclaration.Name.ToString() == ProgramDeclaration.EntryPointPath)
                {
                    entryPointClass = Classes[i];
                }

                i++;
            }

            if (entryPointClass == null)
            {
                ChangeState(this, new AlgorithmInterpreterStateEventArgs(new Error(new MissingEntryPointMethodException(ProgramDeclaration.EntryPointPath)), GetDebugInfo()));
                return;
            }

            // TODO: try to use the Instanciate & InvokeMethod interpreter's functions
            EntryPointInstance = entryPointClass.CreateNewInstance();
            EntryPointInstance.StateChanged           += ChangeState;
            EntryPointInstance.OnGetParentInterpreter += new Func <ProgramInterpreter>(() => this);
            EntryPointInstance.OnDone += new Action <ClassInterpreter>((cl) =>
            {
                cl.StateChanged -= ChangeState;
            });
            EntryPointInstance.Initialize();
            EntryPointInstance.CreateNewInstanceCallConstructors(null);

            EntryPointInstance.EntryPoint.StateChanged           += ChangeState;
            EntryPointInstance.EntryPoint.OnGetParentInterpreter += new Func <ClassInterpreter>(() => EntryPointInstance);
            EntryPointInstance.EntryPoint.OnDone += new Action <MethodInterpreter>((met) =>
            {
                met.Dispose();
                met.StateChanged -= ChangeState;
            });
            EntryPointInstance.EntryPoint.Initialize();
            EntryPointInstance.EntryPoint.Run(false, new Collection <object>(), Guid.Empty);

            EntryPointInstance.StateChanged -= ChangeState;
        }