public static Symbol GetSymbol(this Cobject This) { if (!TryGetSymbol(This, out var symbol)) { throw new BinderException($"`{This}´ can't be a symbol"); } return(symbol); }
public static Special Define(Symbol symbol, Cobject value) { return(new Special( (scope, stack) => { value.Eval(scope, stack); value = stack.Pop(); scope.Define(symbol, value); })); }
public static bool TryGetSymbol(this Cobject This, out Symbol symbol) { if (!(This is Block block) || !block.TryGetQuotedSymbol(out symbol)) { symbol = null; return(false); } return(true); }
public void Update(Symbol symbol, Cobject value) { var binding = Find(symbol); if (binding.IsSealed.Value) { throw new BinderException($"`{symbol}´ is marked as sealed and can't be updated"); } binding.Value = value; }
public void Define(Symbol symbol, Cobject value, bool isSealed = false, bool isOpaque = false) { if (TryFind(symbol, out var binding)) { throw new BinderException($"`{symbol}´ already defined in current scope"); } binding = new Binding(this, value, Bool.From(isSealed), Bool.From(isOpaque)); this.bindings.Add(symbol, binding); this.symbols.Add(symbol); }
public static void Eval(this Cobject This, IScope scope, IStack stack) { if (This is Cobject cvalue) { cvalue.Eval(scope, stack); } else { stack.Push(This); } }
public static IEnumerable <Cobject> Enumerate(this Cobject This) { /*// ReSharper disable once UsePatternMatching*/ var enumerable = This as IEnumerable <Cobject>; // ReSharper disable once ConvertIfStatementToNullCoalescingExpression if (enumerable == null) { enumerable = Enumerable.Repeat(This, 1); } return(enumerable); }
public void Define(Symbol symbol, Cobject value, bool isSealed = false, bool isOpaque = false) { if (TryFind(symbol, out var binding)) { if (Equals(binding.Binder, this.Binder)) { throw new BinderException($"`{symbol}´ already defined in current scope"); } if (binding.IsOpaque.Value) { throw new BinderException($"`{symbol}´ is marked as opaque and can't be redefined"); } } this.Binder.Define(symbol, value, isSealed, isOpaque); }
public static Special SingleDefine(Cobject symbol) { return(MultiDefine(Enumerable.Repeat(symbol, 1))); }
public void GetValue(Symbol symbol, out Cobject value) { value = Find(symbol).Value; }