Skip to content

Commit 5f2f48e

Browse files
committed
Elemten expressions working in lists and hash too!
1 parent a1d64d1 commit 5f2f48e

File tree

10 files changed

+795
-68
lines changed

10 files changed

+795
-68
lines changed

VM_CS/Interpreter/InstructionSet.cs

+36
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,39 @@ private void runJUMP_IF_FALSE(int target){
563563
}
564564
}
565565

566+
// Element access
567+
private void runBINARY_SUBSCR()
568+
{
569+
try
570+
{
571+
dynamic index = pilaExprs.pop();
572+
dynamic data = pilaExprs.pop();
573+
if (data.GetType() == typeof(List<dynamic>))
574+
{
575+
List<dynamic> list = data;
576+
pilaExprs.push(list[index]);
577+
578+
}
579+
else
580+
{
581+
Dictionary<dynamic, dynamic> hash = data;
582+
foreach (KeyValuePair<dynamic, dynamic> kvp in hash)
583+
{
584+
if (kvp.Key.ToString().Equals(index.ToString()))
585+
{
586+
pilaExprs.push(kvp.Value);
587+
}
588+
}
589+
}
590+
}
591+
catch (Exception e)
592+
{
593+
Console.WriteLine("SERVER> ERROR : ( " + actualInstrIndex + " ) " + "instruction in method BINARY_SUBSCR: " + e.Message);
594+
throw;
595+
}
596+
}
597+
598+
566599
// Hash
567600
private void runBUILD_CONST_KEY_MAP(int size)
568601
{
@@ -819,6 +852,9 @@ private void runMain(){
819852
case "BUILD_CONST_KEY_MAP":
820853
runBUILD_CONST_KEY_MAP(instSet[actualInstrIndex].Value);
821854
break;
855+
case "BINARY_SUBSCR":
856+
runBINARY_SUBSCR();
857+
break;
822858
//default:
823859
//throw new Exception("Instrucción no conocida : (" +actualInstrIndex + " )");
824860
}

VM_CS/bin/Debug/Minics.exe

2 KB
Binary file not shown.

VM_CS/bin/Debug/Minics.pdb

4 KB
Binary file not shown.

0 commit comments

Comments
 (0)