parrotcode: Untitled | |
Contents | Language Implementations | .Net |
This document details the PMCs (Parrot Magic Cookies) that are used to read in .NET assemblies and provide access to the data held in them from PIR.
This PMC represents an entire .NET CLI EXE or DLL file. It handles loading of a .NET assembly and instantiates all other PMCs that relate to the assembly. It also provides access to some of the global data
# Load an .NET CLI DLL or EXE file.
$P1 = new .DotNetAssembly
$P1 = "Example.dll"
$P1.load()
# Get name of loaded file.
$S1 = $P1
# Is it a DLL?
$I1 = $P1.is_dll()
if $I1 = 0 goto EXE
print "This is a DLL\n"
goto CONTINUE
EXE:
print "This is an EXE file\n"
CONTINUE:
# Get an array of classes.
$P2 = $P1.get_classes()
# Get the globals pseudo-class.
$P3 = $P1.get_global()
Sets the filename of the .NET assembly to be loaded.
Gets the filename of the .NET assembly that is loaded or to be loaded.
With the exception of load, all of these methods should only be called when after the load method.
Attempts to load the .NET assembly whose filenmae is stored in the string representation of the PMC.
Returns a non-zero integer if the file is a DLL and zero otherwise.
Gets the string with at the position identifier i from the strings heap. This is the string heap that is used for internal identifiers and are UTF-8 encoded.
Gets the string at position i from the user strings heap. This is the string heap that is used for strings that make up various bits of user data. Strings on the user heap are encoded as 16-bit unicode.
Gets the blob at position i from the blobs heap. A blob is a lump of binary data; Parrot strings can handle these fine, though.
Returns a PMC array of classes that are defined by the assembly. Each element of the PMC array will be a DotNetClassMetadata PMC.
Returns an integer array specifying indexes into the PMC array of classes as returned by the get_classes method. This array provides an ordering that ensures parent types come before their children.
Returns a DotNetClassMetadata PMC representing the global pseudoclass. The fields and methods of this class are global variables/subs.
Returns a DotNetFieldMetadata PMC representing the field at the given row of the Field metadata table.
Returns a DotNetMethodMetadata PMC representing the method at the given row of the MethodDef metadata table.
Returns a PMC array of DotNetTypeRefMetadata PMCs, each one representing a type from an external module or assembly.
Returns a PMC array of DotNetMemberRefMetadata PMCs, each one representing a field or method (aka member) from an external module or assembly.
This PMC represents the metadata associated with a particular class.
# Imagining $P2 is an array of DotNetClassMetadata PMCs...
$P3 = $P2[0]
# Get name and namespace.
$S1 = $P3
$S2 = $P3.get_namespace()
# Get flags bit vector
$I1 = $P3.get_flags()
# Get fields and methods.
$P4 = $P3.get_fields()
$P5 = $P3.get_methods()
Gets the name of the class.
Returns a string that is the namespace the class is in.
Returns a bit vector of flags set on the method. For details of what the flags mean, see Partition II Clause 22.1.4 of the .NET Specification.
Returns a PMC array of fields belonging to this class. Each element of the PMC array will be a DotNetFieldMetadata PMC.
Returns a PMC array of methods belonging to this class. Each element of the PMC array will be a DotNetMethodMetadata PMC.
Returns the ID of the parent class.
Returns the type of the parent class ID - that is, whether it is a type in the current assembly or in another one.
Returns an integer array PMC containing the IDs of the interfaces that the type implements.
Returns an integer array PMC containing the type of each of the IDs that was returned by get_interface_ids.
This PMC represents the metadata associated with a particular method. Note that some additional metadata about a method is stored in a seperate header preceding the instruction stream itself. This data is not accessible through this PMC; the DotNetBytecode PMC provides access to that.
# Imagine $P1 contains an array of DotNetMethodMetadata PMCs...
$P2 = $P1[0]
# Get the name of the method.
$S1 = $P2
# Get the position of the blob holding a signature for the method.
$I0 = $P2.get_signature()
# Get flags bit vector
$I1 = $P2.get_flags()
# Get the method implementation (a DotNetBytecode PMC).
$P4 = $P2.get_bytecode()
# Get parameters (an array of DotNetParamMetadata PMCs).
$P5 = $P2.get_params()
Gets the name of the method.
Returns an integer specifying the position in the blobs heap of the signature for the method.
Returns a bit vector of flags set on the method. For details of what the flags mean, see Partition II Clause 22.1.9 of the .NET Specification.
Returns a DotNetBytecode PMC that allows the bytecode that specifies the method body to be walked over easily.
Returns a PMC array of DotNetParamMetadata PMCs, one describing each of the parameters of the method.
This PMC represents the metadata associated with a particular field.
# Imagine $P1 contains an array of DotNetFieldMetadata PMCs...
$P2 = $P1[0]
# Get the name of the field.
$S1 = $P2
# Get the position of the blob holding a signature for the field.
$I0 = $P2.get_signature()
# Get flags bit vector
$I1 = $P2.get_flags()
Gets the name of the field.
Returns an integer specifying the position in the blobs heap of the signature for the field.
Returns a bit vector of flags set on the field. For details of what the flags mean, see Partition II Clause 22.1.5 of the .NET Specification.
No handling of fields with some RVAs.
This PMC represents a parameter of a method.
# Imagine $P1 contains an array of DotNetParamMetadata PMCs...
$P2 = $P1[0]
# Get the name of the parameter.
$S1 = $P2
# Get flags for the parameter.
$I0 = $P2.get_flags()
# Get sequence number.
$I1 = $P2.get_sequence()
Gets the name of the parameter.
Returns a bit vector of flags set on the parameter. For details of what the flags mean, see Partition II Clause 22.1.12 of the .NET Specification.
Returns an integer specifying the sequence number of the parameter. This is the position of the parameter. Sequence number 0 corresponds to the return value rather than a parameter. Sequence numbers should then increase, according to the .NET specification, however gaps are allowed. Quite what a gap in the sequence would imply is unclear, however.
Signatures in .NET are represented as binary blobs of data. This PMC, one assigned a string representing a blob, provides some assistance to programs walking signatures, hiding away the compression scheme. This PMC does not understand the structure of different types of signature.
$P0 = new DotNetSignature
$S0 = assembly.get_blob(blob_position)
$P0 = $S0
type = $P0.read_byte()
# etc
Assigns a string containing the concents of the signature blob. This must be done before any other operations are performed or an exception will be thrown. Doing this also resets the current internal position pointer to zero.
Reads 1 unsigned byte of data. Updates the internal current position pointer.
Reads a compressed integer, compressed according to the method described in Partition II Section 22.2 of the .NET specification. Updates the current internal position pointer.
This PMC provides useful methods for walking .NET CLI instruction streams and accessing data in the metadata encoded within the instruction stream, rather than the main metadata tables.
$P0.set_pos(0)
$I0 = $P0.read_uint8()
$N0 = $P0.read_float32()
$I1 = $P0.get_pos() # $I1 will contain 5
None.
Returns an integer specifying the position in the blobs heap of the signature for the local variables of the method.
Returns an integer that is 0 if the initialize locals flag is set for the method and a non-zero value if it is.
Returns a PMC array of DotNetEH (.NET exception handdler info) PMCs.
Returns an integer value specifying the current offset into the instruction stream that is being held. This position is changed when any of the read_* methods are called.
Sets the current offset into the instruction stream that is being held.
Reads a signed 8-bit integer and returns it as a native sized integer. Increments the current read position by 1 byte.
Reads an unsigned 8-bit integer and returns it as a native sized integer. Increments the current read position by 1 byte.
Reads a signed 16-bit integer and returns it as a native sized integer. Increments the current read position by 2 bytes.
Reads an unsigned 16-bit integer and returns it as a native sized integer. Increments the current read position by 2 bytes.
Reads a signed 32-bit integer and returns it as a native sized integer. Increments the current read position by 4 bytes.
Reads an unsigned 32-bit integer and returns it as a native sized integer. Increments the current read position by 4 bytes.
Reads a 32-bit (single precision) float and returns it as the native sized floating point number type used for Parrot's N registers. Increments the current read position by 4 bytes.
Reads a 64-bit (single precision) float and returns it as the native sized floating point number type used for Parrot's N registers. Increments the current read position by 8 bytes.
Subtle issues relating to 32-bit unsigned integers and I registers, 64-bit integers.
This PMC represents the metadata associated with a type in an external module.
# Imagining $P2 is an array of DotNetTypeRefMetadata PMCs...
$P3 = $P2[0]
# Get name and namespace.
$S1 = $P3
$S2 = $P3.get_namespace()
# Get resolution scope.
$I1 = $P3.get_resolution_scope()
Gets the name of the class.
Returns a string that is the namespace the class is in.
Returns an integer that defines the module or assembly containing the implementation of the type.
XXX TO DO
XXX TO DO
|