/interpreter/tags/reactive-pattern-matching/src/edu/vub/at/objects/coercion/ATConversions.java

http://ambienttalk.googlecode.com/ · Java · 190 lines · 108 code · 15 blank · 67 comment · 0 complexity · bbeef956b5c3f4c7b614a3cae69bbbed MD5 · raw file

  1. /**
  2. * AmbientTalk/2 Project
  3. * ATConversions.java created on Jul 23, 2006 at 2:20:16 PM
  4. * (c) Programming Technology Lab, 2006 - 2007
  5. * Authors: Tom Van Cutsem & Stijn Mostinckx
  6. *
  7. * Permission is hereby granted, free of charge, to any person
  8. * obtaining a copy of this software and associated documentation
  9. * files (the "Software"), to deal in the Software without
  10. * restriction, including without limitation the rights to use,
  11. * copy, modify, merge, publish, distribute, sublicense, and/or
  12. * sell copies of the Software, and to permit persons to whom the
  13. * Software is furnished to do so, subject to the following
  14. * conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be
  17. * included in all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  20. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  21. * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  22. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  23. * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  24. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  25. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  26. * OTHER DEALINGS IN THE SOFTWARE.
  27. */
  28. package edu.vub.at.objects.coercion;
  29. import edu.vub.at.actors.ATActorMirror;
  30. import edu.vub.at.actors.ATAsyncMessage;
  31. import edu.vub.at.actors.ATFarReference;
  32. import edu.vub.at.actors.ATLetter;
  33. import edu.vub.at.actors.natives.NATFarReference;
  34. import edu.vub.at.eval.Import.DelegateMethod;
  35. import edu.vub.at.exceptions.InterpreterException;
  36. import edu.vub.at.exceptions.XTypeMismatch;
  37. import edu.vub.at.objects.ATBoolean;
  38. import edu.vub.at.objects.ATClosure;
  39. import edu.vub.at.objects.ATField;
  40. import edu.vub.at.objects.ATHandler;
  41. import edu.vub.at.objects.ATMessage;
  42. import edu.vub.at.objects.ATMethod;
  43. import edu.vub.at.objects.ATMethodInvocation;
  44. import edu.vub.at.objects.ATNumber;
  45. import edu.vub.at.objects.ATTable;
  46. import edu.vub.at.objects.ATTypeTag;
  47. import edu.vub.at.objects.grammar.ATAssignVariable;
  48. import edu.vub.at.objects.grammar.ATBegin;
  49. import edu.vub.at.objects.grammar.ATDefinition;
  50. import edu.vub.at.objects.grammar.ATExpression;
  51. import edu.vub.at.objects.grammar.ATMessageCreation;
  52. import edu.vub.at.objects.grammar.ATQuote;
  53. import edu.vub.at.objects.grammar.ATSplice;
  54. import edu.vub.at.objects.grammar.ATStatement;
  55. import edu.vub.at.objects.grammar.ATSymbol;
  56. import edu.vub.at.objects.grammar.ATUnquoteSplice;
  57. import edu.vub.at.objects.mirrors.NATIntrospectiveMirror;
  58. import edu.vub.at.objects.mirrors.NATMirage;
  59. import edu.vub.at.objects.natives.NATBoolean;
  60. import edu.vub.at.objects.natives.NATFraction;
  61. import edu.vub.at.objects.natives.NATNumber;
  62. import edu.vub.at.objects.natives.NATNumeric;
  63. import edu.vub.at.objects.natives.NATObject;
  64. import edu.vub.at.objects.natives.NATTable;
  65. import edu.vub.at.objects.natives.NATText;
  66. import edu.vub.at.objects.symbiosis.JavaClass;
  67. import edu.vub.at.objects.symbiosis.JavaMethod;
  68. import edu.vub.at.objects.symbiosis.JavaObject;
  69. import edu.vub.at.signals.ATBehavior;
  70. import edu.vub.at.signals.ATEventSource;
  71. /**
  72. * ATConversions is an interface defining all conversion methods between different
  73. * types of ambienttalk language elements. They are hidden from the language level
  74. * because they neither belong to base- nor meta-level.
  75. *
  76. * @author smostinc
  77. */
  78. public interface ATConversions {
  79. /**
  80. * Used to distinguish between symbol, assignment, splice in formal param list.
  81. */
  82. public boolean isSymbol() throws InterpreterException;
  83. /**
  84. * Used to check in <tt>o.m()@exp</tt> if exp is a table or not.
  85. */
  86. public boolean isTable() throws InterpreterException;
  87. /**
  88. * Used to recognize unquote-splice elements when quoting a table.
  89. */
  90. public boolean isUnquoteSplice() throws InterpreterException;
  91. /**
  92. * Used to distinguish between symbol, assignment, splice in formal param list
  93. */
  94. public boolean isVariableAssignment() throws InterpreterException;
  95. /**
  96. * Used to distinguish between symbol, assignment, splice in formal param list and
  97. * to recognize spliced elements during table evaluation.
  98. */
  99. public boolean isSplice() throws InterpreterException;
  100. /**
  101. * Used in message send expressions to print, to check between <tt><+</tt> and
  102. * <tt>./^/<-</tt> operators.
  103. */
  104. public boolean isMessageCreation() throws InterpreterException;
  105. /**
  106. * Used to identify type tags for comparison using <tt>==</tt>.
  107. */
  108. public boolean isTypeTag() throws InterpreterException;
  109. /**
  110. * Used when sending an asynchronous message, to determine whether to
  111. * invoke <tt>receive</tt> on the receiver object directly, or to pass
  112. * via the actor's queue first.
  113. */
  114. public boolean isFarReference() throws InterpreterException;
  115. public boolean isBehavior() throws InterpreterException;
  116. public ATClosure asClosure() throws InterpreterException;
  117. public ATSymbol asSymbol() throws InterpreterException;
  118. public ATTable asTable() throws InterpreterException;
  119. public ATBoolean asBoolean() throws InterpreterException;
  120. public ATNumber asNumber() throws InterpreterException;
  121. public ATMessage asMessage() throws InterpreterException;
  122. public ATField asField() throws InterpreterException;
  123. public ATMethod asMethod() throws InterpreterException;
  124. public ATMethodInvocation asMethodInvocation() throws InterpreterException;
  125. public ATHandler asHandler() throws InterpreterException;
  126. public ATTypeTag asTypeTag() throws InterpreterException;
  127. public ATFarReference asFarReference() throws InterpreterException;
  128. public ATAsyncMessage asAsyncMessage() throws InterpreterException;
  129. public ATActorMirror asActorMirror() throws InterpreterException;
  130. public ATLetter asLetter() throws InterpreterException;
  131. public ATBehavior asBehavior() throws InterpreterException;
  132. public ATEventSource asEventSource() throws InterpreterException;
  133. // Abstract Grammar Elements
  134. public ATStatement asStatement() throws InterpreterException;
  135. public ATDefinition asDefinition() throws InterpreterException;
  136. public ATExpression asExpression() throws InterpreterException;
  137. public ATBegin asBegin() throws InterpreterException;
  138. public ATQuote asQuote() throws InterpreterException;
  139. public ATMessageCreation asMessageCreation() throws InterpreterException;
  140. public ATUnquoteSplice asUnquoteSplice() throws InterpreterException;
  141. public ATAssignVariable asVariableAssignment() throws InterpreterException;
  142. public ATSplice asSplice() throws InterpreterException;
  143. // Native Value Elements
  144. // The isNative / asNative type-casting protocol is crucial for correct
  145. // semantics in the case of e.g. wrapped natives in a Coercer (for symbiosis)
  146. // Never use Java type-casts explicitly!
  147. public boolean isNativeBoolean();
  148. public boolean isNativeText();
  149. public boolean isAmbientTalkObject(); // distinguish native from non-native objects
  150. public boolean isCallFrame() throws InterpreterException; // distinguish call frames from objects
  151. public boolean isJavaObjectUnderSymbiosis();
  152. public boolean isJavaClassUnderSymbiosis();
  153. public boolean isJavaMethodUnderSymbiosis();
  154. public boolean isNativeField();
  155. public boolean isNativeFarReference();
  156. public boolean isNativeFraction();
  157. public boolean isNativeNumber();
  158. public boolean isNativeIntrospectiveMirror();
  159. public boolean isNativeDelegateMethod();
  160. public boolean isMirage();
  161. public NATObject asAmbientTalkObject() throws XTypeMismatch;
  162. public NATMirage asMirage() throws XTypeMismatch;
  163. public NATNumber asNativeNumber() throws XTypeMismatch;
  164. public NATFraction asNativeFraction() throws XTypeMismatch;
  165. public NATText asNativeText() throws XTypeMismatch;
  166. public NATTable asNativeTable() throws XTypeMismatch;
  167. public NATBoolean asNativeBoolean() throws XTypeMismatch;
  168. public NATNumeric asNativeNumeric() throws XTypeMismatch;
  169. public NATFarReference asNativeFarReference() throws XTypeMismatch;
  170. public NATIntrospectiveMirror asNativeIntrospectiveMirror() throws XTypeMismatch;
  171. public DelegateMethod asNativeDelegateMethod() throws XTypeMismatch;
  172. public JavaObject asJavaObjectUnderSymbiosis() throws XTypeMismatch;
  173. public JavaClass asJavaClassUnderSymbiosis() throws XTypeMismatch;
  174. public JavaMethod asJavaMethodUnderSymbiosis() throws XTypeMismatch;
  175. }