Example #1
0
		protected override object DoEvaluate(ScriptThread thread)
		{
			// standard prolog
			thread.CurrentNode = this;
			object result = null;

			// is this variable a part of a pattern?
			if (UseType == NodeUseType.Name)
			{
				// don't evaluate it
				result = CreateVariable();
			}
			else
			{
				// get last recognized pattern
				var pattern = thread.GetLastPattern();
				if (pattern == null)
				{
					thread.ThrowScriptError("No pattern recognized!");
					return null;
				}

				// read variable from the last recognized pattern
				result = pattern.GetVariable(Index);
			}

			// standard epilog
			thread.CurrentNode = Parent;
			return result;
		}
Example #2
0
        protected override object DoEvaluate(ScriptThread thread)
        {
            thread.CurrentNode = this;  //standard prolog
            var pi = thread.GetPageInfo();

            var test = globalNode.AsString.ToLower();
            if (test.Contains(":")) {
                Console.WriteLine("");
            }
            if ( test == "pagenumber") {
                return pi.PageNumber;
            } else if (test == "pages") {
                return pi.TotalPages;
            } else if (test == "reportname") {
                return pi.ReportName;
            } else if (test == "reportfolder") {
                return pi.ReportFolder;
            } else if (test == "reportfilename") {
                return pi.ReportFileName;
            }

            else {
                return String.Format(CultureInfo.CurrentCulture,"Syntaxerror in Globals <{0}>",globalNode.AsString);
            }
        }
Example #3
0
        protected override object DoEvaluate(Irony.Interpreter.ScriptThread thread)
        {
            thread.CurrentNode = this;
            try
            {
                var res = new MtResult();

                var accessor = thread.Bind(_targetName.AsString, BindingRequestFlags.Write | BindingRequestFlags.ExistingOrNew);
                accessor.SetValueRef(thread, res);

                // To allow recursive definitions, we have
                // to evaluate _expression inside the new context.
                var exprResult = _expression.Evaluate(thread) as MtResult;
                exprResult.GetValue((o) =>
                {
                    res.SetValue((state) =>
                    {
                        return(o);
                    });
                });

                return(res);
            }
            catch (Exception e)
            {
                throw new Exception("Exception on MtBind.DoEvaluate", e);
            }
            finally
            {
                //thread.CurrentNode = Parent;
            }
        }
Example #4
0
 // Evaluation for special forms
 private object EvaluateSpecialForm(ScriptThread thread)
 {
     thread.CurrentNode = this;  //standard prolog
       var result = _specialForm(thread, _specialFormArgs);
       thread.CurrentNode = Parent; //standard epilog
       return result;
 }
        protected override object ReallyDoEvaluate(ScriptThread thread)
        {
            Context.CurrentAct = actnumber;
            thread.rs().Action.At(Span).Label(actnumber);

            return base.ReallyDoEvaluate(thread);
        }
        public static object Iif(ScriptThread thread, AstNode[] childNodes)
        {
            var testValue = childNodes[0].Evaluate(thread);
            object result = thread.Runtime.IsTrue(testValue) ? childNodes[1].Evaluate(thread) : childNodes[2].Evaluate(thread);
            return result;

        }
Example #7
0
		protected override object DoEvaluate(ScriptThread thread)
		{
			// standard prolog
			thread.CurrentNode = this;

			if (EntryPoint == null)
			{
				thread.ThrowScriptError("No entry point defined (entry point is a function named «Go»)");
				return null;
			}

			// define built-in runtime library functions
			var libraryFunctions = LibraryFunction.ExtractLibraryFunctions(thread, new RefalLibrary(thread));
			foreach (var libFun in libraryFunctions)
			{
				var binding = thread.Bind(libFun.Name, BindingRequestFlags.Write | BindingRequestFlags.ExistingOrNew);
				binding.SetValueRef(thread, libFun);
			}

			// define functions declared in the compiled program
			foreach (var fun in FunctionList)
			{
				fun.Evaluate(thread);
			}

			// call entry point with an empty expression
			EntryPoint.Call(thread, new object[] { PassiveExpression.Build() });

			// standard epilog
			thread.CurrentNode = Parent;
			return null;
		}
