@@ -443,19 +443,18 @@ static void checkudata (global_State *g, Udata *u) {
443443
444444
445445static void checkproto (global_State *g, Proto *f) {
446- int i;
447446 GCObject *fgc = obj2gco (f);
448447 checkobjrefN (g, fgc, f->getSource ());
449- for (i= 0 ; i< f->getConstantsSize (); i++ ) {
450- if (iscollectable (f-> getConstants () + i ))
451- checkobjref (g, fgc, gcvalue (f-> getConstants () + i ));
448+ for (const auto & constant : f->getConstantsSpan () ) {
449+ if (iscollectable (&constant ))
450+ checkobjref (g, fgc, gcvalue (&constant ));
452451 }
453- for (i= 0 ; i< f->getUpvaluesSize (); i++ )
454- checkobjrefN (g, fgc, f-> getUpvalues ()[i] .getName ());
455- for (i= 0 ; i< f->getProtosSize (); i++ )
456- checkobjrefN (g, fgc, f-> getProtos ()[i] );
457- for (i= 0 ; i< f->getLocVarsSize (); i++ )
458- checkobjrefN (g, fgc, f-> getLocVars ()[i] .getVarName ());
452+ for (const auto & upval : f->getUpvaluesSpan () )
453+ checkobjrefN (g, fgc, upval .getName ());
454+ for (Proto* proto : f->getProtosSpan () )
455+ checkobjrefN (g, fgc, proto );
456+ for (const auto & locvar : f->getDebugInfo (). getLocVarsSpan () )
457+ checkobjrefN (g, fgc, locvar .getVarName ());
459458}
460459
461460
@@ -487,8 +486,10 @@ static int lua_checkpc (CallInfo *ci) {
487486 else {
488487 StkId f = ci->funcRef ().p ;
489488 Proto *p = clLvalue (s2v (f))->getProto ();
490- return p->getCode () <= ci->getSavedPC () &&
491- ci->getSavedPC () <= p->getCode () + p->getCodeSize ();
489+ auto codeSpan = p->getCodeSpan ();
490+ const Instruction* savedPC = ci->getSavedPC ();
491+ return codeSpan.data () <= savedPC &&
492+ savedPC <= codeSpan.data () + codeSpan.size ();
492493 }
493494}
494495
@@ -781,11 +782,14 @@ static int listcode (lua_State *L) {
781782 lua_newtable (L);
782783 setnameval (L, " maxstack" , p->getMaxStackSize ());
783784 setnameval (L, " numparams" , p->getNumParams ());
784- for (pc=0 ; pc<p->getCodeSize (); pc++) {
785+ pc = 0 ;
786+ for (const auto & instr : p->getCodeSpan ()) {
787+ (void )instr; /* unused */
785788 char buff[100 ];
786789 lua_pushinteger (L, pc+1 );
787790 lua_pushstring (L, buildop (p, pc, buff));
788791 lua_settable (L, -3 );
792+ pc++;
789793 }
790794 return 1 ;
791795}
@@ -799,9 +803,12 @@ static int printcode (lua_State *L) {
799803 p = getproto (obj_at (L, 1 ));
800804 printf (" maxstack: %d\n " , p->getMaxStackSize ());
801805 printf (" numparams: %d\n " , p->getNumParams ());
802- for (pc=0 ; pc<p->getCodeSize (); pc++) {
806+ pc = 0 ;
807+ for (const auto & instr : p->getCodeSpan ()) {
808+ (void )instr; /* unused */
803809 char buff[100 ];
804810 printf (" %s\n " , buildop (p, pc, buff));
811+ pc++;
805812 }
806813 return 0 ;
807814}
@@ -813,10 +820,13 @@ static int listk (lua_State *L) {
813820 luaL_argcheck (L, lua_isfunction (L, 1 ) && !lua_iscfunction (L, 1 ),
814821 1 , " Lua function expected" );
815822 p = getproto (obj_at (L, 1 ));
816- lua_createtable (L, p->getConstantsSize (), 0 );
817- for (i=0 ; i<p->getConstantsSize (); i++) {
818- pushobject (L, p->getConstants ()+i);
823+ auto constantsSpan = p->getConstantsSpan ();
824+ lua_createtable (L, static_cast <int >(constantsSpan.size ()), 0 );
825+ i = 0 ;
826+ for (const auto & constant : constantsSpan) {
827+ pushobject (L, &constant);
819828 lua_rawseti (L, -2 , i+1 );
829+ i++;
820830 }
821831 return 1 ;
822832}
@@ -829,12 +839,15 @@ static int listabslineinfo (lua_State *L) {
829839 1 , " Lua function expected" );
830840 p = getproto (obj_at (L, 1 ));
831841 luaL_argcheck (L, p->getAbsLineInfo () != nullptr , 1 , " function has no debug info" );
832- lua_createtable (L, 2 * p->getAbsLineInfoSize (), 0 );
833- for (i=0 ; i < p->getAbsLineInfoSize (); i++) {
834- lua_pushinteger (L, p->getAbsLineInfo ()[i].getPC ());
842+ auto absLineInfoSpan = p->getDebugInfo ().getAbsLineInfoSpan ();
843+ lua_createtable (L, 2 * static_cast <int >(absLineInfoSpan.size ()), 0 );
844+ i = 0 ;
845+ for (const auto & absline : absLineInfoSpan) {
846+ lua_pushinteger (L, absline.getPC ());
835847 lua_rawseti (L, -2 , 2 * i + 1 );
836- lua_pushinteger (L, p-> getAbsLineInfo ()[i] .getLine ());
848+ lua_pushinteger (L, absline .getLine ());
837849 lua_rawseti (L, -2 , 2 * i + 2 );
850+ i++;
838851 }
839852 return 1 ;
840853}
0 commit comments