@@ -27,8 +27,8 @@ namespace IronPython.Compiler.Ast {
2727
2828 public class ClassDefinition : ScopeStatement {
2929 private readonly string _name ;
30- private readonly Arg [ ] _bases ;
31- private readonly Arg [ ] _keywords ;
30+ private readonly Expression [ ] _bases ;
31+ private readonly Keyword [ ] _keywords ;
3232
3333 private LightLambdaExpression ? _dlrBody ; // the transformed body including all of our initialization, etc...
3434
@@ -37,10 +37,10 @@ public class ClassDefinition : ScopeStatement {
3737 private static readonly MSAst . ParameterExpression _parentContextParam = Ast . Parameter ( typeof ( CodeContext ) , "$parentContext" ) ;
3838 private static readonly MSAst . Expression _tupleExpression = MSAst . Expression . Call ( AstMethods . GetClosureTupleFromContext , _parentContextParam ) ;
3939
40- public ClassDefinition ( string name , IReadOnlyList < Arg > ? bases , IReadOnlyList < Arg > ? keywords , Statement ? body = null ) {
40+ public ClassDefinition ( string name , IReadOnlyList < Expression > ? bases , IReadOnlyList < Keyword > ? keywords , Statement ? body = null ) {
4141 _name = name ;
42- _bases = bases ? . ToArray ( ) ?? Array . Empty < Arg > ( ) ;
43- _keywords = keywords ? . ToArray ( ) ?? Array . Empty < Arg > ( ) ;
42+ _bases = bases ? . ToArray ( ) ?? Array . Empty < Expression > ( ) ;
43+ _keywords = keywords ? . ToArray ( ) ?? Array . Empty < Keyword > ( ) ;
4444 Body = body ?? EmptyStatement . PreCompiledInstance ;
4545 }
4646
@@ -50,9 +50,9 @@ public ClassDefinition(string name, IReadOnlyList<Arg>? bases, IReadOnlyList<Arg
5050
5151 public override string Name => _name ;
5252
53- public IReadOnlyList < Arg > Bases => _bases ;
53+ public IReadOnlyList < Expression > Bases => _bases ;
5454
55- public IReadOnlyList < Arg > Keywords => _keywords ;
55+ public IReadOnlyList < Keyword > Keywords => _keywords ;
5656
5757 public Statement Body { get ; set ; }
5858
@@ -194,42 +194,35 @@ public override MSAst.Expression Reduce() {
194194 classDef = AddDecorators ( classDef , Decorators ) ;
195195
196196 return GlobalParent . AddDebugInfoAndVoid (
197- AssignValue ( Parent . GetVariableExpression ( PythonVariable ! ) , classDef ) ,
197+ AssignValue ( Parent . GetVariableExpression ( PythonVariable ! ) , classDef ) ,
198198 new SourceSpan (
199199 GlobalParent . IndexToLocation ( StartIndex ) ,
200200 GlobalParent . IndexToLocation ( HeaderIndex )
201201 )
202202 ) ;
203203
204204 // Compare to: CallExpression.Reduce.__UnpackListHelper
205- static MSAst . Expression UnpackBasesHelper ( IReadOnlyList < Arg > bases ) {
206- if ( bases . Count == 0 ) {
205+ static MSAst . Expression UnpackBasesHelper ( ReadOnlySpan < Expression > bases ) {
206+ if ( bases . Length == 0 ) {
207207 return Expression . Call ( AstMethods . MakeEmptyTuple ) ;
208- } else if ( bases . All ( arg => arg . ArgumentInfo . Kind is ArgumentType . Simple ) ) {
209- return Expression . Call ( AstMethods . MakeTuple ,
210- Expression . NewArrayInit (
211- typeof ( object ) ,
212- ToObjectArray ( bases . Select ( arg => arg . Expression ) . ToList ( ) )
213- )
214- ) ;
215- } else {
216- var expressions = new ReadOnlyCollectionBuilder < MSAst . Expression > ( bases . Count + 2 ) ;
217- var varExpr = Expression . Variable ( typeof ( PythonList ) , "$coll" ) ;
218- expressions . Add ( Expression . Assign ( varExpr , Expression . Call ( AstMethods . MakeEmptyList ) ) ) ;
219- foreach ( var arg in bases ) {
220- if ( arg . ArgumentInfo . Kind == ArgumentType . List ) {
221- expressions . Add ( Expression . Call ( AstMethods . ListExtend , varExpr , AstUtils . Convert ( arg . Expression , typeof ( object ) ) ) ) ;
222- } else {
223- expressions . Add ( Expression . Call ( AstMethods . ListAppend , varExpr , AstUtils . Convert ( arg . Expression , typeof ( object ) ) ) ) ;
224- }
208+ }
209+ foreach ( var arg in bases ) {
210+ if ( arg is StarredExpression ) {
211+ return Expression . Call ( AstMethods . ListToTuple ,
212+ Expression . UnpackSequenceHelper < PythonList > ( bases , AstMethods . MakeEmptyList , AstMethods . ListAppend , AstMethods . ListExtend )
213+ ) ;
225214 }
226- expressions . Add ( Expression . Call ( AstMethods . ListToTuple , varExpr ) ) ;
227- return Expression . Block ( typeof ( PythonTuple ) , new MSAst . ParameterExpression [ ] { varExpr } , expressions ) ;
228215 }
216+ return Expression . Call ( AstMethods . MakeTuple ,
217+ Expression . NewArrayInit (
218+ typeof ( object ) ,
219+ ToObjectArray ( bases )
220+ )
221+ ) ;
229222 }
230223
231224 // Compare to: CallExpression.Reduce.__UnpackDictHelper
232- static MSAst . Expression UnpackKeywordsHelper ( MSAst . Expression context , IReadOnlyList < Arg > kwargs ) {
225+ static MSAst . Expression UnpackKeywordsHelper ( MSAst . Expression context , IReadOnlyList < Keyword > kwargs ) {
233226 if ( kwargs . Count == 0 ) {
234227 return AstUtils . Constant ( null , typeof ( PythonDictionary ) ) ;
235228 }
@@ -238,7 +231,7 @@ static MSAst.Expression UnpackKeywordsHelper(MSAst.Expression context, IReadOnly
238231 var varExpr = Expression . Variable ( typeof ( PythonDictionary ) , "$dict" ) ;
239232 expressions . Add ( Expression . Assign ( varExpr , Expression . Call ( AstMethods . MakeEmptyDict ) ) ) ;
240233 foreach ( var arg in kwargs ) {
241- if ( arg . ArgumentInfo . Kind == ArgumentType . Dictionary ) {
234+ if ( arg . Name is null ) {
242235 expressions . Add ( Expression . Call ( AstMethods . DictMerge , context , varExpr , AstUtils . Convert ( arg . Expression , typeof ( object ) ) ) ) ;
243236 } else {
244237 expressions . Add ( Expression . Call ( AstMethods . DictMergeOne , context , varExpr , AstUtils . Constant ( arg . Name , typeof ( object ) ) , AstUtils . Convert ( arg . Expression , typeof ( object ) ) ) ) ;
@@ -346,10 +339,10 @@ public override void Walk(PythonWalker walker) {
346339 decorator . Walk ( walker ) ;
347340 }
348341 }
349- foreach ( Arg b in _bases ) {
342+ foreach ( var b in _bases ) {
350343 b . Walk ( walker ) ;
351344 }
352- foreach ( Arg b in _keywords ) {
345+ foreach ( var b in _keywords ) {
353346 b . Walk ( walker ) ;
354347 }
355348 Body . Walk ( walker ) ;
0 commit comments