Example #8
0
		protected override object DoEvaluate(ScriptThread thread)
		{
			// standard prolog
			thread.CurrentNode = this;

			var binding = thread.Bind(FunctionName, BindingRequestFlags.Read);
			var result = binding.GetValueRef(thread);
			if (result == null)
			{
				thread.ThrowScriptError("Unknown identifier: {0}", FunctionName);
				return null;
			}

			CallTarget = result as ICallTarget;
			if (CallTarget == null)
			{
				thread.ThrowScriptError("This identifier cannot be called: {0}", FunctionName);
				return null;
			}

			// set Evaluate pointer
			Evaluate = DoCall;

			// standard epilog is done by DoCall
			return DoCall(thread);
		}
        protected override object DoEvaluate(ScriptThread thread)
        {
            thread.CurrentNode = this;
            try
            {
                var result = new MtResult();
                var targetThread = _target.NewScriptThread(thread);
                var rTarget = _target.Evaluate(targetThread) as MtResult;

                var sourceThread = _source.NewScriptThread(thread);
                var rSource = _source.Evaluate(sourceThread) as MtResult;

                rTarget.GetValue(target =>
                {
                    rSource.GetValue(source =>
                    {
                        MtStream.ReadFromWriteTo(
                            source.Value as MtStream, target.Value as MtStream, () => {
                                result.SetValue(MtObject.True);
                            });
                    });
                });

                return result;
            }
            catch (Exception e)
            {
                throw new Exception("Exception on MtFlowRightToLeft.DoEvaluate", e);
            }
            finally
            {
                //thread.CurrentNode = Parent;
            }
        }
 protected override object DoEvaluate(ScriptThread thread)
 {
     thread.CurrentNode = this;  //standard prolog
       //assign implementation method
       switch (Op) {
     case ExpressionType.AndAlso:
       this.Evaluate = EvaluateAndAlso;
       break;
     case ExpressionType.OrElse:
       this.Evaluate = EvaluateOrElse;
       break;
     default:
       this.Evaluate = DefaultEvaluateImplementation;
       break;
       }
       // actually evaluate and get the result.
       var result = Evaluate(thread);
       // Check if result is constant - if yes, save the value and switch to method that directly returns the result.
       if (IsConstant()) {
     _constValue = result;
     AsString = Op + "(operator) Const=" + _constValue;
     this.Evaluate = EvaluateConst;
       }
       thread.CurrentNode = Parent; //standard epilog
       return result;
 }
Example #11
0
		public static object Sum(ScriptThread thread, AstNode[] childNodes) {
			double sum =  0;
			var fieldName = childNodes[0].Evaluate(thread).ToString();
			
			var dataSource = thread.GetDataSource();
			
			var grouped = ImportAggregateHelper.IsGrouped(dataSource);
			
			if (grouped != null) {
				
				foreach (var element in grouped) {
					var s = element.Sum(o => {
					                    	var v = ReadValueFromObject(fieldName, o);
					                    	return TypeNormalizer.EnsureType<double>(v);
					                    });
					sum = sum + s;
				}
			} else {
				if (ImportAggregateHelper.FieldExist(dataSource.FirstOrDefault(),fieldName)) {
					sum = dataSource.Sum(o => {
					                     	var v = ReadValueFromObject(fieldName, o);
					                     	return TypeNormalizer.EnsureType<double>(v);
					                     });
				}
			}
			return sum.ToString();
		}
