Exemple #1
0
        public static QVariable AllocConst(string typename, QObj environment, string contextName, string rootContext)
        {
            var           type     = environment.LocateType(typename);
            var           variable = new QVariable(type, true);
            QContextEntry context  = new QContextEntry(variable, contextName, rootContext);

            environment.PutContext(context.FullContext, context);
            return(variable);
        }
Exemple #2
0
        private void IterateParseTree(ParseTree tree)
        {
            // setup root context for this script
            QCodeBlock    rootBlock   = new QCodeBlock(ROOT_CONTEXT_NAME);
            QContextEntry rootContext = new QContextEntry(rootBlock, rootBlock.Context, null);

            Env.PutContext(null, rootContext);
            PushTask(rootBlock, tree.Root);
            ExecuteTaskStack();
        }
Exemple #3
0
 /// <summary>
 /// Register a context entry, later used for lookups
 /// </summary>
 /// <param name="fullContext"></param>
 /// <param name="entry"></param>
 public void PutContext(string fullContext, QContextEntry entry)
 {
     if (fullContext is null)
     {
         if (RootContext != null)
         {
             throw new InvalidOperationException("Cannot put a root context when a root context already exists");
         }
         RootContext = entry;
         return;
     }
     if (ContextualEntries.ContainsKey(fullContext))
     {
         throw new DuplicateNameException($"Name '{fullContext}' already exists.");
     }
     ContextualEntries[fullContext] = entry;
 }
Exemple #4
0
        private IEnumerable <QOperand> Emit_NamedBlock(QOperand currentTask)
        {
            // node {name} {paramsList} {codeBlock}
            var node = currentTask.ObjectNode;

            // Build context information
            string functionName = node.ChildNodes[0].Token.ValueString;
            string newContext   = $"{currentTask.CurrentBlock.Context}.{functionName}";

            // Create a new export
            QCodeBlock    exportBlock  = new QCodeBlock(newContext);
            QContextEntry contextEntry = new QContextEntry(exportBlock, functionName, currentTask.CurrentBlock.Context);

            Env.PutContext(newContext, contextEntry);

            // collect the parameter references
            foreach (var pnode in node.ChildNodes[1].ChildNodes)
            {
                yield return(new QOperand(exportBlock, pnode));
            }

            // populate a params array
            var numParams = node.ChildNodes[1].ChildNodes.Count;

            QVariable[] parameters = new QVariable[numParams];
            for (int i = parameters.Length - 1; i > -1; i--)
            {
                parameters[i] = ValueStack.Pop().ObjectValue as QVariable;
                if (parameters[i] is null)
                {
                    throw new InvalidCastException($"Failed to create a qvariable from a parameter index {i}");
                }
            }

            // Put params in the target export context
            exportBlock.SetParameters(parameters);

            // Link the export block into the current context so it is emitted
            currentTask.CurrentBlock.Add(exportBlock);

            // function.codeblock.directives
            yield return(new QOperand(exportBlock, node.ChildNodes[2].ChildNodes[0]));
        }