Ejemplo n.º 1
0
 /// <summary>
 /// Executes a script from the beginging.
 /// </summary>
 /// <param name="script">The script tu execute.</param>
 /// <param name="data">Stack with the addresses of parameters on the heap. These addresses point to the beginning of the parameters in the heap Stack.</param>
 /// <param name="heap">Stack containing the parameter.</param>
 public void execute(XmlScriptCompiled script, Stack data, Heap heap)
 {
     script.reset();
     executeSub(script.ProgramCode, script.EntryPoint, data, heap);
 }
Ejemplo n.º 2
0
        public IScript Compile(String scriptCode, String name)
        {
            Stack stack = new Stack();
            //System.Diagnostics.Debugger.Launch();
            XDocument script = XDocument.Parse(scriptCode.Trim());

            m_entryPoint = -1;

            m_currentProgramCode = new MemoryStream();
            m_parameterSequence = new ParameterSequence();
            XElement root = script.Element("Root");
            if (root == null)
            {
                root = script.Element("root");
                if (root == null)
                {
                    throw new Exception("Error. Script must contain a root node.");
                }
            }
            foreach (XElement node in root.Elements())
            {
                bool isMain = false;
                if (node.Name.LocalName == "Main" || node.Name.LocalName == "main")
                {
                    // scripts starts here
                    m_entryPoint = (int)m_currentProgramCode.Position;
                    // push all attributes to the parameter sequencer (so the script can run with default parameters)
                    ParameterSequenceBuilder sequenceBuilder = new ParameterSequenceBuilder();
                    sequenceBuilder.createSequence();
                    foreach (XAttribute attr in node.Attributes())
                    {
                        sequenceBuilder.addParameter(new StringParameter(attr.Name.ToString(), attr.Value));
                    }
                    m_parameterSequence = sequenceBuilder.CurrentSequence;
                    stack = new Stack(m_parameterSequence.getMemStream());
                    isMain = true;
                }
                // add node as a function
                else
                {
                    //m_dataTable.Data.Add(node.Name.LocalName, (int)m_currentProgramCode.Position);
                    m_functionTable.add(node.Name.LocalName, (int)m_currentProgramCode.Position);
                    isMain = false;
                }
                compileRoutine(node, isMain,stack);
            }

            // end of program
            m_currentProgramCode.Writer.Write((int)XmlScriptExecutor.OpCode.HALT);

            XmlScriptCompiled compiledScript = new XmlScriptCompiled(scriptCode);
            compiledScript.Name = name;
            compiledScript.ProgramCode = m_currentProgramCode;
            compiledScript.EntryPoint = m_entryPoint;
            compiledScript.ParameterSequence = m_parameterSequence;

            if (m_entryPoint == -1)
            {
                throw new Exception("Error no entrypoint for script: " + name);
            }
            return compiledScript;
        }
Ejemplo n.º 3
0
        // URGENT: Use Parameter Sequencer
        /// <summary>
        /// Execute a script with the given parameters.
        /// </summary>
        /// <param name="script"></param>
        /// <param name="parameters"></param>
        public void execute(XmlScriptCompiled script, String[] parameters)
        {
            Stack data = new Stack();
            Heap heap = new Heap();
            // parameters in reverse order
            for(int i = parameters.Length-1; i >= 0; --i)
            {
                int a = heap.allocString(parameters[i]);
                data.push(a);
            }
            // push eip
            data.push(0);
            // push base pointer
            data.push(0);

            execute(script, data, heap);
        }