Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sgscript.h>
- static int Fsgs__fmt_bytenum( SGS_CTX, sgs_VarObj* obj )
- {
- int ret = 0;
- SGSFN( "fmt_bytenum" );
- sgs_Variable T[ 9 ];
- sgs_Variable* CN = (sgs_Variable*) obj->data;
- sgs_PushItem( C, 0 );
- sgs_StoreVariable( C, T+0 );
- { int i; for( i = 1; i < 9; ++i )
- T[ i ].type = SGS_VT_NULL; }
- // set
- sgs_Assign( C, T+1, T+0 );
- // set
- sgs_Assign( C, T+2, CN+0 );
- // push
- sgs_PushVariable( C, CN+1 );
- // push
- sgs_PushVariable( C, CN+2 );
- // push
- sgs_PushVariable( C, CN+3 );
- // array
- sgs_Release( C, T+3 );
- sgs_InitArray( C, T+3, 3 );
- _op6:;
- // gt
- { int V = (sgs_Compare( C, T+0, CN+4 ) > 0);
- sgs_Release( C, T+5 ); sgs_InitBool( T+5, V ); }
- // jump_if_true
- if( sgs_GetBoolP( C, T+5 ) ) goto _op10;
- // set
- sgs_Assign( C, T+4, T+5 );
- // jump
- goto _op15;
- _op10:;
- // getprop
- sgs_Release( C, T+8 );
- sgs_GetIndexPPP( C, T+3, CN+5, T+8, 1 );
- // sub
- sgs_ArithOp( C, T+7, T+8, CN+6, SGS_EOP_SUB );
- // lt
- { int V = (sgs_Compare( C, T+2, T+7 ) < 0);
- sgs_Release( C, T+6 ); sgs_InitBool( T+6, V ); }
- // set
- sgs_Assign( C, T+4, T+6 );
- // nop
- _op15:;
- // jump_if_false
- if( !sgs_GetBoolP( C, T+4 ) ) goto _op20;
- // div
- sgs_ArithOp( C, T+4, T+0, CN+7, SGS_EOP_DIV );
- // set
- sgs_Assign( C, T+0, T+4 );
- // inc
- sgs_IncDec( C, T+2, T+2, 1 );
- // jump
- goto _op6;
- _op20:;
- // push
- sgs_PushVariable( C, T+0 );
- // push
- sgs_PushVariable( C, CN+8 );
- // getindex
- sgs_Release( C, T+5 );
- sgs_GetIndexPPP( C, T+3, T+2, T+5, 0 );
- // push
- sgs_PushVariable( C, T+5 );
- // push
- sgs_PushVariable( C, CN+9 );
- // push
- sgs_PushVariable( C, T+1 );
- // push
- sgs_PushVariable( C, CN+10 );
- // mconcat
- sgs_Release( C, T+4 );
- sgs_StringConcat( C, 6 );
- sgs_StoreVariable( C, T+4 );
- // push
- sgs_PushVariable( C, T+4 );
- // return
- ret = 1;
- goto _ret;
- // ---
- _ret:
- sgs_ReleaseArray( C, T, 9 );
- return ret;
- }
- static int Dsgs__fmt_bytenum( SGS_CTX, sgs_VarObj* obj )
- {
- sgs_ReleaseArray( C, (sgs_Variable*) obj->data, 11 );
- }
- static int Gsgs__fmt_bytenum( SGS_CTX, sgs_VarObj* obj )
- {
- sgs_GCMarkArray( C, (sgs_Variable*) obj->data, 11 );
- }
- static sgs_ObjInterface Tsgs__fmt_bytenum[1] =
- {{
- "func",
- Dsgs__fmt_bytenum, Gsgs__fmt_bytenum,
- NULL, NULL,
- NULL, NULL, NULL, NULL,
- Fsgs__fmt_bytenum, NULL
- }};
- static int Isgs__fmt_bytenum( SGS_CTX, sgs_Variable* out )
- {
- sgs_Variable* CN = (sgs_Variable*)
- sgs_InitObjectIPA( C, out, sizeof(sgs_Variable) * 11, Tsgs__fmt_bytenum );
- sgs_InitInt( CN+0, 0LL );
- sgs_InitStringBuf( C, CN+1, "B", 1 );
- sgs_InitStringBuf( C, CN+2, "kB", 2 );
- sgs_InitStringBuf( C, CN+3, "MB", 2 );
- sgs_InitInt( CN+4, 2048LL );
- sgs_InitStringBuf( C, CN+5, "size", 4 );
- sgs_InitInt( CN+6, 1LL );
- sgs_InitInt( CN+7, 1024LL );
- sgs_InitStringBuf( C, CN+8, " ", 1 );
- sgs_InitStringBuf( C, CN+9, " (", 2 );
- sgs_InitStringBuf( C, CN+10, " bytes)", 7 );
- }
- int sgscript_main( SGS_CTX )
- {
- int ret = 0;
- SGSFN( "<main>" );
- sgs_Variable T[ 32 ];
- sgs_Variable CN[ 27 ];
- { int i; for( i = 0; i < 32; ++i )
- T[ i ].type = SGS_VT_NULL; }
- Isgs__fmt_bytenum( C, CN+0 );
- sgs_InitStringBuf( C, CN+1, "fmt_bytenum", 11 );
- sgs_InitInt( CN+2, 100000LL );
- sgs_InitStringBuf( C, CN+3, "sys_stat", 8 );
- sgs_InitInt( CN+4, 3LL );
- sgs_InitInt( CN+5, 6LL );
- sgs_InitStringBuf( C, CN+6, "map", 3 );
- sgs_InitStringBuf( C, CN+7, "ftime", 5 );
- sgs_InitInt( CN+8, 0LL );
- sgs_InitStringBuf( C, CN+9, "unset", 5 );
- sgs_InitNull( CN+10 );
- sgs_InitStringBuf( C, CN+11, "printlns", 8 );
- sgs_InitStringBuf( C, CN+12, "-- info --", 10 );
- sgs_InitStringBuf( C, CN+13, "count: ", 7 );
- sgs_InitStringBuf( C, CN+14, "-- time --", 10 );
- sgs_InitStringBuf( C, CN+15, "set: ", 5 );
- sgs_InitStringBuf( C, CN+16, "get: ", 5 );
- sgs_InitStringBuf( C, CN+17, "unset: ", 7 );
- sgs_InitStringBuf( C, CN+18, "-- memory --", 12 );
- sgs_InitStringBuf( C, CN+19, "before: ", 8 );
- sgs_InitStringBuf( C, CN+20, "load: ", 6 );
- sgs_InitStringBuf( C, CN+21, "unload: ", 8 );
- sgs_InitStringBuf( C, CN+22, "memory after dict free: ", 24 );
- sgs_InitStringBuf( C, CN+23, "delta: ", 7 );
- sgs_InitStringBuf( C, CN+24, "junk memory after unset: ", 25 );
- sgs_InitStringBuf( C, CN+25, "accumulated overhead: ", 22 );
- sgs_InitStringBuf( C, CN+26, "-- allocation count --", 22 );
- // setvar
- sgs_SetGlobalPP( C, CN+1, CN+0 );
- // set
- sgs_Assign( C, T+0, CN+2 );
- // getvar
- sgs_Release( C, T+16 );
- sgs_GetGlobalPP( C, CN+3, T+16 );
- // set
- sgs_Assign( C, T+15, CN+4 );
- // call
- sgs_PushVariable( C, T+15 );
- sgs_FCallP( C, T+16, 1, 1, 0 );
- sgs_Release( C, T+15 );
- sgs_StoreVariable( C, T+15 );
- // set
- sgs_Assign( C, T+1, T+15 );
- // getvar
- sgs_Release( C, T+16 );
- sgs_GetGlobalPP( C, CN+3, T+16 );
- // set
- sgs_Assign( C, T+15, CN+5 );
- // call
- sgs_PushVariable( C, T+15 );
- sgs_FCallP( C, T+16, 1, 1, 0 );
- sgs_Release( C, T+15 );
- sgs_StoreVariable( C, T+15 );
- // set
- sgs_Assign( C, T+2, T+15 );
- // getvar
- sgs_Release( C, T+15 );
- sgs_GetGlobalPP( C, CN+6, T+15 );
- // call
- sgs_FCallP( C, T+15, 0, 1, 0 );
- sgs_Release( C, T+15 );
- sgs_StoreVariable( C, T+15 );
- // set
- sgs_Assign( C, T+3, T+15 );
- // getvar
- sgs_Release( C, T+15 );
- sgs_GetGlobalPP( C, CN+7, T+15 );
- // call
- sgs_FCallP( C, T+15, 0, 1, 0 );
- sgs_Release( C, T+15 );
- sgs_StoreVariable( C, T+15 );
- // set
- sgs_Assign( C, T+4, T+15 );
- // set
- sgs_Assign( C, T+5, CN+8 );
- _op17:;
- // lt
- { int V = (sgs_Compare( C, T+5, T+0 ) < 0);
- sgs_Release( C, T+15 ); sgs_InitBool( T+15, V ); }
- // jump_if_false
- if( !sgs_GetBoolP( C, T+15 ) ) goto _op24;
- // getvar
- sgs_Release( C, T+15 );
- sgs_GetGlobalPP( C, CN+7, T+15 );
- // call
- sgs_FCallP( C, T+15, 0, 1, 0 );
- sgs_Release( C, T+15 );
- sgs_StoreVariable( C, T+15 );
- // setindex
- sgs_SetIndexPPP( C, T+3, T+5, T+15, 0 );
- // inc
- sgs_IncDec( C, T+5, T+5, 1 );
- // jump
- goto _op17;
- _op24:;
- // getvar
- sgs_Release( C, T+16 );
- sgs_GetGlobalPP( C, CN+3, T+16 );
- // set
- sgs_Assign( C, T+15, CN+4 );
- // call
- sgs_PushVariable( C, T+15 );
- sgs_FCallP( C, T+16, 1, 1, 0 );
- sgs_Release( C, T+15 );
- sgs_StoreVariable( C, T+15 );
- // set
- sgs_Assign( C, T+6, T+15 );
- // getvar
- sgs_Release( C, T+16 );
- sgs_GetGlobalPP( C, CN+3, T+16 );
- // set
- sgs_Assign( C, T+15, CN+5 );
- // call
- sgs_PushVariable( C, T+15 );
- sgs_FCallP( C, T+16, 1, 1, 0 );
- sgs_Release( C, T+15 );
- sgs_StoreVariable( C, T+15 );
- // set
- sgs_Assign( C, T+7, T+15 );
- // getvar
- sgs_Release( C, T+15 );
- sgs_GetGlobalPP( C, CN+7, T+15 );
- // call
- sgs_FCallP( C, T+15, 0, 1, 0 );
- sgs_Release( C, T+15 );
- sgs_StoreVariable( C, T+15 );
- // set
- sgs_Assign( C, T+8, T+15 );
- // set
- sgs_Assign( C, T+5, CN+8 );
- _op36:;
- // lt
- { int V = (sgs_Compare( C, T+5, T+0 ) < 0);
- sgs_Release( C, T+15 ); sgs_InitBool( T+15, V ); }
- // jump_if_false
- if( !sgs_GetBoolP( C, T+15 ) ) goto _op41;
- // getindex
- sgs_Release( C, T+9 );
- sgs_GetIndexPPP( C, T+3, T+5, T+9, 0 );
- // inc
- sgs_IncDec( C, T+5, T+5, 1 );
- // jump
- goto _op36;
- _op41:;
- // getvar
- sgs_Release( C, T+15 );
- sgs_GetGlobalPP( C, CN+7, T+15 );
- // call
- sgs_FCallP( C, T+15, 0, 1, 0 );
- sgs_Release( C, T+15 );
- sgs_StoreVariable( C, T+15 );
- // set
- sgs_Assign( C, T+10, T+15 );
- // set
- sgs_Assign( C, T+5, CN+8 );
- _op45:;
- // lt
- { int V = (sgs_Compare( C, T+5, T+0 ) < 0);
- sgs_Release( C, T+15 ); sgs_InitBool( T+15, V ); }
- // jump_if_false
- if( !sgs_GetBoolP( C, T+15 ) ) goto _op53;
- // getvar
- sgs_Release( C, T+17 );
- sgs_GetGlobalPP( C, CN+9, T+17 );
- // set
- sgs_Assign( C, T+15, T+3 );
- // set
- sgs_Assign( C, T+16, T+5 );
- // call
- sgs_PushVariable( C, T+15 );
- sgs_PushVariable( C, T+16 );
- sgs_FCallP( C, T+17, 2, 0, 0 );
- // inc
- sgs_IncDec( C, T+5, T+5, 1 );
- // jump
- goto _op45;
- _op53:;
- // getvar
- sgs_Release( C, T+16 );
- sgs_GetGlobalPP( C, CN+3, T+16 );
- // set
- sgs_Assign( C, T+15, CN+4 );
- // call
- sgs_PushVariable( C, T+15 );
- sgs_FCallP( C, T+16, 1, 1, 0 );
- sgs_Release( C, T+15 );
- sgs_StoreVariable( C, T+15 );
- // set
- sgs_Assign( C, T+11, T+15 );
- // getvar
- sgs_Release( C, T+16 );
- sgs_GetGlobalPP( C, CN+3, T+16 );
- // set
- sgs_Assign( C, T+15, CN+5 );
- // call
- sgs_PushVariable( C, T+15 );
- sgs_FCallP( C, T+16, 1, 1, 0 );
- sgs_Release( C, T+15 );
- sgs_StoreVariable( C, T+15 );
- // set
- sgs_Assign( C, T+12, T+15 );
- // getvar
- sgs_Release( C, T+15 );
- sgs_GetGlobalPP( C, CN+7, T+15 );
- // call
- sgs_FCallP( C, T+15, 0, 1, 0 );
- sgs_Release( C, T+15 );
- sgs_StoreVariable( C, T+15 );
- // set
- sgs_Assign( C, T+13, T+15 );
- // set
- sgs_Assign( C, T+3, CN+10 );
- // getvar
- sgs_Release( C, T+16 );
- sgs_GetGlobalPP( C, CN+3, T+16 );
- // set
- sgs_Assign( C, T+15, CN+4 );
- // call
- sgs_PushVariable( C, T+15 );
- sgs_FCallP( C, T+16, 1, 1, 0 );
- sgs_Release( C, T+15 );
- sgs_StoreVariable( C, T+15 );
- // set
- sgs_Assign( C, T+14, T+15 );
- // getvar
- sgs_Release( C, T+17 );
- sgs_GetGlobalPP( C, CN+11, T+17 );
- // set
- sgs_Assign( C, T+15, CN+12 );
- // concat
- sgs_PushVariable( C, CN+13 );
- sgs_PushVariable( C, T+0 );
- sgs_Release( C, T+16 );
- sgs_StringConcat( C, 2 );
- sgs_StoreVariable( C, T+16 );
- // call
- sgs_PushVariable( C, T+15 );
- sgs_PushVariable( C, T+16 );
- sgs_FCallP( C, T+17, 2, 0, 0 );
- // getvar
- sgs_Release( C, T+19 );
- sgs_GetGlobalPP( C, CN+11, T+19 );
- // set
- sgs_Assign( C, T+15, CN+14 );
- // sub
- sgs_ArithOp( C, T+21, T+8, T+4, SGS_EOP_SUB );
- // concat
- sgs_PushVariable( C, CN+15 );
- sgs_PushVariable( C, T+21 );
- sgs_Release( C, T+16 );
- sgs_StringConcat( C, 2 );
- sgs_StoreVariable( C, T+16 );
- // sub
- sgs_ArithOp( C, T+21, T+10, T+8, SGS_EOP_SUB );
- // concat
- sgs_PushVariable( C, CN+16 );
- sgs_PushVariable( C, T+21 );
- sgs_Release( C, T+17 );
- sgs_StringConcat( C, 2 );
- sgs_StoreVariable( C, T+17 );
- // sub
- sgs_ArithOp( C, T+21, T+13, T+10, SGS_EOP_SUB );
- // concat
- sgs_PushVariable( C, CN+17 );
- sgs_PushVariable( C, T+21 );
- sgs_Release( C, T+18 );
- sgs_StringConcat( C, 2 );
- sgs_StoreVariable( C, T+18 );
- // call
- sgs_PushVariable( C, T+15 );
- sgs_PushVariable( C, T+16 );
- sgs_PushVariable( C, T+17 );
- sgs_PushVariable( C, T+18 );
- sgs_FCallP( C, T+19, 4, 0, 0 );
- // getvar
- sgs_Release( C, T+27 );
- sgs_GetGlobalPP( C, CN+11, T+27 );
- // set
- sgs_Assign( C, T+15, CN+18 );
- // getvar
- sgs_Release( C, T+30 );
- sgs_GetGlobalPP( C, CN+1, T+30 );
- // set
- sgs_Assign( C, T+29, T+1 );
- // call
- sgs_PushVariable( C, T+29 );
- sgs_FCallP( C, T+30, 1, 1, 0 );
- sgs_Release( C, T+29 );
- sgs_StoreVariable( C, T+29 );
- // concat
- sgs_PushVariable( C, CN+19 );
- sgs_PushVariable( C, T+29 );
- sgs_Release( C, T+16 );
- sgs_StringConcat( C, 2 );
- sgs_StoreVariable( C, T+16 );
- // getvar
- sgs_Release( C, T+30 );
- sgs_GetGlobalPP( C, CN+1, T+30 );
- // set
- sgs_Assign( C, T+29, T+6 );
- // call
- sgs_PushVariable( C, T+29 );
- sgs_FCallP( C, T+30, 1, 1, 0 );
- sgs_Release( C, T+29 );
- sgs_StoreVariable( C, T+29 );
- // concat
- sgs_PushVariable( C, CN+20 );
- sgs_PushVariable( C, T+29 );
- sgs_Release( C, T+17 );
- sgs_StringConcat( C, 2 );
- sgs_StoreVariable( C, T+17 );
- // getvar
- sgs_Release( C, T+30 );
- sgs_GetGlobalPP( C, CN+1, T+30 );
- // set
- sgs_Assign( C, T+29, T+11 );
- // call
- sgs_PushVariable( C, T+29 );
- sgs_FCallP( C, T+30, 1, 1, 0 );
- sgs_Release( C, T+29 );
- sgs_StoreVariable( C, T+29 );
- // concat
- sgs_PushVariable( C, CN+21 );
- sgs_PushVariable( C, T+29 );
- sgs_Release( C, T+18 );
- sgs_StringConcat( C, 2 );
- sgs_StoreVariable( C, T+18 );
- // getvar
- sgs_Release( C, T+30 );
- sgs_GetGlobalPP( C, CN+1, T+30 );
- // set
- sgs_Assign( C, T+29, T+14 );
- // call
- sgs_PushVariable( C, T+29 );
- sgs_FCallP( C, T+30, 1, 1, 0 );
- sgs_Release( C, T+29 );
- sgs_StoreVariable( C, T+29 );
- // concat
- sgs_PushVariable( C, CN+22 );
- sgs_PushVariable( C, T+29 );
- sgs_Release( C, T+19 );
- sgs_StringConcat( C, 2 );
- sgs_StoreVariable( C, T+19 );
- // getvar
- sgs_Release( C, T+30 );
- sgs_GetGlobalPP( C, CN+1, T+30 );
- // sub
- sgs_ArithOp( C, T+29, T+6, T+1, SGS_EOP_SUB );
- // call
- sgs_PushVariable( C, T+29 );
- sgs_FCallP( C, T+30, 1, 1, 0 );
- sgs_Release( C, T+29 );
- sgs_StoreVariable( C, T+29 );
- // concat
- sgs_PushVariable( C, CN+23 );
- sgs_PushVariable( C, T+29 );
- sgs_Release( C, T+20 );
- sgs_StringConcat( C, 2 );
- sgs_StoreVariable( C, T+20 );
- // getvar
- sgs_Release( C, T+30 );
- sgs_GetGlobalPP( C, CN+1, T+30 );
- // sub
- sgs_ArithOp( C, T+29, T+11, T+14, SGS_EOP_SUB );
- // call
- sgs_PushVariable( C, T+29 );
- sgs_FCallP( C, T+30, 1, 1, 0 );
- sgs_Release( C, T+29 );
- sgs_StoreVariable( C, T+29 );
- // concat
- sgs_PushVariable( C, CN+24 );
- sgs_PushVariable( C, T+29 );
- sgs_Release( C, T+21 );
- sgs_StringConcat( C, 2 );
- sgs_StoreVariable( C, T+21 );
- // getvar
- sgs_Release( C, T+30 );
- sgs_GetGlobalPP( C, CN+1, T+30 );
- // sub
- sgs_ArithOp( C, T+29, T+14, T+1, SGS_EOP_SUB );
- // call
- sgs_PushVariable( C, T+29 );
- sgs_FCallP( C, T+30, 1, 1, 0 );
- sgs_Release( C, T+29 );
- sgs_StoreVariable( C, T+29 );
- // concat
- sgs_PushVariable( C, CN+25 );
- sgs_PushVariable( C, T+29 );
- sgs_Release( C, T+22 );
- sgs_StringConcat( C, 2 );
- sgs_StoreVariable( C, T+22 );
- // set
- sgs_Assign( C, T+23, CN+26 );
- // concat
- sgs_PushVariable( C, CN+19 );
- sgs_PushVariable( C, T+2 );
- sgs_Release( C, T+24 );
- sgs_StringConcat( C, 2 );
- sgs_StoreVariable( C, T+24 );
- // concat
- sgs_PushVariable( C, CN+20 );
- sgs_PushVariable( C, T+7 );
- sgs_Release( C, T+25 );
- sgs_StringConcat( C, 2 );
- sgs_StoreVariable( C, T+25 );
- // concat
- sgs_PushVariable( C, CN+21 );
- sgs_PushVariable( C, T+12 );
- sgs_Release( C, T+26 );
- sgs_StringConcat( C, 2 );
- sgs_StoreVariable( C, T+26 );
- // call
- sgs_PushVariable( C, T+15 );
- sgs_PushVariable( C, T+16 );
- sgs_PushVariable( C, T+17 );
- sgs_PushVariable( C, T+18 );
- sgs_PushVariable( C, T+19 );
- sgs_PushVariable( C, T+20 );
- sgs_PushVariable( C, T+21 );
- sgs_PushVariable( C, T+22 );
- sgs_PushVariable( C, T+23 );
- sgs_PushVariable( C, T+24 );
- sgs_PushVariable( C, T+25 );
- sgs_PushVariable( C, T+26 );
- sgs_FCallP( C, T+27, 12, 0, 0 );
- // ---
- _ret:
- sgs_ReleaseArray( C, T, 32 );
- sgs_ReleaseArray( C, CN, 27 );
- return ret;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement