The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
CGRuntimeIsInstructionOperation.cs
Go to the documentation of this file.
1 using TypeSystem.Operations;
2 using TypeSystem;
3 using ErrorManagement;
4 using AST;
5 using Tools;
6 using System.Collections.Generic;
7 using CodeGeneration.ExceptionManagement;
8 namespace CodeGeneration.Operations {
12  public class CGRuntimeIsInstructionOperation <T> : TypeSystemOperation where T:ILCodeGenerator {
13  private T codeGenerator;
14  private int indent;
15  public CGRuntimeIsInstructionOperation(int indent, T codeGenerator) {
16  this.indent = indent;
17  this.codeGenerator = codeGenerator;
18  }
24  public override object Exec(IntType operand, object arg) {
25  string notACharLabel = this.codeGenerator.NewLabel;
26  string endLabel = this.codeGenerator.NewLabel;
27 
28  // * char to int
29  // * If we could promote to an integer, a Char could be on the stack
30  this.codeGenerator.dup(this.indent);
31  this.codeGenerator.isinst(this.indent, CharType.Instance);
32  this.codeGenerator.dup(this.indent);
33  this.codeGenerator.brfalse(this.indent, notACharLabel);
34  this.codeGenerator.br(this.indent, endLabel);
35  this.codeGenerator.WriteLabel(this.indent, notACharLabel);
36  this.codeGenerator.pop(this.indent);
37  this.codeGenerator.dup(this.indent);
38  this.codeGenerator.isinst(this.indent, IntType.Instance);
39  this.codeGenerator.WriteLabel(this.indent, endLabel);
40  return null;
41  }
47  public override object Exec(DoubleType operand, object arg) {
48  string notACharLabel = this.codeGenerator.NewLabel;
49  string notAInt32Label = this.codeGenerator.NewLabel;
50  string endLabel = this.codeGenerator.NewLabel;
51 
52  // * char to double or int to double
53  // * If we could promote to an double, a Char or a Int32 could be on the stack
54  this.codeGenerator.dup(this.indent);
55  this.codeGenerator.isinst(this.indent, CharType.Instance);
56  this.codeGenerator.dup(this.indent);
57  this.codeGenerator.brfalse(this.indent, notACharLabel);
58  this.codeGenerator.br(indent, endLabel);
59  this.codeGenerator.WriteLabel(this.indent, notACharLabel);
60  this.codeGenerator.pop(this.indent);
61  this.codeGenerator.dup(this.indent);
62  this.codeGenerator.isinst(this.indent, IntType.Instance);
63  this.codeGenerator.dup(this.indent);
64  this.codeGenerator.brfalse(this.indent, notAInt32Label);
65  this.codeGenerator.br(this.indent, endLabel);
66  this.codeGenerator.WriteLabel(this.indent, notAInt32Label);
67  this.codeGenerator.pop(this.indent);
68  this.codeGenerator.dup(this.indent);
69  this.codeGenerator.isinst(this.indent, DoubleType.Instance);
70  this.codeGenerator.WriteLabel(this.indent, endLabel);
71 
72  return null;
73  }
79  public override object Exec(TypeExpression operand, object arg) {
80  // * If not promotion is needed, we simply check the stack
81  // * Nothing to do if it is not a value type
82  this.codeGenerator.dup(this.indent);
83  this.codeGenerator.isinst(this.indent, operand);
84  return null;
85  }
91  public override object Exec(TypeVariable operand, object arg) {
92  if (!operand.IsValueType())
93  return null;
94  if (TypeExpression.Is<IntType>(operand))
95  return this.Exec(TypeExpression.As<IntType>(operand), arg);
96  if (TypeExpression.Is<DoubleType>(operand))
97  return this.Exec(TypeExpression.As<DoubleType>(operand), arg);
98  return this.Exec((TypeExpression)operand, arg);
99  }
100 
101 
102  public override object ReportError(TypeExpression tE) {
103  ErrorManager.Instance.NotifyError(new CodeGenerationError("No se ha definido la operación solicitada. El código generado es incorrecto"));
104  return null;
105  }
106 
107  }
108 
109 }
override bool IsValueType()
True if type expression is a ValueType. Otherwise, false.
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
override object Exec(TypeExpression operand, object arg)
The promotion coul be to other type, not IntType nor DoubleType
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...
override object Exec(DoubleType operand, object arg)
The promotion could be to a DoubleType
Represents a double type.
Definition: DoubleType.cs:36
override object Exec(TypeVariable operand, object arg)
It delegates the trying to promotion to other methods.
override object Exec(IntType operand, object arg)
The promotion could be to a IntType