Example #12
0
		public static LibraryFunction[] ExtractLibraryFunctions(ScriptThread thread, object instance)
		{
			if (instance == null)
				return new LibraryFunction[0];

			var list = new List<LibraryFunction>();
			var languageCaseSensitive = thread.App.Language.Grammar.CaseSensitive;

			MethodInfo[] methods = instance.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
			foreach (MethodInfo method in methods)
			{
				var fun = method.CreateDelegate<LibraryDelegate>(instance, false);
				if (fun != null)
				{
					var fname = method.GetCustomAttribute<FunctionNamesAttribute>();
					var names = (fname == null) ? new string[] { method.Name } : fname.Names;
					foreach (var strName in names)
					{
						string name = languageCaseSensitive ? strName : strName.ToLowerInvariant();
						list.Add(new LibraryFunction(name, fun));
					}
				}
			}

			return list.ToArray();
		}
Example #13
0
		public RefalLibrary(ScriptThread thread)
		{
			ScriptThread = thread;
			OpenFiles = new Dictionary<string, object>();
			BuriedKeys = new Dictionary<string, PassiveExpression>();
			BuriedValues = new Dictionary<string, PassiveExpression>();
			CommandLineArguments = null;
		}
Example #14
0
 protected override object DoEvaluate(ScriptThread thread)
 {
     thread.CurrentNode = this;  //standard prolog
       SetupEvaluateMethod(thread);
       var result = Evaluate(thread);
       thread.CurrentNode = Parent; //standard epilog
       return result;
 }
Example #15
0
 protected override object DoEvaluate(ScriptThread thread)
 {
     thread.CurrentNode = this;  //standard prolog
       var arg = Argument.Evaluate(thread);
       var result = thread.Runtime.ExecuteUnaryOperator(base.ExpressionType, arg, ref _lastUsed);
       thread.CurrentNode = Parent; //standard epilog
       return result;
 }
Example #16
0
        protected override object DoEvaluate(ScriptThread thread)
        {
            thread.CurrentNode = this;
            try
            {
                var programResult = new MtResult();

                // do NOT use this for anything else other than counting the number of to-finish-threads
                var count = _chains.Count;
                var waitForAllToEnd = new ManualResetEvent(false);

                // TODO THIS NEEDS TO BE FIXED!
                // The rest of the program only cares about the result of the last expression
                // which doesn't depend of the result of the previous expressions;
                // however, the program shouldn't end.
                // SOLUTION: Keep a global counter of all awaiting MtResults?

                for (int i = 0; i < _chains.Count; ++i)
                {
                    // This is here because of issues with closures using the for variable
                    var safe_i = i + 0;
                    var ch = _chains[i];
                    var subthread = ch.NewScriptThread(thread);
                    var chResult = ch.Evaluate(subthread) as MtResult;

                    // Lookout:
                    // do not capture anything loop related inside here
                    chResult.GetValue(delegate(MtObject x)
                    {
                        if (Interlocked.Decrement(ref count) == 0)
                        {
                            waitForAllToEnd.Set();
                        }

                        // Wait for the last chain to end.
                        // Last refers in the order of the chain in the code,
                        // not the order of execution!!!
                        if (safe_i == _chains.Count - 1)
                        {
                            // Wait for the end of *all* the chains before returning ...
                            waitForAllToEnd.WaitOne();
                            programResult.SetValue(x);
                        }
                    });
                }

                // Return value does not matter. This is asynchronous, remember?
                return programResult;
            }
            catch (Exception e)
            {
                throw new Exception("Exception on MtProgram.", e);
            }
            finally
            {
                //thread.CurrentNode = Parent;
            }
        }
		internal PassiveExpression EvaluateExpression(ScriptThread thread)
		{
			if (InnerExpression == null)
			{
				return PassiveExpression.Build(new OpeningBrace(), new ClosingBrace());
			}

			return PassiveExpression.Build(new OpeningBrace(), InnerExpression.Evaluate(thread), new ClosingBrace());
		}
