public Binding Bind(string symbol, BindingRequestFlags options) {
   var request = new BindingRequest(this, CurrentNode, symbol, options);
   var binding = Bind(request); 
   if (binding == null)
     ThrowScriptError("Unknown symbol '{0}'.", symbol); 
   return binding; 
 }
        }//method

        public virtual Binding BindSymbolForRead(BindingRequest request)
        {
            var symbol = request.Symbol;
            // First check current and enclosing scopes
            var currScope = request.Thread.CurrentScope;
            do
            {
                var existingSlot = currScope.Info.GetSlot(symbol);
                if (existingSlot != null)
                    return new SlotBinding(existingSlot, request.FromNode, request.FromScopeInfo);
                currScope = currScope.Parent;
            } while (currScope != null);

            // If not found, check imports
            foreach (var imp in request.FromModule.Imports)
            {
                var result = imp.Bind(request);
                if (result != null)
                    return result;
            }

            // Check built-in modules
            var builtIn = BuiltIns.Bind(request);
            if (builtIn != null) return builtIn;

            // if not found, return null
            return null;
        }
Exemple #3
0
        //IBindingSource Members
        public Binding Bind(BindingRequest request)
        {
            IBindingSource target;

            if (TryGetValue(request.Symbol, out target))
            {
                return(target.Bind(request));
            }
            return(null);
        }
Exemple #4
0
        public Binding Bind(string symbol, BindingRequestFlags options)
        {
            var request = new BindingRequest(this, CurrentNode, symbol, options);
            var binding = Bind(request);

            if (binding == null)
            {
                ThrowScriptError("Unknown symbol '{0}'.", symbol);
            }
            return(binding);
        }
Exemple #5
0
        public virtual Binding BindSymbolForWrite(BindingRequest request)
        {
            var scope        = request.Thread.CurrentScope;
            var existingSlot = scope.Info.GetSlot(request.Symbol);

            //1. If new only, check it does not exist yet, create and return it
            if (request.Flags.IsSet(BindingRequestFlags.NewOnly))
            {
                if (existingSlot != null)
                {
                    request.Thread.ThrowScriptError("Variable {0} already exists.", request.Symbol);
                }

                var newSlot = scope.AddSlot(request.Symbol);
                return(new SlotBinding(newSlot, request.FromNode, request.FromScopeInfo));
            }

            //2. If exists, then return it
            if (existingSlot != null && request.Flags.IsSet(BindingRequestFlags.ExistingOrNew))
            {
                //TODO: For external client, check that slot is actually public or exported
                return(new SlotBinding(existingSlot, request.FromNode, request.FromScopeInfo));
            }

            //3. Check external module imports
            foreach (var imp in request.FromModule.Imports)
            {
                var result = imp.Bind(request);
                if (result != null)
                {
                    return(result);
                }
            }

            //4. If nothing found, create new slot in current scope
            if (request.Flags.IsSet(BindingRequestFlags.ExistingOrNew))
            {
                var newSlot = scope.AddSlot(request.Symbol);
                return(new SlotBinding(newSlot, request.FromNode, request.FromScopeInfo));
            }

            //5. Check built-in methods
            var builtIn = BuiltIns.Bind(request);

            if (builtIn != null)
            {
                return(builtIn);
            }

            //6. If still not found, return null.
            return(null);
        }
 //Binds to local variables, enclosing scopes, module scopes/globals and built-ins
 public virtual Binding Bind(BindingRequest request) {
   var symbol = request.Symbol;
   var mode = request.Flags;
   if (mode.IsSet(BindingRequestFlags.Write))
     return BindSymbolForWrite(request);
   else if (mode.IsSet(BindingRequestFlags.Read))
     return BindSymbolForRead(request);
   else {
     //TODO: need to throw fatal error here
     request.Thread.ThrowScriptError("Invalid binding request, access type (Read or Write) is not set in request Options.");
     return null; // never happens
   }
 }//method
