9
9
*/
10
10
package org .truffleruby .core .cast ;
11
11
12
+ import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
12
13
import com .oracle .truffle .api .dsl .GenerateCached ;
13
14
import com .oracle .truffle .api .dsl .GenerateInline ;
14
15
import com .oracle .truffle .api .nodes .Node ;
16
+ import com .oracle .truffle .api .source .Source ;
15
17
import org .truffleruby .core .method .RubyMethod ;
16
18
import org .truffleruby .core .method .RubyUnboundMethod ;
17
19
import org .truffleruby .core .proc .RubyProc ;
20
+ import org .truffleruby .core .string .TStringWithEncoding ;
18
21
import org .truffleruby .language .RubyBaseNode ;
19
22
20
23
import com .oracle .truffle .api .RootCallTarget ;
21
24
import com .oracle .truffle .api .dsl .Specialization ;
25
+ import org .truffleruby .language .RubyGuards ;
26
+ import org .truffleruby .language .library .RubyStringLibrary ;
27
+ import org .truffleruby .language .loader .ByteBasedCharSequence ;
28
+ import org .truffleruby .parser .ParserContext ;
29
+ import org .truffleruby .parser .RubySource ;
30
+ import org .truffleruby .parser .TranslatorEnvironment ;
22
31
23
32
@ GenerateInline
24
33
@ GenerateCached (false )
@@ -41,4 +50,21 @@ static RootCallTarget proc(RubyProc proc) {
41
50
return proc .callTarget ;
42
51
}
43
52
53
+ @ TruffleBoundary
54
+ @ Specialization
55
+ static RootCallTarget string (Node node , Object string ) {
56
+ var code = new TStringWithEncoding (RubyGuards .asTruffleStringUncached (string ),
57
+ RubyStringLibrary .getUncached ().getEncoding (string ));
58
+ Source source = Source .newBuilder ("ruby" , new ByteBasedCharSequence (code ), "<parse_ast>" ).build ();
59
+ TranslatorEnvironment .resetTemporaryVariablesIndex ();
60
+ var parserContext = ParserContext .TOP_LEVEL ;
61
+
62
+ return getContext (node ).getCodeLoader ().parse (
63
+ new RubySource (source , source .getName ()),
64
+ parserContext ,
65
+ null ,
66
+ getContext (node ).getRootLexicalScope (),
67
+ node );
68
+ }
69
+
44
70
}
0 commit comments