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;
        }
Exemple #2
0
        public void beginElement(String elementType)
        {
            if (m_activeElement != null)
            {
                throw new Exception("Error. New Element created before old one was finished.");
            }

            m_activeElementType = m_registeredTypes[elementType];
            m_activeSequence = m_registeredSequences[m_activeElementType];
            m_activeSequence.reset();
        }
 public void createSequence()
 {
     m_currentSequence = new ParameterSequence();
     m_currentSequence.ParameterStack.Push(m_currentSequence.Root);
 }
Exemple #4
0
 public void registerElement(IConstructor constructor, ParameterSequence parameterSequence, Type elementType, String elementName, List<ParameterSequence> messages)
 {
     m_registeredElements[elementType] = constructor;
     m_registeredSequences[elementType] = parameterSequence;
     m_registeredTypes[elementName] = elementType;
     if (messages != null && messages.Count > 0)
         m_registeredMessages[elementType] = messages;
     //m_registeredTypes[elementType.ToString()] = elementType;
 }