The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
CGStoreArrayElementOperation.cs
Go to the documentation of this file.
1 using System;
2 using TypeSystem.Operations;
3 using TypeSystem;
4 namespace CodeGeneration.Operations {
8  internal class CGStoreArrayElementOperation<T> : TypeSystemOperation where T : ILCodeGenerator {
9 
13  private T codeGenerator;
17  private int indent;
18 
19 
20  public CGStoreArrayElementOperation(T codeGenerator, int indent) {
21  this.codeGenerator = codeGenerator;
22  this.indent = indent;
23  }
24  public override object Exec(ClassType ct, object arg) {
25  this.codeGenerator.stelemRef(this.indent);
26  return null;
27  }
28  public override object Exec(StringType s, object arg) {
29  this.codeGenerator.stelemRef(this.indent);
30  return null;
31  }
32  public override object Exec(ArrayType a, object arg) {
33  this.codeGenerator.stelemRef(this.indent);
34  return null;
35  }
36  public override object Exec(TypeVariable t, object arg)
37  {
38  if (t.Substitution != null && !t.Substitution.IsValueType())
39  this.codeGenerator.stelemRef(this.indent);
40  else
41  {
42  String tempIndex = this.codeGenerator.NewLabel + "_temp";
43  String tempValue = this.codeGenerator.NewLabel + "_temp";
44  this.codeGenerator.WriteAuxiliarLocalVariable(this.indent, tempValue, "object");
45  this.codeGenerator.WriteAuxiliarLocalVariable(this.indent, tempIndex, "int32");
46  this.codeGenerator.stloc(this.indent, tempValue);
47  this.codeGenerator.stloc(this.indent, tempIndex);
48  this.codeGenerator.ldloc(this.indent, tempValue);
49  this.codeGenerator.ldloc(this.indent, tempIndex);
50  this.codeGenerator.CallVirt(this.indent, "instance", "void", "class [mscorlib]System.Array", "SetValue",
51  new string[] {"class [mscorlib]System.Object", "int32"});
52  }
53  return null;
54  }
55  public override object Exec(UnionType t, object arg) {
56  this.codeGenerator.stelemRef(this.indent);
57  return null;
58  }
59  public override object Exec(DoubleType d, object arg) {
60  this.codeGenerator.stelemDouble(this.indent);
61  return null;
62  }
63  public override object Exec(TypeExpression t, object arg) {
64  this.codeGenerator.stelemInt(this.indent);
65  return null;
66  }
67  }
68 
69 }
Representa a union type.
Definition: UnionType.cs:36
Representa an array type.
Definition: ArrayType.cs:35
Represent a string type.
Definition: StringType.cs:36
This class represent the entry wnen sending a message to an operation object derived from TypeExpress...
Abstract class that represents all different types.
Represents a generic type expression
Definition: TypeVariable.cs:36
abstract bool IsValueType()
True if type expression is a ValueType. Otherwise, false.
Represents a double type.
Definition: DoubleType.cs:36
TypeExpression Substitution
Gets the substitution; null if it does not exist
Represents a class type.
Definition: ClassType.cs:35