Exemple #7
0
        //Binds to local variables, enclosing scopes, module scopes/globals and built-ins
        public virtual Binding Bind(BindingRequest request)
        {
            var mode = request.Flags;

            if (mode.IsSet(BindingRequestFlags.Write))
            {
                return(BindSymbolForWrite(request));
            }
            else if (mode.IsSet(BindingRequestFlags.Read))
            {
                return(BindSymbolForRead(request));
            }
            else
            {
                //TODO: need to throw fatal error here
                request.Thread.ThrowScriptError("Invalid binding request, access type (Read or Write) is not set in request Options.");
                return(null); // never happens
            }
        }
        }//method

        public virtual Binding BindSymbolForWrite(BindingRequest request)
        {
            var scope = request.Thread.CurrentScope;
            var existingSlot = scope.Info.GetSlot(request.Symbol);
            //1. If new only, check it does not exist yet, create and return it
            if (request.Flags.IsSet(BindingRequestFlags.NewOnly))
            {
                if (existingSlot != null)
                    request.Thread.ThrowScriptError("Variable {0} already exists.", request.Symbol);
                var newSlot = scope.AddSlot(request.Symbol);
                return new SlotBinding(newSlot, request.FromNode, request.FromScopeInfo);
            }
            //2. If exists, then return it
            if (existingSlot != null && request.Flags.IsSet(BindingRequestFlags.ExistingOrNew))
            {
                //TODO: For external client, check that slot is actually public or exported
                return new SlotBinding(existingSlot, request.FromNode, request.FromScopeInfo);
            }

            //3. Check external module imports
            foreach (var imp in request.FromModule.Imports)
            {
                var result = imp.Bind(request);
                if (result != null)
                    return result;
            }

            //4. If nothing found, create new slot in current scope
            if (request.Flags.IsSet(BindingRequestFlags.ExistingOrNew))
            {
                var newSlot = scope.AddSlot(request.Symbol);
                return new SlotBinding(newSlot, request.FromNode, request.FromScopeInfo);
            }

            //5. Check built-in methods
            var builtIn = BuiltIns.Bind(request);
            if (builtIn != null) return builtIn;

            //6. If still not found, return null.
            return null;
        }//method
Exemple #9
0
        public virtual Binding BindSymbolForRead(BindingRequest request)
        {
            var symbol = request.Symbol;
            // First check current and enclosing scopes
            var currScope = request.Thread.CurrentScope;

            do
            {
                var existingSlot = currScope.Info.GetSlot(symbol);
                if (existingSlot != null)
                {
                    return(new SlotBinding(existingSlot, request.FromNode, request.FromScopeInfo));
                }
                currScope = currScope.Parent;
            } while (currScope != null);

            // If not found, check imports
            foreach (var imp in request.FromModule.Imports)
            {
                var result = imp.Bind(request);
                if (result != null)
                {
                    return(result);
                }
            }

            // Check built-in modules
            var builtIn = BuiltIns.Bind(request);

            if (builtIn != null)
            {
                return(builtIn);
            }

            // if not found, return null
            return(null);
        }
 public virtual Binding Bind(BindingRequest request) {
   throw new NotImplementedException();
 }
Exemple #11
0
 public Binding Bind(BindingRequest request)
 {
     return(null);
 }
 public override Binding Bind(BindingRequest request)
 {
     return(_binding);
 }
Exemple #13
0
 //Implement IBindingSource.Bind
 public Binding Bind(BindingRequest request)
 {
     return(BindingInstance);
 }
 public Binding Bind(BindingRequest request) {
   return Binding; 
 }
Exemple #15
0
 //Used for imported modules
 public Binding BindToExport(BindingRequest request)
 {
     return(null);
 }
Exemple #16
0
 public Binding Bind(BindingRequest request)
 {
     return(Runtime.Bind(request));
 }
Exemple #17
0
 public virtual Binding Bind(BindingRequest request)
 {
     throw new NotImplementedException();
 }
 public override Binding Bind(BindingRequest request) {
   return _binding;
 }
 //Binds symbol to a public member exported by a module.
 public virtual Binding BindSymbol(BindingRequest request, ModuleInfo module)
 {
     return module.BindToExport(request);
 }
 //Implement IBindingSource.Bind
 public Binding Bind(BindingRequest request) {
   return BindingInstance;
 }
Exemple #21
0
 public Binding Bind(BindingRequest request) {
   return null;
 }
Exemple #22
0
 //Binds symbol to a public member exported by a module.
 public virtual Binding BindSymbol(BindingRequest request, ModuleInfo module)
 {
     return(module.BindToExport(request));
 }
 public Binding Bind(BindingRequest request) {
   return Runtime.Bind(request);
 }
Exemple #24
0
 //IBindingSource Members
 public Binding Bind(BindingRequest request)
 {
     return(TryGetValue(request.Symbol, out IBindingSource target) ? target.Bind(request) : null);
 }