Example #18
0
        protected override object DoEvaluate(ScriptThread thread)
        {
            thread.CurrentNode=this;

            object ret=_Identifier.Evaluate(thread);

            thread.CurrentNode=Parent;
            return ret;
        }
 protected object DefaultEvaluateImplementation(ScriptThread thread)
 {
     thread.CurrentNode = this;  //standard prolog
       var arg1 = Left.Evaluate(thread);
       var arg2 = Right.Evaluate(thread);
       var result = thread.Runtime.ExecuteBinaryOperator(this.Op, arg1, arg2, ref _lastUsed);
       thread.CurrentNode = Parent; //standard epilog
       return result;
 }
Example #20
0
 //Executed only once, on the first call
 protected override object DoEvaluate(ScriptThread thread)
 {
     thread.CurrentNode = this;  //standard prolog
       _accessor = thread.Bind(Symbol, BindingRequestFlags.Read);
       this.Evaluate = _accessor.GetValueRef; // Optimization - directly set method ref to accessor's method. EvaluateReader;
       var result = this.Evaluate(thread);
       thread.CurrentNode = Parent; //standard epilog
       return result;
 }
Example #21
0
 private object EvaluateAfter(ScriptThread thread)
 {
     thread.CurrentNode = this;  //standard prolog
       var closure = new Closure(thread.CurrentScope, this);
       if (NameNode != null)
     NameNode.SetValue(thread, closure);
       thread.CurrentNode = Parent; //standard epilog
       return closure;
 }
Example #22
0
 public override void DoSetValue(ScriptThread thread, object value)
 {
     thread.CurrentNode = this;  //standard prolog
       if (_accessor == null) {
     _accessor = thread.Bind(Symbol, BindingRequestFlags.Write | BindingRequestFlags.ExistingOrNew);
       }
       _accessor.SetValueRef(thread, value);
       thread.CurrentNode = Parent;  //standard epilog
 }
Example #23
0
 public BindingRequest(ScriptThread thread, AstNode fromNode, string symbol, BindingRequestFlags flags) {
   Thread = thread;
   FromNode = fromNode;
   FromModule = thread.App.DataMap.GetModule(fromNode.ModuleNode);
   Symbol = symbol;
   Flags = flags;
   FromScopeInfo = thread.CurrentScope.Info;
   IgnoreCase = !thread.Runtime.Language.Grammar.CaseSensitive;
 }
Example #24
0
 protected override object DoEvaluate(ScriptThread thread)
 {
     thread.CurrentNode = this;  //standard prolog
       var oldValue = Argument.Evaluate(thread);
       var newValue = thread.Runtime.ExecuteBinaryOperator(BinaryOp, oldValue, 1, ref _lastUsed);
       Argument.SetValue(thread, newValue);
       var result = IsPostfix ? oldValue : newValue;
       thread.CurrentNode = Parent; //standard epilog
       return result;
 }
Example #25
0
 private object EvaluateAugmented(ScriptThread thread)
 {
     thread.CurrentNode = this;  //standard prolog
       var value = Target.Evaluate(thread);
       var exprValue = Expression.Evaluate(thread);
       var result = thread.Runtime.ExecuteBinaryOperator(BinaryExpressionType, value, exprValue, ref _lastUsed);
       Target.SetValue(thread, result);
       thread.CurrentNode = Parent; //standard epilog
       return result;
 }
        protected override object DoEvaluate(Irony.Interpreter.ScriptThread thread)
        {
            base.DoEvaluate(thread);
            thread.CurrentNode = this;  //standard prolog
            var obj = ReallyDoEvaluate(thread);

            thread.CurrentNode = Parent; //standard epilog

            return(obj);
        }
 protected override object DoEvaluate(ScriptThread thread)
 {
     BasicParameter result = null;
     thread.CurrentNode = this;  //standard prolog
     var parametersCollection = thread.GetParametersCollection();
     result = parametersCollection.Find(parameterNode.AsString);
     if (result == null)
         return ExpressionHelper.ComposeAstNodeError("Parameters",parameterNode);
     return result.ParameterValue;
 }
