Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //// IN
- a = 5;
- function f() use( a )
- {
- a = 10;
- }
- f();
- println( a );
- //// OUT
- #include <sgscript.h>
- static int Fsgs__f( SGS_CTX, sgs_VarObj* obj )
- {
- int ret = 0;
- SGSFN( "f" );
- sgs_Variable* CN = (sgs_Variable*) obj->data;
- // setclsr
- sgs_ClSetItem( C, 0, CN+0 );
- // ---
- _ret:
- return ret;
- }
- static int Dsgs__f( SGS_CTX, sgs_VarObj* obj )
- {
- sgs_ReleaseArray( C, (sgs_Variable*) obj->data, 1 );
- }
- static int Gsgs__f( SGS_CTX, sgs_VarObj* obj )
- {
- sgs_GCMarkArray( C, (sgs_Variable*) obj->data, 1 );
- }
- static sgs_ObjInterface Tsgs__f[1] =
- {{
- "func",
- Dsgs__f, Gsgs__f,
- NULL, NULL,
- NULL, NULL, NULL, NULL,
- Fsgs__f, NULL
- }};
- static int Isgs__f( SGS_CTX, sgs_Variable* out )
- {
- sgs_Variable* CN = (sgs_Variable*)
- sgs_InitObjectIPA( C, out, sizeof(sgs_Variable) * 1, Tsgs__f );
- sgs_InitInt( CN+0, 10LL );
- }
- int sgscript_main( SGS_CTX )
- {
- int ret = 0;
- SGSFN( "<main>" );
- sgs_Variable T[ 3 ];
- sgs_Variable CN[ 4 ];
- { int i; for( i = 0; i < 3; ++i )
- T[ i ].type = SGS_VT_NULL; }
- sgs_InitInt( CN+0, 5LL );
- Isgs__f( C, CN+1 );
- sgs_InitStringBuf( C, CN+2, "f", 1 );
- sgs_InitStringBuf( C, CN+3, "println", 7 );
- // genclsr
- sgs_ClPushNulls( C, 1 );
- // setclsr
- sgs_ClSetItem( C, 0, CN+0 );
- // pushclsr
- sgs_ClPushItem( C, 0 );
- // makeclsr
- sgs_MakeClosure( C, CN+1, 1, T+0 );
- // setvar
- sgs_SetGlobalPP( C, CN+2, T+0 );
- // getvar
- sgs_Release( C, T+0 );
- sgs_GetGlobalPP( C, CN+2, T+0 );
- // call
- sgs_FCallP( C, T+0, 0, 0, 0 );
- // getvar
- sgs_Release( C, T+1 );
- sgs_GetGlobalPP( C, CN+3, T+1 );
- // getclsr
- sgs_Release( C, T+2 );
- sgs_ClGetItem( C, 0, T+2 );
- // set
- sgs_Assign( C, T+0, T+2 );
- // call
- sgs_PushVariable( C, T+0 );
- sgs_FCallP( C, T+1, 1, 0, 0 );
- // ---
- _ret:
- sgs_ReleaseArray( C, T, 3 );
- sgs_ReleaseArray( C, CN, 4 );
- return ret;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement