Changeset 22288 for v6

Show
Ignore:
Timestamp:
09/20/08 01:03:21 (2 months ago)
Author:
ruoso
Message:

[smop] YAY! SMOP now supports lazy map, for now there is only map in Void context, which means eager evaluation...

Location:
v6/smop
Files:
1 added
6 modified

Legend:

Unmodified
Added
Removed
  • v6/smop/CMakeLists.txt

    r22281 r22288  
    131131    src/smop_s1p_pureprototypehow.c 
    132132    src/smop_s1p_emptylist.c 
     133    src/smop_s1p_endofiterator.c 
    133134    src/smop_s1p_bindcapturesignature.c 
    134135    src/smop_s1p_defaultblocksignature.c 
  • v6/smop/include/smop_s1p.h

    r22272 r22288  
    77extern SMOP__Object* SMOP__S1P__Array; 
    88extern SMOP__Object* SMOP__S1P__Array_Iterator; 
     9extern SMOP__Object* SMOP__S1P__EndOfIterator; 
    910extern SMOP__Object* SMOP__S1P__Str; 
    1011extern SMOP__Object* SMOP__S1P__Hash; 
  • v6/smop/src/native_bool.c

    r22183 r22288  
    2222    SMOP_RELEASE(interpreter,capture); 
    2323    return invocant; 
     24  } else if (identifier = SMOP__ID__defined) { 
     25    SMOP_RELEASE(interpreter,capture); 
     26    return SMOP__NATIVE__bool_true; 
    2427  } else { 
    2528    ___UNKNOWN_METHOD___; 
  • v6/smop/src/smop_internal.h

    r22272 r22288  
    6565     smop_s1p_map_init();                   \ 
    6666     smop_s1p_array_iterator_init();        \ 
    67      smop_s1p_emptylist_init(); 
     67     smop_s1p_emptylist_init();             \ 
     68     smop_s1p_endofiterator_init(); 
    6869#define SMOP_INTERNAL_DESTROY_SEQUENCE      \ 
     70     smop_s1p_endofiterator_destr();        \ 
    6971     smop_s1p_emptylist_destr();            \ 
    7072     smop_s1p_array_iterator_destr();       \ 
     
    164166void smop_s1p_emptylist_init(); 
    165167void smop_s1p_emptylist_destr(); 
     168void smop_s1p_endofiterator_init(); 
     169void smop_s1p_endofiterator_destr(); 
    166170 
    167171#endif 
  • v6/smop/src/smop_s1p_emptylist.c

    r22272 r22288  
    1616  if (identifier == SMOP__ID__new) { 
    1717    ret = SMOP__S1P__EmptyList; 
     18 
     19  } else if (identifier == SMOP__ID__defined) { 
     20    ret = SMOP__NATIVE__bool_true; 
    1821 
    1922  } else if (identifier == SMOP__ID__postcircumfix_square) { 
  • v6/smop/src/smop_s1p_map.sm0p

    r22287 r22288  
    1212  SMOP__Object* input_iterator; 
    1313  SMOP__Object* code; 
    14 } smop_s1p_array_struct; 
     14} smop_s1p_map_iterator_struct; 
    1515 
    1616static SMOP__Object* map_iterator_consume_mold; 
     17static SMOP__Object* map_iterator_voidcontext_mold; 
    1718 
    1819static SMOP__Object* smop_s1p_map_message(SMOP__Object* interpreter, 
     
    2627 
    2728  if (identifier == SMOP__ID__postcircumfix_parens) { 
    28     ret = smop_lowlevel_alloc(sizeof(smop_s1p_array_struct)); 
     29    ret = smop_lowlevel_alloc(sizeof(smop_s1p_map_iterator_struct)); 
    2930    ret->RI = (SMOP__ResponderInterface*)SMOP__S1P__map; 
    30     ((smop_s1p_array_struct*)ret)->code = SMOP__NATIVE__capture_positional(interpreter,capture,0); 
    31     ((smop_s1p_array_struct*)ret)->input_iterator = SMOP__NATIVE__capture_positional(interpreter,capture,1); 
     31    ((smop_s1p_map_iterator_struct*)ret)->code = SMOP__NATIVE__capture_positional(interpreter,capture,0); 
     32    ((smop_s1p_map_iterator_struct*)ret)->input_iterator = SMOP__NATIVE__capture_positional(interpreter,capture,1); 
    3233 
    3334  } else if (identifier == SMOP__ID__Void) { 
    3435    // map in void context should evaluate eagerly. 
     36 
     37    SMOP__Object* frame = (SMOP__Object*)SMOP__Mold__Frame_create(interpreter,SMOP_REFERENCE(interpreter,map_iterator_voidcontext_mold)); 
     38    SMOP__Object* back = SMOP_DISPATCH(interpreter, SMOP_RI(interpreter), 
     39      SMOP__ID__continuation, 
     40      SMOP__NATIVE__capture_create(interpreter,SMOP_REFERENCE(interpreter,interpreter), 
     41        NULL,NULL)); 
     42 
     43    mold_reg_set(interpreter,frame,0,SMOP_REFERENCE(interpreter,interpreter)); 
     44    mold_reg_set(interpreter,frame,1,SMOP_REFERENCE(interpreter,capture)); 
     45    mold_reg_set(interpreter,frame,2,back); 
     46    mold_reg_set(interpreter,frame,3,SMOP_REFERENCE(interpreter,invocant)); 
     47 
     48    SMOP_DISPATCH(interpreter,SMOP_RI(interpreter),SMOP__ID__goto,frame); 
    3549     
     50  } else if (identifier == SMOP__ID__prefix_equal) { 
     51    // this is the bare iterator without a context applied, which 
     52    // means that it returns the bare return of the code. 
     53 
     54    smop_lowlevel_rdlock(invocant); 
     55    SMOP__Object* code = ((smop_s1p_map_iterator_struct*)invocant)->code; 
     56    SMOP__Object* in = ((smop_s1p_map_iterator_struct*)invocant)->input_iterator; 
     57    smop_lowlevel_unlock(invocant); 
     58 
     59    SMOP__Object* frame = (SMOP__Object*)SMOP__Mold__Frame_create(interpreter,SMOP_REFERENCE(interpreter,map_iterator_consume_mold)); 
     60    SMOP__Object* back = SMOP_DISPATCH(interpreter, SMOP_RI(interpreter), 
     61      SMOP__ID__continuation, 
     62      SMOP__NATIVE__capture_create(interpreter,SMOP_REFERENCE(interpreter,interpreter), 
     63        NULL,NULL)); 
     64 
     65    mold_reg_set(interpreter,frame,0,SMOP_REFERENCE(interpreter,interpreter)); 
     66    mold_reg_set(interpreter,frame,1,SMOP_REFERENCE(interpreter,capture)); 
     67    mold_reg_set(interpreter,frame,2,back); 
     68    mold_reg_set(interpreter,frame,3,SMOP_REFERENCE(interpreter,code)); 
     69    mold_reg_set(interpreter,frame,4,SMOP_REFERENCE(interpreter,in)); 
     70 
     71    SMOP_DISPATCH(interpreter,SMOP_RI(interpreter),SMOP__ID__goto,frame); 
    3672 
    3773  } else if (identifier == SMOP__ID__DESTROYALL) { 
    3874    smop_lowlevel_wrlock(invocant); 
    39     SMOP__Object* code = ((smop_s1p_array_struct*)invocant)->code; 
    40     ((smop_s1p_array_struct*)invocant)->code = NULL; 
    41     SMOP__Object* in = ((smop_s1p_array_struct*)invocant)->input_iterator; 
    42     ((smop_s1p_array_struct*)invocant)->input_iterator = NULL; 
     75    SMOP__Object* code = ((smop_s1p_map_iterator_struct*)invocant)->code; 
     76    ((smop_s1p_map_iterator_struct*)invocant)->code = NULL; 
     77    SMOP__Object* in = ((smop_s1p_map_iterator_struct*)invocant)->input_iterator; 
     78    ((smop_s1p_map_iterator_struct*)invocant)->input_iterator = NULL; 
    4379    smop_lowlevel_unlock(invocant); 
    4480     
     
    71107  SMOP__Object* interpreter = SMOP__GlobalInterpreter; 
    72108  map_iterator_consume_mold = q:m0ld { 
     109    my $interpreter; 
    73110    my $capture; 
    74111    my $back; 
    75     my $interpreter; 
     112    my $code; 
     113    my $input_iterator; 
     114     
     115    my $next_item = $input_iterator."prefix:="(); 
     116    my $list = $next_item."List"(); 
     117    my $elems = $list."elems"(); 
     118    my $greater = $elems."infix:>"(0); 
     119    my $bool = $greater."bool"(); 
     120    if $bool { goto iteration } else { goto end }; 
    76121 
    77  
    78     my $result; 
     122    iteration: 
     123    my $item = $next_item."FETCH"(); 
     124    my $result = $code."postcircumfix:( )"($item); 
    79125    my $void = $back."setr"($result); 
    80126    $void = $interpreter."goto"($back); 
     127 
     128    end: 
     129    $void = $back."setr"(¢SMOP__S1P__EndOfIterator); 
     130    $void = $interpreter."goto"($back); 
     131 
     132  }; 
     133 
     134  map_iterator_voidcontext_mold = q:m0ld { 
     135    my $interpreter; 
     136    my $capture; 
     137    my $back; 
     138    my $invocant; 
     139 
     140    while: 
     141    my $result = $invocant."prefix:="(); 
     142    my $defined = $result."defined"(); 
     143     
     144    if $defined { goto iteration } else { goto end }; 
     145     
     146    iteration: 
     147    goto while; 
     148     
     149    end: 
     150    my $void = $interpreter."goto"($back); 
     151     
    81152  }; 
    82153 
     
    86157  SMOP_RELEASE(SMOP__GlobalInterpreter, map_iterator_consume_mold); 
    87158  map_iterator_consume_mold = NULL; 
     159  SMOP_RELEASE(SMOP__GlobalInterpreter, map_iterator_voidcontext_mold); 
     160  map_iterator_voidcontext_mold = NULL; 
    88161} 
    89162