@@ -102,6 +102,8 @@ public static void main(String[] args) {
102
102
private String warnOptions = null ;
103
103
private String checkHashPycsMode = "default" ;
104
104
105
+ boolean useASTInterpreter = false ;
106
+
105
107
protected static void setStartupTime () {
106
108
if (GraalPythonMain .startupNanoTime == -1 ) {
107
109
GraalPythonMain .startupNanoTime = System .nanoTime ();
@@ -122,6 +124,7 @@ protected List<String> preprocessArguments(List<String> givenArgs, Map<String, S
122
124
List <String > subprocessArgs = new ArrayList <>();
123
125
programArgs = new ArrayList <>();
124
126
boolean posixBackendSpecified = false ;
127
+ boolean toolInstrumentWarning = true ;
125
128
for (Iterator <String > argumentIterator = arguments .iterator (); argumentIterator .hasNext ();) {
126
129
String arg = argumentIterator .next ();
127
130
if (arg .startsWith ("-" )) {
@@ -192,8 +195,19 @@ protected List<String> preprocessArguments(List<String> givenArgs, Map<String, S
192
195
}
193
196
checkHashPycsMode = argumentIterator .next ();
194
197
continue ;
198
+ case "--use-ast-interpreter" :
199
+ case "--python.UseASTInterpreter" :
200
+ useASTInterpreter = true ;
201
+ continue ;
195
202
default :
196
- if (arg .startsWith ("--llvm." ) ||
203
+ if (argStartsWith (arg , "--agentscript" , "--coverage" , "--cpusampler" , "--cputracer" , "--dap" ,
204
+ "--heap." , "--heapmonitor" , "--insight" , "--inspect" , "--lsp" , "--memtracer" , "--sandbox." )) {
205
+ useASTInterpreter = true ;
206
+ if (toolInstrumentWarning ) {
207
+ toolInstrumentWarning = false ;
208
+ System .out .println ("WARNING: Switching to AST interpreter due to instruments option " + arg );
209
+ }
210
+ } else if (arg .startsWith ("--llvm." ) ||
197
211
matchesPythonOption (arg , "CoreHome" ) ||
198
212
matchesPythonOption (arg , "StdLibHome" ) ||
199
213
matchesPythonOption (arg , "CAPI" ) ||
@@ -520,6 +534,8 @@ private String getExecutable() {
520
534
521
535
@ Override
522
536
protected void launch (Builder contextBuilder ) {
537
+ String cachePrefix = null ;
538
+
523
539
// prevent the use of System.out/err - they are PrintStreams which suppresses exceptions
524
540
contextBuilder .out (new FileOutputStream (FileDescriptor .out ));
525
541
contextBuilder .err (new FileOutputStream (FileDescriptor .err ));
@@ -547,10 +563,7 @@ protected void launch(Builder contextBuilder) {
547
563
warnOptions = envWarnOptions + "," + warnOptions ;
548
564
}
549
565
}
550
- String cachePrefix = System .getenv ("PYTHONPYCACHEPREFIX" );
551
- if (cachePrefix != null ) {
552
- contextBuilder .option ("python.PyCachePrefix" , cachePrefix );
553
- }
566
+ cachePrefix = System .getenv ("PYTHONPYCACHEPREFIX" );
554
567
555
568
String encoding = System .getenv ("PYTHONIOENCODING" );
556
569
if (encoding != null ) {
@@ -577,7 +590,6 @@ protected void launch(Builder contextBuilder) {
577
590
contextBuilder .option ("python.VerboseFlag" , Boolean .toString (verboseFlag ));
578
591
contextBuilder .option ("python.IsolateFlag" , Boolean .toString (isolateFlag ));
579
592
contextBuilder .option ("python.WarnOptions" , warnOptions );
580
- contextBuilder .option ("python.DontWriteBytecodeFlag" , Boolean .toString (dontWriteBytecode ));
581
593
if (verboseFlag ) {
582
594
contextBuilder .option ("log.python.level" , "FINE" );
583
595
}
@@ -603,6 +615,18 @@ protected void launch(Builder contextBuilder) {
603
615
contextBuilder .option ("python.InputFilePath" , inputFile );
604
616
}
605
617
618
+ if (useASTInterpreter ) {
619
+ contextBuilder .option ("python.DontWriteBytecodeFlag" , "true" );
620
+ contextBuilder .option ("python.PyCachePrefix" , "/dev/null" );
621
+ contextBuilder .option ("python.EnableBytecodeInterpreter" , "false" );
622
+ contextBuilder .option ("python.DisableFrozenModules" , "true" );
623
+ } else {
624
+ contextBuilder .option ("python.DontWriteBytecodeFlag" , Boolean .toString (dontWriteBytecode ));
625
+ if (cachePrefix != null ) {
626
+ contextBuilder .option ("python.PyCachePrefix" , cachePrefix );
627
+ }
628
+ }
629
+
606
630
if (multiContext ) {
607
631
contextBuilder .engine (Engine .newBuilder ().allowExperimentalOptions (true ).options (enginePolyglotOptions ).build ());
608
632
}
@@ -655,6 +679,15 @@ private static boolean matchesPythonOption(String arg, String key) {
655
679
return arg .startsWith ("--python." + key ) || arg .startsWith ("--" + key );
656
680
}
657
681
682
+ private static boolean argStartsWith (String arg , String ... tools ) {
683
+ for (String t : tools ) {
684
+ if (arg .startsWith (t )) {
685
+ return true ;
686
+ }
687
+ }
688
+ return false ;
689
+ }
690
+
658
691
private String getContextOptionIfSetViaCommandLine (String key ) {
659
692
if (System .getProperty ("polyglot.python." + key ) != null ) {
660
693
return System .getProperty ("polyglot.python." + key );
0 commit comments