Exemplo n.º 1
0
 public void SetDynamic( string identifier, Dynamic dynamic )
 {
     if ( !TrySetDynamic ( identifier, dynamic ) )
     {
         AddDynamic(identifier, dynamic);
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Adds the varible at this level of scope 
 /// </summary>
 public void AddDynamic( string identifier, Dynamic dynamic )
 {
     if (dynamic == null)
         _lookup.Remove ( identifier );
     else
         _lookup[identifier] = dynamic;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Evaluate a block sticks it in a dynamic and returns it 
        /// for later execution.
        /// </summary>
        /// <param name="heap"></param>
        /// <returns></returns>
        public override Dynamic Evaluate()
        {
            var result = new Dynamic
            {
                Scope = Scope,
                BlockValue = this
            };

            return result;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Setting a variable with an indexer - the original variable must have already been set
        /// </summary>
        public void SetDynamic( string identifier, Dynamic indexer, Dynamic dynamic )
        {
            Dynamic variable = TryGetDynamic ( identifier );
            if (variable == null) // TODO Better error
                throw new Exception ("Indexing into non-existant array");

            if (variable.Type != DynamicType.arrayType) // TODO Better error
                throw new Exception ("Indexing into non-array");

            variable.ArrayValue[(Int32)Math.Truncate(indexer.NumberValue)] = dynamic;
        }
Exemplo n.º 5
0
        public Dynamic GetDynamic( string identifier )
        {
            Dynamic result = TryGetDynamic ( identifier );

            if ( result != null )
                return result;

            Dynamic newDynamic = new Dynamic ()
            {
                Scope = this
            };

            _lookup.Add ( identifier, newDynamic );

            return newDynamic;
        }
Exemplo n.º 6
0
 private Dynamic EvaluateSub( Dynamic left, Dynamic right )
 {
     return new Dynamic ( )
     {
         NumberValue = left.NumberValue - right.NumberValue,
         Scope = this.Scope
     };
 }
Exemplo n.º 7
0
        /// <summary>
        /// Calls a block that this variable is assigned to.
        /// Returns a Variable which holds a block if that was the 
        /// tail call of this block.
        /// </summary>
        public ITailCallExecution Execute( Variable variable, Dynamic parameters )
        {
            Dynamic dynamic = Scope.GetDynamic ( variable.Ident );
            if (dynamic.Type == DynamicType.arrayType)
            {
                Dynamic index = variable.Indexer.Evaluate();
                dynamic = dynamic.ArrayValue[(Int32)Math.Truncate (index.NumberValue)];
            }

            if ( dynamic.BlockValue != null )
            {
                _debug.PrintDebugInfo ( "Executing block : " + variable.Ident );

                dynamic.BlockValue.Scope.AddDynamic ( "$", parameters );
                ITailCallExecution tailCall = dynamic.BlockValue.ExecuteBlockWithTailCallElimination ();

                if (tailCall != null)
                    _debug.PrintDebugInfo ( "Tail call returned : " + tailCall.ToString()  );

                return tailCall;
            }

            return null;
        }
Exemplo n.º 8
0
        /// <summary>
        /// Try to set the variable at a scope level that has this defined. 
        /// </summary>
        /// <returns>
        /// True if variable has been set.
        /// False if variable has not been set <see cref="System.Boolean"/>
        /// </returns>
        public bool TrySetDynamic( string identifier, Dynamic dynamic )
        {
            if (_lookup.ContainsKey ( identifier ) )
            {
                _lookup[identifier] = dynamic;
                return true;
            }
            else if ( _inheritedScope != null )
                return _inheritedScope.TrySetDynamic( identifier, dynamic );

            return false;
        }