Example #28
0
 protected override object DoEvaluate(ScriptThread thread)
 {
     thread.CurrentNode = this;  //standard prolog
       var values = new object[ChildNodes.Count];
       for (int i = 0; i < values.Length; i++) {
     values[i] = ChildNodes[i].Evaluate(thread);
       }
       thread.CurrentNode = Parent; //standard epilog
       return values;
 }
        protected override object DoEvaluate(ScriptThread thread)
        {
            switch (_value.ToLower())
            {
                case "true":  case "vrai": return true;
                case "false": case "faux": return false;
            }

            return base.DoEvaluate(thread);
        }
Example #30
0
 protected override object DoEvaluate(ScriptThread thread)
 {
     thread.CurrentNode = this;  //standard prolog
     var container = thread.GetCurrentContainer();
     var column = (ExportText)container.ExportedItems.Where(x => x.Name == fieldNode.AsString).FirstOrDefault();
     if (column == null) {
         return ExpressionHelper.ComposeAstNodeError("Fields",fieldNode);
     }
     return	column.Text;
 }
Example #31
0
 protected override object DoEvaluate(ScriptThread thread)
 {
     thread.CurrentNode = this;  //standard prolog
     var ret = new object[this.ChildNodes.Count];
     // Creates parameter slots
     for (int i = 0; i < this.ChildNodes.Count; i++)
         ret[i] = this.ChildNodes[i].Evaluate(thread);
     thread.CurrentNode = Parent; //standard epilog
     return ret;
 }
Example #32
0
 private object EvaluateMultiple(ScriptThread thread)
 {
     thread.CurrentNode = this;  //standard prolog
       object result = null;
       for (int i=0; i< ChildNodes.Count; i++) {
     result = ChildNodes[i].Evaluate(thread);
       }
       thread.CurrentNode = Parent; //standard epilog
       return result; //return result of last statement
 }
Example #33
0
        protected override object DoEvaluate(Irony.Interpreter.ScriptThread thread)
        {
            // PROLOG
            thread.CurrentNode = this;
            try
            {
                var appResult = new MtResult();

                MtResult[] args = _args.Evaluate(thread) as MtResult[];
                if (args == null)
                {
                    throw new Exception("Args evaluated to null!");
                }

                var subthreadF = _head.NewScriptThread(thread);
                var headResult = _head.Evaluate(subthreadF);
                if (headResult == null)
                {
                    throw new Exception("Head can't evaluate to null!");
                }

                MtFunctionObjectBase.ExtractAsFunction(headResult, (wrkFun) =>
                {
#if DEBUG && !SILVERLIGHT
                    if (wrkFun is BuiltInCallTarget)
                    {
                        var builtin = wrkFun as BuiltInCallTarget;
                        Debug.Print("Calling builtin: {0}", builtin.Name);
                    }
                    else
                    {
                        Debug.Print("Calling user function");
                    }
#endif

                    var resultFun = wrkFun.Call(thread, args) as MtResult;
                    resultFun.GetValue((r3) =>
                    {
                        appResult.SetValue(r3);
                    });
                });

                return(appResult);
            }
            catch (Exception e)
            {
                throw new Exception("Exception on MtApplication.", e);
            }
            finally
            {
                // EPILOG
                //thread.CurrentNode = Parent;
            }
        }
