| 1 |
|
| #include "EXTERN.h" |
| 2 |
|
| #include "perl.h" |
| 3 |
|
| #include "XSUB.h" |
| 4 |
|
| |
| 5 |
|
| #include "ppport.h" |
| 6 |
|
| |
| 7 |
|
| #ifdef CIAO |
| 8 |
|
| #include <dmstack.h> |
| 9 |
|
| #else |
| 10 |
|
| #include <stklib/stack.h> |
| 11 |
|
| #endif |
| 12 |
|
| |
| 13 |
|
| typedef Stack CIAO_Lib_StackIO; |
| 14 |
|
| |
| 15 |
|
| |
| 16 |
|
| MODULE = CIAO::Lib::StackIO PACKAGE = CIAO::Lib::StackIO::Private |
| 17 |
|
| |
| 18 |
|
| # don't really want the user to see these. eventually new() will |
| 19 |
|
| # be in here and these can go away |
| 20 |
|
| |
| 21 |
|
| CIAO_Lib_StackIO * |
| 22 |
|
| stk_build(list) |
| 23 |
|
| char * list |
| 24 |
|
| |
| 25 |
|
| CIAO_Lib_StackIO * |
| 26 |
|
| stk_build_gen(list) |
| 27 |
|
| char * list |
| 28 |
|
| |
| 29 |
|
| |
| 30 |
|
| CIAO_Lib_StackIO * |
| 31 |
|
| stk_expand_n(list, int_suf_num) |
| 32 |
|
| char * list |
| 33 |
|
| long int_suf_num |
| 34 |
|
| |
| 35 |
|
| |
| 36 |
|
| ########################################################################### |
| 37 |
|
| ########################################################################### |
| 38 |
|
| |
| 39 |
|
| # these are actual class methods. where possible, use the library directly |
| 40 |
|
| |
| 41 |
|
| MODULE = CIAO::Lib::StackIO PACKAGE = CIAO::Lib::StackIOPtr PREFIX = stk_ |
| 42 |
|
| |
| 43 |
|
| ########################################################################### |
| 44 |
|
| |
| 45 |
|
| int |
| 46 |
|
| append(stack, descriptor, ...) |
| 47 |
|
| CIAO_Lib_StackIO * stack |
| 48 |
|
| char * descriptor |
| 49 |
|
| PREINIT: |
| 50 |
2 |
▶ | int prepend = 0; |
Branch: 1 branch
| Branch | True | False | Total |
| int prepend = 0; |
2 |
0 |
2 |
|
| 51 |
|
| CODE: |
| 52 |
2 |
▶ | if ( items > 2 ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( items > 2 ) |
1 |
1 |
2 |
|
| 53 |
1 |
| prepend = SvIV(ST(2)); |
| 54 |
2 |
▶ | RETVAL = prepend ? |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = prepend ? |
0 |
2 |
2 |
|
| 55 |
2 |
▶ | stk_append( stack, descriptor ) : |
Branch: 1 branch
| Branch | True | False | Total |
| stk_append( stack, descriptor ) : |
1 |
1 |
2 |
|
| 56 |
1 |
| stk_append_gen( stack, descriptor ) ; |
| 57 |
|
| OUTPUT: |
| 58 |
|
| RETVAL |
| 59 |
|
| |
| 60 |
|
| ########################################################################### |
| 61 |
|
| |
| 62 |
|
| int |
| 63 |
|
| change(stack, descriptor, ...) |
| 64 |
|
| CIAO_Lib_StackIO * stack |
| 65 |
|
| char * descriptor |
| 66 |
|
| PREINIT: |
| 67 |
|
| int idx; |
| 68 |
|
| CODE: |
| 69 |
3 |
▶ | if ( items > 2 ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( items > 2 ) |
2 |
1 |
3 |
|
| 70 |
|
| { |
| 71 |
2 |
| idx = SvIV(ST(2)); |
| 72 |
2 |
▶ | if ( idx == -1 ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( idx == -1 ) |
1 |
1 |
2 |
|
| 73 |
1 |
| idx = stk_count( stack ); |
| 74 |
2 |
| stk_change_num( stack, descriptor, idx ); |
| 75 |
|
| } |
| 76 |
|
| else |
| 77 |
|
| { |
| 78 |
1 |
| RETVAL = stk_change_current( stack, descriptor ); |
| 79 |
|
| } |
| 80 |
|
| OUTPUT: |
| 81 |
|
| RETVAL |
| 82 |
|
| |
| 83 |
|
| ########################################################################### |
| 84 |
|
| |
| 85 |
|
| int |
| 86 |
|
| stk_count(stack) |
| 87 |
|
| CIAO_Lib_StackIO * stack |
| 88 |
|
| |
| 89 |
|
| ########################################################################### |
| 90 |
|
| |
| 91 |
|
| int |
| 92 |
|
| current(stack, ... ) |
| 93 |
|
| CIAO_Lib_StackIO * stack |
| 94 |
|
| PREINIT: |
| 95 |
|
| int idx; |
| 96 |
|
| CODE: |
| 97 |
18 |
| RETVAL = stk_current( stack ); |
| 98 |
18 |
▶ | if ( items > 1 ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( items > 1 ) |
7 |
11 |
18 |
|
| 99 |
|
| { |
| 100 |
7 |
| idx = SvIV(ST(1)); |
| 101 |
7 |
▶ | if ( 0 == idx ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( 0 == idx ) |
2 |
5 |
7 |
|
| 102 |
2 |
| stk_rewind( stack ); |
| 103 |
|
| else |
| 104 |
|
| { |
| 105 |
5 |
▶ | if ( -1 == idx ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( -1 == idx ) |
1 |
4 |
5 |
|
| 106 |
1 |
| idx = stk_count( stack ); |
| 107 |
5 |
| stk_set_current( stack, idx ); |
| 108 |
|
| } |
| 109 |
|
| } |
| 110 |
|
| OUTPUT: |
| 111 |
|
| RETVAL |
| 112 |
|
| |
| 113 |
|
| ########################################################################### |
| 114 |
|
| |
| 115 |
|
| int |
| 116 |
|
| delete(stack, ... ) |
| 117 |
|
| CIAO_Lib_StackIO * stack |
| 118 |
|
| PREINIT: |
| 119 |
|
| int idx; |
| 120 |
|
| CODE: |
| 121 |
3 |
▶ | if ( items > 1 ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( items > 1 ) |
2 |
1 |
3 |
|
| 122 |
|
| { |
| 123 |
2 |
| idx = SvIV(ST(1)); |
| 124 |
2 |
▶ | if ( idx == -1 ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( idx == -1 ) |
1 |
1 |
2 |
|
| 125 |
1 |
| idx = stk_count( stack ); |
| 126 |
|
| /* make up for bug in stk_delete_num which doesn't |
| 127 |
|
| handle error checking */ |
| 128 |
2 |
▶ | RETVAL = idx < 0 ? -1 : stk_delete_num( stack, idx ); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = idx < 0 ? -1 : stk_delete_num( stack, idx ); |
2 |
0 |
2 |
|
| 129 |
|
| } |
| 130 |
|
| else |
| 131 |
|
| { |
| 132 |
1 |
| RETVAL = stk_delete_current( stack ); |
| 133 |
|
| } |
| 134 |
|
| OUTPUT: |
| 135 |
|
| RETVAL |
| 136 |
|
| |
| 137 |
|
| ########################################################################### |
| 138 |
|
| |
| 139 |
|
| void |
| 140 |
|
| DESTROY(stack) |
| 141 |
|
| CIAO_Lib_StackIO * stack |
| 142 |
|
| CODE: |
| 143 |
6 |
| stk_close( stack ); |
| 144 |
|
| |
| 145 |
|
| ########################################################################### |
| 146 |
|
| |
| 147 |
|
| void |
| 148 |
|
| stk_disp(stack) |
| 149 |
|
| CIAO_Lib_StackIO * stack |
| 150 |
|
| |
| 151 |
|
| ########################################################################### |
| 152 |
|
| |
| 153 |
|
| SV * |
| 154 |
|
| read(stack, ...) |
| 155 |
|
| CIAO_Lib_StackIO * stack |
| 156 |
|
| PREINIT: |
| 157 |
|
| int idx; |
| 158 |
|
| char *retval; |
| 159 |
|
| PPCODE: |
| 160 |
|
| /* no particular entry requested */ |
| 161 |
33 |
▶ | if ( items == 1 ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( items == 1 ) |
24 |
9 |
33 |
|
| 162 |
|
| { |
| 163 |
|
| /* |
| 164 |
|
| scalar context: return the next entry |
| 165 |
|
| */ |
| 166 |
24 |
▶ | if ( GIMME_V == G_SCALAR ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( GIMME_V == G_SCALAR ) |
21 |
3 |
24 |
|
| 167 |
|
| { |
| 168 |
21 |
| retval = stk_read_next( stack ); |
| 169 |
21 |
▶ | EXTEND(SP, 1); |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 1); |
0 |
21 |
21 |
|
| 170 |
21 |
▶ | if ( retval ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( retval ) |
20 |
1 |
21 |
|
| 171 |
|
| { |
| 172 |
20 |
| PUSHs(sv_2mortal(newSVpv(retval, 0))); |
| 173 |
20 |
| Safefree( retval ); |
| 174 |
|
| } |
| 175 |
|
| else |
| 176 |
|
| { |
| 177 |
1 |
| PUSHs(sv_newmortal()); |
| 178 |
|
| } |
| 179 |
|
| } |
| 180 |
|
| /* |
| 181 |
|
| array context: return it all |
| 182 |
|
| */ |
| 183 |
3 |
▶ | else if ( GIMME_V == G_ARRAY ) |
Branch: 1 branch
| Branch | True | False | Total |
| else if ( GIMME_V == G_ARRAY ) |
3 |
0 |
3 |
|
| 184 |
|
| { |
| 185 |
3 |
| int current = stk_current( stack ); |
| 186 |
3 |
▶ | EXTEND(SP, stk_count(stack) ); |
Branch: 2 branches
| Branch | True | False | Total |
| EXTEND(SP, stk_count(stack) ); |
3 |
0 |
3 |
| EXTEND(SP, stk_count(stack) ); |
0 |
3 |
3 |
|
| 187 |
3 |
| stk_rewind(stack); |
| 188 |
33 |
▶ | while( retval = stk_read_next( stack ) ) |
Branch: 1 branch
| Branch | True | False | Total |
| while( retval = stk_read_next( stack ) ) |
30 |
3 |
33 |
|
| 189 |
|
| { |
| 190 |
30 |
| PUSHs(sv_2mortal(newSVpv(retval, 0))); |
| 191 |
30 |
| Safefree( retval ); |
| 192 |
|
| } |
| 193 |
3 |
▶ | if ( current ) stk_set_current( stack, current ); |
Branch: 1 branch
| Branch | True | False | Total |
| if ( current ) stk_set_current( stack, current ); |
2 |
1 |
3 |
|
| 194 |
1 |
| else stk_rewind( stack ); |
| 195 |
|
| } |
| 196 |
|
| } |
| 197 |
|
| /* particular entry requested */ |
| 198 |
|
| else |
| 199 |
|
| { |
| 200 |
9 |
| idx = SvIV(ST(1)); |
| 201 |
9 |
▶ | if ( idx == -1 ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( idx == -1 ) |
4 |
5 |
9 |
|
| 202 |
4 |
| idx = stk_count( stack ); |
| 203 |
9 |
| retval = stk_read_num( stack, idx ); |
| 204 |
9 |
▶ | EXTEND(SP, 1); |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 1); |
0 |
9 |
9 |
|
| 205 |
9 |
▶ | if ( retval ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( retval ) |
9 |
0 |
9 |
|
| 206 |
|
| { |
| 207 |
9 |
| PUSHs(sv_2mortal(newSVpv(retval, 0))); |
| 208 |
9 |
| Safefree( retval ); |
| 209 |
|
| } |
| 210 |
|
| else |
| 211 |
|
| { |
| 212 |
0 |
| PUSHs(sv_newmortal()); |
| 213 |
|
| } |
| 214 |
|
| } |
| 215 |
|
| |
| 216 |
|
| |
| 217 |
|
| ########################################################################### |
| 218 |
|
| |
| 219 |
|
| void |
| 220 |
|
| stk_rewind(stack) |
| 221 |
|
| CIAO_Lib_StackIO * stack |
| 222 |
|
| |
| 223 |
|
| ########################################################################### |
| 224 |
|
| |