Exemplo n.º 1
0
        public static Symbol GetSymbol(this Cobject This)
        {
            if (!TryGetSymbol(This, out var symbol))
            {
                throw new BinderException($"`{This}´ can't be a symbol");
            }

            return(symbol);
        }
Exemplo n.º 2
0
 public static Special Define(Symbol symbol, Cobject value)
 {
     return(new Special(
                (scope, stack) =>
     {
         value.Eval(scope, stack);
         value = stack.Pop();
         scope.Define(symbol, value);
     }));
 }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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;
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
 public static void Eval(this Cobject This, IScope scope, IStack stack)
 {
     if (This is Cobject cvalue)
     {
         cvalue.Eval(scope, stack);
     }
     else
     {
         stack.Push(This);
     }
 }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
 public static Special SingleDefine(Cobject symbol)
 {
     return(MultiDefine(Enumerable.Repeat(symbol, 1)));
 }
Exemplo n.º 10
0
 public void GetValue(Symbol symbol, out Cobject value)
 {
     value = Find(symbol).Value;
 }