The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
CGRuntimeCheckArgumentOperation.cs
Go to the documentation of this file.
1 using TypeSystem.Operations;
2 using TypeSystem;
3 using ErrorManagement;
4 using System.Collections.Generic;
5 namespace CodeGeneration.Operations {
9  public class CGRuntimeCheckArgumentOperation <T> : TypeSystemOperation where T: ILCodeGenerator{
13  private List<string> nextMethod;
17  private T codeGenerator;
21  private int indent;
28  public CGRuntimeCheckArgumentOperation(int indent, T codeGenerator, List<string> nextMethod) {
29  this.indent = indent;
30  this.nextMethod = nextMethod;
31  this.codeGenerator = codeGenerator;
32  }
39  public override object Exec(TypeExpression operand, object arg) {
40  if (operand.IsValueType())
41  return null;
42  this.codeGenerator.dup(this.indent);
43  this.codeGenerator.isinst(this.indent, operand);
44  // if check fail then check nextMethod
45  this.nextMethod.Add(this.codeGenerator.NewLabel);
46  this.codeGenerator.brfalse(this.indent, nextMethod[nextMethod.Count - 1]);
47  return null;
48  }
56  private object MultiTypeExec(TypeExpression operand, object arg) {
57  this.codeGenerator.dup(this.indent);
58  this.codeGenerator.isinst(this.indent, operand);
59  // if check fail then check nextMethod
60  this.nextMethod.Add(this.codeGenerator.NewLabel);
61  this.codeGenerator.brfalse(this.indent, nextMethod[nextMethod.Count - 1]);
62  if (operand.IsValueType())
63  this.codeGenerator.UnboxAny(this.indent, operand);
64  return null;
65  }
72  public override object Exec(CharType operand, object arg) {
73  return this.MultiTypeExec(operand, arg);
74  }
81  public override object Exec(BoolType operand, object arg) {
82  return this.MultiTypeExec(operand, arg);
83  }
84 
92  public override object Exec(IntType operand, object arg) {
93  string nextArgument = this.codeGenerator.NewLabel;
94  CharType.Instance.AcceptOperation(new CGRuntimeCheckTypeExpressionOperation<T>(this.indent, this.codeGenerator, nextArgument, false), arg);
95  IntType.Instance.AcceptOperation(new CGRuntimeCheckTypeExpressionOperation<T>(this.indent, this.codeGenerator, nextArgument, false), arg);
96 
97  this.nextMethod.Add(this.codeGenerator.NewLabel);
98  this.codeGenerator.br(this.indent, this.nextMethod[this.nextMethod.Count - 1]);
99  this.codeGenerator.WriteLabel(this.indent, nextArgument);
100  return null;
101  }
109  public override object Exec(DoubleType operand, object arg) {
110  string nextArgument = this.codeGenerator.NewLabel;
111 
112  CharType.Instance.AcceptOperation(new CGRuntimeCheckTypeExpressionOperation<T>(this.indent, this.codeGenerator, nextArgument, true), arg);
113  IntType.Instance.AcceptOperation(new CGRuntimeCheckTypeExpressionOperation<T>(this.indent, this.codeGenerator, nextArgument, true), arg);
114  DoubleType.Instance.AcceptOperation(new CGRuntimeCheckTypeExpressionOperation<T>(this.indent, this.codeGenerator, nextArgument, true), arg);
115 
116  nextMethod.Add(this.codeGenerator.NewLabel);
117  this.codeGenerator.br(this.indent, this.nextMethod[this.nextMethod.Count - 1]);
118  this.codeGenerator.WriteLabel(this.indent, nextArgument);
119  return null;
120  }
121  public override object ReportError(TypeExpression tE) {
122  ErrorManager.Instance.NotifyError(new CodeGenerationError("No se ha definido la operación solicitada"));
123  return null;
124  }
125 
126  }
127 }
override object Exec(DoubleType operand, object arg)
Checks if the Double Type parameter passed (operand) matches with the proper argument. It makes to 3calls to CGRuntimeCheckTypeExpressionOperation operation. One using a CharType object, second with IntType object, and last usint a double type, all of them trying a convert to double (toDouble parameter = true)
This class represent the entry wnen sending a message to an operation object derived from TypeExpress...
Represent a character type.
Definition: CharType.cs:38
override object Exec(TypeExpression operand, object arg)
Checks if the parameter passed (operand) matches with the proper argument. In this method only proces...
override object Exec(IntType operand, object arg)
Checks if the IntType parameter passed (operand) matches with the proper argument. It makes to 2 calls to CGRuntimeCheckTypeExpressionOperation operation. One using a CharType object, and the other with IntType object, with no try to convert to double (toDouble parameter = false)
Abstract class that represents all different types.
override object Exec(CharType operand, object arg)
Checks if the CharType parameter passed (operand) matches with the proper argument. Finally, it perforns an unbox.any over the the operand
Represent a integer type.
Definition: IntType.cs:37
Represents a error produced when a MethodType has class information and tries to assign other class i...
abstract bool IsValueType()
True if type expression is a ValueType. Otherwise, false.
Represents a double type.
Definition: DoubleType.cs:36
It tries to convert the top of the stack to a Type Expression indicated by operand. Firstly it duplicates the top of the stack Next check if the top of he stack is the same type of argument &#39;operand&#39;. If the conversion is wrong. In a execution context we&#39;d&#39;ve finished so it&#39;s necessary to write an opcode jump, brfalse, to the end of this code (endLabel). Next it unboxes the result the top of the stack to the desired type. If a Convertion to double is requested, (member this.toDouble), it generates convToDouble If it success it jumps to the rest of code else it generates the label to jump if isinst fails.
override object Exec(BoolType operand, object arg)
Checks if the BoolType parameter passed (operand) matches with the proper argument. Finally, it perforns an unbox.any over the the operand
CGRuntimeCheckArgumentOperation(int indent, T codeGenerator, List< string > nextMethod)
Constructor of CGRuntimeCheckArgumentOperation
Represent a bool type.
Definition: BoolType.cs:36