Question: Rewrite the list insertion method of Example C 16.40 in F# instead of C#. Compile to CIL and compare to the right side of Figure
Rewrite the list insertion method of Example C 16.40 in F# instead of C#. Compile to CIL and compare to the right side of Figure C 16.7. Discuss any differences you find.
Figure 16.7

. method private hidebysig public void insert (int v) { instance default void insert (int32 v) cil managed { // Method begins at RVA Ox210c // Code size 108 (Ox6c) // RVA == relative // virtual address .maxstack 3 .locals init ( class LLset/node // n V_0, V_1) class LLset/node // t node n = head; IL 0000: ldarg.0 IL_0001: ldfld class LLset/node LLset: :head IL_0006: stloc.0 // jump to header of rotated loop // n -- beginning of loop body IL_0007: br IL_0013 IL 000c: ldloc.0 IL 000d: 1dfld class LLset/node LLset/node::next IL 0012: stloc.0 -3- // n = n.next // n -- beginning of loop test while (n.next != null IL_0013: ldloc.0 &k n.next.val < v) { IL_0014: ldfld class LLset/node LLset/node: :next IL_0019: brfalse IL_002f // exit loop if n null // n IL_001e: ldloc.0 IL 001f: ldfld class LLset/node LLset/node::next IL 0024: 1dfld int32 LLset/node::val n = n.next; } // v // continue loop IL_0029: 1darg.1 IL_002a: blt IL 000c // n if (n.next == null || n.next.val > v) { IL_002f : ldloc.0 IL 0030: 1dfld class LLset/node LLset/node:: IL_0035: brfalse IL 004b IL_003a: ldloc.0 IL 003b: 1dfld class LLset/node LLset/node::nex IL 0040: 1dfld int32 LLset/node:: val next // n t // v IL_0045: ldarg.1 IL_0046: ble IL 006b IL_004b: newobj instance void class LLset/node::'.ctor' () IL 0050: stloc.1 IL_0051: ldloc.1 IL 0052: 1darg.1 IL 0053: stfld int32 LLset/node::val node t = new node (); // t // t // v t.val = v; // t // n IL_0058: ldloc.1 IL 0059: ldloc.0 IL_005a: ldfld class LLset/node LLset/node::next IL_005f: stfld class LLset/node LLset/node::next t.next = n.next; // n // t n.next = t; IL 0064: ldloc.0 IL_0065: 1dloc.1 IL 0066: stfld class LLset/node LLset/node::next } // else v already in set IL_006b: ret } // end of method LLset::insert
Step by Step Solution
3.54 Rating (157 Votes )
There are 3 Steps involved in it
ANSWER let insert v int let rec l... View full answer
Get step-by-step solutions from verified subject matter experts
