Changeset 22799 for v6

Show
Ignore:
Timestamp:
10/28/08 16:24:24 (2 months ago)
Author:
ruoso
Message:

[smop-XS] one step from running mold code directly from p5

Location:
v6/smop/SMOP
Files:
1 added
1 modified

Legend:

Unmodified
Added
Removed
  • v6/smop/SMOP/SMOP.xs

    r22798 r22799  
    103103    RETVAL 
    104104 
     105MODULE = SMOP       PACKAGE = SMOP::Mold 
     106 
     107SV* 
     108create(SV* p5class, SV* consts, SV* bytecode) 
     109  CODE: 
     110    AV* constsav = (AV*)SvRV(consts); 
     111    int constslen = av_len(constsav); 
     112    SMOP__Object** consts_arr = calloc(constslen+1,sizeof(void*)); 
     113    int i; 
     114    for (i = 0; i < constslen; i++) { 
     115        SV** e = av_fetch(constsav,i,0); 
     116        SMOP__Object* object; 
     117        if (SvROK(*e)) { 
     118            SV* value = SvRV(*e); 
     119            object = SMOP_REFERENCE(SMOP__GlobalInterpreter, (SMOP__Object*)SvIV(value)); 
     120        } else if (SvIOK(*e)) { 
     121            object = SMOP__NATIVE__int_create(SvIV(*e)); 
     122        } else if (SvPOK(*e)) { 
     123            STRLEN len; 
     124            char* p = SvPV(*e,len); 
     125            object = SMOP__NATIVE__idconst_createn(p,len); 
     126        } else { 
     127            printf("Unknown value sent to mold->create\n"); 
     128            object = SMOP__NATIVE__bool_false; 
     129        } 
     130        consts_arr[i] = object; 
     131    } 
     132    AV* codeav = (AV*)SvRV(bytecode); 
     133    int codelen = av_len(codeav); 
     134    int* code_arr = calloc(codelen+1,sizeof(void*)); 
     135    for (i = 0; i < codelen; i++) { 
     136        SV** e = av_fetch(codeav,i,0); 
     137        code_arr[i] = SvIV(*e); 
     138    } 
     139    SMOP__Object* mold = SMOP__Mold_create(constslen, consts_arr, codelen, code_arr); 
     140    SV* pointer = newSViv((int)mold); 
     141    SV* object = newRV_noinc(pointer); 
     142    HV* class = gv_stashpv("SMOP::Object", 0); 
     143    RETVAL = sv_bless(object, class); 
     144  OUTPUT: 
     145    RETVAL 
     146 
     147MODULE = SMOP       PACKAGE = SMOP::MoldFrame 
     148 
     149SV* 
     150create(SV* p5class, SV* moldrv) 
     151  CODE: 
     152    SV* value = SvRV(moldrv); 
     153    SMOP__Object* mold = (SMOP__Object*)SvIV(value); 
     154    SMOP__Object* frame = SMOP__Mold__Frame_create(SMOP__GlobalInterpreter, mold); 
     155    SV* pointer = newSViv((int)frame); 
     156    SV* object = newRV_noinc(pointer); 
     157    HV* class = gv_stashpv("SMOP::Object", 0); 
     158    RETVAL = sv_bless(object, class); 
     159  OUTPUT: 
     160    RETVAL     
     161 
     162MODULE = SMOP       PACKAGE = SMOP::Interpreter 
     163 
     164SV* 
     165run(SV* p5class, SV* continuation) 
     166  CODE: 
     167    SV* value = SvRV(continuation); 
     168    SMOP__Object* object = (SMOP__Object*)SvIV(value); 
     169    SMOP_DISPATCH(SMOP__GlobalInterpreter, SMOP_RI(SMOP__GlobalInterpreter), 
     170                  SMOP__ID__goto, SMOP__NATIVE__capture_create(SMOP__GlobalInterpreter, 
     171                                                               SMOP_REFERENCE(SMOP__GlobalInterpreter, object), 
     172                                                               NULL, NULL)); 
     173    SMOP_DISPATCH(SMOP__GlobalInterpreter, SMOP_RI(SMOP__GlobalInterpreter), 
     174                  SMOP__ID__loop, SMOP__NATIVE__capture_create(SMOP__GlobalInterpreter, 
     175                                                               SMOP_REFERENCE(SMOP__GlobalInterpreter, SMOP__GlobalInterpreter), 
     176                                                               NULL, NULL)); 
     177 
     178 
    105179MODULE = SMOP       PACKAGE = SMOP::S1P 
    106180