/interpreter/tags/at2dist030708/src/edu/vub/at/objects/coercion/ATConversions.java

http://ambienttalk.googlecode.com/ · Java · 182 lines · 103 code · 12 blank · 67 comment · 0 complexity · 5cc6e1d9665b09034f4fc4783061d5ec 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. /**
  70. * ATConversions is an interface defining all conversion methods between different
  71. * types of ambienttalk language elements. They are hidden from the language level
  72. * because they neither belong to base- nor meta-level.
  73. *
  74. * @author smostinc
  75. */
  76. public interface ATConversions {
  77. /**
  78. * Used to distinguish between symbol, assignment, splice in formal param list.
  79. */
  80. public boolean isSymbol() throws InterpreterException;
  81. /**
  82. * Used to check in <tt>o.m()@exp</tt> if exp is a table or not.
  83. */
  84. public boolean isTable() throws InterpreterException;
  85. /**
  86. * Used to recognize unquote-splice elements when quoting a table.
  87. */
  88. public boolean isUnquoteSplice() throws InterpreterException;
  89. /**
  90. * Used to distinguish between symbol, assignment, splice in formal param list
  91. */
  92. public boolean isVariableAssignment() throws InterpreterException;
  93. /**
  94. * Used to distinguish between symbol, assignment, splice in formal param list and
  95. * to recognize spliced elements during table evaluation.
  96. */
  97. public boolean isSplice() throws InterpreterException;
  98. /**
  99. * Used in message send expressions to print, to check between <tt><+</tt> and
  100. * <tt>./^/<-</tt> operators.
  101. */
  102. public boolean isMessageCreation() throws InterpreterException;
  103. /**
  104. * Used to identify type tags for comparison using <tt>==</tt>.
  105. */
  106. public boolean isTypeTag() throws InterpreterException;
  107. /**
  108. * Used when sending an asynchronous message, to determine whether to
  109. * invoke <tt>receive</tt> on the receiver object directly, or to pass
  110. * via the actor's queue first.
  111. */
  112. public boolean isFarReference() throws InterpreterException;
  113. public ATClosure asClosure() throws InterpreterException;
  114. public ATSymbol asSymbol() throws InterpreterException;
  115. public ATTable asTable() throws InterpreterException;
  116. public ATBoolean asBoolean() throws InterpreterException;
  117. public ATNumber asNumber() throws InterpreterException;
  118. public ATMessage asMessage() throws InterpreterException;
  119. public ATField asField() throws InterpreterException;
  120. public ATMethod asMethod() throws InterpreterException;
  121. public ATMethodInvocation asMethodInvocation() throws InterpreterException;
  122. public ATHandler asHandler() throws InterpreterException;
  123. public ATTypeTag asTypeTag() throws InterpreterException;
  124. public ATFarReference asFarReference() throws InterpreterException;
  125. public ATAsyncMessage asAsyncMessage() throws InterpreterException;
  126. public ATActorMirror asActorMirror() throws InterpreterException;
  127. public ATLetter asLetter() throws InterpreterException;
  128. // Abstract Grammar Elements
  129. public ATStatement asStatement() throws InterpreterException;
  130. public ATDefinition asDefinition() throws InterpreterException;
  131. public ATExpression asExpression() throws InterpreterException;
  132. public ATBegin asBegin() throws InterpreterException;
  133. public ATQuote asQuote() throws InterpreterException;
  134. public ATMessageCreation asMessageCreation() throws InterpreterException;
  135. public ATUnquoteSplice asUnquoteSplice() throws InterpreterException;
  136. public ATAssignVariable asVariableAssignment() throws InterpreterException;
  137. public ATSplice asSplice() throws InterpreterException;
  138. // Native Value Elements
  139. // The isNative / asNative type-casting protocol is crucial for correct
  140. // semantics in the case of e.g. wrapped natives in a Coercer (for symbiosis)
  141. // Never use Java type-casts explicitly!
  142. public boolean isNativeBoolean();
  143. public boolean isNativeText();
  144. public boolean isAmbientTalkObject(); // distinguish native from non-native objects
  145. public boolean isCallFrame() throws InterpreterException; // distinguish call frames from objects
  146. public boolean isJavaObjectUnderSymbiosis();
  147. public boolean isJavaClassUnderSymbiosis();
  148. public boolean isJavaMethodUnderSymbiosis();
  149. public boolean isNativeField();
  150. public boolean isNativeFarReference();
  151. public boolean isNativeFraction();
  152. public boolean isNativeNumber();
  153. public boolean isNativeIntrospectiveMirror();
  154. public boolean isNativeDelegateMethod();
  155. public boolean isMirage();
  156. public NATObject asAmbientTalkObject() throws XTypeMismatch;
  157. public NATMirage asMirage() throws XTypeMismatch;
  158. public NATNumber asNativeNumber() throws XTypeMismatch;
  159. public NATFraction asNativeFraction() throws XTypeMismatch;
  160. public NATText asNativeText() throws XTypeMismatch;
  161. public NATTable asNativeTable() throws XTypeMismatch;
  162. public NATBoolean asNativeBoolean() throws XTypeMismatch;
  163. public NATNumeric asNativeNumeric() throws XTypeMismatch;
  164. public NATFarReference asNativeFarReference() throws XTypeMismatch;
  165. public NATIntrospectiveMirror asNativeIntrospectiveMirror() throws XTypeMismatch;
  166. public DelegateMethod asNativeDelegateMethod() throws XTypeMismatch;
  167. public JavaObject asJavaObjectUnderSymbiosis() throws XTypeMismatch;
  168. public JavaClass asJavaClassUnderSymbiosis() throws XTypeMismatch;
  169. public JavaMethod asJavaMethodUnderSymbiosis() throws XTypeMismatch;
  170. }