public Builder(BuilderOptions options, DyLinker linker) { this.referencedUnits = new Dictionary <string, UnitInfo>(); this.types = new Dictionary <string, TypeInfo>(); this.memberNames = new Dictionary <string, int>(); this.options = options; this.linker = linker; counters = new Stack <int>(); pdb = new DebugWriter(); isDebug = options.Debug; globalScope = new Scope(true, null); unit = new Unit { GlobalScope = globalScope, Symbols = pdb.Symbols }; cw = new CodeWriter(unit); currentScope = globalScope; programEnd = cw.DefineLabel(); }
public Builder(Builder builder) { this.iterative = true; this.linker = builder.linker; this.types = builder.types; this.memberNames = builder.memberNames; this.referencedUnits = builder.referencedUnits; this.counters = new Stack <int>(); this.options = builder.options; this.pdb = builder.pdb.Clone(); this.unit = builder.unit.Clone(this.pdb.Symbols); this.cw = builder.cw.Clone(this.unit); this.globalScope = unit.GlobalScope; this.currentScope = builder.currentScope != builder.globalScope ? builder.currentScope.Clone() : this.globalScope; this.isDebug = builder.isDebug; this.lastLocation = builder.lastLocation; this.Messages = new List <BuildMessage>(); this.counters = new Stack <int>(builder.counters.ToArray()); this.currentCounter = builder.currentCounter; this.programEnd = cw.DefineLabel(); }
private static IList <FunSet> Compile(IEnumerable <string> files, BuilderOptions buildOptions, out List <BuildMessage> warns) { var funColl = new List <FunSet>(); warns = new List <BuildMessage>(); foreach (var file in files) { var linker = new DyLinker(FileLookup.Create(Path.GetDirectoryName(file)), buildOptions); var cres = linker.Make(SourceBuffer.FromFile(file)); var funs = new FunSet(); funs.Funs = new Dictionary <string, DyFunction>(StringComparer.OrdinalIgnoreCase); funs.FileName = file; if (!cres.Success) { throw new DyBuildException(cres.Messages); } warns.AddRange(cres.Messages.Where(m => m.Type == BuildMessageType.Warning)); var ctx = DyMachine.CreateExecutionContext(cres.Value); funs.Context = ctx; DyMachine.Execute(ctx); foreach (var v in DyMachine.DumpVariables(ctx)) { if (v.Value is DyFunction fn) { funs.Funs.Remove(v.Name); funs.Funs.Add(v.Name, fn); } } funColl.Add(funs); } return(funColl); }
public static DyObject?Eval(SourceBuffer buffer, BuilderOptions options, FileLookup lookup, object?args = null) { DyTuple?tup = null; if (args is not null) { var arr = args.GetType().GetProperties().Select(pi => new DyLabel(pi.Name, TypeConverter.ConvertFrom(pi.GetValue(args)))).ToArray(); tup = new DyTuple(arr); } var linker = new DyLinker(lookup ?? FileLookup.Default, options ?? BuilderOptions.Default(), tup); var result = linker.Make(buffer); if (!result.Success) { throw new DyBuildException(result.Messages); } var ctx = DyMachine.CreateExecutionContext(result.Value !); var result2 = DyMachine.Execute(ctx); return(result2.Value); }
public DyCompiler(DyCompiler compiler) { options = compiler.options; linker = compiler.linker; builder = new(compiler.builder); }
public DyCompiler(BuilderOptions options, DyLinker linker) { this.options = options ?? BuilderOptions.Default(); this.linker = linker; builder = new(this.options, linker); }
public DyCompiler(DyCompiler compiler) { this.options = compiler.options; this.linker = compiler.linker; this.builder = new Builder(compiler.builder); }