How are different types handled on the stack in CIL

Christian Ivicevic

Experimenting with ildasm to dive into CIL code it became obvious that CIL itself is working stack-based to support expressions like

IL_0001:    ldc.i4.s 13     ; 1f 0d
IL_0003:    stloc.0         ; 0a
IL_0004:    ldc.i4.s 31     ; 1f 1f
IL_0006:    stloc.1         ; 0b
IL_0007:    ldloc.0         ; 06
IL_0008:    ldloc.1         ; 07
IL_0009:    add             ; 58

Doing the same with float32 instead of int32 by using ldc.r4 <num> there is no difference in calling add thus making me wonder whether there are different stacks for different types or if there is only one stack which holds metadata which type a specific element has on the stack. Is there any information about the specific implementation in ECMA-335 or somewhere else?

Damien_The_Unbeliever

This is specifically addressed in Partition I, part 12 (from e.g. this pdf), which discusses the Virtual Execution System (VES):

As described below, CIL instructions do not specify their operand types. Instead, the CLI keeps track of operand types based on data flow and aided by a stack consistency requirement described below. For example, the single add instruction will add two integers or two floats from the stack.

And:

Most CIL instructions that deal with numbers take their operands from the evaluation stack (see §I.12.3.2.1), and these inputs have an associated type that is known to the VES. As a result, a single operation like add can have inputs of any numeric data type, although not all instructions can deal with all combinations of operand types.

Where I.12.1.4 goes into considerably more detail also.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Bootstrap: how to stack divs of different heights?

From Dev

Can the CIL evaluation stack contain value types?

From Dev

How are different signals handled in python

From Dev

How are different types stored in memory

From Dev

How are each of the iOS background fetch UIBackgroundFetchResult types handled after the completion handler is called?

From Dev

How to deserialize collection with different types?

From Dev

Cypher - How is negation handled?

From Dev

Different types have same signatures in CIL

From Dev

How are hash collisions handled?

From Dev

How is color handled in AppleScript?

From Dev

How is "<" in HTML handled by browsers?

From Dev

How strings are handled in java

From Dev

How session is handled?

From Dev

how to pass different types to a function

From Dev

How references are handled in memory

From Dev

How are arrays handled in memory?

From Dev

How to launch an Activity in different task stack?

From Dev

How to stack matrices with different size

From Dev

Can the CIL evaluation stack contain value types?

From Dev

How to connect different types of controllers?

From Dev

How to deserialize collection with different types?

From Dev

How is argv handled internally?

From Dev

How to get different types of ICMP

From Dev

Where is ICCs handled in the Android stack?

From Dev

How to create a stack of different types of variable?

From Dev

How to load different primitive datas to the operand stack

From Dev

How to return different types of arrays?

From Dev

numpy - stack two arrays with different types

From Dev

How to pass different types of activities