Exemplo n.º 1
0
        //Get an AlgoValue of type EmulatedFunction by supplying an external function load context.
        public AlgoValue GetEmulatedFuncValue(algoParser.Stat_loadFuncExtContext context)
        {
            //Attempt to get the text (as array) of the class and function from obj_access.
            if (context.particle().Length != 1)
            {
                Error.Fatal(context, "Import function is invalid, must be in the form \"Class.Function\".");
                return(null);
            }

            string className = context.IDENTIFIER()[1].GetText();
            string funcName  = context.particle()[0].IDENTIFIER().GetText();

            //Attempt to grab the plugin from the plugins manager.
            if (!PluginExists(className))
            {
                Error.Fatal(context, "Plugin name '" + className + "' is invalid or not loaded.");
                return(null);
            }
            IFunctionPlugin classPlugin = GetPlugin(className);

            //Does the plugin contain a function with the given name?
            if (classPlugin.Functions.FindIndex(x => x.Name == funcName) == -1)
            {
                Error.Fatal(context, "Plugin '" + className + "' does not contain a function of name '" + funcName + "', so cannot load it.");
                return(null);
            }

            //Return an EmulatedFunction AlgoValue.
            return(new AlgoValue()
            {
                Type = AlgoValueType.EmulatedFunction,
                Value = classPlugin.Functions.Find(x => x.Name == funcName)
            });
        }
Exemplo n.º 2
0
        //When an external or internal plugin library function is loaded.
        public override object VisitStat_loadFuncExt([NotNull] algoParser.Stat_loadFuncExtContext context)
        {
            //Get the value of the function.
            AlgoValue func = Plugins.GetEmulatedFuncValue(context);

            //Check if a variable with the supplied name already exists in scope.
            if (Scopes.VariableExists(context.IDENTIFIER()[0].GetText()))
            {
                Error.Fatal(context, "A variable with the name '" + context.IDENTIFIER()[0].GetText() + "' already exists, can't redefine it.");
                return(null);
            }

            //Add to scope.
            Scopes.AddVariable(context.IDENTIFIER()[0].GetText(), func);
            return(null);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="algoParser.stat_loadFuncExt"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitStat_loadFuncExt([NotNull] algoParser.Stat_loadFuncExtContext context)
 {
     return(VisitChildren(context));
 }
Exemplo n.º 4
0
 /// <summary>
 /// Exit a parse tree produced by <see cref="algoParser.stat_loadFuncExt"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitStat_loadFuncExt([NotNull] algoParser.Stat_loadFuncExtContext context)
 {
 }