32 private readonly List<Action<BadExecutionContext>>
m_ConfigureContext =
new List<Action<BadExecutionContext>>();
34 private readonly List<Action<BadExecutionContext, string, BadModuleImporter>>
m_ConfigureModuleImporter =
new List<Action<BadExecutionContext, string, BadModuleImporter>>();
40 new List<Action<BadExecutionContextOptions>>();
45 private readonly List<IDisposable>
m_Disposables =
new List<IDisposable>();
275 ctx.Scope.AddSingleton(
this);
288 action(ctx, workingDirectory, importer);
291 ctx.Scope.AddSingleton(importer);
342 return Execute(
ParseFile(file, fs), fs.GetFullPath(Path.GetDirectoryName(fs.GetFullPath(file)) ?? fs.GetCurrentDirectory()));
350 public static IEnumerable<BadExpression>
Parse(
string source)
352 return Parse(source,
"<memory>");
361 public static IEnumerable<BadExpression>
Parse(
string source,
string file)
365 IEnumerable<BadExpression> result = parser.
Parse();
389 return Parse(fs.ReadAllText(file), file);
466 return ConfigureModuleImporter((ctx, workingDir, importer) => importer.AddHandler(f(ctx, workingDir, importer)));
Exposes the BadScript Runtime Functionality to Consumers.
BadModuleImporter? Importer
BadRuntime UseDebugger(IBadDebugger debugger)
Configures the Runtime to use the specified Debugger.
BadRuntime UseFileLogWriter(string path)
Configures the Runtime to use the file log writer implementation.
BadExecutionContextOptions CreateOptions()
Creates and configures the Options for the Context.
BadRuntime UseLogWriter(BadLogWriter writer)
Configures the Runtime to use the specified logwriter implementation.
BadRuntime UseExtension< T >()
Uses a specified Extension.
BadRuntime ConfigureModuleImporter(Action< string, BadModuleImporter > action)
Configures the Module Importer.
BadModuleStore ModuleStore
BadRuntime UseLogMask(params BadLogMask[] mask)
Configures the Runtime to use the specified log masks.
readonly List< Action< BadExecutionContextOptions > > m_ConfigureOptions
Configuration Actions for the Options.
readonly List< Action< BadExecutionContext, string, BadModuleImporter > > m_ConfigureModuleImporter
Func< BadExecutionContext, IEnumerable< BadExpression >, BadObject > m_Executor
The Executor Function used to Execute a list of Expressions.
BadRuntime Clone()
Clone this Runtime.
BadRuntimeExecutionResult Execute(IEnumerable< BadExpression > expressions, string workingDirectory)
Executes the specified expressions.
BadRuntime UseLogMask(params string[] mask)
Configures the Runtime to use the specified log masks.
BadRuntime UseConsoleLogWriter()
Configures the Runtime to use the default log writer implementation(log to console)
BadRuntime ConfigureModuleImporter(Action< BadModuleImporter > action)
Configures the Module Importer.
static BadObject Executor(BadExecutionContext ctx, IEnumerable< BadExpression > exprs)
The Default Executor Function.
readonly List< IDisposable > m_Disposables
List of Disposables.
BadRuntime UseLocalModules(IFileSystem? fs=null)
Registers the Local Path Handler to the Module Importer.
BadRuntime UseImportHandler(Func< string, BadModuleImporter, BadImportHandler > f)
Configures a Module Importer to use the specified Import Handler.
BadRuntime()
Creates a new BadScript Runtime with the default options.
BadRuntime UseSingleton< T >(T obj)
Uses the specified Singleton Object.
BadRuntime UseCompilerApi()
Configures the Runtime to expose the CompilerAPI to the Scripts.
BadRuntime UseImportHandler(BadImportHandler handler)
Configures a Module Importer to use the specified Import Handler.
BadRuntime UseImportHandler(Func< BadExecutionContext, BadModuleImporter, BadImportHandler > f)
Configures a Module Importer to use the specified Import Handler.
readonly List< Action< BadExecutionContext > > m_ConfigureContext
Configuration Actions for the Context.
BadRuntime UseApi(BadInteropApi api, bool replace=false)
Adds or Replaces a specified API.
BadRuntime(BadExecutionContextOptions options)
Creates a new BadScript Runtime with the specified options.
BadRuntime UseImportHandler(Func< BadExecutionContext, string, BadModuleImporter, BadImportHandler > f)
Configures a Module Importer to use the specified Import Handler.
BadRuntime ConfigureModuleImporter(Action< BadExecutionContext, BadModuleImporter > action)
Configures the Module Importer.
BadRuntime LoadSettings(string settingsFile, IFileSystem? fileSystem=null)
Loads the specified settings file.
BadRuntime UseImportHandler(Func< BadModuleImporter, BadImportHandler > f)
Configures a Module Importer to use the specified Import Handler.
BadRuntime UseApis(IEnumerable< BadInteropApi > apis, bool replace=false)
Adds or Replaces a specified APIs.
BadRuntimeExecutionResult Execute(string source)
Executes the specified script.
BadRuntime ConfigureContext(params Action< BadExecutionContext >[] action)
Adds the specified Context Configuration Actions.
void Dispose()
Disposes all Disposables.
BadRuntime ConfigureContextOptions(params Action< BadExecutionContextOptions >[] action)
Adds the specified Option Configuration Actions.
BadRuntime UseExecutor(Func< BadExecutionContext, IEnumerable< BadExpression >, BadObject > executor)
Configures the Runtime to use the specified Executor.
BadExecutionContext CreateContext(string workingDirectory)
Creates a new Context with the configured Options.
BadRuntime UseConsole(IBadConsole console)
Configures the Runtime to use the specified console implementation.
BadRuntime ConfigureModuleImporter(Action< BadExecutionContext, string, BadModuleImporter > action)
Configures the Module Importer.
static IEnumerable< BadExpression > Parse(string source)
Parses the specified source.
BadRuntimeExecutionResult ExecuteFile(string file, IFileSystem? fileSystem=null)
Executes the specified script file.
static IEnumerable< BadExpression > ParseFile(string file, IFileSystem? fileSystem=null)
Parses the specified script file.
readonly BadExecutionContextOptions m_Options
The Options for the Context.
BadRuntimeExecutionResult Execute(string source, string file)
Executes the specified script.
static IEnumerable< BadExpression > Parse(string source, string file)
Parses the specified source.
Implements a Mask for Log Messages.
static BadLogMask GetMask(params BadLogMask[] masks)
Returns a combined mask of all masks provided.
Public facing interface for a logger.
static void Log(string message)
Writes a Log to the Message Handler.
Implements a simple file writer for the log system.
Base Class of all log writers.
void Register()
Registers the Log Writer to the Log System.
Wrapper class for the console abstraction.
static void SetConsole(IBadConsole console)
Sets the Current Console Implementation.
Public Debugger Interface.
static bool IsAttached
True if a debugger is attached.
static void Attach(IBadDebugger debugger)
Attaches a debugger to the system.
static void Detach()
Detaches the debugger from the system.
Public interface for the filesystem abstraction of the BadScript Engine.
static IFileSystem Instance
File System implementation.
Implements a simple constant folding optimization.
static BadExpression Optimize(BadExpression expr)
Optimizes the given expression.
Contains the Implementation of the Constant Substitution Optimization This optimization replaces expr...
static IEnumerable< BadExpression > Optimize(BadConstantSubstitutionOptimizerScope scope, IEnumerable< BadExpression > expressions)
Substitutes all variables in the expressions with their constant value.
The Parser of the Language. It turns Source Code into an Expression Tree.
static BadSourceParser Create(string fileName, string source)
Creates a BadSourceParser Instance based on the source and filename provided.
static IEnumerable< BadExpression > Parse(string fileName, string source)
Parses a BadExpression from the Source Reader.
The Execution Context. Every execution of a script needs a context the script is running in....
BadObject ExecuteScript(IEnumerable< BadExpression > expressions)
Executes an enumeration of expressions and returns the last value.
BadScope Scope
The Root Scope of the Context.
Provides settings for creating a new BadExecutionContext
BadExecutionContext Build()
Builds a new BadExecutionContext with the options provided in this Options Instance.
void AddApi(BadInteropApi api)
Adds a new Api to the context.
BadExecutionContextOptions Clone()
Clones this BadExecutionContextOptions instance.
BadObject GetExports()
Returns the exported key value pairs of the scope.
Implements an Interop API for the BS2 Language.
Public Extension API for the BS2 Runtime.
Defines the shape of the import handler for the module importer.
The Class that manages the importing of modules.
BadModuleImporter Clone(bool onlyTransient=true)
Is the store for all loaded modules.
Imports a module from a local path.
The Base Class for all BadScript Objects.
Defines Settings for Native Optimizations.
Implements an API for the Compiler.
Public Api for the Settings System.
Helper class that can be used to automatically load a settings object from a file.
static void SetRootSettings(BadSettings settings)
Sets the Root Settings Object.
static T Instance
Returns the Instance of the Settings Provider.
static bool HasRootSettings
Returns true if the root setting has been set.
static BadSettings RootSettings
Returns the Root Settings Object.
Reads a JSON file and returns the resulting BadSettings Object.
BadSettings ReadSettings()
Returns a new Instance of BadSettings with all source files loaded.
Interface that abstracts the console.
Defines the Debugging Interface.
Defines the interface for a file system.
string GetCurrentDirectory()
Returns the Current Directory.
string GetFullPath(string path)
Returns the full path of the given path.
Contains Writer Implementations for the BadScript Logging System.
Contains Logging system for the BadScript Runtime.
Contains a Console Abstraction Layer to be able to Simulate Console Input/Output over the Network.
Contains the debugging abstractions for the BadScript2 Runtime.
Contains IO Implementation for the BadScript2 Runtime.
Contains the BadScript2 Constant Folding Optimizations.
Contains the BadScript2 Constant Substitution Optimizations.
Contains the Expressions for the BadScript2 Language.
Contains the Parser for the BadScript2 Language.
Contains the Interop Abstractions and Implementations for the BadScript2 Language.
Contains the Runtime Objects.
Contains Runtime Settings Objects.
Contains the Compiler for the BadVirtualMachine.
Contains the Runtime Implementation.
Contains the Settings Implementation.
The main namespace for the BadScript2 Language.
Gets returned by the bad runtime when an execution is finished.