4949import com .oracle .graal .python .builtins .objects .PNone ;
5050import com .oracle .graal .python .builtins .objects .PNotImplemented ;
5151import com .oracle .graal .python .builtins .objects .buffer .PythonBufferAccessLibrary ;
52- import com .oracle .graal .python .builtins .objects .bytes .PBytes ;
52+ import com .oracle .graal .python .builtins .objects .bytes .BytesNodes . GetBytesStorage ;
5353import com .oracle .graal .python .builtins .objects .code .CodeBuiltinsClinicProviders .CodeConstructorNodeClinicProviderGen ;
54- import com .oracle .graal .python .builtins .objects .common .SequenceNodes ;
54+ import com .oracle .graal .python .builtins .objects .common .SequenceStorageNodes ;
5555import com .oracle .graal .python .builtins .objects .str .StringUtils .SimpleTruffleStringFormatNode ;
5656import com .oracle .graal .python .builtins .objects .tuple .PTuple ;
5757import com .oracle .graal .python .builtins .objects .type .TpSlots ;
6161import com .oracle .graal .python .compiler .CodeUnit ;
6262import com .oracle .graal .python .compiler .OpCodes ;
6363import com .oracle .graal .python .compiler .SourceMap ;
64+ import com .oracle .graal .python .lib .PyBytesCheckNode ;
6465import com .oracle .graal .python .lib .PyObjectGetIter ;
6566import com .oracle .graal .python .lib .PyObjectHashNode ;
67+ import com .oracle .graal .python .lib .PyTupleCheckNode ;
6668import com .oracle .graal .python .lib .RichCmpOp ;
6769import com .oracle .graal .python .nodes .ErrorMessages ;
6870import com .oracle .graal .python .nodes .PGuards ;
6971import com .oracle .graal .python .nodes .PRaiseNode ;
72+ import com .oracle .graal .python .nodes .builtins .TupleNodes .GetTupleStorage ;
7073import com .oracle .graal .python .nodes .bytecode_dsl .PBytecodeDSLRootNode ;
7174import com .oracle .graal .python .nodes .function .PythonBuiltinBaseNode ;
7275import com .oracle .graal .python .nodes .function .builtins .PythonClinicBuiltinNode ;
@@ -124,23 +127,32 @@ public abstract static class CodeConstructorNode extends PythonClinicBuiltinNode
124127 static PCode call (VirtualFrame frame , @ SuppressWarnings ("unused" ) Object cls , int argcount ,
125128 int posonlyargcount , int kwonlyargcount ,
126129 int nlocals , int stacksize , int flags ,
127- PBytes codestring , PTuple constants , PTuple names , PTuple varnames ,
130+ Object codestring , Object constants , Object names , Object varnames ,
128131 TruffleString filename , TruffleString name , TruffleString qualname ,
129- int firstlineno , PBytes linetable , @ SuppressWarnings ( "unused" ) PBytes exceptiontable ,
130- PTuple freevars , PTuple cellvars ,
132+ int firstlineno , Object linetable , Object exceptiontable ,
133+ Object freevars , Object cellvars ,
131134 @ Bind Node inliningTarget ,
132135 @ CachedLibrary (limit = "1" ) PythonBufferAccessLibrary bufferLib ,
133136 @ Cached CodeNodes .CreateCodeNode createCodeNode ,
134- @ Cached SequenceNodes .GetObjectArrayNode getObjectArrayNode ,
137+ @ Cached GetBytesStorage getBytesStorage ,
138+ @ Cached GetTupleStorage getTupleStorage ,
139+ @ Cached SequenceStorageNodes .ToArrayNode toArrayNode ,
140+ @ Cached PyBytesCheckNode bytesCheckNode ,
141+ @ Cached PyTupleCheckNode tupleCheckNode ,
135142 @ Cached CastToTruffleStringNode castToTruffleStringNode ) {
136- byte [] codeBytes = bufferLib .getCopiedByteArray (codestring );
137- byte [] linetableBytes = bufferLib .getCopiedByteArray (linetable );
138-
139- Object [] constantsArr = getObjectArrayNode .execute (inliningTarget , constants );
140- TruffleString [] namesArr = objectArrayToTruffleStringArray (inliningTarget , getObjectArrayNode .execute (inliningTarget , names ), castToTruffleStringNode );
141- TruffleString [] varnamesArr = objectArrayToTruffleStringArray (inliningTarget , getObjectArrayNode .execute (inliningTarget , varnames ), castToTruffleStringNode );
142- TruffleString [] freevarsArr = objectArrayToTruffleStringArray (inliningTarget , getObjectArrayNode .execute (inliningTarget , freevars ), castToTruffleStringNode );
143- TruffleString [] cellcarsArr = objectArrayToTruffleStringArray (inliningTarget , getObjectArrayNode .execute (inliningTarget , cellvars ), castToTruffleStringNode );
143+ byte [] codeBytes = getBytes (inliningTarget , codestring , bytesCheckNode , getBytesStorage , bufferLib );
144+ byte [] linetableBytes = getBytes (inliningTarget , linetable , bytesCheckNode , getBytesStorage , bufferLib );
145+ checkBytes (inliningTarget , exceptiontable , bytesCheckNode );
146+
147+ Object [] constantsArr = getTupleArray (inliningTarget , constants , tupleCheckNode , getTupleStorage , toArrayNode );
148+ TruffleString [] namesArr = objectArrayToTruffleStringArray (inliningTarget ,
149+ getTupleArray (inliningTarget , names , tupleCheckNode , getTupleStorage , toArrayNode ), castToTruffleStringNode );
150+ TruffleString [] varnamesArr = objectArrayToTruffleStringArray (inliningTarget ,
151+ getTupleArray (inliningTarget , varnames , tupleCheckNode , getTupleStorage , toArrayNode ), castToTruffleStringNode );
152+ TruffleString [] freevarsArr = objectArrayToTruffleStringArray (inliningTarget ,
153+ getTupleArray (inliningTarget , freevars , tupleCheckNode , getTupleStorage , toArrayNode ), castToTruffleStringNode );
154+ TruffleString [] cellcarsArr = objectArrayToTruffleStringArray (inliningTarget ,
155+ getTupleArray (inliningTarget , cellvars , tupleCheckNode , getTupleStorage , toArrayNode ), castToTruffleStringNode );
144156
145157 return createCodeNode .execute (frame , argcount , posonlyargcount , kwonlyargcount ,
146158 nlocals , stacksize , flags ,
@@ -150,15 +162,27 @@ static PCode call(VirtualFrame frame, @SuppressWarnings("unused") Object cls, in
150162 firstlineno , linetableBytes );
151163 }
152164
153- @ Fallback
154- @ SuppressWarnings ("unused" )
155- static PCode call (Object cls , Object argcount , Object kwonlyargcount , Object posonlyargcount ,
156- Object nlocals , Object stacksize , Object flags ,
157- Object codestring , Object constants , Object names , Object varnames ,
158- Object filename , Object name , Object qualname ,
159- Object firstlineno , Object linetable , Object exceptiontable ,
160- Object freevars , Object cellvars ,
161- @ Bind Node inliningTarget ) {
165+ private static byte [] getBytes (Node inliningTarget , Object object , PyBytesCheckNode bytesCheckNode ,
166+ GetBytesStorage getBytesStorage , PythonBufferAccessLibrary bufferLib ) {
167+ checkBytes (inliningTarget , object , bytesCheckNode );
168+ return bufferLib .getCopiedByteArray (getBytesStorage .execute (inliningTarget , object ));
169+ }
170+
171+ private static void checkBytes (Node inliningTarget , Object object , PyBytesCheckNode bytesCheckNode ) {
172+ if (!bytesCheckNode .execute (inliningTarget , object )) {
173+ throw invalidArgs (inliningTarget );
174+ }
175+ }
176+
177+ private static Object [] getTupleArray (Node inliningTarget , Object object , PyTupleCheckNode tupleCheckNode ,
178+ GetTupleStorage getTupleStorage , SequenceStorageNodes .ToArrayNode toArrayNode ) {
179+ if (!tupleCheckNode .execute (inliningTarget , object )) {
180+ throw invalidArgs (inliningTarget );
181+ }
182+ return toArrayNode .execute (inliningTarget , getTupleStorage .execute (inliningTarget , object ));
183+ }
184+
185+ private static RuntimeException invalidArgs (Node inliningTarget ) {
162186 throw PRaiseNode .raiseStatic (inliningTarget , TypeError , ErrorMessages .INVALID_ARGS , "code" );
163187 }
164188
0 commit comments