124124import com .oracle .truffle .api .nodes .UnexpectedResultException ;
125125import com .oracle .truffle .api .source .Source ;
126126import com .oracle .truffle .api .source .SourceSection ;
127+ import com .oracle .truffle .api .test .TestAPIAccessor ;
127128
128129/**
129130 * <p>
@@ -217,7 +218,7 @@ static class ConstantTag extends Tag {
217218 public static final String [] TAG_NAMES = new String []{"EXPRESSION" , "DEFINE" , "CONTEXT" , "LOOP" , "STATEMENT" , "CALL" , "RECURSIVE_CALL" , "CALL_WITH" , "BLOCK" , "ROOT_BODY" , "ROOT" , "CONSTANT" ,
218219 "VARIABLE" , "ARGUMENT" , "READ_VAR" , "PRINT" , "ALLOCATION" , "SLEEP" , "SPAWN" , "JOIN" , "INVALIDATE" , "INTERNAL" , "INNER_FRAME" , "MATERIALIZE_CHILD_EXPRESSION" ,
219220 "MATERIALIZE_CHILD_STMT_AND_EXPR" , "MATERIALIZE_CHILD_STMT_AND_EXPR_NC" , "MATERIALIZE_CHILD_STMT_AND_EXPR_SEPARATELY" , "MATERIALIZE_CHILD_STATEMENT" , "BLOCK_NO_SOURCE_SECTION" ,
220- "TRY" , "CATCH" , "THROW" , "UNEXPECTED_RESULT" , "MULTIPLE" , "EXIT" };
221+ "TRY" , "CATCH" , "THROW" , "UNEXPECTED_RESULT" , "MULTIPLE" , "EXIT" , "CANCEL" , "RETURN" };
221222
222223 public InstrumentationTestLanguage () {
223224 }
@@ -383,7 +384,7 @@ private BaseNode statement() {
383384
384385 int numberOfIdents = 0 ;
385386 if (tag .equals ("DEFINE" ) || tag .equals ("ARGUMENT" ) || tag .equals ("READ_VAR" ) || tag .equals ("CALL" ) || tag .equals ("LOOP" ) || tag .equals ("CONSTANT" ) || tag .equals ("UNEXPECTED_RESULT" ) ||
386- tag .equals ("SLEEP" ) || tag .equals ("SPAWN" ) || tag .equals ("CATCH" ) || tag .equals ("EXIT" )) {
387+ tag .equals ("SLEEP" ) || tag .equals ("SPAWN" ) || tag .equals ("CATCH" ) || tag .equals ("EXIT" ) || tag . equals ( "RETURN" ) ) {
387388 numberOfIdents = 1 ;
388389 } else if (tag .equals ("VARIABLE" ) || tag .equals ("RECURSIVE_CALL" ) || tag .equals ("CALL_WITH" ) || tag .equals ("PRINT" ) || tag .equals ("THROW" )) {
389390 numberOfIdents = 2 ;
@@ -554,6 +555,10 @@ private static BaseNode createNode(String tag, String[] idents, SourceSection so
554555 return new MultipleNode (childArray , multipleTags );
555556 case "EXIT" :
556557 return new ExitNode (idents [0 ]);
558+ case "CANCEL" :
559+ return new CancelNode ();
560+ case "RETURN" :
561+ return new ReturnNode (idents [0 ]);
557562 default :
558563 throw new AssertionError ();
559564 }
@@ -1770,6 +1775,31 @@ protected BaseNode copyUninitialized(Set<Class<? extends Tag>> materializedTags)
17701775 }
17711776 }
17721777
1778+ private static class ReturnNode extends InstrumentedNode {
1779+
1780+ private final String identifier ;
1781+
1782+ ReturnNode (String identifier ) {
1783+ this .identifier = identifier ;
1784+ }
1785+
1786+ @ Override
1787+ public Object execute (VirtualFrame frame ) {
1788+ InstrumentContext ctx = InstrumentContext .get (this );
1789+ return returnFunction (ctx );
1790+ }
1791+
1792+ @ TruffleBoundary
1793+ private Object returnFunction (InstrumentContext ctx ) {
1794+ return ctx .callFunctions .findFunction (identifier );
1795+ }
1796+
1797+ @ Override
1798+ protected BaseNode copyUninitialized (Set <Class <? extends Tag >> materializedTags ) {
1799+ return new ReturnNode (identifier );
1800+ }
1801+ }
1802+
17731803 static class ExitNode extends InstrumentedNode {
17741804 private final int exitCode ;
17751805
@@ -1795,6 +1825,28 @@ protected BaseNode copyUninitialized(Set<Class<? extends Tag>> materializedTags)
17951825 }
17961826 }
17971827
1828+ static class CancelNode extends InstrumentedNode {
1829+
1830+ CancelNode () {
1831+ }
1832+
1833+ @ Override
1834+ public Object execute (VirtualFrame frame ) {
1835+ throwCancelException ();
1836+ return null ;
1837+ }
1838+
1839+ @ TruffleBoundary
1840+ private void throwCancelException () {
1841+ TestAPIAccessor .engineAccess ().getCurrentCreatorTruffleContext ().closeCancelled (this , null );
1842+ }
1843+
1844+ @ Override
1845+ protected BaseNode copyUninitialized (Set <Class <? extends Tag >> materializedTags ) {
1846+ return new CancelNode ();
1847+ }
1848+ }
1849+
17981850 private static class SpawnNode extends InstrumentedNode {
17991851
18001852 private final String identifier ;
0 commit comments