Beispiel #1
0
 /// <summary>
 /// Simple static helper to evaluate an expression (typically a pure expression without side effects).
 /// </summary>
 /// <param name="e">The expression to evaluate.</param>
 /// <param name="ctx">The <see cref="GlobalContext"/>. When null, a new default GlobalContext is used.</param>
 /// <returns>The result of the evaluation.</returns>
 public static RuntimeObj Evaluate( Expr e, GlobalContext ctx = null )
 {
     EvalVisitor v = new EvalVisitor( ctx ?? new GlobalContext() );
     return v.VisitExpr( e ).Result;
 }
Beispiel #2
0
 /// <summary>
 /// Initializes a new <see cref="ScriptEngine"/>, optionally bound to an existing <see cref="GlobalContext"/>.
 /// </summary>
 /// <param name="ctx">Optional global context to use.</param>
 /// <param name="breakPointManager">Optional <see cref="BreakpointManager"/> instance to use.</param>
 /// <param name="scopeManager">Optional <see cref="DynamicScope"/> to use.</param>
 public ScriptEngine( GlobalContext ctx = null, BreakpointManager breakPointManager = null, DynamicScope scopeManager = null )
 {
     _breakpoints = breakPointManager ?? new BreakpointManager();
     _globalContext = ctx ?? new GlobalContext();
     _visitor = new EvalVisitor( _globalContext, _breakpoints.MustBreak, scopeManager );
 }
Beispiel #3
0
 /// <summary>
 /// Simple static helper to evaluate a string (typically a pure expression without side effects).
 /// </summary>
 /// <param name="s">The string to evaluate.</param>
 /// <param name="ctx">The <see cref="GlobalContext"/>. When null, a new default GlobalContext is used.</param>
 /// <returns>The result of the evaluation.</returns>
 public static RuntimeObj Evaluate( string s, GlobalContext ctx = null )
 {
     return Evaluate( ExprAnalyser.AnalyseString( s ) );
 }
Beispiel #4
0
 public override object ToNative(GlobalContext c) => _value;
Beispiel #5
0
 /// <summary>
 /// Initializes a new <see cref="ScriptEngine"/>, optionally bound to an existing <see cref="GlobalContext"/>.
 /// </summary>
 /// <param name="ctx">Optional global context to use.</param>
 /// <param name="breakPointManager">Optional <see cref="BreakpointManager"/> instance to use.</param>
 /// <param name="scopeManager">Optional <see cref="DynamicScope"/> to use.</param>
 public ScriptEngine(GlobalContext ctx = null, BreakpointManager breakPointManager = null, DynamicScope scopeManager = null)
 {
     _breakpoints   = breakPointManager ?? new BreakpointManager();
     _globalContext = ctx ?? new GlobalContext();
     _visitor       = new EvalVisitor(_globalContext, _breakpoints.MustBreak, scopeManager);
 }
Beispiel #6
0
        /// <summary>
        /// Simple static helper to evaluate an expression (typically a pure expression without side effects).
        /// </summary>
        /// <param name="e">The expression to evaluate.</param>
        /// <param name="ctx">The <see cref="GlobalContext"/>. When null, a new default GlobalContext is used.</param>
        /// <returns>The result of the evaluation.</returns>
        public static RuntimeObj Evaluate(Expr e, GlobalContext ctx = null)
        {
            EvalVisitor v = new EvalVisitor(ctx ?? new GlobalContext());

            return(v.VisitExpr(e).Result);
        }
Beispiel #7
0
 /// <summary>
 /// Simple static helper to evaluate a string (typically a pure expression without side effects).
 /// </summary>
 /// <param name="s">The string to evaluate.</param>
 /// <param name="ctx">The <see cref="GlobalContext"/>. When null, a new default GlobalContext is used.</param>
 /// <returns>The result of the evaluation.</returns>
 public static RuntimeObj Evaluate(string s, GlobalContext ctx = null)
 {
     return(Evaluate(ExprAnalyser.AnalyseString(s)));
 }