Example #34
0
        protected override object ReallyDoEvaluate(Irony.Interpreter.ScriptThread thread)
        {
            var sw = thread.tc().Writer;

            sw.WriteLine("/*********************************************************************");
            sw.WriteLine(" *   This C# program was generated by Shakespeare2CS by James Curran *");
            sw.WriteLine(" *   based on spl2c, the Shakespeare to C                            *");
            sw.WriteLine(" *          converter by Jon Åslund and Karl Hasselström.            *");
            sw.WriteLine(" *********************************************************************/");
            sw.WriteLine();
            sw.WriteLine("using System;");
            sw.WriteLine("using Shakespeare.Support;");
            sw.WriteLine();
            sw.WriteLine("namespace Shakespeare.Program");
            sw.WriteLine("{");
            sw.WriteLine("\tclass Program");
            sw.WriteLine("\t{");
            sw.WriteLine("\t\tstatic void Main(string[] args)");
            sw.WriteLine("\t\t{");
            sw.WriteLine("\t\t\tvar script = new Script();");
            sw.WriteLine("\t\t\tscript.Action();");
            sw.WriteLine("\t\t}");
            sw.WriteLine("\t}");
            sw.WriteLine();
            sw.WriteLine("\t\tclass Script : Dramaturge");
            sw.WriteLine("\t\t{");
            sw.WriteLine();
            sw.WriteLine("\t\tpublic Script()");
            sw.WriteLine("\t\t : base(Console.In, Console.Out)");
            sw.WriteLine("\t\t{ }");
            sw.WriteLine();
            sw.WriteLine("\t\tpublic void Action()");
            sw.WriteLine("\t\t{");

            AstNode1.Evaluate(thread);              // Title
            sw.WriteLine();
            var cdl = AstNode2 as CharacterDeclarationListNode;

            foreach (var ch in cdl.Characters)
            {
                ch.Evaluate(thread);
            }

            sw.WriteLine();
            AstNode3.Evaluate(thread);

            sw.WriteLine("\t\t}");
            sw.WriteLine("\t}");
            sw.WriteLine("}");
            sw.Flush();
            sw.Close();
            return(sw);
        }
Example #35
0
        protected override object ReallyDoEvaluate(Irony.Interpreter.ScriptThread thread)
        {
            var rs = thread.rs();
            var ag = rs.AG;

            using (ag.Namespace("Shakespeare.Program"))
            {
                TypeGen scriptClass = ag.Public.Class("Script", typeof(Shakespeare.Support.Dramaturge));
                {
                    rs.Script = scriptClass;

                    var console = typeof(Console);

                    CodeGen ctor = scriptClass.Public.Constructor();
                    ctor.InvokeBase(Static.Property(console, "In"), Static.Property(console, "Out"));
                    {
                    }

                    CodeGen action = scriptClass.Public.Void("Action");
                    {
                        rs.Action = action;
                        action.At(Span);
                        AstNode1.Evaluate(thread);
                        var cdl = AstNode2 as CharacterDeclarationListNode;
                        foreach (var ch in cdl.Characters)
                        {
                            ch.Evaluate(thread);
                        }

                        AstNode3.Evaluate(thread);
                    }
                }
                scriptClass.Complete();

                TypeGen MyClass = ag.Public.Class("Program");
                CodeGen Main    = MyClass.Public.Static.Void("Main").Parameter <string[]>("args");
                {
                    var script = Main.Local(Exp.New(scriptClass.GetCompletedType()));
                    Main.Invoke(script, "Action");
                }
            }
            ag.Save();

            return(ag.GetAssembly().GetName().Name);
        }
