예제 #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);
        }
예제 #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);
     }));
 }
예제 #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);
        }
예제 #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;
        }
예제 #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);
        }
예제 #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);
     }
 }
예제 #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);
        }
예제 #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);
        }
예제 #9
0
 public static Special SingleDefine(Cobject symbol)
 {
     return(MultiDefine(Enumerable.Repeat(symbol, 1)));
 }
예제 #10
0
 public void GetValue(Symbol symbol, out Cobject value)
 {
     value = Find(symbol).Value;
 }