Beispiel #1
0
        public static CScript CreateRunner(string[] srcs, ScriptConfig scriptConfig = null, RunConfig config = null)
        {
            if (srcs == null || srcs.Length == 0)
            {
                throw new ArgumentException(nameof(srcs));
            }

            if (scriptConfig == null)
            {
                scriptConfig = ScriptConfig.Default;
            }
            if (config == null)
            {
                config = RunConfig.Default;
            }

            var r     = new Runner(scriptConfig, config);
            var roots = new List <SyntaxNode>();

            foreach (var src in srcs)
            {
                var root = ParseAndValidate(src, scriptConfig.PredefinedSymbols);
                r.LoadSyntax(root);
                roots.Add(root);
            }

            return(new CScript(r, roots.ToArray()));
        }
Beispiel #2
0
        public static CScript CreateRunner(string[] srcs, ScriptConfig scriptConfig = null, RunConfig config = null)
        {
            if (srcs == null || srcs.Length == 0)
            {
                throw new ArgumentException(nameof(srcs));
            }

            if (scriptConfig == null)
            {
                scriptConfig = ScriptConfig.Default;
            }
            if (config == null)
            {
                config = RunConfig.Default;
            }

            var r = new Runner(scriptConfig, config);

            foreach (var src in srcs)
            {
                var root = ParseAndValidate(src);
                r.LoadSyntax(root);
            }

            return(new CScript(r));
        }
Beispiel #3
0
        public static object Run(string src, ScriptConfig scriptConfig = null, RunConfig config = null)
        {
            var r = CreateRunner(src, scriptConfig, config);

            var ret = r.RunMain();

            if (ret == null)
            {
                return(null);
            }
            return(ret.Unwrap());
        }
Beispiel #4
0
        public static object RunSimple(string src, ScriptConfig scriptConfig = null, RunConfig config = null)
        {
            return(Run(@"
using System;

class CScript__ {
public static object Main() {
    return " + src + @";
}
}
", scriptConfig, config));
        }
Beispiel #5
0
        public static CScript CreateRunner(ScriptConfig scriptConfig = null, RunConfig config = null)
        {
            if (scriptConfig == null)
            {
                scriptConfig = ScriptConfig.Default;
            }
            if (config == null)
            {
                config = RunConfig.Default;
            }

            var r = new Runner(scriptConfig, config);

            return(new CScript(r, new SyntaxNode[] { }));
        }
Beispiel #6
0
        public Runner(ScriptConfig scriptConfig, RunConfig config)
        {
            this.Ctx          = new RunContext(config);
            this.ScriptConfig = scriptConfig;
            this.Globals      = new GlobalStorage();

            var assemblies = AppDomain.CurrentDomain.GetAssemblies();

            this.OptCache    = new OptNodeCache();
            this.Lookup      = new IdLookup(assemblies);
            this.Catches     = new Stack <CatchFrame>();
            this.Frames      = new Stack <VarFrame>();
            this.ExtResolver = new ExtensionMethodResolver(assemblies);
            this.Resolver    = new TypeResolver(Ctx, assemblies);

            AddDefaultUsings();
            PrewarmTypes();
        }
Beispiel #7
0
 public static CScript CreateRunner(string src, ScriptConfig scriptConfig = null, RunConfig config = null)
 => CreateRunner(new string[] { src }, scriptConfig, config);