Example #36
0
        protected override object DoEvaluate(Irony.Interpreter.ScriptThread thread)
        {
            thread.CurrentNode = this;
            try
            {
                var myRes = new MtResult();

                // Eval expression
                var subthread = _expression.NewScriptThread(thread);
                var res       = _expression.Evaluate(subthread) as MtResult;
                res.GetValue((resExpr) =>
                {
                    AstNode toEval = null;
                    if (resExpr.Value == MtObject.False.Value)
                    {
                        // Evaluate false branch
                        toEval = _falseBranch;
                    }
                    else
                    {
                        // Evaluate true branch
                        toEval = _trueBranch;
                    }

                    // Evaluate!
                    var subsubthread = toEval.NewScriptThread(thread);
                    var resBranch    = toEval.Evaluate(subsubthread) as MtResult;
                    resBranch.GetValue((_resBranch) =>
                    {
                        myRes.SetValue(_resBranch);
                    });
                });

                return(myRes);
            }
            catch (Exception e)
            {
                throw new Exception("Exception on If.DoEvaluate.", e);
            }
            finally
            {
                //thread.CurrentNode = Parent;
            }
        }
        object ICallTarget.Call(Irony.Interpreter.ScriptThread thread, object[] parameters)
        {
            try
            {
                if (_thread != null)
                {
                    thread = _thread;
                }

                var body_to_eval = _body.ConvertToTS(); // Cloners.Convert(_body);

                // 2. Function object is responsable for:
                // 2.1 Create a new context
                var subthread = body_to_eval.NewScriptThread(thread);

                // 2.2 For each parameter, bind its correspondent argument
                // (ignore extra parameters, set missing to Empty)
                for (var i = 0; i < _args.ArgList.Length; ++i)
                {
                    var argDecl  = _args.ArgList[i];
                    var accessor = subthread.Bind(argDecl.AsString, BindingRequestFlags.Write | BindingRequestFlags.ExistingOrNew);
                    accessor.SetValueRef(subthread, parameters[i]);
                }

                // Add var for recursive definitions
                {
                    var accessor = subthread.Bind("$", BindingRequestFlags.Write | BindingRequestFlags.ExistingOrNew);
                    accessor.SetValueRef(subthread, this);
                }

                // 2.3 Call body in this new context
                var res = body_to_eval.Evaluate(subthread) as MtResult;
                if (res == null)
                {
                    throw new Exception("Function can't evaluate to null!");
                }
                return(res);
            }
            catch (Exception e)
            {
                throw new Exception("Exception on Function Object call.", e);
            }
        }
        protected override object DoEvaluate(Irony.Interpreter.ScriptThread thread)
        {
            thread.CurrentNode = this;
            try
            {
                var ret = new MtResult();

                ret.SetValue(new MtObject(new MtFunctionObject(_body, _arguments, thread)));

                return(ret);
            }
            catch (Exception e)
            {
                throw new Exception("Error on MtFunctionLiteral.DoEvaluate", e);
            }
            finally
            {
                //thread.CurrentNode = Parent;
            }
        }
Example #39
0
        //Actual implementation
        private object EvaluateParsedScript()
        {
            LastScript.Tag = DataMap;
            var root = LastScript.Root.AstNode as AstNode;

            root.DependentScopeInfo = MainScope.Info;

            Status = AppStatus.Evaluating;
            ScriptThread thread = null;

            try {
                thread = new ScriptThread(this);
                var result = root.Evaluate(thread);
                if (result != null)
                {
                    thread.App.WriteLine(result.ToString());
                }
                Status = AppStatus.Ready;
                return(result);
            } catch (ScriptException se) {
                Status              = AppStatus.RuntimeError;
                se.Location         = thread.CurrentNode.Location;
                se.ScriptStackTrace = thread.GetStackTrace();
                LastException       = se;
                if (RethrowExceptions)
                {
                    throw;
                }
                return(null);
            } catch (Exception ex) {
                Status = AppStatus.RuntimeError;
                var se = new ScriptException(ex.Message, ex, thread.CurrentNode.Location, thread.GetStackTrace());
                LastException = se;
                if (RethrowExceptions)
                {
                    throw se;
                }
                return(null);
            }//catch
        }
