Microsoft.Dynamic
Provides binding semantics for a language. This include conversions as well as support
for producing rules for actions. These optimized rules are used for calling methods,
performing operators, and getting members using the ActionBinder's conversion semantics.
Determines if the binder should allow access to non-public members.
By default the binder does not allow access to non-public members. Base classes
can inherit and override this value to customize whether or not private binding
is available.
Converts an object at runtime into the specified type.
Determines if a conversion exists from fromType to toType at the specified narrowing level.
toNotNullable is true if the target variable doesn't allow null values.
Provides ordering for two parameter types if there is no conversion between the two parameter types.
Converts the provided expression to the given type. The expression is safe to evaluate multiple times.
Gets the members that are visible from the provided type of the specified name.
The default implemetnation first searches the type, then the flattened heirachy of the type, and then
registered extension methods.
Called when a set is attempting to assign to a field or property from a derived class through the base class.
The default behavior is to allow the assignment.
Creates an ErrorInfo object when a static property is accessed from an instance member. The default behavior is throw
an exception indicating that static members properties be accessed via an instance. Languages can override this to
customize the exception, message, or to produce an ErrorInfo object which reads or writes to the property being accessed.
The static property being accessed through an instance
True if the user is assigning to the property, false if the user is reading from the property
The parameters being used to access the property. This includes the instance as the first entry, any index parameters, and the
value being assigned as the last entry if isAssignment is true.
Provides a way for the binder to provide a custom error message when lookup fails. Just
doing this for the time being until we get a more robust error return mechanism.
Deprecated, use the non-generic version instead
Gets the extension members of the given name from the provided type. Base classes are also
searched for their extension members. Once any of the types in the inheritance hierarchy
provide an extension member the search is stopped.
Gets the extension members of the given name from the provided type. Subclasses of the
type and their extension members are not searched.
Provides an opportunity for languages to replace all MemberTracker's with their own type.
Alternatlely a language can expose MemberTracker's directly.
The member which is being returned to the user.
Tthe type which the memberTrack was accessed from
TODO: Alternatively, it should be sufficient to remember indices for this, list, dict and block.
Convention for an individual argument at a callsite.
Multiple different callsites can match against a single declaration.
Some argument kinds can be "unrolled" into multiple arguments, such as list and dictionary.
Simple unnamed positional argument.
In Python: foo(1,2,3) are all simple arguments.
Argument with associated name at the callsite
In Python: foo(a=1)
Argument containing a list of arguments.
In Python: foo(*(1,2*2,3)) would match 'def foo(a,b,c)' with 3 declared arguments such that (a,b,c)=(1,4,3).
it could also match 'def foo(*l)' with 1 declared argument such that l=(1,4,3)
Argument containing a dictionary of named arguments.
In Python: foo(**{'a':1, 'b':2})
Richly represents the signature of a callsite.
Array of additional meta information about the arguments, such as named arguments.
Null for a simple signature that's just an expression list. eg: foo(a*b,c,d)
Number of arguments in the signature.
All arguments are unnamed and matched by position.
True if the OldCallAction includes an ArgumentInfo of ArgumentKind.Dictionary or ArgumentKind.Named.
Gets the number of positional arguments the user provided at the call site.
Gets the index into _args array indicating the first post-splat argument or -1 of there are no splatted arguments.
For call site f(a,b,*c,d) and preSplatLimit == 1 and postSplatLimit == 2
args would be (a,b,c[0],c[n-2],c[n-1],d) with splat index 3, where n = c.Count.
The number of arguments not counting the collapsed ones.
Gets the number of hidden arguments (used for error reporting).
Gets the total number of visible arguments passed to the call site including collapsed ones.
Binds named arguments to the parameters. Returns a permutation of indices that captures the relationship between
named arguments and their corresponding parameters. Checks for duplicate and unbound named arguments.
Ensures that for all i: namedArgs[i] binds to parameters[args.Length + bindingPermutation[i]]
ArgBuilder provides an argument value used by the MethodBinder. One ArgBuilder exists for each
physical parameter defined on a method.
Contrast this with ParameterWrapper which represents the logical argument passed to the method.
Gets the priority.
The number of actual arguments consumed by this builder.
Provides the Expression which provides the value to be passed to the argument.
If null is returned the argument is skipped (not passed to the callee).
Returns the type required for the argument or null if the ArgBuilder
does not consume a type.
Provides an Expression which will update the provided value after a call to the method. May
return null if no update is required.
If the argument produces a return value (e.g. a ref or out value) this provides
the additional value to be returned.
An assignable value that is passed to a byref parameter
After the call it will contain the updated value
Indicates the specific type of failure, if any, from binding to a method.
The binding succeeded. Only one method was applicable or had the best conversion.
More than one method was applicable for the provided parameters and no method was considered the best.
There are no overloads that match the number of parameters required for the call
None of the target method(s) can successfully be called. The failure can be due to:
1. Arguments could not be successfully converted for the call
2. Keyword arguments could not be assigned to positional arguments
3. Keyword arguments could be assigned but would result in an argument being assigned
multiple times (keyword and positional arguments conflit or dupliate keyword arguments).
Actual arguments cannot be constructed.
No method is callable. For example, all methods have an unbound generic parameter.
Encapsulates the result of an attempt to bind to one or methods using the OverloadResolver.
Users should first check the Result property to see if the binding was successful or
to determine the specific type of failure that occured. If the binding was successful
MakeExpression can then be called to create an expression which calls the method.
If the binding was a failure callers can then create a custom error message based upon
the reason the call failed.
Creates a new BindingTarget when the method binding has succeeded.
Creates a new BindingTarget when the method binding has failed due to an incorrect argument count
Creates a new BindingTarget when the method binding has failued due to
one or more parameters which could not be converted.
Creates a new BindingTarget when the match was ambiguous
Other failure.
Gets the result of the attempt to bind.
Gets an Expression which calls the binding target if the method binding succeeded.
Throws InvalidOperationException if the binding failed.
Returns the method if the binding succeeded, or null if no method was applicable.
Returns the selected overload if the binding succeeded, or null if no one was applicable.
Gets the name of the method as supplied to the OverloadResolver.
Returns the MethodTarget if the binding succeeded, or null if no method was applicable.
Returns the methods which don't have any matches or null if Result == BindingResult.AmbiguousMatch
Returns the methods and their associated conversion failures if Result == BindingResult.CallFailure.
Returns the acceptable number of arguments which can be passed to the method if Result == BindingResult.IncorrectArgumentCount.
Returns the total number of arguments provided to the call. 0 if the call succeeded or failed for a reason other
than argument count mismatch.
Gets the MetaObjects which we originally did binding against in their restricted form.
The members of the array correspond to each of the arguments. All members of the array
have a value.
Returns the return type of the binding, or null if no method was applicable.
Gets the NarrowingLevel of the method if the call succeeded.
If the call failed returns NarrowingLevel.None.
Returns true if the binding was succesful, false if it failed.
This is an alias for BindingTarget.Result == BindingResult.Success.
Represents the reason why a call to a specific method could not be performed by the OverloadResolver.
The reason for the failure is specified by the CallFailureReason property. Once this property
has been consulted the other properties can be consulted for more detailed information regarding
the failure.
If reason is ConversionFailure the ConversionResults property will be non-null.
If reason is UnassignableKeyword the KeywordArguments property will be non-null and include
the keywords which could not be assigned.
If reason is DuplicateKeyword the KeywordArguments property will be non-null and include
the keywords which were duplicated (either by the keywords themselves or by positional
arguments).
MethodTarget is always set and indicates the method which failed to bind.
Gets the MethodTarget which the call failed for.
Gets the reason for the call failure which determines the other
properties of the CallFailure which should be consulted.
Gets a list of ConversionResult's for each parameter indicating
whether the conversion was successful or failed and the types
being converted.
Gets the list of keyword arguments that were either dupliated or
unassignable.
Default value, their was no CallFailure.
One of more parameters failed to be converted
One or more keyword arguments could not be successfully assigned to a positional argument
One or more keyword arguments were duplicated or would have taken the spot of a
provided positional argument.
Type arguments could not be inferred
Represents a collection of MethodCandidate's which all accept the
same number of logical parameters. For example a params method
and a method with 3 parameters would both be a CandidateSet for 3 parameters.
Represents information about a failure to convert an argument from one
type to another.
Value of the argument or null if it is not available.
Argument actual type or its limit type if the value not known.
DynamicNull if the argument value is null.
ArgBuilder which provides a default parameter value for a method call.
The number of actual arguments consumed by this builder.
ArgBuilder which provides a value for a keyword argument.
The KeywordArgBuilder calculates its position at emit time using it's initial
offset within the keyword arguments, the number of keyword arguments, and the
total number of arguments provided by the user. It then delegates to an
underlying ArgBuilder which only receives the single correct argument.
Delaying the calculation of the position to emit time allows the method binding to be
done without knowing the exact the number of arguments provided by the user. Hence,
the method binder can be dependent only on the set of method overloads and keyword names,
but not the user arguments. While the number of user arguments could be determined
upfront, the current MethodBinder does not have this design.
The underlying builder should expect a single parameter as KeywordArgBuilder is responsible
for calculating the correct parameter to use
Updates fields/properties of the returned value with unused keyword parameters.
MethodCandidate represents the different possible ways of calling a method or a set of method overloads.
A single method can result in multiple MethodCandidates. Some reasons include:
- Every optional parameter or parameter with a default value will result in a candidate
- The presence of ref and out parameters will add a candidate for languages which want to return the updated values as return values.
- ArgumentKind.List and ArgumentKind.Dictionary can result in a new candidate per invocation since the list might be different every time.
Each MethodCandidate represents the parameter type for the candidate using ParameterWrapper.
Builds a new MethodCandidate which takes count arguments and the provided list of keyword arguments.
The basic idea here is to figure out which parameters map to params or a dictionary params and
fill in those spots w/ extra ParameterWrapper's.
Narrowing conversions are conversions that cannot be proved to always succeed, conversions that are
known to possibly lose information, and conversions across domains of types sufficiently different
to merit narrowing notation like casts.
Its upto every language to define the levels for conversions. The narrowling levels can be used by
for method overload resolution, where the overload is based on the parameter types (and not the number
of parameters).
Conversions at this level do not do any narrowing. Typically, this will include
implicit numeric conversions, Type.IsAssignableFrom, StringBuilder to string, etc.
Language defined prefered narrowing conversion. First level that introduces narrowing
conversions.
Language defined preferred narrowing conversion. Second level that introduces narrowing
conversions and should have more conversions than One.
Language defined preferred narrowing conversion. Third level that introduces narrowing
conversions and should have more conversions that Two.
A somewhat meaningful conversion is possible, but it will quite likely be lossy.
For eg. BigInteger to an Int32, Boolean to Int32, one-char string to a char,
larger number type to a smaller numeric type (where there is no overflow), etc
Builds the argument for an out argument when not passed a StrongBox. The out parameter
is returned as an additional return value.
Defines a method overload abstraction for the purpose of overload resolution.
It provides the overload resolver the metadata it needs to perform the resolution.
WARNING: This is a temporary API that will undergo breaking changes in future versions.
Null for constructors.
The method arity can vary, i.e. the method has params array or params dict parameters.
Represents a method overload that is bound to a .
Not thread safe.
WARNING: This is a temporary API that will undergo breaking changes in future versions.
Provides binding and overload resolution to .NET methods.
MethodBinder's can be used for:
generating new AST code for calling a method
calling a method via reflection at runtime
(not implemented) performing an abstract call
MethodBinder's support default arguments, optional arguments, by-ref (in and out), and keyword arguments.
Implementation Details:
The MethodBinder works by building up a CandidateSet for each number of effective arguments that can be
passed to a set of overloads. For example a set of overloads such as:
foo(object a, object b, object c)
foo(int a, int b)
would have 2 target sets - one for 3 parameters and one for 2 parameters. For parameter arrays
we fallback and create the appropriately sized CandidateSet on demand.
Each CandidateSet consists of a set of MethodCandidate's. Each MethodCandidate knows the flattened
parameters that could be received. For example for a function such as:
foo(params int[] args)
When this method is in a CandidateSet of size 3 the MethodCandidate takes 3 parameters - all of them
ints; if it's in a CandidateSet of size 4 it takes 4 parameters. Effectively a MethodCandidate is
a simplified view that allows all arguments to be treated as required positional arguments.
Each MethodCandidate in turn refers to a MethodTarget. The MethodTarget is composed of a set
of ArgBuilder's and a ReturnBuilder which know how to consume the positional arguments and pass
them to the appropriate argument of the destination method. This includes routing keyword
arguments to the correct position, providing the default values for optional arguments, etc...
After binding is finished the MethodCandidates are thrown away and a BindingTarget is returned.
The BindingTarget indicates whether the binding was successful and if not any additional information
that should be reported to the user about the failed binding. It also exposes the MethodTarget which
allows consumers to get the flattened list of required parameters for the call. MethodCandidates
are not exposed and are an internal implementation detail of the MethodBinder.
Resolves a method overload and returns back a BindingTarget.
The BindingTarget can then be tested for the success or particular type of
failure that prevents the method from being called. If successfully bound the BindingTarget
contains a list of argument meta-objects with additional restrictions that ensure the selection
of the particular overload.
Checks to see if the language allows named arguments to be bound to instance fields or
properties and turned into setters. By default this is only allowed on contructors.
Gets an expression that evaluates to the result of GetByRefArray operation.
Allow to bind an array/dictionary instance or a null reference to params array/dictionary parameter.
Called before arguments binding.
A bitmask that indicates (set bits) the parameters that were mapped by this method.
A default mapping will be constructed for the remaining parameters (cleared bits).
Return null if arguments cannot be constructed and overload resolution should produce an error.
Determines whether given overloads are overloaded on index-th parameter (the types of the index-th parameters are the same).
Selects the best (of two) candidates for conversion from actualType
Provides ordering for two parameter types if there is no conversion between the two parameter types.
The method is called each time an item of lazily splatted argument is needed.
Gets the next argument to consume.
Maps out parameters to return args and ref parameters to ones that don't accept StrongBox.
ParameterWrapper represents the logical view of a parameter. For eg. the byref-reduced signature
of a method with byref parameters will be represented using a ParameterWrapper of the underlying
element type, since the logical view of the byref-reduced signature is that the argument will be
passed by value (and the updated value is included in the return value).
Contrast this with ArgBuilder which represents the real physical argument passed to the method.
ParameterInfo is not available.
True if the wrapper represents a params-array parameter (false for parameters created by expansion of a params-array).
True if the wrapper represents a params-dict parameter (false for parameters created by expansion of a params-dict).
Creates a parameter that represents an expanded item of params-array.
Builds the parameter for a params dictionary argument - this collects all the extra name/value
pairs provided to the function into a SymbolDictionary which is passed to the function.
An argument that the user wants to explicitly pass by-reference (with copy-in copy-out semantics).
The user passes a StrongBox[T] object whose value will get updated when the call returns.
True if there are restrictions beyond just simple type restrictions
Creates a ReturnBuilder
the type the ReturnBuilder will leave on the stack
Builds a parameter for a reference argument when a StrongBox has not been provided. The
updated return value is returned as one of the resulting return values.
SimpleArgBuilder produces the value produced by the user as the argument value. It
also tracks information about the original parameter and is used to create extended
methods for params arrays and param dictionary functions.
Parameter info is not available for this argument.
Type and whether the parameter is a params-array or params-dictionary is derived from info.
Gets the index of actual argument expression.
Gets the generic arguments for method based upon the constraints discovered during
type inference. Returns null if not all generic arguments had their types inferred.
Creates a new set of arg builders for the given generic method definition which target the new
parameters.
Creates a new list of ParameterWrappers for the generic method replacing the old parameters with the new ones.
Gets the generic type arguments sorted so that the type arguments
that are depended upon by other type arguments are sorted before
their dependencies.
Checks to see if the x type parameter is dependent upon the y type parameter.
Builds a mapping based upon generic parameter constraints between related generic
parameters. This is then used to sort the generic parameters so that we can process
the least dependent parameters first. For example given the method:
void Foo{T0, T1}(T0 x, T1 y) where T0 : T1
We need to first infer the type information for T1 before we infer the type information
for T0 so that we can ensure the constraints are correct.
Returns a mapping from generic type parameter to the input DMOs which map to it.
Adds any additional ArgumentInputs entries for the given object and parameter type.
Walks the nested generic hierarchy to construct all of the generic parameters referred
to by this type. For example if getting the generic parameters for the x parameter on
the method:
void Foo{T0, T1}(Dictionary{T0, T1} x);
We would add both typeof(T0) and typeof(T1) to the list of generic arguments.
Maps a single type parameter to the possible parameters and DynamicMetaObjects
we can get inference from. For example for the signature:
void Foo{T0, T1}(T0 x, T1 y, IList{T1} z);
We would have one ArgumentInput for T0 which holds onto the DMO providing the argument
value for x. We would also have one ArgumentInput for T1 which holds onto the 2 DMOs
for y and z. Associated with y would be a GenericParameterInferer and associated with
z would be a ConstructedParameterInferer.
Provides generic type inference for a single parameter.
For example:
M{T}(T x)
M{T}(IList{T} x)
M{T}(ref T x)
M{T}(T[] x)
M{T}(ref Dictionary{T,T}[] x)
Provides generic type inference for a single parameter.
For example:
M{T}(T x)
M{T}(IList{T} x)
M{T}(ref T x)
M{T}(T[] x)
M{T}(ref Dictionary{T,T}[] x)
Checks if the constraints are violated by the given input for the specified generic method parameter.
This method must be supplied with a mapping for any dependent generic method type parameters which
this one can be constrained to. For example for the signature "void Foo{T0, T1}(T0 x, T1 y) where T0 : T1".
we cannot know if the constraints are violated unless we know what we have calculated T1 to be.
Finds all occurences of genericParameter in openType and the corresponding concrete types in closedType.
Returns true iff all occurences of the generic parameter in the open type correspond to the same concrete type in the closed type
and this type satisfies given constraints. Returns the concrete type in match if so.
Implemented by DynamicMetaObject subclasses when the associated object
can participate in generic method type inference. This interface
is used when the inference engine is attempting to perform type inference
for a parameter which is typed to a delegate type.
Returns the type inferred for parameterType when performing
inference for a conversion to delegateType.
Provides information about the result of a custom object which dynamically infers back types.
Currently only used for invokable objects to feedback the types for a delegate type.
A tree rewriter which will find dynamic sites which consume dynamic sites and
turn them into a single combo dynamic site. The combo dynamic site will then run the
individual meta binders and produce the resulting code in a single dynamic site.
A reducible node which we use to generate the combo dynamic sites. Each time we encounter
a dynamic site we replace it with a ComboDynamicSiteExpression. When a child of a dynamic site
turns out to be a ComboDynamicSiteExpression we will then merge the child with the parent updating
the binding mapping info. If any of the inputs cause side effects then we'll stop the combination.
A binder which can combine multiple binders into a single dynamic site. The creator
of this needs to perform the mapping of parameters, constants, and sub-site expressions
and provide a List of BinderMappingInfo representing this data. From there the ComboBinder
just processes the list to create the resulting code.
Provides a mapping for inputs of combo action expressions. The input can map
to either an input of the new dynamic site, an input of a previous DynamicExpression,
or a ConstantExpression which has been pulled out of the dynamic site arguments.
Contains the mapping information for a single Combo Binder. This includes the original
meta-binder and the mapping of parameters, sub-sites, and constants into the binding.
Builds up a series of conditionals when the False clause isn't yet known. We can
keep appending conditions and if true's. Each subsequent true branch becomes the
false branch of the previous condition and body. Finally a non-conditional terminating
branch must be added.
Adds a new conditional and body. The first call this becomes the top-level
conditional, subsequent calls will have it added as false statement of the
previous conditional.
Adds the non-conditional terminating node.
Adds the non-conditional terminating node.
Gets the resulting meta object for the full body. FinishCondition
must have been called.
Adds a variable which will be scoped at the level of the final expression.
Determines the result of a conversion action. The result can either result in an exception, a value that
has been successfully converted or default(T), or a true/false result indicating if the value can be converted.
Attempts to perform available implicit conversions and throws if there are no available conversions.
Attempst to perform available implicit and explicit conversions and throws if there are no available conversions.
Attempts to perform available implicit conversions and returns default(ReturnType) if no conversions can be performed.
If the return type of the rule is a value type then the return value will be zero-initialized. If the return type
of the rule is object or another class then the return type will be null (even if the conversion is to a value type).
This enables ImplicitTry to be used to do TryConvertTo even if the type is value type (and the difference between
null and a real value can be distinguished).
Attempts to perform available implicit and explicit conversions and returns default(ReturnType) if no conversions
can be performed.
If the return type of the rule is a value type then the return value will be zero-initialized. If the return type
of the rule is object or another class then the return type will be null (even if the conversion is to a value type).
This enables ExplicitTry to be used to do TryConvertTo even if the type is value type (and the difference between
null and a real value can be distinguished).
A custom member tracker which enables languages to plug in arbitrary
members into the lookup process.
Provides binding semantics for a language. This include conversions as well as support
for producing rules for actions. These optimized rules are used for calling methods,
performing operators, and getting members using the ActionBinder's conversion semantics.
Checks if the conversion is to object and produces a target if it is.
Checks if any conversions are available and if so builds the target for that conversion.
Checks if the conversion can be handled by a simple cast.
Checks if the conversion can be handled by calling a user-defined conversion method.
Helper that checkes both types to see if either one defines the specified conversion
method.
Checks if any of the members of the MemberGroup provide the applicable conversion and
if so uses it to build a conversion rule.
Checks if the conversion is to applicable by extracting the value from Extensible of T.
Checks if there's an implicit numeric conversion for primitive data types.
Checks if there's a conversion to/from Nullable of T.
Checks to see if there's a conversion of null to a reference type
Helper to produce an error when a conversion cannot occur
Helper to produce a rule which just boxes a value type
Helper to produce a conversion rule by calling the helper method to do the convert
Helper to produce a conversion rule by calling the helper method to do the convert
Helper to produce a conversion rule by calling the method to do the convert. This version takes the parameter
to be passed to the conversion function and we call it w/ our own value or w/ our Extensible.Value.
Helper to wrap explicit conversion call into try/catch incase it throws an exception. If
it throws the default value is returned.
Helper to produce a rule when no conversion is required (the strong type of the expression
input matches the type we're converting to or has an implicit conversion at the IL level)
Helper to produce a rule when no conversion is required from an extensible type's
underlying storage to the type we're converting to. The type of extensible type
matches the type we're converting to or has an implicit conversion at the IL level.
Helper to extract the value from an Extensible of T
Helper to convert a null value to nullable of T
Helper to produce the rule for converting T to Nullable of T
Helper to produce the rule for converting T to Nullable of T
Returns a value which indicates failure when a OldConvertToAction of ImplicitTry or
ExplicitTry.
Helper to extract the Value of an Extensible of T from the
expression being converted.
Helper that checks if fromType is an Extensible of T or a subtype of
Extensible of T and if so returns the T. Otherwise it returns fromType.
This is used to treat extensible types the same as their underlying types.
Creates a target which returns null for a reference type.
Provides a way for the binder to provide a custom error message when lookup fails. Just
doing this for the time being until we get a more robust error return mechanism.
Called when the user is accessing a protected or private member on a get.
The default implementation allows access to the fields or properties using reflection.
Provides a way for the binder to provide a custom error message when lookup fails. Just
doing this for the time being until we get a more robust error return mechanism.
if a member-injector is defined-on or registered-for this type call it
Helper class for flowing information about the GetMember request.
Builds a MetaObject for performing a member get. Supports all built-in .NET members, the OperatorMethod
GetBoundMember, and StrongBox instances.
The name of the member to retrieve. This name is not processed by the DefaultBinder and
is instead handed off to the GetMember API which can do name mangling, case insensitive lookups, etc...
The MetaObject from which the member is retrieved.
Returns a DynamicMetaObject which represents the value that will be returned when the member is accessed.
The returned DynamicMetaObject may be strongly typed to a value type which needs boxing before being
returned from a standard DLR GetMemberBinder. The language is responsible for performing any boxing
so that it has an opportunity to perform custom boxing.
Builds a MetaObject for performing a member get. Supports all built-in .NET members, the OperatorMethod
GetBoundMember, and StrongBox instances.
The name of the member to retrieve. This name is not processed by the DefaultBinder and
is instead handed off to the GetMember API which can do name mangling, case insensitive lookups, etc...
The MetaObject from which the member is retrieved.
Provides overload resolution and method binding for any calls which need to be performed for the GetMember.
Returns a DynamicMetaObject which represents the value that will be returned when the member is accessed.
The returned DynamicMetaObject may be strongly typed to a value type which needs boxing before being
returned from a standard DLR GetMemberBinder. The language is responsible for performing any boxing
so that it has an opportunity to perform custom boxing.
Builds a MetaObject for performing a member get. Supports all built-in .NET members, the OperatorMethod
GetBoundMember, and StrongBox instances.
The name of the member to retrieve. This name is not processed by the DefaultBinder and
is instead handed off to the GetMember API which can do name mangling, case insensitive lookups, etc...
The MetaObject from which the member is retrieved.
An OverloadResolverFactory which can be used for performing overload resolution and method binding.
True if the operation should return Operation.Failed on failure, false if it
should return the exception produced by MakeMissingMemberError.
The meta object to be used if the get results in an error.
Returns a DynamicMetaObject which represents the value that will be returned when the member is accessed.
The returned DynamicMetaObject may be strongly typed to a value type which needs boxing before being
returned from a standard DLR GetMemberBinder. The language is responsible for performing any boxing
so that it has an opportunity to perform custom boxing.
Builds a MetaObject for performing a member get. Supports all built-in .NET members, the OperatorMethod
GetBoundMember, and StrongBox instances.
The name of the member to retrieve. This name is not processed by the DefaultBinder and
is instead handed off to the GetMember API which can do name mangling, case insensitive lookups, etc...
The MetaObject from which the member is retrieved.
True if the operation should return Operation.Failed on failure, false if it
should return the exception produced by MakeMissingMemberError.
The meta object to be used if the get results in an error.
Returns a DynamicMetaObject which represents the value that will be returned when the member is accessed.
The returned DynamicMetaObject may be strongly typed to a value type which needs boxing before being
returned from a standard DLR GetMemberBinder. The language is responsible for performing any boxing
so that it has an opportunity to perform custom boxing.
if a member-injector is defined-on or registered-for this type call it
Helper class for flowing information about the GetMember request.
Provides default binding for performing a call on the specified meta objects.
The signature describing the call
The meta object to be called.
Additional meta objects are the parameters for the call as specified by the CallSignature in the CallAction.
A MetaObject representing the call or the error.
Provides default binding for performing a call on the specified meta objects.
The signature describing the call
The meta object to be called.
Additional meta objects are the parameters for the call as specified by the CallSignature in the CallAction.
Overload resolver factory.
A MetaObject representing the call or the error.
Provides default binding for performing a call on the specified meta objects.
The signature describing the call
The meta object to be called.
Additional meta objects are the parameters for the call as specified by the CallSignature in the CallAction.
Overload resolver factory.
The result should the object be uncallable.
A MetaObject representing the call or the error.
Gets a TargetInfo object for performing a call on this object.
If this object is a delegate we bind to the Invoke method.
If this object is a MemberGroup or MethodGroup we bind to the methods in the member group.
If this object is a BoundMemberTracker we bind to the methods with the bound instance.
If the underlying type has defined an operator Call method we'll bind to that method.
Binds to the methods in a method group.
Binds to the methods in a member group.
TODO: We should really only have either MemberGroup or MethodGroup, not both.
Binds to the BoundMemberTracker and uses the instance in the tracker and restricts
based upon the object instance type.
Binds to the Invoke method on a delegate if this is a delegate type.
Attempts to bind to an operator Call method.
Encapsulates information about the target of the call. This includes an implicit instance for the call,
the methods that we'll be calling as well as any restrictions required to perform the call.
Performs binding against a set of overloaded methods using the specified arguments. The arguments are
consumed as specified by the CallSignature object.
Overload resolver.
The methods to be called
A meta object which results from the call.
Performs binding against a set of overloaded methods using the specified arguments. The arguments are
consumed as specified by the CallSignature object.
Overload resolver.
The methods to be called
The name of the method or null to use the name from targets.
A meta object which results from the call.
Performs binding against a set of overloaded methods using the specified arguments. The arguments are
consumed as specified by the CallSignature object.
Overload resolver.
The methods to be called
Additional restrictions which should be applied to the resulting MetaObject.
A meta object which results from the call.
Performs binding against a set of overloaded methods using the specified arguments. The arguments are
consumed as specified by the CallSignature object.
Overload resolver.
The methods to be called
Additional restrictions which should be applied to the resulting MetaObject.
The name of the method or null to use the name from targets.
A meta object which results from the call.
Performs binding against a set of overloaded methods using the specified arguments. The arguments are
consumed as specified by the CallSignature object.
TODO.
TODO.
Overload resolver.
The methods to be called
Additional restrictions which should be applied to the resulting MetaObject.
The resulting binding target which can be used for producing error information.
The name of the method or null to use the name from targets.
A meta object which results from the call.
Makes test for param arrays and param dictionary parameters.
Pulls out the right argument to build the splat test. MakeParamsTest makes the actual test.
Builds the restrictions for calling with a splatted argument array. Ensures that the
argument is still an ICollection of object and that it has the same number of arguments.
Builds the restrictions for calling with keyword arguments. The restrictions include
tests on the individual keys of the dictionary to ensure they have the same names.
Creates the MetaObject for indexing directly into arrays or indexing into objects which have
default members. Returns null if we're not an indexing operation.
Creates the MetaObject for indexing directly into arrays or indexing into objects which have
default members. Returns null if we're not an indexing operation.
Creates the meta object for the rest of the operations: comparisons and all other
ExpressionType. If the operation cannot be completed a MetaObject which indicates an
error will be returned.
Creates the meta object for the rest of the operations: comparisons and all other
ExpressionType. If the operation cannot be completed a MetaObject which indicates an
error will be returned.
Produces a rule for comparing a value to null - supports comparing object references and nullable types.
Builds a MetaObject for performing a member get. Supports all built-in .NET members, the OperatorMethod
GetBoundMember, and StrongBox instances.
The name of the member to retrieve. This name is not processed by the DefaultBinder and
is instead handed off to the GetMember API which can do name mangling, case insensitive lookups, etc...
The MetaObject from which the member is retrieved.
The value being assigned to the target member.
Builds a MetaObject for performing a member get. Supports all built-in .NET members, the OperatorMethod
GetBoundMember, and StrongBox instances.
The name of the member to retrieve. This name is not processed by the DefaultBinder and
is instead handed off to the GetMember API which can do name mangling, case insensitive lookups, etc...
The MetaObject from which the member is retrieved.
The value being assigned to the target member.
Provides overload resolution and method binding for any calls which need to be performed for the SetMember.
Builds a MetaObject for performing a member get. Supports all built-in .NET members, the OperatorMethod
GetBoundMember, and StrongBox instances.
The name of the member to retrieve. This name is not processed by the DefaultBinder and
is instead handed off to the GetMember API which can do name mangling, case insensitive lookups, etc...
The MetaObject from which the member is retrieved.
The value being assigned to the target member.
Provides a DynamicMetaObject that is to be used as the result if the member cannot be set. If null then then a language
specific error code is provided by ActionBinder.MakeMissingMemberErrorForAssign which can be overridden by the language.
Builds a MetaObject for performing a member get. Supports all built-in .NET members, the OperatorMethod
GetBoundMember, and StrongBox instances.
The name of the member to retrieve. This name is not processed by the DefaultBinder and
is instead handed off to the GetMember API which can do name mangling, case insensitive lookups, etc...
The MetaObject from which the member is retrieved.
The value being assigned to the target member.
Provides overload resolution and method binding for any calls which need to be performed for the SetMember.
Provides a DynamicMetaObject that is to be used as the result if the member cannot be set. If null then then a language
specific error code is provided by ActionBinder.MakeMissingMemberErrorForAssign which can be overridden by the language.
if a member-injector is defined-on or registered-for this type call it
Returns true if the method should not be displayed in the stack frame.
Encapsulates information about the result that should be produced when
a OldDynamicAction cannot be performed. The ErrorInfo can hold one of:
an expression which creates an Exception to be thrown
an expression which produces a value which should be returned
directly to the user and represents an error has occured (for
example undefined in JavaScript)
an expression which produces a value which should be returned
directly to the user but does not actually represent an error.
ErrorInfo's are produced by an ActionBinder in response to a failed
binding.
Private constructor - consumers must use static From* factories
to create ErrorInfo objects.
Creates a new ErrorInfo which represents an exception that should
be thrown.
Creates a new ErrorInfo which represents a value which should be
returned to the user.
Crates a new ErrorInfo which represents a value which should be returned
to the user but does not represent an error.
The ErrorInfo expression produces an exception
The ErrorInfo expression produces a value which represents the error (e.g. undefined)
The ErrorInfo expression produces a value which is not an error
A MetaObject which was produced as the result of a failed binding.
Doesn't need to check PrivateBinding setting: no method that is part of the event is public the entire event is private.
If the code has already a reference to the event tracker instance for a private event its "static-ness" is not influenced
by private-binding setting.
Gets the stub list for a COM Object. For COM objects we store the stub list
directly on the object using the Marshal APIs. This allows us to not have
any circular references to deal with via weak references which are challenging
in the face of COM.
Holds on a list of delegates hooked to the event.
We need the list because we cannot enumerate the delegates hooked to CLR event and we need to do so in
handler removal (we need to do custom delegate comparison there). If BCL enables the enumeration we could remove this.
Storage for the handlers - a key value pair of the callable object and the delegate handler.
Storage for the handlers - a key value pair of the callable object and the delegate handler.
The delegate handler is closed over the callable object. Therefore as long as the object is alive the
delegate will stay alive and so will the callable object. That means it's fine to have a weak reference
to both of these objects.
Represents extension method.
Gets the declaring type of the extension method. Since this is an extension method,
the declaring type is in fact the type this extension method extends,
not Method.DeclaringType
Implemented by binders which support light exceptions. Dynamic objects
binding against a binder which implements this interface can check
SupportsLightThrow to see if the binder currently supports safely
returning a light exception. Light exceptions can be created with
LightException.Throw.
Binders also need to implement GetlightBinder. This method
returns a new call site binder which may return light exceptions if
the binder supports them.
Returns true if a callsite binding against this binder can
return light exceptions.
Gets a binder which will support light exception if one is
available.
Interceptor prototype. The interceptor is a call site binder that wraps
a real call site binder and can perform arbitrary operations on the expression
trees that the wrapped binder produces:
* Dumping the trees
* Additional rewriting
* Static compilation
* ...
MemberGroups are a collection of MemberTrackers which are commonly produced
on-demand to talk about the available members. They can consist of a mix of
different member types or multiple membes of the same type.
The most common source of MemberGroups is from ActionBinder.GetMember. From here
the DLR will perform binding to the MemberTrackers frequently producing the value
resulted from the user. If the result of the action produces a member it's self
the ActionBinder can provide the value exposed to the user via ReturnMemberTracker.
ActionBinder provides default functionality for both getting members from a type
as well as exposing the members to the user. Getting members from the type maps
closely to reflection and exposing them to the user exposes the MemberTrackers
directly.
Specifies the action for which the default binder is requesting a member.
Represents a logical member of a type. The member could either be real concrete member on a type or
an extension member.
This seperates the "physical" members that .NET knows exist on types from the members that
logically exist on a type. It also provides other abstractions above the level of .NET reflection
such as MemberGroups and NamespaceTracker's.
It also provides a wrapper around the reflection APIs which cannot be extended from partial trust.
We ensure we only produce one MemberTracker for each member which logically lives on the declaring type. So
for example if you get a member from a derived class which is declared on the base class it should be the same
as getting the member from the base class. That’s easy enough until you get into extension members – here there
might be one extension member which is being applied to multiple types. Therefore we need to take into account the
extension type when ensuring that we only have 1 MemberTracker ever created.
The type of member tracker.
The logical declaring type of the member.
The name of the member.
Gets the expression that creates the value.
Returns null if it's an error to get the value. The caller can then call GetErrorForGet to get
the correct error Expression (or null if they should provide a default).
Gets an expression that assigns a value to the left hand side.
Returns null if it's an error to assign to. The caller can then call GetErrorForSet to
get the correct error Expression (or null if a default error should be provided).
Gets an expression that assigns a value to the left hand side.
Returns null if it's an error to assign to. The caller can then call GetErrorForSet to
get the correct error Expression (or null if a default error should be provided).
Gets an expression that performs a call on the object using the specified arguments.
Returns null if it's an error to perform the specific operation. The caller can then call
GetErrorsForDoCall to get the correct error Expression (or null if a default error should be provided).
Returns the error associated with getting the value.
A null return value indicates that the default error message should be provided by the caller.
Returns the error associated with accessing this member via a bound instance.
A null return value indicates that the default error message should be provided by the caller.
Helper for getting values that have been bound. Called from BoundMemberTracker. Custom member
trackers can override this to provide their own behaviors when bound to an instance.
Helper for setting values that have been bound. Called from BoundMemberTracker. Custom member
trackers can override this to provide their own behaviors when bound to an instance.
Helper for setting values that have been bound. Called from BoundMemberTracker. Custom member
trackers can override this to provide their own behaviors when bound to an instance.
Binds the member tracker to the specified instance rturning a new member tracker if binding
is possible. If binding is not possible the existing member tracker will be returned. For example
binding to a static field results in returning the original MemberTracker. Binding to an instance
field results in a new BoundMemberTracker which will get GetBoundValue/SetBoundValue to pass the
instance through.
MethodGroup's represent a unique collection of method's. Typically this
unique set is all the methods which are overloaded by the same name including
methods with different arity. These methods represent a single logically
overloaded element of a .NET type.
The base DLR binders will produce MethodGroup's when provided with a MemberGroup
which contains only methods. The MethodGroup's will be unique instances per
each unique group of methods.
Returns a BuiltinFunction bound to the provided type arguments. Returns null if the binding
cannot be performed.
NamespaceTracker represent a CLS namespace.
Loads all the types from all assemblies that contribute to the current namespace (but not child namespaces)
Populates the tree with nodes for each part of the namespace
Full namespace name. It can be null (for top-level types)
As a fallback, so if the type does exist in any assembly. This would happen if a new type was added
that was not in the hardcoded list of types.
This code is not accurate because:
1. We dont deal with generic types (TypeCollision).
2. Previous calls to GetCustomMemberNames (eg. "from foo import *" in Python) would not have included this type.
3. This does not deal with new namespaces added to the assembly
This stores all the public non-nested type names in a single namespace and from a single assembly.
This allows inspection of the namespace without eagerly loading all the types. Eagerly loading
types slows down startup, increases working set, and is semantically incorrect as it can trigger
TypeLoadExceptions sooner than required.
Marks a method as not having side effects. used by the combo binder
to allow calls to methods.
OperatorInfo provides a mapping from DLR ExpressionType to their associated .NET methods.
Given an operator returns the OperatorInfo associated with the operator or null
Gets the operator the OperatorInfo provides info for.
Gets the primary method name associated with the method.
This method name is usally in the form of op_Operator (e.g. op_Addition).
Gets the secondary method name associated with the method.
This method name is usually a standard .NET method name with pascal casing (e.g. Add).
Represents a logical Property as a member of a Type. This Property can either be a real
concrete Property on a type (implemented with a ReflectedPropertyTracker) or an extension
property (implemented with an ExtensionPropertyTracker).
Represents the top reflected package which contains extra information such as
all the assemblies loaded and the built-in modules.
returns the package associated with the specified namespace and
updates the associated module to mark the package as imported.
Ensures that the assembly is loaded
true if the assembly was loaded for the first time.
false if the assembly had already been loaded before
When an (interop) assembly is loaded, we scan it to discover the GUIDs of COM interfaces so that we can
associate the type definition with COM objects with that GUID.
Since scanning all loaded assemblies can be expensive, in the future, we might consider a more explicit
user binder to trigger scanning of COM types.
Specifies that the member is a constructor, representing a ConstructorTracker
Specifies that the member is an event, representing a EventTracker
Specifies that the member is a field, representing a FieldTracker
Specifies that the member is a method, representing a MethodTracker
Specifies that the member is a property, representing a PropertyTracker
Specifies that the member is a property, representing a TypeTracker
Specifies that the member is a namespace, representing a NamespaceTracker
Specifies that the member is a group of method overloads, representing a MethodGroup
Specifies that the member is a group of types that very by arity, representing a TypeGroup
Specifies that the member is a custom meber, represetning a CustomTracker
Specifies that the member is a bound to an instance, representing a BoundMemberTracker
A TypeCollision is used when we have a collision between
two types with the same name. Currently this is only possible w/ generic
methods that should logically have arity as a portion of their name. For eg:
System.EventHandler and System.EventHandler[T]
System.Nullable and System.Nullable[T]
System.IComparable and System.IComparable[T]
The TypeCollision provides an indexer but also is a real type. When used
as a real type it is the non-generic form of the type.
The indexer allows the user to disambiguate between the generic and
non-generic versions. Therefore users must always provide additional
information to get the generic version.
The merged list so far. Could be null
The new type(s) to add to the merged list
The merged list. Could be a TypeTracker or TypeGroup
Gets the arity of generic parameters
No non-generic type is represented by this group.
This returns the DeclaringType of all the types in the TypeGroup
This returns the base name of the TypeGroup (the name shared by all types minus arity)
This will return the result only for the non-generic type if one exists, and will throw
an exception if all types in the TypeGroup are generic
This will return the result only for the non-generic type if one exists, and will throw
an exception if all types in the TypeGroup are generic
Enables implicit Type to TypeTracker conversions accross dynamic languages.
Factory methods.
Null coalescing expression
{result} ::= ((tmp = {_left}) == null) ? {right} : tmp
'??' operator in C#.
True coalescing expression.
{result} ::= IsTrue(tmp = {left}) ? {right} : tmp
Generalized AND semantics.
False coalescing expression.
{result} ::= IsTrue(tmp = {left}) ? tmp : {right}
Generalized OR semantics.
True coalescing expression.
{result} ::= IsTrue(tmp = {left}) ? {right} : tmp
Generalized AND semantics.
False coalescing expression.
{result} ::= IsTrue(tmp = {left}) ? tmp : {right}
Generalized OR semantics.
Wraps the given value in a WeakReference and returns a tree that will retrieve
the value from the WeakReference.
Creates a generator with type IEnumerable{T}, where T is the label.Type
Creates new instance of the LambdaBuilder with the specified name and return type.
Return type of the lambda being built.
Name for the lambda being built.
new LambdaBuilder instance
The helper to create the AST method call node. Will add conversions (Utils.Convert)
to parameters and instance if necessary.
The helper to create the AST method call node. Will add conversions (Utils.Convert)
to parameters and instance if necessary.
The complex call helper to create the AST method call node.
Will add conversions (Expression.Convert()), deals with default parameter values and params arrays.
Converts an expression to a void type.
An to convert to void.
An that has the property equal to and the and property set to void.
Returns an expression that boxes a given value. Uses boxed objects cache for Int32 and Boolean types.
Determines whether specified expression type represents an assignment.
True if the expression type represents an assignment.
Note that some other nodes can also assign to variables, members or array items:
MemberInit, NewArrayInit, Call with ref params, New with ref params, Dynamic with ref params.
Determines if the left child of the given expression is read or written to or both.
Returns null if no expression was added into the builder.
If only a single expression was added returns it.
Otherwise returns a containing the expressions added to the builder.
If the number of items added to the builder is greater than 4 returns a read-only collection builder containing all the items.
Returns null otherwise.
Wrapping a tree in this node enables jumps from finally blocks
It does this by generating control-flow logic in the tree
Reducing this node requires a full tree walk of its body
(but not nested lambdas)
WARNING: this node cannot contain jumps across blocks, because it
assumes any unknown jumps are jumps to an outer scope.
The purpose of this rewriter is simple: ETs do not allow jumps (break, continue, return, goto)
that would go through a finally/fault. So we replace them with code that instead stores a flag,
and then jumps to the end of the finally/fault. At the end of the try-finally, we emit a switch
that then jumps to the correct label.
A few things that make this more complicated:
1. If a finally contains a jump out, then jumps in the try/catch need to be replaced as well.
It's to support cases like this:
# returns 234
def foo():
try: return 123
finally: return 234
We need to replace the "return 123" because after it jumps, we'll go to the finally, which
might decide to jump again, but once the IL finally exits, it ignores the finally jump and
keeps going with the original jump. The moral of the story is: if any jumps in finally are
rewritten, try/catch jumps must be also.
2. To generate better code, we only have one state variable, so if we have to jump out of
multiple finallys we just keep jumping. It looks sort of like this:
foo:
try { ... } finally {
try { ... } finally {
...
if (...) {
// was: goto foo;
$flow = 1; goto endInnerFinally;
}
...
endInnerFinally:
}
switch ($flow) {
case 1: goto endOuterFinally;
}
...
endOuterFinally:
}
switch ($flow) {
case 1: $flow = 0; goto foo;
}
...
A parameterless generator, that is of type IEnumerable, IEnumerable{T},
IEnumerator, or IEnumerator{T}. Its body can contain a series of
YieldExpressions. Each call into MoveNext on the enumerator reenters
the generator, and executes until it reaches a YieldReturn or YieldBreak
expression
The label used by YieldBreak and YieldReturn expressions to yield
from this generator
The body of the generator, which can contain YieldBreak and
YieldReturn expressions
Indicates whether the lhs instances are preserved when assignments
are made to expressions containing yields.
When finding a yield return or yield break, this rewriter flattens out
containing blocks, scopes, and expressions with stack state. All
scopes encountered have their variables promoted to the generator's
closure, so they survive yields.
Makes an assignment to this variable. Pushes the assignment as far
into the right side as possible, to allow jumps into it.
Returns true if the expression remains constant no matter when it is evaluated.
Implemented by expressions which can provide a version which is aware of light exceptions.
Normally these expressions will simply reduce to a version which throws a real exception.
When the expression is used inside of a region of code which supports light exceptions
the light exception re-writer will call ReduceForLightExceptions. The expression can
then return a new expression which can return a light exception rather than throwing
a real .NET exception.
The builder for creating the LambdaExpression node.
Since the nodes require that parameters and variables are created
before hand and then passed to the factories creating LambdaExpression
this builder keeps track of the different pieces and at the end creates
the LambdaExpression.
TODO: This has some functionality related to CodeContext that should be
removed, in favor of languages handling their own local scopes
The name of the lambda.
Currently anonymous/unnamed lambdas are not allowed.
Return type of the lambda being created.
List of lambda's local variables for direct manipulation.
List of lambda's parameters for direct manipulation
The params array argument, if any.
The body of the lambda. This must be non-null.
The generated lambda should have dictionary of locals
instead of allocating them directly on the CLR stack.
The scope is visible (default). Invisible if false.
Creates a parameter on the lambda with a given name and type.
Parameters maintain the order in which they are created,
however custom ordering is possible via direct access to
Parameters collection.
Creates a parameter on the lambda with a given name and type.
Parameters maintain the order in which they are created,
however custom ordering is possible via direct access to
Parameters collection.
adds existing parameter to the lambda.
Parameters maintain the order in which they are created,
however custom ordering is possible via direct access to
Parameters collection.
Creates a hidden parameter on the lambda with a given name and type.
Parameters maintain the order in which they are created,
however custom ordering is possible via direct access to
Parameters collection.
Creates a params array argument on the labmda.
The params array argument is added to the signature immediately. Before the lambda is
created, the builder validates that it is still the last (since the caller can modify
the order of parameters explicitly by maniuplating the parameter list)
Creates a local variable with specified name and type.
TODO: simplify by pushing logic into callers
Creates a local variable with specified name and type.
TODO: simplify by pushing logic into callers
Creates a temporary variable with specified name and type.
Adds the temporary variable to the list of variables maintained
by the builder. This is useful in cases where the variable is
created outside of the builder.
Creates the LambdaExpression from the builder.
After this operation, the builder can no longer be used to create other instances.
Desired type of the lambda.
New LambdaExpression instance.
Creates the LambdaExpression from the builder.
After this operation, the builder can no longer be used to create other instances.
New LambdaExpression instance.
Creates the generator LambdaExpression from the builder.
After this operation, the builder can no longer be used to create other instances.
New LambdaExpression instance.
Fixes up lambda body and parameters to match the signature of the given delegate if needed.
Validates that the builder has enough information to create the lambda.
Provides a method call to a method which may return light exceptions.
The call is to a method which supports light exceptions. When reducing
an additional check and throw is added. When a block code of is re-written
for light exceptions this instead reduces to not throw a .NET exception.
Internal re-writer class which creates code which is light exception aware.
Class used to be avoid overhead of creating expression trees when we're usually
Adds light exception handling to the provided expression which
is light exception aware.
Expression which produces a light exception value. This should be constructed
with the expression which creates the exception and this method will then call
a helper method which wraps the exception in our internal light exception class.
Represents either a YieldBreak or YieldReturn in a GeneratorExpression
If Value is non-null, it's a YieldReturn; otherwise it's a YieldBreak
and executing it will stop enumeration of the generator, causing
MoveNext to return false.
The value yieled from this expression, if it is a yield return
Gets the label used to yield from this generator
These are some generally useful helper methods. Currently the only methods are those to
cached boxed representations of commonly used primitive types so that they can be shared.
This is useful to most dynamic languages that use object as a universal type.
The methods in RuntimeHelepers are caleld by the generated code. From here the methods may
dispatch to other parts of the runtime to get bulk of the work done, but the entry points
should be here.
Used by prologue code that is injected in lambdas to ensure that delegate signature matches what
lambda body expects. Such code typically unwraps subset of the params array manually,
but then passes the rest in bulk if lambda body also expects params array.
This calls ArrayUtils.ShiftLeft, but performs additional checks that
ArrayUtils.ShiftLeft assumes.
A singleton boxed boolean true.
A singleton boxed boolean false.
Gets a singleton boxed value for the given integer if possible, otherwise boxes the integer.
The value to box.
The boxed value.
Helper method to create an instance. Work around for Silverlight where Activator.CreateInstance
is SecuritySafeCritical.
TODO: Why can't we just emit the right thing for default(T)?
It's always null for reference types and it's well defined for value types
EventInfo.EventHandlerType getter is marked SecuritySafeCritical in CoreCLR
This method is to get to the property without using Reflection
Provides the test to see if an interpreted call site should switch over to being compiled.
Enables an object to be serializable to an Expression tree. The expression tree can then
be emitted into an assembly enabling the de-serialization of the object.
Wraps all arguments passed to a dynamic site with more arguments than can be accepted by a Func/Action delegate.
The binder generating a rule for such a site should unwrap the arguments first and then perform a binding to them.
Gets the number of items in _arguments that represent the arguments.
Helper methods that calls are generated to from the default DLR binders.
Helper function to combine an object array with a sequence of additional parameters that has been splatted for a function call.
EventInfo.EventHandlerType getter is marked SecuritySafeCritical in CoreCLR
This method is to get to the property without using Reflection
The MethodBinder will perform normal method binding.
The MethodBinder will return the languages definition of NotImplemented if the arguments are
incompatible with the signature.
The MethodBinder will set properties/fields for unused keyword arguments on the instance
that gets returned from the method.
The delegate representing the DLR Main function
Implements explicit casts supported by the runtime.
Implements explicit casts supported by the runtime.
Explicitly casts the object to a given type (and returns it as object)
Represents the context that is flowed for doing Compiler. Languages can derive
from this class to provide additional contextual information.
Gets the source unit currently being compiled in the CompilerContext.
Gets the sink for parser callbacks (e.g. brace matching, etc.).
Gets the current error sink.
Gets the compiler specific options.
Abstract base class used for optimized thread-safe dictionaries which have a set
of pre-defined string keys.
Implementers derive from this class and override the GetExtraKeys, TrySetExtraValue,
and TryGetExtraValue methods. When looking up a value first the extra keys will be
searched using the optimized Try*ExtraValue functions. If the value isn't found there
then the value is stored in the underlying .NET dictionary.
This dictionary can store object values in addition to string values. It also supports
null keys.
Gets a list of the extra keys that are cached by the the optimized implementation
of the module.
Try to set the extra value and return true if the specified key was found in the
list of extra values.
Try to get the extra value and returns true if the specified key was found in the
list of extra values. Returns true even if the value is Uninitialized.
Used as the value for the ScriptingRuntimeHelpers.GetDelegate method caching system
Generates stub to receive the CLR call and then call the dynamic language code.
Used as the key for the LanguageContext.GetDelegate method caching system
An attribute that is applied to saved ScriptCode's to be used to re-create the ScriptCode
from disk.
Gets names stored in optimized scope.
Provides a mechanism for providing documentation stored in an assembly as metadata.
Applying this attribute will enable documentation to be provided to the user at run-time
even if XML Documentation files are unavailable.
Provides support for converting objects to delegates using the DLR binders
available by the provided language context.
Primarily this supports converting objects implementing IDynamicMetaObjectProvider
to the appropriate delegate type.
If the provided object is already a delegate of the appropriate type then the
delegate will simply be returned.
Creates a delegate with a given signature that could be used to invoke this object from non-dynamic code (w/o code context).
A stub is created that makes appropriate conversions/boxing and calls the object.
The stub should be executed within a context of this object's language.
The converted delegate.
The object is either a subclass of Delegate but not the requested type or does not implement IDynamicMetaObjectProvider.
Represents the type of a null value.
Private constructor is never called since 'null' is the only valid instance.
Updates an exception before it's getting re-thrown so
we can present a reasonable stack trace to the user.
Returns all the stack traces associates with an exception
Marks a class in the assembly as being an extension type for another type.
Marks a type in the assembly as being an extension type for another type.
The type which is being extended
The type which provides the extension members.
The type which contains extension members which are added to the type being extended.
The type which is being extended by the extension type.
Indicates that a DynamicMetaObject might be convertible to a CLR type.
Given an ID returns the object associated with that ID.
Gets a unique ID for an object
Goes over the hashtable and removes empty entries
Weak-ref wrapper caches the weak reference, our hash code, and the object ID.
WrapperComparer treats Wrapper as transparent envelope
Provides a list of all the members of an instance.
Indicates that a MetaObject is already representing a restricted type. Useful
when we're already restricted to a known type but this isn't captured in
the type info (e.g. the type is not sealed).
A useful interface for taking slices of numeric arrays, inspired by Python's Slice objects.
The starting index of the slice or null if no first index defined
The ending index of the slice or null if no ending index defined
The length of step to take
Internal class which binds a LanguageContext, StreamContentProvider, and Encoding together to produce
a TextContentProvider which reads binary data with the correct language semantics.
Provides support for light exceptions. These exceptions are propagated by
returning an instance of a private wrapper class containing the exception. Code
which is aware of light exceptions will branch to apporiate exception handling
blocks when in a try and otherwise return the value up the stack. This avoids
using the underlying CLR exception mechanism with overhead such as creating stack
traces.
When a light exception reaches the boundary of code which is not light exception
aware the caller must check to see if a light exception is being thrown and if
so raise a .NET exception.
This class provides methods for re-writing expression trees to support light exceptions,
methods to create light throw objects, check if an object is a light
throw object, and turn such an object back into a .NET Exception which can be thrown.
Light exceptions also don't build up stack traces or interoperate with filter blocks
via 2-pass exception handling.
Rewrites the provided expression to support light exceptions.
Calls to the returned expression, if not from other light-weight aware calls,
need to call GetLightException on return to see if an exception was thrown
and if so throw it.
Returns a new expression which will lazily reduce to a light
expression re-written version of the same expression.
Returns a new expression which is re-written for light exceptions
but will throw an exception if it escapes the expression. If this
expression is part of a larger experssion which is later re-written
for light exceptions then it will propagate the light exception up.
Returns an object which represents a light exception.
Returns an object which represents a light exception.
Returns an object which represents a light exception.
If the binder supports light exceptions then a light exception throwing expression is returned.
Otherwise a normal throwing expression is returned.
If the binder supports light exceptions then a light exception throwing expression is returned.
Otherwise a normal throwing expression is returned.
Throws the exception if the value represents a light exception
Wraps the expression in a check and rethrow.
Checks to see if the provided value is a light exception.
Gets the light exception from an object which may contain a light
exception. Returns null if the object is not a light exception.
Used for throwing the exception at non-light exception boundaries.
Returns true if the call site binder is a light exception binder and supports
light throws. Returns false otherwise.
Sealed wrapper class to indicate something is a light exception.
Marks a method which may return a light exception. Such
methods need to have their return value checked and the exception
will need to be thrown if the caller is not light exception aware.
Creates a dictionary of locals in this scope
Returns Microsoft.Scripting.Runtime.DynamicNull if the object contains a null value,
otherwise, returns self.LimitType
Returns Microsoft.Scripting.Runtime.DynamicNull if the object contains a null value,
otherwise, returns self.RuntimeType
Event args for when a ScriptScope has had its contents changed.
Creates a new ModuleChangeEventArgs object with the specified name and type.
Creates a nwe ModuleChangeEventArgs with the specified name, type, and changed value.
Gets the name of the symbol that has changed.
Gets the way in which the symbol has changed: Set or Delete.
Gets the symbol has been set provides the new value.
The way in which a module has changed : Set or Delete
A new value has been set in the module (or a previous value has changed).
A value has been removed from the module.
A NullTextContentProvider to be provided when we have a pre-compiled ScriptCode which doesn't
have source code associated with it.
Singleton instance returned from an operator method when the operator method cannot provide a value.
Represents an ops-extension method which is added as an operator.
The name must be a well-formed name such as "Add" that matches the CLS
naming conventions for adding overloads associated with op_* methods.
Efficiently tracks (line,column) information as text is added, and
collects line mappings between the original and generated source code
so we can generate correct debugging information later
Marks the current position of the writer as corresponding to the
original location passed in
the line pragma corresponding to the
current position in the generated code
Represents an ops-extension method which is used to implement a property.
Provides a cache of reflection members. Only one set of values is ever handed out per a
specific request.
TODO: Make me private again
Indicates an extension method should be added as a static method, not a instance method.
Sets the current position inside current token or one character behind it.
Sets the current position inside current token or one character behind it.
A relative displacement with respect to the current position in the token is specified.
Marks token end. Enables to read the current token.
Marks token start. It means the buffer can drop the current token.
Can be called even if no token has been read yet.
Reads till the end of line and returns the character that stopped the reading.
The returned character is not skipped.
Resizes an array to a speficied new size and copies a portion of the original array into its beginning.
Provides services for loading XAML and binding events to dynamic language code definitions.
Loads XAML from the specified stream and returns the deserialized object. Any event handlers
are bound to methods defined in the provided Scope and converted using the provided DynamicOperations
object.
Loads XAML from the specified filename and returns the deserialized object. Any event handlers
are bound to methods defined in the provided Scope and converted using the provided DynamicOperations
object.
Loads XAML from the specified XmlReader and returns the deserialized object. Any event handlers
are bound to methods defined in the provided Scope and converted using the provided DynamicOperations
object.
Loads XAML from the specified TextReader and returns the deserialized object. Any event handlers
are bound to methods defined in the provided Scope and converted using the provided DynamicOperations
object.
Loads XAML from the specified XamlXmlReader and returns the deserialized object. Any event handlers
are bound to methods defined in the provided Scope and converted using the provided DynamicOperations
object.
Returns the list of x:Name'd objects that we saw and should set on the root object.
Dummy, should never be called
Stores information needed to emit debugging symbol information for a
source file, in particular the file name and unique language identifier
Gets the source file name.
Gets the language's unique identifier, if any.
Gets the language vendor's unique identifier, if any.
ArgBuilder provides an argument value used by the MethodBinder. One ArgBuilder exists for each
physical parameter defined on a method.
Contrast this with ParameterWrapper which represents the logical argument passed to the method.
Provides the Expression which provides the value to be passed to the argument.
Provides the Expression which provides the value to be passed to the argument.
This method is called when result is intended to be used ByRef.
Provides an Expression which will update the provided value after a call to the method.
May return null if no update is required.
Provides the implementation of performing AddAssign and SubtractAssign binary operations.
The binder provided by the call site.
The handler for the operation.
The result of the operation.
true if the operation is complete, false if the call site should determine behavior.
Adds a handler to an event.
The handler to be added.
The original event with handler added.
Removes handler from the event.
The handler to be removed.
The original event with handler removed.
Provides helper methods to bind COM objects dynamically.
Determines if an object is a COM object.
The object to test.
true if the object is a COM object, false otherwise.
Tries to perform binding of the dynamic get member operation.
An instance of the that represents the details of the dynamic operation.
The target of the dynamic operation.
The new representing the result of the binding.
true if member evaluation may be delayed.
true if operation was bound successfully; otherwise, false.
Tries to perform binding of the dynamic get member operation.
An instance of the that represents the details of the dynamic operation.
The target of the dynamic operation.
The new representing the result of the binding.
true if operation was bound successfully; otherwise, false.
Tries to perform binding of the dynamic set member operation.
An instance of the that represents the details of the dynamic operation.
The target of the dynamic operation.
The representing the value for the set member operation.
The new representing the result of the binding.
true if operation was bound successfully; otherwise, false.
Tries to perform binding of the dynamic invoke operation.
An instance of the that represents the details of the dynamic operation.
The target of the dynamic operation.
An array of instances - arguments to the invoke member operation.
The new representing the result of the binding.
true if operation was bound successfully; otherwise, false.
Tries to perform binding of the dynamic invoke member operation.
An instance of the that represents the details of the dynamic operation.
The target of the dynamic operation.
An array of instances - arguments to the invoke member operation.
The new representing the result of the binding.
true if operation was bound successfully; otherwise, false.
Tries to perform binding of the dynamic get index operation.
An instance of the that represents the details of the dynamic operation.
The target of the dynamic operation.
An array of instances - arguments to the invoke member operation.
The new representing the result of the binding.
true if operation was bound successfully; otherwise, false.
Tries to perform binding of the dynamic set index operation.
An instance of the that represents the details of the dynamic operation.
The target of the dynamic operation.
An array of instances - arguments to the invoke member operation.
The representing the value for the set index operation.
The new representing the result of the binding.
true if operation was bound successfully; otherwise, false.
Tries to perform binding of the dynamic Convert operation.
An instance of the that represents the details of the dynamic operation.
The target of the dynamic operation.
The new representing the result of the binding.
true if operation was bound successfully; otherwise, false.
Gets the member names associated with the object.
This function can operate only with objects for which returns true.
The object for which member names are requested.
The collection of member names.
Gets the member names of the data-like members associated with the object.
This function can operate only with objects for which returns true.
The object for which member names are requested.
The collection of member names.
Gets the data-like members and associated data for an object.
This function can operate only with objects for which returns true.
The object for which data members are requested.
The enumeration of names of data members for which to retrieve values.
The collection of pairs that represent data member's names and their data.
Special binder that indicates special semantics for COM GetMember operation.
This class implements an event sink for a particular RCW.
Unlike the implementation of events in TlbImp'd assemblies,
we will create only one event sink per RCW (theoretically RCW might have
several ComEventSink evenk sinks - but all these implement different source intefaces).
Each ComEventSink contains a list of ComEventSinkMethod objects - which represent
a single method on the source interface an a multicast delegate to redirect
the calls. Notice that we are chaining multicast delegates so that same
ComEventSinkMedhod can invoke multiple event handlers).
ComEventSink implements an IDisposable pattern to Unadvise from the connection point.
Typically, when RCW is finalized the corresponding Dispose will be triggered by
ComEventSinksContainer finalizer. Notice that lifetime of ComEventSinksContainer
is bound to the lifetime of the RCW.
Contains a methods DISPID (in a string formatted of "[DISPID=N]"
and a chained list of delegates to invoke
ComEventSinkProxy class is responsible for handling QIs for sourceIid
on instances of ComEventSink.
Background: When a COM even sink advises to a connection point it is
supposed to hand over the dispinterface. Now, some hosts will trust
the COM client to pass the correct pointer, but some will not.
E.g. Excel's implementation of Connection Points will not cause a
QI on the pointer that has been passed, however Word will QI the
pointer to return the required interface.
ComEventSink does not, strongly speaking, implements the interface
that it claims to implement - it is just "faking" it by using IReflect.
Thus, Word's QIs on the pointer passed to ICP::Advise would fail. To
prevent this we take advangate of RealProxy's ability of
"dressing up" like other classes and hence successfully respond to QIs
for interfaces that it does not really support( it is OK to say
"I implement this interface" for event sinks only since the common
practice is to use IDistpach.Invoke when calling into event sinks).
ComEventSinksContainer is just a regular list with a finalizer.
This list is usually attached as a custom data for RCW object and
is finalized whenever RCW is finalized.
Layout of the IDispatch vtable
Invokes the object. If it falls back, just produce an error.
Splats the arguments to another nested dynamic site, which does the
real invocation of the IDynamicMetaObjectProvider.
Create a stub for the target of the optimized lopop.
Gets expressions to access all the arguments. This includes the instance argument.
This is a helper class for runtime-callable-wrappers of COM instances. We create one instance of this type
for every generic RCW instance.
This is the factory method to get the ComObject corresponding to an RCW
The parameter description of a method defined in a type library
Creates a representation for the paramter of a COM method
Creates a representation for the return value of a COM method
TODO: Return values should be represented by a different type
DBNull.Value if there is no default value
Look for typeinfo using IDispatch.GetTypeInfo
Some COM objects just dont expose typeinfo. In these cases, this method will return null.
Some COM objects do intend to expose typeinfo, but may not be able to do so if the type-library is not properly
registered. This will be considered as acceptable or as an error condition depending on throwIfMissingExpectedTypeInfo
This method should be called when typeinfo is not available for an object. The function
will check if the typeinfo is expected to be missing. This can include error cases where
the same error is guaranteed to happen all the time, on all machines, under all circumstances.
In such cases, we just have to operate without the typeinfo.
However, if accessing the typeinfo is failing in a transient way, we might want to throw
an exception so that we will eagerly predictably indicate the problem.
This class contains methods that either cannot be expressed in C#, or which require writing unsafe code.
Callers of these methods need to use them extremely carefully as incorrect use could cause GC-holes
and other problems.
Ensure that "value" is a local variable in some caller's frame. So converting
the byref to an IntPtr is a safe operation. Alternatively, we could also allow
allowed "value" to be a pinned object.
We will emit an indirect call to an unmanaged function pointer from the vtable of the given interface pointer.
This approach can take only ~300 instructions on x86 compared with ~900 for Marshal.Release. We are relying on
the JIT-compiler to do pinvoke-stub-inlining and calling the pinvoke target directly.
We will emit an indirect call to an unmanaged function pointer from the vtable of the given IDispatch interface pointer.
It is not possible to express this in C#. Using an indirect pinvoke call allows us to do our own marshalling.
We can allocate the Variant arguments cheaply on the stack. We are relying on the JIT-compiler to do
pinvoke-stub-inlining and calling the pinvoke target directly.
The alternative of calling via a managed interface declaration of IDispatch would have a performance
penalty of going through a CLR stub that would have to re-push the arguments on the stack, etc.
Marshal.GetDelegateForFunctionPointer could be used here, but its too expensive (~2000 instructions on x86).
Cached information from a TLB. Only information that is required is saved. CoClasses are used
for event hookup. Enums are stored for accessing symbolic names from scripts.
Reads the latest registered type library for the corresponding GUID,
reads definitions of CoClass'es and Enum's from this library
and creates a IDynamicMetaObjectProvider that allows to instantiate coclasses
and get actual values for the enums.
Type Library Guid
ComTypeLibDesc object
Gets an ITypeLib object from OLE Automation compatible RCW ,
reads definitions of CoClass'es and Enum's from this library
and creates a IDynamicMetaObjectProvider that allows to instantiate coclasses
and get actual values for the enums.
OLE automation compatible RCW
ComTypeLibDesc object
This represents a bound dispmember on a IDispatch object.
This is similar to ComTypes.EXCEPINFO, but lets us do our own custom marshaling
An object that implements IDispatch
This currently has the following issues:
1. If we prefer ComObjectWithTypeInfo over IDispatchComObject, then we will often not
IDispatchComObject since implementations of IDispatch often rely on a registered type library.
If we prefer IDispatchComObject over ComObjectWithTypeInfo, users get a non-ideal experience.
2. IDispatch cannot distinguish between properties and methods with 0 arguments (and non-0
default arguments?). So obj.foo() is ambiguous as it could mean invoking method foo,
or it could mean invoking the function pointer returned by property foo.
We are attempting to find whether we need to call a method or a property by examining
the ITypeInfo associated with the IDispatch. ITypeInfo tell's use what parameters the method
expects, is it a method or a property, what is the default property of the object, how to
create an enumerator for collections etc.
3. IronPython processes the signature and converts ref arguments into return values.
However, since the signature of a DispMethod is not available beforehand, this conversion
is not possible. There could be other signature conversions that may be affected. How does
VB6 deal with ref arguments and IDispatch?
We also support events for IDispatch objects:
Background:
COM objects support events through a mechanism known as Connect Points.
Connection Points are separate objects created off the actual COM
object (this is to prevent circular references between event sink
and event source). When clients want to sink events generated by
COM object they would implement callback interfaces (aka source
interfaces) and hand it over (advise) to the Connection Point.
Implementation details:
When IDispatchComObject.TryGetMember request is received we first check
whether the requested member is a property or a method. If this check
fails we will try to determine whether an event is requested. To do
so we will do the following set of steps:
1. Verify the COM object implements IConnectionPointContainer
2. Attempt to find COM object's coclass's description
a. Query the object for IProvideClassInfo interface. Go to 3, if found
b. From object's IDispatch retrieve primary interface description
c. Scan coclasses declared in object's type library.
d. Find coclass implementing this particular primary interface
3. Scan coclass for all its source interfaces.
4. Check whether to any of the methods on the source interfaces matches
the request name
Once we determine that TryGetMember requests an event we will return
an instance of BoundDispEvent class. This class has InPlaceAdd and
InPlaceSubtract operators defined. Calling InPlaceAdd operator will:
1. An instance of ComEventSinksContainer class is created (unless
RCW already had one). This instance is hanged off the RCW in attempt
to bind the lifetime of event sinks to the lifetime of the RCW itself,
meaning event sink will be collected once the RCW is collected (this
is the same way event sinks lifetime is controlled by PIAs).
Notice: ComEventSinksContainer contains a Finalizer which will go and
unadvise all event sinks.
Notice: ComEventSinksContainer is a list of ComEventSink objects.
2. Unless we have already created a ComEventSink for the required
source interface, we will create and advise a new ComEventSink. Each
ComEventSink implements a single source interface that COM object
supports.
3. ComEventSink contains a map between method DISPIDs to the
multicast delegate that will be invoked when the event is raised.
4. ComEventSink implements IReflect interface which is exposed as
custom IDispatch to COM consumers. This allows us to intercept calls
to IDispatch.Invoke and apply custom logic - in particular we will
just find and invoke the multicast delegate corresponding to the invoked
dispid.
ArgBuilder which always produces null.
SimpleArgBuilder produces the value produced by the user as the argument value. It
also tracks information about the original parameter and is used to create extended
methods for params arrays and param dictionary functions.
If a managed user type (as opposed to a primitive type or a COM object) is passed as an argument to a COM call, we need
to determine the VarEnum type we will marshal it as. We have the following options:
1. Raise an exception. Languages with their own version of primitive types would not be able to call
COM methods using the language's types (for eg. strings in IronRuby are not System.String). An explicit
cast would be needed.
2. We could marshal it as VT_DISPATCH. Then COM code will be able to access all the APIs in a late-bound manner,
but old COM components will probably malfunction if they expect a primitive type.
3. We could guess which primitive type is the closest match. This will make COM components be as easily
accessible as .NET methods.
4. We could use the type library to check what the expected type is. However, the type library may not be available.
VarEnumSelector implements option # 3
Gets the managed type that an object needs to be coverted to in order for it to be able
to be represented as a Variant.
In general, there is a many-to-many mapping between Type and VarEnum. However, this method
returns a simple mapping that is needed for the current implementation. The reason for the
many-to-many relation is:
1. Int32 maps to VT_I4 as well as VT_ERROR, and Decimal maps to VT_DECIMAL and VT_CY. However,
this changes if you throw the wrapper types into the mix.
2. There is no Type to represent COM types. __ComObject is a private type, and Object is too
general.
Creates a family of COM types such that within each family, there is a completely non-lossy
conversion from a type to an earlier type in the family.
Get the (one representative type for each) primitive type families that the argument can be converted to
If there is more than one type family that the argument can be converted to, we will throw a
AmbiguousMatchException instead of randomly picking a winner.
Is there a unique primitive type that has the best conversion for the argument
Get the COM Variant type that argument should be marshaled as for a call to COM
Variant is the basic COM type for late-binding. It can contain any other COM data type.
This type definition precisely matches the unmanaged data layout so that the struct can be passed
to and from COM calls.
Primitive types are the basic COM types. It includes valuetypes like ints, but also reference types
like BStrs. It does not include composite types like arrays and user-defined COM types (IUnknown/IDispatch).
Get the managed object representing the Variant.
Release any unmanaged memory associated with the Variant
VariantBuilder handles packaging of arguments into a Variant for a call to IDispatch.Invoke
Strongly-typed and parameterized string factory.
Strongly-typed and parameterized string factory.
A string like "COM object is expected."
A string like "Cannot perform call."
A string like "COM object does not support events."
A string like "COM object does not support specified source interface."
A string like "Marshal.SetComObjectData failed."
A string like "This method exists only to keep the compiler happy."
A string like "Unexpected VarEnum {0}."
A string like "Error while invoking {0}."
A string like "Error while invoking {0}."
A string like "Error while invoking {0}. Named arguments are not supported."
A string like "Error while invoking {0}."
A string like "Could not convert argument {0} for call to {1}."
A string like "Error while invoking {0}. A required parameter was omitted."
A string like "ResolveComReference.CannotRetrieveTypeInformation."
A string like "IDispatch::GetIDsOfNames behaved unexpectedly for {0}."
A string like "Attempting to wrap an unsupported enum type."
A string like "Attempting to pass an event handler of an unsupported type."
A string like "Could not get dispatch ID for {0} (error: {1})."
A string like "There are valid conversions from {0} to {1}."
A string like "Variant.GetAccessor cannot handle {0}."
A string like "Cannot access member {1} declared on type {0} because the type contains generic parameters."
A string like "Type '{0}' is missing or cannot be loaded."
A string like "static property "{0}" of "{1}" can only be read through a type, not an instance"
A string like "static property "{0}" of "{1}" can only be assigned to through a type, not an instance"
A string like "Method precondition violated"
A string like "Invalid argument value"
A string like "Non-empty string required"
A string like "Non-empty collection required"
A string like "must by an Exception instance"
A string like "Type of test must be bool"
A string like "Type of the expression must be bool"
A string like "Empty string is not a valid path."
A string like "Invalid delegate type (Invoke method not found)."
A string like "expected only static property"
A string like "Property doesn't exist on the provided type"
A string like "Field doesn't exist on provided type"
A string like "Type doesn't have constructor with a given signature"
A string like "Type doesn't have a method with a given name."
A string like "Type doesn't have a method with a given name and signature."
A string like "Count must be non-negative."
A string like "arrayType must be an array type"
A string like "Either code or target must be specified."
A string like "Type parameter is {0}. Expected a delegate."
A string like "Cannot cast from type '{0}' to type '{1}"
A string like "unknown member type: '{0}'. "
A string like "RuleBuilder can only be used with delegates whose first argument is CallSite."
A string like "no instance for call."
A string like "Missing Test."
A string like "Missing Target."
A string like "The operation requires a non-generic type for {0}, but this represents generic types only"
A string like "Invalid operation: '{0}'"
A string like "Finally already defined."
A string like "Can not have fault and finally."
A string like "Fault already defined."
A string like "Cannot create default value for type {0}."
A string like "Unhandled convert: {0}"
A string like "{0}.{1} has no publiclly visible method."
A string like "Global/top-level local variable names must be unique."
A string like "Generating code from non-serializable CallSiteBinder."
A string like "Specified path is invalid."
A string like "Dictionaries are not hashable."
A string like "language already registered."
A string like "The method or operation is not implemented."
A string like "No exception."
A string like "Extension type {0} must be public."
A string like "Already initialized."
A string like "CreateScopeExtension must return a scope extension."
A string like "Invalid number of parameters for the service."
A string like "Invalid type of argument {0}; expecting {1}."
A string like "Cannot change non-caching value."
A string like "Field {0} is read-only"
A string like "Property {0} is read-only"
A string like "Expected event from {0}.{1}, got event from {2}.{3}."
A string like "expected bound event, got {0}."
A string like "Expected type {0}, got {1}."
A string like "can only write to member {0}."
A string like "No code to compile."
A string like "Invalid stream type: {0}."
A string like "Queue empty."
A string like "Enumeration has not started. Call MoveNext."
A string like "Enumeration already finished."
A string like "can't add another casing for identifier {0}"
A string like "can't add new identifier {0}"
A string like "Type '{0}' doesn't provide a suitable public constructor or its implementation is faulty: {1}"
A string like "Invalid output directory."
A string like "Invalid assembly name or file extension."
A string like "Cannot emit constant {0} ({1})"
A string like "No implicit cast from {0} to {1}"
A string like "No explicit cast from {0} to {1}"
A string like "name '{0}' not defined"
A string like "No default value for a given type."
A string like "Specified language provider type is not registered."
A string like "can't read from property"
A string like "can't write to property"
A string like "Cannot create instance of {0} because it contains generic parameters"
A string like "Non-verifiable assembly generated: {0}:\nAssembly preserved as {1}\nError text:\n{2}\n"
Strongly-typed and parameterized exception factory.
Strongly-typed and parameterized exception factory.
ArgumentException with message like "COM object does not support events."
ArgumentException with message like "COM object does not support specified source interface."
InvalidOperationException with message like "Marshal.SetComObjectData failed."
InvalidOperationException with message like "This method exists only to keep the compiler happy."
InvalidOperationException with message like "Unexpected VarEnum {0}."
System.Reflection.TargetParameterCountException with message like "Error while invoking {0}."
MissingMemberException with message like "Error while invoking {0}."
ArgumentException with message like "Error while invoking {0}. Named arguments are not supported."
OverflowException with message like "Error while invoking {0}."
ArgumentException with message like "Could not convert argument {0} for call to {1}."
ArgumentException with message like "Error while invoking {0}. A required parameter was omitted."
InvalidOperationException with message like "ResolveComReference.CannotRetrieveTypeInformation."
ArgumentException with message like "IDispatch::GetIDsOfNames behaved unexpectedly for {0}."
InvalidOperationException with message like "Attempting to wrap an unsupported enum type."
InvalidOperationException with message like "Attempting to pass an event handler of an unsupported type."
MissingMemberException with message like "Could not get dispatch ID for {0} (error: {1})."
System.Reflection.AmbiguousMatchException with message like "There are valid conversions from {0} to {1}."
NotImplementedException with message like "Variant.GetAccessor cannot handle {0}."
ArgumentException with message like "Either code or target must be specified."
InvalidOperationException with message like "Type parameter is {0}. Expected a delegate."
InvalidOperationException with message like "Cannot cast from type '{0}' to type '{1}"
InvalidOperationException with message like "unknown member type: '{0}'. "
InvalidOperationException with message like "RuleBuilder can only be used with delegates whose first argument is CallSite."
InvalidOperationException with message like "no instance for call."
InvalidOperationException with message like "Missing Test."
InvalidOperationException with message like "Missing Target."
TypeLoadException with message like "The operation requires a non-generic type for {0}, but this represents generic types only"
ArgumentException with message like "Invalid operation: '{0}'"
InvalidOperationException with message like "Finally already defined."
InvalidOperationException with message like "Can not have fault and finally."
InvalidOperationException with message like "Fault already defined."
ArgumentException with message like "Cannot create default value for type {0}."
ArgumentException with message like "Unhandled convert: {0}"
InvalidOperationException with message like "{0}.{1} has no publiclly visible method."
ArgumentException with message like "Global/top-level local variable names must be unique."
ArgumentException with message like "Generating code from non-serializable CallSiteBinder."
ArgumentException with message like "Specified path is invalid."
ArgumentTypeException with message like "Dictionaries are not hashable."
InvalidOperationException with message like "language already registered."
NotImplementedException with message like "The method or operation is not implemented."
InvalidOperationException with message like "No exception."
ArgumentException with message like "Extension type {0} must be public."
InvalidOperationException with message like "Already initialized."
InvalidImplementationException with message like "CreateScopeExtension must return a scope extension."
ArgumentException with message like "Invalid number of parameters for the service."
ArgumentException with message like "Invalid type of argument {0}; expecting {1}."
ArgumentException with message like "Cannot change non-caching value."
MissingMemberException with message like "Field {0} is read-only"
MissingMemberException with message like "Property {0} is read-only"
ArgumentException with message like "Expected event from {0}.{1}, got event from {2}.{3}."
ArgumentTypeException with message like "expected bound event, got {0}."
ArgumentTypeException with message like "Expected type {0}, got {1}."
MemberAccessException with message like "can only write to member {0}."
InvalidOperationException with message like "No code to compile."
ArgumentException with message like "Invalid stream type: {0}."
InvalidOperationException with message like "Queue empty."
InvalidOperationException with message like "Enumeration has not started. Call MoveNext."
InvalidOperationException with message like "Enumeration already finished."
InvalidOperationException with message like "can't add another casing for identifier {0}"
InvalidOperationException with message like "can't add new identifier {0}"
ArgumentException with message like "Invalid output directory."
ArgumentException with message like "Invalid assembly name or file extension."
ArgumentException with message like "Cannot emit constant {0} ({1})"
ArgumentException with message like "No implicit cast from {0} to {1}"
ArgumentException with message like "No explicit cast from {0} to {1}"
MissingMemberException with message like "name '{0}' not defined"
ArgumentException with message like "No default value for a given type."
ArgumentException with message like "Specified language provider type is not registered."
InvalidOperationException with message like "can't read from property"
InvalidOperationException with message like "can't write to property"
ArgumentException with message like "Cannot create instance of {0} because it contains generic parameters"
System.Security.VerificationException with message like "Non-verifiable assembly generated: {0}:\nAssembly preserved as {1}\nError text:\n{2}\n"
Used by compilers to provide additional debug information about LambdaExpression to DebugContext
Implemented by compilers to allow the traceback engine to get additional information.
Provides services to compilers for instrumenting code with tracebacks.
Creates a new instance of DebugContext
Transforms a LambdaExpression to a debuggable LambdaExpression
Transforms a LambdaExpression to a debuggable LambdaExpression
Resets a state associated with a source file that's maintained in the DebugContext
Threads
Hook
Thread
FrameOrder
Variables
CurrentSequencePointIndex
// This method is called from the generator to update the frame with generator's locals
Remaps the frame's state to use the generator for execution.
Int32.MaxValue to map to latest version
DebuggableLambdaBuilder is used to transform a DLR expression tree into a debuggable lambda expression.
Used to wrap a lambda that was already a generator prior to transform.
Used to rewrite expressions containing DebugInfoExpressions.
Combines source file and span. Also provides Contains and Intersects functionality.
Implementation of IDebugRuntimeVariables, which wraps IRuntimeVariables + FunctionInfo/DebugMarker
Default implementation of BaseDebugThread, which uses DLR's RuntimeVariablesExpression for lifting locals.
Default implementation of IDebugThreadFactory, which uses DLR's RuntimeVariablesExpression for lifting locals.
SequencePoints
Gets the name.
Gets the custom payload.
GetTraceLocations
Callback that is fired by the traceback engine
Used to extract locals information from expressions.
Strongly-typed and parameterized string factory.
IDebugRuntimeVariables is used to wrap IRuntimeVariables and add properties for retrieving
FunctionInfo and DebugMarker from debuggable labmdas.
IDebugThreadFactory is used to abstract how frames and local variables are maintained at run/debug time.
Implements IRuntimeVariables in a way that preserves scoping within the lambda.
TraceSession.
Basically holds a list of last encountered DebugFrame instances
(one per running thread).
Used to provide information about locals/parameters at debug time.
Index within byref variables list or within strongbox variables list.
Index within the combined list.
Gets the variable type.
Gets the name.
Gets or sets a value indicating whether it is a parameter.
This class holds onto internal debugging options used in this assembly.
These options can be set via environment variables DLR_{option-name}.
Boolean options map "true" to true and other values to false.
These options are for internal debugging only, and should not be
exposed through any public APIs.
True if the MethodBase is method which is going to construct an object
Returns the System.Type for any object, including null. The type of null
is represented by None.Type and all other objects just return the
result of Object.GetType
Simply returns a Type[] from calling GetType on each element of args.
EMITTED
Used by default method binder to check types of splatted arguments.
Given a MethodInfo which may be declared on a non-public type this attempts to
return a MethodInfo which will dispatch to the original MethodInfo but is declared
on a public type.
Returns the original method if the method if a public version cannot be found.
Non-public types can have public members that we find when calling type.GetMember(...). This
filters out the non-visible members by attempting to resolve them to the correct visible type.
If no correct visible type can be found then the member is not visible and we won't call it.
Sees if two MemberInfos point to the same underlying construct in IL. This
ignores the ReflectedType property which exists on MemberInfos which
causes direct comparisons to be false even if they are the same member.
Returns a value which indicates failure when a OldConvertToAction of ImplicitTry or
ExplicitTry.
Creates an interpreted delegate for the lambda.
The lambda to compile.
A delegate which can interpret the lambda.
Creates an interpreted delegate for the lambda.
The lambda to compile.
The number of iterations before the interpreter starts compiling
A delegate which can interpret the lambda.
Creates an interpreted delegate for the lambda.
The lambda's delegate type.
The lambda to compile.
A delegate which can interpret the lambda.
Creates an interpreted delegate for the lambda.
The lambda to compile.
The number of iterations before the interpreter starts compiling
A delegate which can interpret the lambda.
Compiles the lambda into a method definition.
the lambda to compile
A which will be used to hold the lambda's IL.
A parameter that indicates if debugging information should be emitted to a PDB symbol store.
Compiles the LambdaExpression.
If the lambda is compiled with emitDebugSymbols, it will be
generated into a TypeBuilder. Otherwise, this method is the same as
calling LambdaExpression.Compile()
This is a workaround for a CLR limitiation: DynamicMethods cannot
have debugging information.
the lambda to compile
true to generate a debuggable method, false otherwise
the compiled delegate
Compiles the LambdaExpression, emitting it into a new type, and
optionally making it debuggable.
This is a workaround for a CLR limitiation: DynamicMethods cannot
have debugging information.
the lambda to compile
Debugging information generator used by the compiler to mark sequence points and annotate local variables.
True if debug symbols (PDBs) are emitted by the .
the compiled delegate
Removes all live objects and places them in static fields of a type.
Reduces the provided DynamicExpression into site.Target(site, *args).
Tests to see if the expression is a constant with the given value.
The expression to examine
The constant value to check for.
true/false
Tests to see if the expression is a constant with the given value.
The expression to examine
The constant value to check for.
true/false
Provides a simple expression which enables embedding FieldBuilder's
in an AST before the type is complete.
Begins a catch block.
Begins an exception block for a filtered exception.
Begins an exception block for a non-filtered exception.
Begins an exception fault block
Begins a finally block
Ends an exception block.
Begins a lexical scope.
Ends a lexical scope.
Declares a local variable of the specified type.
Declares a local variable of the specified type, optionally
pinning the object referred to by the variable.
Declares a new label.
Marks the label at the current position.
Emits an instruction.
Emits an instruction with a byte argument.
Emits an instruction with the metadata token for the specified contructor.
Emits an instruction with a double argument.
Emits an instruction with the metadata token for the specified field.
Emits an instruction with a float argument.
Emits an instruction with an int argument.
Emits an instruction with a label argument.
Emits an instruction with multiple target labels (switch).
Emits an instruction with a reference to a local variable.
Emits an instruction with a long argument.
Emits an instruction with the metadata token for a specified method.
Emits an instruction with a signed byte argument.
Emits an instruction with a short argument.
Emits an instruction with a signature token.
Emits an instruction with a string argument.
Emits an instruction with the metadata token for a specified type argument.
Emits a call or a virtual call to the varargs method.
Emits an unmanaged indirect call instruction.
Emits a managed indirect call instruction.
Marks a sequence point.
Specifies the namespace to be used in evaluating locals and watches for the
current active lexical scope.
Emits a Ldind* instruction for the appropriate type
Emits a Stind* instruction for the appropriate type.
Emits a Stelem* instruction for the appropriate type.
Boxes the value of the stack. No-op for reference types. Void is
converted to a null reference. For almost all value types this
method will box them in the standard way. Int32 and Boolean are
handled with optimized conversions that reuse the same object for
small values. For Int32 this is purely a performance optimization.
For Boolean this is use to ensure that True and False are always
the same objects.
Emits an array of constant values provided in the given list.
The array is strongly typed.
Emits an array of values of count size. The items are emitted via the callback
which is provided with the current item index to emit.
Emits an array construction code.
The code assumes that bounds for all dimensions
are already emitted.
Emits default(T)
Semantics match C# compiler behavior
A simple dictionary of queues, keyed off a particular type
This is useful for storing free lists of variables
Helper class to remove methods w/ identical signatures. Used for GetDefaultMembers
which returns members from all types in the hierarchy.
Directory where snippet assembly will be saved if SaveSnippets is set.
Save snippets to an assembly (see also SnippetsDirectory, SnippetsFileName).
Serializes constants and dynamic sites so the code can be saved to disk
Gets the Compiler associated with the Type Initializer (cctor) creating it if necessary.
Command line hosting service.
Scope is not remotable, and this only works in the same AppDomain.
Executes the comand line - depending upon the options provided we will
either run a single file, a single command, or enter the interactive loop.
Runs the command line. Languages can override this to provide custom behavior other than:
1. Running a single command
2. Running a file
3. Entering the interactive console loop.
Runs the specified filename
Starts the interactive loop. Performs any initialization necessary before
starting the loop and then calls RunInteractiveLoop to start the loop.
Returns the exit code when the interactive loop is completed.
Runs the interactive loop. Repeatedly parse and run interactive actions
until an exit code is received. If any exceptions are unhandled displays
them to the console
Attempts to run a single interaction and handle any language-specific
exceptions. Base classes can override this and call the base implementation
surrounded with their own exception handling.
Returns null if successful and execution should continue, or an exit code.
Parses a single interactive command or a set of statements and executes it.
Returns null if successful and execution should continue, or the appropiate exit code.
We check if the code read is an interactive command or statements is by checking for NewLine
If the code contains NewLine, it's a set of statements (most probably from SendToConsole)
If the code does not contain a NewLine, it's an interactive command typed by the user at the prompt
Private helper function to see if we should treat the current input as a blank link.
We do this if we only have auto-indent text.
Read a statement, which can potentially be a multiple-line statement suite (like a class declaration).
Should the console session continue, or did the user indicate
that it should be terminated?
Expression to evaluate. null for empty input
Gets the next level for auto-indentation
Core functionality to implement an interactive console. This should be derived for concrete implementations
Console Host entry-point .exe name.
Request (from another thread) the console REPL loop to terminate
The caller can specify the exitCode corresponding to the event triggering
the termination. This will be returned from CommandLine.Run
To be called from entry point.
name == null means that the argument doesn't specify an option; the value contains the entire argument
name == "" means that the option name is empty (argument separator); the value is null then
Literal script command given using -c option
Filename to execute passed on the command line options.
Only print the version of the script interpreter and exit
Used to dispatch a single interactive command. It can be used to control things like which Thread
the command is executed on, how long the command is allowed to execute, etc
Handles input and output for the console. It is comparable to System.IO.TextReader,
System.IO.TextWriter, System.Console, etc
Read a single line of interactive input, or a block of multi-line statements.
An event-driven GUI console can implement this method by creating a thread that
blocks and waits for an event indicating that input is available
The indentation level to be used for the current suite of a compound statement.
The console can ignore this argument if it does not want to support auto-indentation
null if the input stream has been closed. A string with a command to execute otherwise.
It can be a multi-line string which should be processed as block of statements
On error.
Supports detecting the remote runtime being killed, and starting up a new one.
Threading model:
ConsoleRestartManager creates a separate thread on which to create and execute the consoles.
There are usually atleast three threads involved:
1. Main app thread: Instantiates ConsoleRestartManager and accesses its APIs. This thread has to stay
responsive to user input and so the ConsoleRestartManager APIs cannot be long-running or blocking.
Since the remote runtime process can terminate asynchronously, the current RemoteConsoleHost can
change at any time (if auto-restart is enabled). The app should typically not care which instance of
RemoteConsoleHost is currently being used. The flowchart of this thread is:
Create ConsoleRestartManager
ConsoleRestartManager.Start
Loop:
Respond to user input | Send user input to console for execution | BreakExecution | RestartConsole | GetMemberNames
ConsoleRestartManager.Terminate
TODO: Currently, BreakExecution and GetMemberNames are called by the main thread synchronously.
Since they execute code in the remote runtime, they could take arbitrarily long. We should change
this so that the main app thread can never be blocked indefinitely.
2. Console thread: Dedicated thread for creating RemoteConsoleHosts and executing code (which could
take a long time or block indefinitely).
Wait for ConsoleRestartManager.Start to be called
Loop:
Create RemoteConsoleHost
Wait for signal for:
Execute code | RestartConsole | Process.Exited
3. CompletionPort async callbacks:
Process.Exited | Process.OutputDataReceived | Process.ErrorDataReceived
4. Finalizer thred
Some objects may have a Finalize method (which possibly calls Dispose). Not many (if any) types
should have a Finalize method.
Accessing _remoteConsoleHost from a thread other than console thread can result in race.
If _remoteConsoleHost is accessed while holding _accessLock, it is guaranteed to be
null or non-disposed.
This is created on the "creating thread", and goes on standby. Start needs to be called for activation.
A host might want one of two behaviors:
1. Keep the REPL loop alive indefinitely, even when a specific instance of the RemoteConsoleHost terminates normally
2. Close the REPL loop when an instance of the RemoteConsoleHost terminates normally, and restart the loop
only if the instance terminates abnormally.
Needs to be called for activation.
Request (from another thread) the console REPL loop to terminate
This allows the RemoteConsoleHost to abort a long-running operation. The RemoteConsoleHost itself
does not know which ThreadPool thread might be processing the remote call, and so it needs
cooperation from the remote runtime server.
Since OnOutputDataReceived is sent async, it can arrive late. The remote console
cannot know if all output from the current command has been received. So
RemoteCommandDispatcher writes out a marker to indicate the end of the output
Aborts the current active call to Execute by doing Thread.Abort
true if a Thread.Abort was actually called. false if there is no active call to Execute
Customize the CommandLine for remote scenarios
CommandDispatcher to ensure synchronize output from the remote runtime
ConsoleHost where the ScriptRuntime is hosted in a separate process (referred to as the remote runtime server)
The RemoteConsoleHost spawns the remote runtime server and specifies an IPC channel name to use to communicate
with each other. The remote runtime server creates and initializes a ScriptRuntime and a ScriptEngine, and publishes
it over the specified IPC channel at a well-known URI. Note that the RemoteConsoleHost cannot easily participate
in the initialization of the ScriptEngine as classes like LanguageContext are not remotable.
The RemoteConsoleHost then starts the interactive loop and executes commands on the ScriptEngine over the remoting channel.
The RemoteConsoleHost listens to stdout of the remote runtime server and echos it locally to the user.
Called if the remote runtime process exits by itself. ie. without the remote console killing it.
Allows the console to customize the environment variables, working directory, etc.
At the least, processInfo.FileName should be initialized
Aborts the current active call to Execute by doing Thread.Abort
true if a Thread.Abort was actually called. false if there is no active call to Execute
The remote runtime server uses this class to publish an initialized ScriptEngine and ScriptRuntime
over a remoting channel.
Publish objects so that the host can use it, and then block indefinitely (until the input stream is open).
Note that we should publish only one object, and then have other objects be accessible from it. Publishing
multiple objects can cause problems if the client does a call like "remoteProxy1(remoteProxy2)" as remoting
will not be able to know if the server object for both the proxies is on the same server.
The IPC channel that the remote console expects to use to communicate with the ScriptEngine
A intialized ScriptScope that is ready to start processing script commands
Class managing the command history.
List of available options
Cursor position management
Beginning position of the cursor - top coordinate.
Beginning position of the cursor - left coordinate.
The console input buffer.
Current position - index into the input buffer
The number of white-spaces displayed for the auto-indenation of the current line
Length of the output currently rendered on screen.
Command history
Tab options available in current context
Cursort anchor - position of cursor when the routine was called
The command line that this console is attached to.
Displays the next option in the option list,
or beeps if no options available for current input prefix.
If no input prefix, simply print tab.
Handle the enter key. Adds the current input (if not empty) to the history.
The input string.
The number of arguments including "this" for instance methods.
Instruction can't be created due to insufficient privileges.
Instruction can't be created due to insufficient privileges.
Gets the next type or null if no more types are available.
Uses reflection to create new instance of the appropriate ReflectedCaller
Fast creation works if we have a known primitive types for the entire
method siganture. If we have any non-primitive types then FastCreate
falls back to SlowCreate which works for all types.
Fast creation is fast because it avoids using reflection (MakeGenericType
and Activator.CreateInstance) to create the types. It does this through
calling a series of generic methods picking up each strong type of the
signature along the way. When it runs out of types it news up the
appropriate CallInstruction with the strong-types that have been built up.
One relaxation is that for return types which are non-primitive types
we can fallback to object due to relaxed delegates.
This instruction implements a goto expression that can jump out of any expression.
It pops values (arguments) from the evaluation stack that the expression tree nodes in between
the goto expression and the target label node pushed and not consumed yet.
A goto expression can jump into a node that evaluates arguments only if it carries
a value and jumps right after the first argument (the carried value will be used as the first argument).
Goto can jump into an arbitrary child of a BlockExpression since the block doesn’t accumulate values
on evaluation stack as its child expressions are being evaluated.
Goto needs to execute any finally blocks on the way to the target label.
{
f(1, 2, try { g(3, 4, try { goto L } finally { ... }, 6) } finally { ... }, 7, 8)
L: ...
}
The goto expression here jumps to label L while having 4 items on evaluation stack (1, 2, 3 and 4).
The jump needs to execute both finally blocks, the first one on stack level 4 the
second one on stack level 2. So, it needs to jump the first finally block, pop 2 items from the stack,
run second finally block and pop another 2 items from the stack and set instruction pointer to label L.
Goto also needs to rethrow ThreadAbortException iff it jumps out of a catch handler and
the current thread is in "abort requested" state.
The first instruction of finally block.
The last instruction of finally block.
The last instruction of a catch exception handler.
The last instruction of a fault exception handler.
Implements dynamic call site with many arguments. Wraps the arguments into .
Attaches a cookie to the last emitted instruction.
Instruction can't be created due to insufficient privileges.
Contains compiler state corresponding to a LabelTarget
See also LabelScopeInfo.
Returns true if we can jump into this node
A single interpreted frame might be represented by multiple subsequent Interpreter.Run CLR frames.
This method filters out the duplicate CLR frames.
A simple forth-style stack machine for executing Expression trees
without the need to compile to IL and then invoke the JIT. This trades
off much faster compilation time for a slower execution performance.
For code that is only run a small number of times this can be a
sweet spot.
The core loop in the interpreter is the RunInstructions method.
Runs instructions within the given frame.
Interpreted stack frames are linked via Parent reference so that each CLR frame of this method corresponds
to an interpreted stack frame in the chain. It is therefore possible to combine CLR stack traces with
interpreted stack traces by aligning interpreted frames to the frames of this method.
Each group of subsequent frames of Run method corresponds to a single interpreted frame.
Manages creation of interpreted delegates. These delegates will get
compiled if they are executed often enough.
true if the compiled delegate has the same type as the lambda;
false if the type was changed for interpretation.
Used by LightLambda to get the compiled delegate.
Create a compiled delegate for the LightLambda, and saves it so
future calls to Run will execute the compiled code instead of
interpreting.
Provides notification that the LightLambda has been compiled.
Visits a LambdaExpression, replacing the constants with direct accesses
to their StrongBox fields. This is very similar to what
ExpressionQuoter does for LambdaCompiler.
Also inserts debug information tracking similar to what the interpreter
would do.
Local variable mapping.
The variable that holds onto the StrongBox{object}[] closure from
the interpreter
A stack of variables that are defined in nested scopes. We search
this first when resolving a variable in case a nested scope shadows
one of our variable instances.
Walks the lambda and produces a higher order function, which can be
used to bind the lambda to a closure array from the interpreter.
The lambda to bind.
Variables which are being accessed defined in the outer scope.
A delegate that can be called to produce a delegate bound to the passed in closure array.
Provides a list of variables, supporing read/write of the values
Gets a copy of the local variables which are defined in the current scope.
Checks to see if the given variable is defined within the current local scope.
Gets the variables which are defined in an outer scope and available within the current scope.
Tracks where a variable is defined and what range of instructions it's used in
marks a field, class, or struct as being safe to have statics which can be accessed
from multiple runtimes.
Static fields which are not read-only or marked with this attribute will be flagged
by a test which looks for state being shared between runtimes. Before applying this
attribute you should ensure that it is safe to share the state. This is typically
state which is lazy initialized or state which is caching values which are identical
in all runtimes and are immutable.
Sets the value at the given index for a tuple of the given size. This set supports
walking through nested tuples to get the correct final index.
Gets the value at the given index for a tuple of the given size. This get
supports walking through nested tuples to get the correct final index.
Gets the unbound generic Tuple type which has at lease size slots or null if a large enough tuple is not available.
Creates a generic tuple with the specified types.
If the number of slots fits within the maximum tuple size then we simply
create a single tuple. If it's greater then we create nested tuples
(e.g. a Tuple`2 which contains a Tuple`128 and a Tuple`8 if we had a size of 136).
Gets the number of usable slots in the provided Tuple type including slots available in nested tuples.
Creates a new instance of tupleType with the specified args. If the tuple is a nested
tuple the values are added in their nested forms.
Gets the values from a tuple including unpacking nested values.
Gets the series of properties that needs to be accessed to access a logical item in a potentially nested tuple.
Gets the series of properties that needs to be accessed to access a logical item in a potentially nested tuple.
Provides an expression for creating a tuple with the specified values.
This class is useful for quickly collecting performance counts for expensive
operations. Usually this means operations involving either reflection or
code gen. Long-term we need to see if this can be plugged better into the
standard performance counter architecture.
temporary categories for quick investigation, use a custom key if you
need to track multiple items, and if you want to keep it then create
a new Categories entry and rename all your temporary entries.
Gets custom data to be serialized when saving script codes to disk.
ScriptCode is an instance of compiled code that is bound to a specific LanguageContext
but not a specific ScriptScope. The code can be re-executed multiple times in different
scopes. Hosting API counterpart for this class is CompiledCode.
This takes an assembly name including extension and saves the provided ScriptCode objects into the assembly.
The provided script codes can constitute code from multiple languages. The assemblyName can be either a fully qualified
or a relative path. The DLR will simply save the assembly to the desired location. The assembly is created by the DLR and
if a file already exists than an exception is raised.
The DLR determines the internal format of the ScriptCode and the DLR can feel free to rev this as appropriate.
This will take an assembly object which the user has loaded and return a new set of ScriptCode’s which have
been loaded into the provided ScriptDomainManager.
If the language associated with the ScriptCode’s has not already been loaded the DLR will load the
LanguageContext into the ScriptDomainManager based upon the saved LanguageContext type.
If the LanguageContext or the version of the DLR the language was compiled against is unavailable a
TypeLoadException will be raised unless policy has been applied by the administrator to redirect bindings.
Provides a StreamContentProvider for a stream of content backed by a file on disk.
Converts a generic ICollection of T into an array of T.
If the collection is already an array of T the original collection is returned.
Converts a generic ICollection of T into an array of R using a given conversion.
If the collection is already an array of R the original collection is returned.
Provides a dictionary-like object used for caches which holds onto a maximum
number of elements specified at construction time.
This class is not thread safe.
Creates a dictionary-like object used for caches.
The maximum number of elements to store.
Tries to get the value associated with 'key', returning true if it's found and
false if it's not present.
Adds a new element to the cache, replacing and moving it to the front if the
element is already present.
Returns the value associated with the given key, or throws KeyNotFoundException
if the key is not present.
Not all .NET enumerators throw exceptions if accessed in an invalid state. This type
can be used to throw exceptions from enumerators implemented in IronPython.
Wraps the provided enumerable into a ReadOnlyCollection{T}
Copies all of the data into a new array, so the data can't be
changed after creation. The exception is if the enumerable is
already a ReadOnlyCollection{T}, in which case we just return it.
Allows wrapping of proxy types (like COM RCWs) to expose their IEnumerable functionality
which is supported after casting to IEnumerable, even though Reflection will not indicate
IEnumerable as a supported interface
Requires the specified index to point inside the array.
Array is null.
Index is outside the array.
Requires the specified index to point inside the array.
Index is outside the array.
Requires the specified index to point inside the array or at the end
Array is null.
Index is outside the array.
Requires the specified index to point inside the array or at the end
Array is null.
Index is outside the array.
Requires the range [offset, offset + count] to be a subset of [0, array.Count].
Offset or count are out of range.
Requires the range [offset, offset + count] to be a subset of [0, array.Count].
Offset or count are out of range.
Requires the range [offset, offset + count] to be a subset of [0, array.Count].
Array is null.
Offset or count are out of range.
Requires the range [offset, offset + count] to be a subset of [0, array.Count].
String is null.
Offset or count are out of range.
Requires the array and all its items to be non-null.
Requires the enumerable collection and all its items to be non-null.
List optimized for few writes and multiple reads. It provides thread-safe read and write access.
Iteration is not thread-safe by default, but GetCopyForRead allows for iteration
without taking a lock.
Gets a copy of the contents of the list. The copy will not change even if the original
CopyOnWriteList object is modified. This method should be used to iterate the list in
a thread-safe way if no lock is taken. Iterating on the original list is not guaranteed
to be thread-safe.
The returned copy should not be modified by the caller.
Presents a flat enumerable view of multiple dictionaries
Returns the list of expressions represented by the instances.
An array of instances to extract expressions from.
The array of expressions.
Creates an instance of for a runtime value and the expression that represents it during the binding process.
The runtime value to be represented by the .
An expression to represent this during the binding process.
The new instance of .
Produces an interpreted binding using the given binder which falls over to a compiled
binding after hitCount tries.
This method should be called whenever an interpreted binding is required. Sometimes it will
return a compiled binding if a previous binding was produced and it's hit count was exhausted.
In this case the binder will not be called back for a new binding - the previous one will
be used.
The delegate type being used for the call site
The binder used for the call site
The number of calls before the binder should switch to a compiled mode.
The arguments that are passed for the binding (as received in a BindDelegate call)
A delegate which represents the interpreted binding.
Expression which reduces to the normal test but under the interpreter adds a count down
check which enables compiling when the count down is reached.
Base class for storing information about the binding that a specific rule is applicable for.
We have a derived generic class but this class enables us to refer to it w/o having the
generic type information around.
This class tracks both the count down to when we should compile. When we compile we
take the Expression[T] that was used before and compile it. While this is happening
we continue to allow the interpreted code to run. When the compilation is complete we
store a thread static which tells us what binding failed and the current rule is no
longer functional. Finally the language binder will call us again and we'll retrieve
and return the compiled overload.
A hybrid dictionary which compares based upon object identity.
Seeks the first character of a specified line in the text stream.
The reader.
Line number. The current position is assumed to be line #1.
Returns true if the line is found, false otherwise.
Reads characters to a string until end position or a terminator is reached.
Doesn't include the terminator into the resulting string.
Returns null, if the reader is at the end position.
Reads characters until end position or a terminator is reached.
Returns true if the character has been found (the reader is positioned right behind the character),
false otherwise.
Calculates the quotient of two 32-bit signed integers rounded towards negative infinity.
Dividend.
Divisor.
The quotient of the specified numbers rounded towards negative infinity, or (int)Floor((double)x/(double)y)
.
is 0.
The caller must check for overflow (x = Int32.MinValue, y = -1)
Calculates the quotient of two 64-bit signed integers rounded towards negative infinity.
Dividend.
Divisor.
The quotient of the specified numbers rounded towards negative infinity, or (int)Floor((double)x/(double)y)
.
is 0.
The caller must check for overflow (x = Int64.MinValue, y = -1)
Calculates the remainder of floor division of two 32-bit signed integers.
Dividend.
Divisor.
The remainder of of floor division of the specified numbers, or x - (int)Floor((double)x/(double)y) * y
.
is 0.
Calculates the remainder of floor division of two 32-bit signed integers.
Dividend.
Divisor.
The remainder of of floor division of the specified numbers, or x - (int)Floor((double)x/(double)y) * y
.
is 0.
Behaves like Math.Round(value, MidpointRounding.AwayFromZero)
Needed because CoreCLR doesn't support this particular overload of Math.Round
Behaves like Math.Round(value, precision, MidpointRounding.AwayFromZero)
However, it works correctly on negative precisions and cases where precision is
outside of the [-15, 15] range.
(This function is also needed because CoreCLR lacks this overload.)
Evaluates a polynomial in v0 where the coefficients are ordered in increasing degree
Evaluates a polynomial in v0 where the coefficients are ordered in increasing degree
if reverse is false, and increasing degree if reverse is true.
A numerically precise version of sin(v0 * pi)
A numerically precise version of |sin(v0 * pi)|
Take the quotient of the 2 polynomials forming the Lanczos approximation
with N=13 and G=13.144565
Computes the Gamma function on positive values, using the Lanczos approximation.
Lanczos parameters are N=13 and G=13.144565.
Computes the Log-Gamma function on positive values, using the Lanczos approximation.
Lanczos parameters are N=13 and G=13.144565.
Thread safe dictionary that allows lazy-creation where readers will block for
the creation of the lazily created value. Call GetOrCreateValue w/ a key
and a callback function. If the value exists it is returned, if not the create
callback is called (w/o any locks held). The create call back will only be called
once for each key.
Helper class which stores the published value
Converts a boxed enum value to the underlying integer value.
Creates an open delegate for the given (dynamic)method.
Creates a closed delegate for the given (dynamic)method.
Gets a Func of CallSite, object * paramCnt, object delegate type
that's suitable for use in a non-strongly typed call site.
Returns true if the specified parameter is mandatory, i.e. is not optional and doesn't have a default value.
Yields all ancestors of the given type including the type itself.
Does not include implemented interfaces.
Like Type.GetInterfaces, but only returns the interfaces implemented by this type
and not its parents.
Enumerates extension methods in given assembly. Groups the methods by declaring namespace.
Uses a global cache if is true.
Binds occurances of generic parameters in against corresponding types in .
Invokes (parameter, type) for each such binding.
Returns false if the is structurally different from or if the binder returns false.
Determines if a given type matches the type that the method extends.
The match might be non-trivial if the extended type is an open generic type with constraints.
Splits text and optionally indents first lines - breaks along words, not characters.
Dictionary[TKey, TValue] is not thread-safe in the face of concurrent reads and writes. SynchronizedDictionary
provides a thread-safe implementation. It holds onto a Dictionary[TKey, TValue] instead of inheriting from
it so that users who need to do manual synchronization can access the underlying Dictionary[TKey, TValue].
This returns the raw unsynchronized Dictionary[TKey, TValue]. Users are responsible for locking
on it before accessing it. Also, it should not be arbitrarily handed out to other code since deadlocks
can be caused if other code incorrectly locks on it.
Provides fast strongly typed thread local storage. This is significantly faster than
Thread.GetData/SetData.
True if the caller will guarantee that all cleanup happens as the thread
unwinds.
This is typically used in a case where the thread local is surrounded by
a try/finally block. The try block pushes some state, the finally block
restores the previous state. Therefore when the thread exits the thread
local is back to it's original state. This allows the ThreadLocal object
to not check the current owning thread on retrieval.
Gets or sets the value for the current thread.
Gets the current value if its not == null or calls the provided function
to create a new value.
Calls the provided update function with the current value and
replaces the current value with the result of the function.
Replaces the current value with a new one and returns the old value.
Gets the StorageInfo for the current thread.
Called when the fast path storage lookup fails. if we encountered the Empty storage
during the initial fast check then spin until we hit non-empty storage and try the fast
path again.
Creates the StorageInfo for the thread when one isn't already present.
Helper class for storing the value. We need to track if a ManagedThreadId
has been re-used so we also store the thread which owns the value.
Caches type member lookup.
When enumerating members (methods, properties, events) of a type (declared or inherited) Reflection enumerates all
runtime members of the type and its base types and caches the result.
When looking for a member of a specific name Reflection still enumerates all and filters out those that don't match the name.
That's inefficient when looking for members of multiple names one by one.
Instead we build a map of name to member list and then answer subsequent queries by simply looking up the dictionary.
Returns a numerical code of the size of a type. All types get both a horizontal
and vertical code. Types that are lower in both dimensions have implicit conversions
to types that are higher in both dimensions.
Represents an array that has value equality.
Simple class for tracking a list of items and enumerating over them.
The items are stored in weak references; if the objects are collected,
they will not be seen when enumerating.
The type of the collection element.
Similar to Dictionary[TKey,TValue], but it also ensures that the keys will not be kept alive
if the only reference is from this collection. The value will be kept alive as long as the key
is alive.
This currently has a limitation that the caller is responsible for ensuring that an object used as
a key is not also used as a value in *any* instance of a WeakHash. Otherwise, it will result in the
object being kept alive forever. This effectively means that the owner of the WeakHash should be the
only one who has access to the object used as a value.
Currently, there is also no guarantee of how long the values will be kept alive even after the keys
get collected. This could be fixed by triggerring CheckCleanup() to be called on every garbage-collection
by having a dummy watch-dog object with a finalizer which calls CheckCleanup().
Check if any of the keys have gotten collected
Currently, there is also no guarantee of how long the values will be kept alive even after the keys
get collected. This could be fixed by triggerring CheckCleanup() to be called on every garbage-collection
by having a dummy watch-dog object with a finalizer which calls CheckCleanup().
Changes the semantics of GC handle to return null instead of throwing
an .
This class represents adler32 checksum algorithm.
This static method returns adler32 checksum of the buffer data
Implementation of the Deflate compression algorithm.
Deflate algorithm configuration parameters class
reduce lazy search above this match length
do not perform lazy search above this match length
quit search above this match length
Constructor which initializes class inner fields
Maximum memory level
Defalult compression method
Default memory level
Deflate class congiration table
block not completed, need more input or more output
Block internalFlush performed
Finish started, need only more output at next deflate
finish done, accept no more input or output
preset dictionary flag in zlib header
The deflate compression method
The size of the buffer
repeat previous bit length 3-6 times (2 bits of repeat count)
repeat a zero length 3-10 times (3 bits of repeat count)
repeat a zero length 11-138 times (7 bits of repeat count)
Gets or sets the Compression level.
Gets or sets the Number of bytes in the pending buffer.
Gets or sets the Output pending buffer.
Gets or sets the next pending byte to output to the stream.
Gets or sets a value indicating whether to suppress zlib header and adler32.
Pointer back to this zlib stream
As the name implies
Size of Pending_buf
UNKNOWN, BINARY or ASCII
STORED (for zip only) or DEFLATED
Value of internalFlush parameter for previous deflate call
LZ77 Window size (32K by default)
log2(w_size) (8..16)
w_size - 1
Sliding Window. Input bytes are ReadPos into the second half of the Window,
and move to the first half later to keep a dictionary of at least wSize
bytes. With this organization, matches are limited to a distance of
wSize-MAX_MATCH bytes, but this ensures that IO is always
performed with a length multiple of the block size. Also, it limits
the Window size to 64K, which is quite useful on MSDOS.
To do: use the user input buffer as sliding Window.
Actual size of Window: 2*wSize, except when the user input buffer is directly used as sliding Window.
Link to older string with same hash index. To limit the size of this
array to 64K, this link is maintained only for the last 32K strings.
An index in this array is thus a Window index modulo 32K.
Heads of the hash chains or NIL.
hash index of string to be inserted
number of elements in hash table
log2(hash_size)
hash_size-1
Number of bits by which ins_h must be shifted at each input
step. It must be such that after MIN_MATCH steps, the oldest
byte no longer takes part in the hash key, that is:
hash_shift * MIN_MATCH >= hash_bits
Window position at the beginning of the current output block. Gets negative when the Window is moved backwards.
length of best match
previous match
set if previous match exists
start of string to insert
start of matching string
number of valid bytes ahead in Window
Length of the best match at previous step. Matches not greater than this
are discarded. This is used in the lazy match evaluation.
To speed up deflation, hash chains are never searched beyond this
length. A higher limit improves compression ratio but degrades the speed.
Attempt to find a better match only when the current match is strictly
smaller than this value. This mechanism is used only for compression
levels >= 4.
favor or force Huffman coding
Use a faster search when the previous match is longer than this
Stop searching when current match exceeds this
literal and length tree
distance tree
Huffman tree for bit lengths
Desc for literal tree
desc for distance tree
desc for bit length tree
number of codes at each bit length for an optimal tree
heap used to build the Huffman trees
number of elements in the heap
element of largest frequency
Depth of each subtree used as tie breaker for trees of equal frequency
index for literals or lengths
Size of match buffer for literals/lengths. There are 4 reasons for
limiting lit_bufsize to 64K:
- frequencies can be kept in 16 bit counters
- if compression is not successful for the first block, all input
data is still in the Window so we can still emit a stored block even
when input comes from standard input. (This can also be done for
all blocks if lit_bufsize is not greater than 32K.)
- if compression is not successful for a file smaller than 64K, we can
even emit a stored file instead of a stored block (saving 5 bytes).
This is applicable only for zip (not gzip or zlib).
- creating new Huffman trees less frequently may not provide fast
adaptation to changes in the input data statistics. (Take for
example a binary file with poorly compressible code followed by
a highly compressible string table.) Smaller buffer sizes give
fast adaptation but have of course the overhead of transmitting
trees more frequently.
- I can't count above 4
running index in l_buf
index of pendig_buf
bit length of current block with optimal trees
bit length of current block with static trees
number of string matches in current block
bit length of EOB code for last block
Output buffer. bits are inserted starting at the bottom (least
significant bits).
Number of valid bits in bi_buf. All bits above the last valid bit
are always zero.
Default constructor
Initialization
Initialize the tree data structures for a new zlib stream.
Initializes block
Restore the heap property by moving down the tree starting at node k,
exchanging a node with the smallest of its two sons if necessary, stopping
when the heap property is re-established (each father smaller than its
two sons).
Scan a literal or distance tree to determine the frequencies of the codes
in the bit length tree.
Construct the Huffman tree for the bit lengths and return the index in
bl_order of the last bit length code to send.
Send the header for a block using dynamic Huffman trees: the counts, the
lengths of the bit length codes, the literal tree and the distance tree.
IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.
Send a literal or distance tree in compressed form, using the codes in
bl_tree.
Output a byte on the stream.
IN assertion: there is enough room in Pending_buf.
Adds a byte to the buffer
Send one empty static block to give enough lookahead for inflate.
This takes 10 bits, of which 7 may remain in the bit buffer.
The current inflate code requires 9 bits of lookahead. If the
last two codes for the previous block (real code plus EOB) were coded
on 5 bits or less, inflate may have only 5+3 bits of lookahead to decode
the last real code. In this case we send two empty static blocks instead
of one. (There are no problems if the previous block is stored or fixed.)
To simplify the code, we assume the worst case of last real code encoded
on one bit only.
Save the match info and tally the frequency counts. Return true if
the current block must be flushed.
Send the block data compressed using the given Huffman trees
Set the data type to ASCII or BINARY, using a crude approximation:
binary if more than 20% of the bytes are <= 6 or >= 128, ascii otherwise.
IN assertion: the fields freq of dyn_ltree are set and the total of all
frequencies does not exceed 64K (to fit in an int on 16 bit machines).
Flush the bit buffer, keeping at most 7 bits in it.
Flush the bit buffer and align the output on a byte boundary
Copy a stored block, storing first the length and its
one's complement if requested.
Flushes block
Copy without compression as much as possible from the input stream, return
the current block state.
This function does not insert new strings in the dictionary since
uncompressible data is probably not useful. This function is used
only for the level=0 compression option.
NOTE: this function should be optimized to avoid extra copying from
Window to Pending_buf.
Send a stored block
Determine the best encoding for the current block: dynamic trees, static
trees or store, and output the encoded block to the zip file.
Fill the Window when the lookahead becomes insufficient.
Updates strstart and lookahead.
IN assertion: lookahead less than MIN_LOOKAHEAD
OUT assertions: strstart less than or equal to window_size-MIN_LOOKAHEAD
At least one byte has been ReadPos, or _avail_in == 0; reads are
performed for at least two bytes (required for the zip translate_eol
option -- not supported here).
Compress as much as possible from the input stream, return the current
block state.
This function does not perform lazy evaluation of matches and inserts
new strings in the dictionary only for unmatched strings or for short
matches. It is used only for the fast compression options.
Same as above, but achieves better compression. We use a lazy
evaluation for matches: a match is finally adopted only if there is
no better match at the next Window position.
Finds the longest matching data part
Deflate algorithm initialization
ZStream object
Compression level
Window bits
A result code
Initializes deflate algorithm
ZStream object
Compression level
Operation result result code
Deflate algorithm initialization
ZStream object
Compression level
Window bits
Memory level
Compression strategy
Operation result code
Resets the current state of deflate object
Finish compression with deflate algorithm
Sets deflate algorithm parameters
Sets deflate dictionary
Performs data compression with the deflate algorithm
Static constructor initializes config_table
current inflate_block mode
if STORED, bytes left to copy
table lengths (14 bits)
index into blens (or border)
bit lengths of codes
bit length tree depth
bit length decoding tree
if CODES, current state
true if this block is the last block
single malloc for tree space
need check
check on output
Gets or sets the sliding window.
Gets or sets the one byte after sliding Window.
Gets or sets the Window ReadPos pointer.
Gets or sets the Window WritePos pointer.
Gets or sets the bits in bit buffer.
Gets or sets the bit buffer.
Resets this InfBlocks class instance
Block processing functions
Frees inner buffers
Sets dictionary
Returns true if inflate is currently at the End of a block generated
by Z_SYNC_FLUSH or Z_FULL_FLUSH.
copy as much as possible from the sliding Window to the output area
Inflate codes mode
This class is used by the InfBlocks class
current inflate_codes mode
length
pointer into tree
current index of the tree
ltree bits decoded per branch
dtree bits decoded per branch
literal/length/eob tree
literal/length/eob tree index
distance tree
distance tree index
Constructor which takes literal, distance trees, corresponding bites decoded for branches, corresponding indexes and a ZStream object
Constructor which takes literal, distance trees, corresponding bites decoded for branches and a ZStream object
Block processing method
An instance of the InfBlocks class
A ZStream object
A result code
Frees allocated resources
Fast inflate procedure. Called with number of bytes left to WritePos in Window at least 258
(the maximum string length) and number of input bytes available
at least ten. The ten bytes are six bytes for the longest length/
distance pair plus four bytes for overloading the bit buffer.
This enumeration contains modes of inflate processing
waiting for method byte
waiting for flag byte
four dictionary check bytes to go
three dictionary check bytes to go
two dictionary check bytes to go
one dictionary check byte to go
waiting for inflateSetDictionary
decompressing blocks
four check bytes to go
three check bytes to go
two check bytes to go
one check byte to go
finished check, done
got an error--stay here
current inflate mode
if FLAGS, method byte
computed check value
stream check value
if BAD, inflateSync's marker bytes count
flag for no wrapper
log2(Window size) (8..15, defaults to 15)
current inflate_blocks state
Resets the Inflate algorithm
A ZStream object
A result code
Finishes the inflate algorithm processing
A ZStream object
Operation result code
Initializes the inflate algorithm
A ZStream object
Window size
Operation result code
Runs inflate algorithm
A ZStream object
Flush strategy
Operation result code
Sets dictionary for the inflate operation
A ZStream object
An array of byte - dictionary
Dictionary length
Operation result code
Inflate synchronization
A ZStream object
Operation result code
Returns true if inflate is currently at the End of a block generated
by Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
implementation to provide an additional safety check. PPP uses Z_SYNC_FLUSH
but removes the length bytes of the resulting empty stored block. When
decompressing, PPP checks that at the End of input packet, inflate is
waiting for these length bytes.
Creates header remover.
As long as header is not completed, call to Remover.MoveNext() returns true and
adjust state of z.
Stream where gzip header will appear.
Contains utility information for the InfTree class
Given a list of code lengths and a maximum table size, make a set of
tables to decode that set of codes.
Return (int)ZLibResultCode.Z_OK on success, (int)ZLibResultCode.Z_DATA_ERROR if the given code set is incomplete (the tables are still built in this case), (int)ZLibResultCode.Z_DATA_ERROR if the input is invalid (an over-subscribed set of lengths), or (int)ZLibResultCode.Z_DATA_ERROR if not enough memory.
Build trees
Builds dynamic trees
Build fixed trees
Bit length codes must not exceed MAX_BL_BITS bits
This class represents a tree and is used in the Deflate class
The dynamic tree
Largest code with non zero frequency
the corresponding static tree
The dynamic tree
Largest code with non zero frequency
the corresponding static tree
Mapping from a distance to a distance code. dist is the distance - 1 and
must not have side effects. _dist_code[256] and _dist_code[257] are never
used.
Compute the optimal bit lengths for a tree and update the total bit length
for the current block.
IN assertion: the fields freq and dad are set, heap[heap_max] and
above are the tree nodes sorted by increasing frequency.
OUT assertions: the field count is set to the optimal bit length, the
array bl_count contains the frequencies for each bit length.
The length opt_len is updated; static_len is also updated if stree is
not null.
Construct one Huffman tree and assigns the code bit strings and lengths.
Update the total bit length for the current block.
IN assertion: the field freq is set for all tree elements.
OUT assertions: the fields count and code are set to the optimal bit length
and corresponding code. The length opt_len is updated; static_len is
also updated if stree is not null. The field max_code is set.
Generate the codes for a given tree and bit counts (which need not be
optimal).
IN assertion: the array bl_count contains the bit length statistics for
the given tree and the field count is set for all tree elements.
OUT assertion: the field code is set for all tree elements of non
zero code length.
Reverse the first count bits of a code, using straightforward code (a faster
method would use a table)
Some constants for specifying compression levels. Methods which takes a compression level as a parameter expects an integer value from 0 to 9. You can either specify an integer value or use constants for some most widely used compression levels.
No compression should be used at all.
Minimal compression, but greatest speed.
Maximum compression, but slowest.
Select default compression level (good compression, good speed).
Compression strategies. The strategy parameter is used to tune the compression algorithm. The strategy parameter only affects the compression ratio but not the correctness of the compressed output even if it is not set appropriately.
This strategy is designed for filtered data. Data which consists of mostly small values, with random distribution should use Z_FILTERED. With this strategy, less string matching is performed.
Z_HUFFMAN_ONLY forces Huffman encoding only (no string match)
The default strategy is the most commonly used. With this strategy, string matching and huffman compression are balanced.
Flush strategies
Do not internalFlush data, but just write data as normal to the output buffer. This is the normal way in which data is written to the output buffer.
Obsolete. You should use Z_SYNC_FLUSH instead.
All pending output is flushed to the output buffer and the output is aligned on a byte boundary, so that the decompressor can get all input data available so far.
All output is flushed as with Z_SYNC_FLUSH, and the compression state is reset so that decompression can restart from this point if previous compressed data has been damaged or if random access is desired. Using Z_FULL_FLUSH too often can seriously degrade the compression. ZLib_InflateSync will locate points in the compression string where a full has been performed.
Notifies the module that the input has now been exhausted. Pending input is processed, pending output is flushed and calls return with Z_STREAM_END if there was enough output space.
Results of operations in ZLib library
No failure was encountered, the operation completed without problem.
No failure was encountered, and the input has been exhausted.
A preset dictionary is required for decompression of the data.
An internal error occurred
The stream structure was inconsistent
Input data has been corrupted (for decompression).
Memory allocation failed.
There was not enough space in the output buffer.
The version supplied does not match that supported by the ZLib module.
States of deflate operation
Data block types, i.e. binary or ascii text
Helper class
Copies large array which was passed as srcBuf to the Initialize method into the destination array which were passes as destBuff
The number of bytes copied
Max Window size
preset dictionary flag in zlib header
The size of the buffer
Deflate compression method index
This method returns the literal value received
The literal to return
The received value
This method returns the literal value received
The literal to return
The received value
This method returns the literal value received
The literal to return
The received value
This method returns the literal value received
The literal to return
The received value
Performs an unsigned bitwise right shift with the specified number
Number to operate on
Ammount of bits to shift
The resulting number from the shift operation
Performs an unsigned bitwise right shift with the specified number
Number to operate on
Ammount of bits to shift
The resulting number from the shift operation
Performs an unsigned bitwise right shift with the specified number
Number to operate on
Ammount of bits to shift
The resulting number from the shift operation
Performs an unsigned bitwise right shift with the specified number
Number to operate on
Ammount of bits to shift
The resulting number from the shift operation
Reads a number of characters from the current source Stream and writes the data to the target array at the specified index.
The source Stream to ReadPos from.
Contains the array of characters ReadPos from the source Stream.
The starting index of the target array.
The maximum number of characters to ReadPos from the source Stream.
The number of characters ReadPos. The number will be less than or equal to count depending on the data available in the source Stream. Returns -1 if the End of the stream is reached.
Reads a number of characters from the current source TextReader and writes the data to the target array at the specified index.
The source TextReader to ReadPos from
Contains the array of characteres ReadPos from the source TextReader.
The starting index of the target array.
The maximum number of characters to ReadPos from the source TextReader.
The number of characters ReadPos. The number will be less than or equal to count depending on the data available in the source TextReader. Returns -1 if the End of the stream is reached.
Converts a string to an array of bytes
The string to be converted
The new array of bytes
Converts an array of bytes to an array of chars
The array of bytes to convert
The new array of chars
see definition of array dist_code below
ZStream is used to store user data to compress/decompress.
Maximum memory level
Next input byte array
Index of the first byte in the input array.
Number of bytes available at _next_in
total nb of input bytes ReadPos so far
Byte array for the next output block
Index of the first byte in the _next_out array
Remaining free space at _next_out
Total number of bytes in output array
A string to store operation result message (corresponding to result codes)
A deflate object to perform data compression
Inflate object to perform data decompression
Adler-32 value for uncompressed data processed so far.
Best guess about the data type: ascii or binary
Gets/Sets the next input byte array.
Index of the first byte in the input array.
Gets/Sets the number of bytes available in the input buffer.
Gets/Sets the total number of bytes in the input buffer.
Gets/Sets the buffer for the next output data.
Gets/Sets the index of the first byte in the byte array to write to.
Gets/Sets the remaining free space in the buffer.
Gets/Sets the total number of bytes in the output array.
Gets sets the last error message occurred during class operations.
A deflate object to perform data compression
Inflate object to perform data decompression
Initializes the internal stream state for decompression. The fields , must be
initialized before by the caller. If is not null and is large
enough (the exact value depends on the compression method), determines the compression
method from the ZLib header and allocates all data structures accordingly; otherwise the allocation will be deferred
to the first call of .
inflateInit returns if success, if there was not enough memory,
if the ZLib library version is incompatible with the version assumed by the caller.
is set to null if there is no error message. does not perform any decompression
apart from reading the ZLib header if present: this will be done by . (So and
may be modified, but and are unchanged.)
This is another version of with an extra parameter. The fields , must be
initialized before by the caller. If is not null and is large enough
(the exact value depends on the compression method), determines the compression method from
the ZLib header and allocates all data structures accordingly; otherwise the allocation will be deferred to the first
call of .
The windowBits parameter is the base two logarithm of the maximum window size (the size of the history buffer).
It should be in the range 8..15 for this version of the library. The default value is 15 if is used instead.
If a compressed stream with a larger window size is given as input, will return with the error code
instead of trying to allocate a larger window.
inflateInit returns if success, if there was not enough memory,
if a parameter is invalid (such as a negative memLevel). is set to null
if there is no error message. does not perform any decompression apart from reading the ZLib header
if present: this will be done by . (So and may be modified,
but and are unchanged.)
This method decompresses as much data as possible, and stops when the input buffer () becomes empty or
the output buffer () becomes full. It may some introduce some output latency (reading input without producing any output)
except when forced to flush.
The detailed semantics are as follows. performs one or both of the following actions:
- Decompress more input starting at and update and
accordingly. If not all input can be processed (because there is not enough room in the output buffer), is updated and
processing will resume at this point for the next call of .
- Provide more output starting at and update and
accordingly. provides as much output as possible, until there is no more input data or no more space in
the output buffer (see below about the parameter).
Flush strategy to use.
Before the call of , the application should ensure that at least one of the actions is possible, by providing
more input and/or consuming more output, and updating the next_* and avail_* values accordingly. The application can consume the uncompressed
output when it wants, for example when the output buffer is full (avail_out == 0), or after each call of .
If returns and with zero , it must be called again
after making room in the output buffer because there might be more output pending.
If the parameter is set to , flushes
as much output as possible to the output buffer. The flushing behavior of is not specified for values of
the parameter other than and ,
but the current implementation actually flushes as much output as possible anyway.
should normally be called until it returns or an error.
However if all decompression is to be performed in a single step (a single call of inflate), the parameter
should be set to . In this case all pending input is processed and all pending output is flushed;
must be large enough to hold all the uncompressed data. (The size of the uncompressed data may have been
saved by the compressor for this purpose.) The next operation on this stream must be to deallocate the decompression
state. The use of is never required, but can be used to inform that a faster
routine may be used for the single call.
If a preset dictionary is needed at this point (see ), sets strm-adler
to the adler32 checksum of the dictionary chosen by the compressor and returns ; otherwise it
sets strm->adler to the adler32 checksum of all output produced so far (that is, bytes) and returns
, or an error code as described below. At the end of the stream,
) checks that its computed adler32 checksum is equal to that saved by the compressor and returns
only if the checksum is correct.
returns if some progress has been made (more input processed or more output produced),
if the end of the compressed data has been reached and all uncompressed output has been produced,
if a preset dictionary is needed at this point, if
the input data was corrupted (input stream not conforming to the ZLib format or incorrect adler32 checksum),
if the stream structure was inconsistent (for example if or
was null), if there was not enough memory,
if no progress is possible or if there was not enough room in the output buffer
when is used. In the case, the application
may then call to look for a good compression block.
All dynamically allocated data structures for this stream are freed. This function discards any unprocessed input and does not flush any
pending output.
inflateEnd returns if success,
if the stream state was inconsistent. In the error case, msg may be set but then points to a static string (which must not be deallocated).
Skips invalid compressed data until a full flush point (see the description of deflate with Z_FULL_FLUSH) can be found,
or until all available input is skipped. No output is provided.
returns if a full flush point has been found,
if no more input was provided, if no flush point has been found, or
if the stream structure was inconsistent. In the success case, the application may save the current
current value of which indicates where valid compressed data was found. In the error case, the application may repeatedly
call , providing more input each time, until success or end of the input data.
Initializes the decompression dictionary from the given uncompressed byte sequence. This function must be called immediately after a call of if this call returned . The dictionary chosen by the compressor can be determined from the Adler32 value returned by this call of . The compressor and decompresser must use exactly the same dictionary.
A byte array - a dictionary.
The length of the dictionary.
inflateSetDictionary returns if success, if a parameter is invalid (such as null dictionary) or the stream state is inconsistent, if the given dictionary doesn't match the expected one (incorrect Adler32 value). inflateSetDictionary does not perform any decompression: this will be done by subsequent calls of .
Initializes the internal stream state for compression.
An integer value from 0 to 9 indicating the desired compression level.
DeflateInit returns if success, if there was not enough memory,
if level is not a valid compression level. is set to null if there is
no error message. does not perform any compression: this will be done by .
Initializes the internal stream state for compression.
An integer value from 0 to 9 indicating the desired compression level.
The windowBits parameter is the base two logarithm of the window size (the size of the history buffer). It should be in the
range 8..15 for this version of the library. Larger values of this parameter result in better compression at the expense of memory usage.
The default value is 15 if DeflateInit is used instead.
DeflateInit returns if success, if there was not enough memory,
if level is not a valid compression level. is set to null if there
is no error message. does not perform any compression: this will be done by .
Deflate compresses as much data as possible, and stops when the input buffer becomes empty or the
output buffer becomes full. It may introduce some output latency (reading input without producing any output)
except when forced to flush.
The detailed semantics are as follows. deflate performs one or both of the following actions:
- Compress more input starting at and update and accordingly.
If not all input can be processed (because there is not enough room in the output buffer), and
are updated and processing will resume at this point for the next call of .
- Provide more output starting at and update and accordingly.
This action is forced if the parameter flush is non zero. Forcing flush frequently degrades the compression ratio, so this parameter should
be set only when necessary (in interactive applications). Some output may be provided even if flush is not set.
The flush strategy to use.
Before the call of , the application should ensure that at least one of the actions is possible, by providing
more input and/or consuming more output, and updating or accordingly ;
should never be zero before the call. The application can consume the compressed output when it wants, for example when the output buffer is full
(avail_out == 0), or after each call of . If returns
and with zero , it must be called again after making room in the output buffer because there might be more output pending.
If the parameter is set to , all pending output is flushed to the
output buffer and the output is aligned on a byte boundary, so that the decompressor can get all input
data available so far. (In particular is zero after the call if enough output space has been provided before the call.)
Flushing may degrade compression for some compression algorithms and so it should be used only when necessary.
If flush is set to , all output is flushed as with ,
and the compression state is reset so that decompression can restart from this point if previous compressed data has been damaged or if
random access is desired. Using too often can seriously degrade the compression.
If deflate returns with == 0, this function must be called again with the same value of the flush
parameter and more output space (updated ), until the flush is complete ( returns with
non-zero ).
If the parameter is set to , pending input is processed, pending
output is flushed and deflate returns with if there was enough output space ;
if deflate returns with , this function must be called again with
and more output space (updated ) but no more input data, until it returns with
or an error. After deflate has returned , the only possible operation on the stream is
.
can be used immediately after if all the compression is to be
done in a single step. In this case, avail_out must be at least 0.1% larger than avail_in plus 12 bytes. If deflate does not return
Z_STREAM_END, then it must be called again as described above.
sets strm-> adler to the adler32 checksum of all input read so far (that is, bytes).
may update data_type if it can make a good guess about the input data type (Z_ASCII or Z_BINARY).
In doubt, the data is considered binary. This field is only for information purposes and does not affect the compression algorithm in any manner.
returns if some progress has been made (more input processed or more output produced),
if all input has been consumed and all output has been produced (only when flush is set to
), if the stream state was inconsistent (for example if
or was null), if no progress is possible
(for example or was zero).
All dynamically allocated data structures for this stream are freed. This function discards any unprocessed input and does not flush any pending
output.
deflateEnd returns if success, if the stream state was inconsistent,
if the stream was freed prematurely (some input or output was discarded). In the error case,
may be set but then points to a static string (which must not be deallocated).
Dynamically update the compression level and compression strategy. The interpretation of level is as in .
This can be used to switch between compression and straight copy of the input data, or to switch to a different kind of input data
requiring a different strategy. If the compression level is changed, the input available so far is compressed with the old level
(and may be flushed); the new level will take effect only at the next call of
An integer value indicating the desired compression level.
A flush strategy to use.
Before the call of , the stream state must be set as for a call of , since the
currently available input may have to be compressed and flushed. In particular, must be non-zero.
deflateParams returns if success, if the source stream
state was inconsistent or if a parameter was invalid, if was zero.
Initializes the compression dictionary from the given byte sequence without producing any compressed output. This function must be called
immediately after , before any call of . The compressor and decompressor must use
exactly the same dictionary (see ).
A byte array - a dictionary.
The length of the dictionary byte array
The dictionary should consist of strings (byte sequences) that are likely to be encountered later in the data to be compressed,
with the most commonly used strings preferably put towards the end of the dictionary. Using a dictionary is most useful when the data
to be compressed is short and can be predicted with good accuracy; the data can then be compressed better than with the default empty dictionary.
Depending on the size of the compression data structures selected by , a part of the dictionary may
in effect be discarded, for example if the dictionary is larger than the window size in . Thus the strings most likely
to be useful should be put at the end of the dictionary, not at the front.
Upon return of this function, adler is set to the Adler32 value of the dictionary; the decompresser may later use this value to determine
which dictionary has been used by the compressor. (The Adler32 value applies to the whole dictionary even if only a subset of the dictionary
is actually used by the compressor.)
deflateSetDictionary returns if success, or if a parameter
is invalid (such as null dictionary) or the stream state is inconsistent (for example if has already been
called for this stream or if the compression method is bsort). does not perform any compression:
this will be done by .
Flush as much pending output as possible. All output goes through this function so some applications may wish to
modify it to avoid allocating a large buffer and copying into it.
Read a new buffer from the current input stream, update the adler32 and total number of bytes read. All input goes
through this function so some applications may wish to modify it to avoid allocating a large buffer and copying from it.
Frees all inner buffers.
Exceptions that occur in ZStream
Default constructor.
Constructor which takes one parameter - an error message