Example #40
0
        protected override object ReallyDoEvaluate(Irony.Interpreter.ScriptThread thread)
        {
            var sw = thread.tc().Writer;

            sw.WriteLine("/********************************************************************");
            sw.WriteLine(" *   This C program was generated by spl2c, the Shakespeare to C    *");
            sw.WriteLine(" *          converter by Jon Åslund and Karl Hasselström.           *");
            sw.WriteLine(" ********************************************************************/");
            sw.WriteLine("");
            sw.WriteLine("/* libspl definitions and function prototypes */");
            sw.WriteLine("#include \"spl.h\"");
            sw.WriteLine("");
            sw.WriteLine("int main(void)");
            sw.WriteLine("{");
            AstNode1.Evaluate(thread);  // Title
            sw.WriteLine();
            var cdl = AstNode2 as CharacterDeclarationListNode;

            foreach (var ch in cdl.Characters)
            {
                sw.WriteLine(ch.Declaration);
            }

            sw.WriteLine("\tint comp1, comp2;");
            sw.WriteLine("\tglobal_initialize();");
            foreach (var ch in cdl.Characters)
            {
                sw.WriteLine(ch.Initialization);
            }

            sw.WriteLine();
            sw.WriteLine();
            AstNode3.Evaluate(thread);
            sw.WriteLine("\treturn 0;");
            sw.WriteLine("}");
            sw.Flush();
            sw.Close();
            return(sw);
        }
Example #41
0
        protected override object DoEvaluate(Irony.Interpreter.ScriptThread thread)
        {
            thread.CurrentNode = this;
            try
            {
                // TODO Create a new context with $ as the current array? RECURSIVE ARRAYS? \ :D /

                var ret = new MtResult();

                var expressions = _expressionList.Evaluate(thread) as MtResult[];

                ret.SetValue(new MtObject(expressions));

                return(ret);
            }
            catch (Exception e)
            {
                throw new Exception("Exception on MtArray.DoEvaluate.", e);
            }
            finally
            {
                //thread.CurrentNode = Parent;
            }
        }
 private void SetPropertyValue(ScriptThread thread, object value)
 {
     Property.SetValue(Instance, value, null);
 }
Example #43
0
        private object GetPropertyValue(ScriptThread thread)
        {
            var result = Field.GetValue(Instance);

            return(result);
        }
 protected virtual object ReallyDoEvaluate(Irony.Interpreter.ScriptThread thread)
 {
     return(null);
 }
Example #45
0
 object ICallTarget.Call(Irony.Interpreter.ScriptThread thread, object[] parameters)
 {
     throw new NotImplementedException("Any child of MtFunctionObjectBase should implement Call().");
 }
Example #46
0
 public object Call(ScriptThread thread, object[] parameters)
 {
     return(Method(thread, parameters));
 }
Example #47
0
        private void SetParentScopeParameter(ScriptThread thread, object value)
        {
            var targetScope = GetTargetScope(thread);

            targetScope.SetParameter(SlotIndex, value);
        }
Example #48
0
        private object GetParentScopeParameter(ScriptThread thread)
        {
            var targetScope = GetTargetScope(thread);

            return(targetScope.GetParameter(SlotIndex));
        }
Example #49
0
 private void SetImmediateParentScopeParameter(ScriptThread thread, object value)
 {
     thread.CurrentScope.Parent.SetParameter(SlotIndex, value);
 }
Example #50
0
 private void SetStatic(ScriptThread thread, object value)
 {
     thread.App.StaticScopes[StaticScopeIndex].SetValue(SlotIndex, value);
 }
Example #51
0
 private void SetCurrentScopeValue(ScriptThread thread, object value)
 {
     thread.CurrentScope.SetValue(SlotIndex, value);
 }
Example #52
0
 private void SetPropertyValue(ScriptThread thread, object value)
 {
     Field.SetValue(Instance, value);
 }
Example #53
0
 private object GetStaticValue(ScriptThread thread)
 {
     try {
         return(thread.App.StaticScopes[StaticScopeIndex].GetValue(SlotIndex));
     } catch { thread.CurrentNode = FromNode; throw; }
 }
        private object GetPropertyValue(ScriptThread thread)
        {
            var result = Property.GetValue(Instance, null);

            return(result);
        }
Example #55
0
 private object GetCurrentScopeParameter(ScriptThread thread)
 {
     try {
         return(thread.CurrentScope.GetParameter(SlotIndex));
     } catch { thread.CurrentNode = FromNode; throw; }
 }
Example #56
0
 public object GetValue(ScriptThread thread)
 {
     return(Target);
 }