Changeset 21202
- Timestamp:
- 07/04/08 02:15:06 (3 months ago)
- Location:
- v6/smop
- Files:
-
- 5 modified
-
src/native_capture.c (modified) (1 diff)
-
src/p6opaque.sm0p (modified) (6 diffs)
-
src/smop_s1p_scalar.c (modified) (3 diffs)
-
src/smop_slime_frame.c (modified) (2 diffs)
-
test/12_p6opaque.sm0p (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
v6/smop/src/native_capture.c
r21182 r21202 308 308 if (res) { 309 309 SMOP__Object* ret = res->value; 310 smop_lowlevel_unlock(capture); 310 311 if (ret) { 311 smop_lowlevel_unlock(capture);312 312 return SMOP_REFERENCE(interpreter,ret); 313 313 } else { -
v6/smop/src/p6opaque.sm0p
r21201 r21202 113 113 114 114 if (invocant == SMOP__p6opaque__RI) { 115 fprintf(stderr, "[SMOP p6opaque] TODO: p6opaque RI's meta undefined yet\n");116 115 ret = SMOP__NATIVE__bool_false; 117 116 } else if (SMOP_RI(invocant) != (SMOP__ResponderInterface*)SMOP__p6opaque__RI) { … … 119 118 ret = SMOP__NATIVE__bool_false; 120 119 } else { 121 if (set) 120 121 if (set) { 122 122 smop_lowlevel_wrlock(invocant); 123 else123 } else { 124 124 smop_lowlevel_rdlock(invocant); 125 } 125 126 126 127 if (((SMOP__p6opaque_struct*)invocant)->metadata) { 127 128 // we have our own metadata. 128 SMOP__Object* old = ((SMOP__p6opaque_struct*)invocant)->metadata->how; 129 ret = old; 129 SMOP__Object* old = NULL; 130 130 if (set) { 131 old = ((SMOP__p6opaque_struct*)invocant)->metadata->how; 131 132 ((SMOP__p6opaque_struct*)invocant)->metadata->how = set; 132 ret = set;133 133 } 134 ret = ((SMOP__p6opaque_struct*)invocant)->metadata->how; 134 135 smop_lowlevel_unlock(invocant); 136 135 137 if (old) SMOP_RELEASE(interpreter, old); 138 SMOP_REFERENCE(interpreter, ret); 136 139 137 140 } else if (((SMOP__p6opaque_struct*)invocant)->instanceof) { … … 143 146 if (set) { 144 147 fprintf(stderr, "[SMOP p6opaque] Can't set how on a instance\n"); 145 SMOP_RELEASE(interpreter,set);146 148 } else { 147 149 … … 173 175 ret = SMOP_REFERENCE(interpreter, set); 174 176 } else { 177 smop_lowlevel_unlock(invocant); 175 178 fprintf(stderr,"[SMOP p6opaque] TODO: invalid .^!how call\n"); 179 ret = SMOP__NATIVE__bool_false; 176 180 } 177 181 } … … 183 187 ret = SMOP__NATIVE__bool_false; 184 188 } 189 190 } else if (identifier == SMOP__ID__REPR_DESTROY) { 191 192 if (SMOP_RI(capture) == (SMOP__ResponderInterface*)SMOP__NATIVE__capture) { 193 SMOP__Object* invocant = SMOP__NATIVE__capture_invocant(interpreter,capture); 194 195 if (invocant == SMOP__p6opaque__RI) { 196 ret = SMOP__NATIVE__bool_false; 197 } else if (SMOP_RI(invocant) != (SMOP__ResponderInterface*)SMOP__p6opaque__RI) { 198 fprintf(stderr, "[SMOP p6opaque] call to repr method with non p6opaque invocant\n"); 199 ret = SMOP__NATIVE__bool_false; 200 } else { 201 smop_lowlevel_wrlock(invocant); 202 SMOP__p6opaque_LOWL_metadata* m = ((SMOP__p6opaque_struct*)invocant)->metadata; 203 ((SMOP__p6opaque_struct*)invocant)->metadata = NULL; 204 smop_lowlevel_unlock(invocant); 205 SMOP_RELEASE(interpreter,m->how); 206 free(m); 207 } 208 209 SMOP_RELEASE(interpreter,invocant); 210 } else { 211 fprintf(stderr, "[SMOP p6opaque] TODO: non-native captures\n"); 212 } 213 } else if (identifier == SMOP__ID__DESTROYALL) { 214 215 ret = SMOP__NATIVE__bool_true; 216 SMOP__Object* frame; 217 SMOP__Object* continuation = SMOP_DISPATCH(interpreter, SMOP_RI(interpreter), 218 SMOP__ID__continuation, 219 SMOP_REFERENCE(interpreter,interpreter)); 220 221 if (SMOP_RI(capture) == (SMOP__ResponderInterface*)SMOP__p6opaque__RI) { 222 SMOP__Object* invocant = capture; 223 $frame = q:sm0p { 224 $capture; 225 $identifier; 226 $invocant; 227 $invocant.SMOP__ID__REPR_how(); 228 SMOP__SLIME__CurrentFrame.copy(1); 229 SMOP__SLIME__CurrentFrame.move_responder(2,2); 230 SMOP__SLIME__CurrentFrame.move_capturize(SMOP__SLIME__Capturize.new(2,(4,5,6),(),1)); 231 SMOP__NATIVE__bool_true.SMOP__ID__dispatch(); 232 $invocant.SMOP__ID__REPR_DESTROY(); 233 $interpreter.goto(|$continuation); 234 }; 235 } else { 236 $frame = q:sm0p { 237 $capture; 238 $identifier; 239 $capture.SMOP__ID__invocant(); 240 $capture.SMOP__ID__invocant(); 241 SMOP__SLIME__CurrentFrame.move_capturize(SMOP__SLIME__Capturize.new(1,(),(),1)); 242 SMOP__p6opaque__RI.SMOP__ID__REPR_how(); 243 SMOP__SLIME__CurrentFrame.copy(1); 244 SMOP__SLIME__CurrentFrame.move_responder(2,2); 245 SMOP__SLIME__CurrentFrame.move_capturize(SMOP__SLIME__Capturize.new(2,(6,7,8),(),1)); 246 SMOP__NATIVE__bool_true.SMOP__ID__dispatch(); 247 $capture.SMOP__ID__invocant(); 248 SMOP__SLIME__CurrentFrame.move_responder(1,3); 249 $capture.SMOP__ID__invocant(); 250 SMOP__SLIME__CurrentFrame.move_capturize(SMOP__SLIME__Capturize.new(1,(),(),1)); 251 SMOP__p6opaque__RI.SMOP__ID__REPR_DESTROY(); 252 $interpreter.goto(|$continuation); 253 }; 254 } 255 256 SMOP_DISPATCH(interpreter, SMOP_RI(interpreter), 257 SMOP__ID__goto, 258 frame); 259 185 260 } else { 186 261 // as we want to support different captures, we'll start to use a … … 196 271 $identifier; 197 272 $capture.SMOP__ID__invocant(); 198 SMOP__SLIME__CurrentFrame.copy(1);273 $capture.SMOP__ID__invocant(); 199 274 SMOP__SLIME__CurrentFrame.move_capturize(SMOP__SLIME__Capturize.new(1,(),(),1)); 200 275 SMOP__p6opaque__RI.SMOP__ID__REPR_how(); -
v6/smop/src/smop_s1p_scalar.c
r20111 r21202 29 29 30 30 SMOP__Object* SMOP__S1P__Scalar_STORE(SMOP__Object* object, SMOP__Object* val) { 31 smop_lowlevel_ rdlock(object);31 smop_lowlevel_wrlock(object); 32 32 SMOP__Object* old = ((SMOP__S1P__Scalar_struct*)object)->cell; 33 33 ((SMOP__S1P__Scalar_struct*)object)->cell = val; … … 54 54 SMOP_RELEASE(interpreter,scalar); 55 55 SMOP_RELEASE(interpreter,capture); 56 56 57 } else if (SMOP__ID__DESTROYALL == identifier) { 57 58 SMOP__S1P__Scalar_struct* s = (SMOP__S1P__Scalar_struct*)capture; … … 62 63 63 64 SMOP_RELEASE(interpreter,cell); 65 64 66 } else { 65 67 fprintf(stderr,"Unknown identifier in lowlevel method object invocation.\n"); 66 68 SMOP_RELEASE(interpreter,capture); 69 67 70 } 68 71 return SMOP__NATIVE__bool_false; -
v6/smop/src/smop_slime_frame.c
r21201 r21202 79 79 ret = SMOP__NATIVE__bool_true; 80 80 } else { 81 smop_lowlevel_unlock(frame); 81 82 ret = SMOP__NATIVE__bool_false; 82 83 } … … 200 201 ret = SMOP__NATIVE__bool_true; 201 202 } else { 203 smop_lowlevel_unlock(frame); 202 204 ret = SMOP__NATIVE__bool_false; 203 205 } -
v6/smop/test/12_p6opaque.sm0p
r21201 r21202 4 4 #include <smop_slime.h> 5 5 #include <smop_oo.h> 6 #include <smop_lowlevel.h> 7 8 static SMOP__Object* test_message(SMOP__Object* interpreter, 9 SMOP__ResponderInterface* responder, 10 SMOP__Object* identifier, 11 SMOP__Object* capture) { 12 if (identifier == SMOP__ID__dispatch) { 13 printf("ok 3 - called dispatch\n"); 14 SMOP_RELEASE(interpreter, capture); 15 } else if (identifier == SMOP__ID__DESTROYALL) { 16 printf("ok 4 - called DESTROYALL\n"); 17 } else { 18 printf("not ok - unkown method\n"); 19 SMOP_RELEASE(interpreter, capture); 20 } 21 return SMOP__NATIVE__bool_true; 22 } 23 24 extern SMOP__Object* test_release(SMOP__Object* interpreter, 25 SMOP__ResponderInterface* responder, 26 SMOP__Object* obj) { 27 printf("-"); 28 smop_lowlevel_refcnt_dec(interpreter, responder, obj); 29 return obj; 30 } 31 32 extern SMOP__Object* test_reference(SMOP__Object* interpreter, 33 SMOP__ResponderInterface* responder, 34 SMOP__Object* obj) { 35 printf("+"); 36 smop_lowlevel_refcnt_inc(interpreter, responder, obj); 37 return obj; 38 } 6 39 7 40 int main() { 8 41 smop_init(); 9 42 10 printf("1.. 4\n");43 printf("1..6\n"); 11 44 12 45 … … 16 49 SMOP__INTPTR__InterpreterInstance,NULL,NULL)); 17 50 SMOP__Object* frame; 18 SMOP__Object* how = SMOP__NATIVE__bool_true; 51 SMOP__Object* how = smop_lowlevel_alloc(sizeof(SMOP__ResponderInterface)); 52 ((SMOP__ResponderInterface*)how)->MESSAGE = &test_message; 53 ((SMOP__ResponderInterface*)how)->REFERENCE = &test_reference; 54 ((SMOP__ResponderInterface*)how)->RELEASE = &test_release; 55 ((SMOP__ResponderInterface*)how)->id = "test metaclass"; 56 19 57 SMOP__Object* p6opaque = 20 58 SMOP_DISPATCH(SMOP__INTPTR__InterpreterInstance, SMOP__p6opaque__RI, … … 24 62 $frame = q:sm0p { 25 63 ; 26 $p6opaque.SMOP__ID__new(); 64 $p6opaque.SMOP__ID__REPR_how($how); 65 $p6opaque.SMOP__ID__STORE(); 27 66 }; 28 // SMOP__SLIME__CurrentFrame.move_responder(7,2);29 // SMOP__SLIME__CurrentFrame.move_capturize(SMOP__SLIME__Capturize.new(9,(),(),1));30 // SMOP__p6opaque__RI.SMOP__ID__new();31 //};32 67 33 68 if (!frame) printf("not "); 34 69 printf("ok 1 - frame created.\n"); 35 70 36 SMOP_RELEASE(interpreter,p6opaque);37 71 SMOP_DISPATCH(interpreter, SMOP_RI(interpreter), 38 72 SMOP__ID__goto, … … 41 75 printf("ok 2 - goto frame.\n"); 42 76 77 SMOP_RELEASE(interpreter,p6opaque); 43 78 SMOP_DISPATCH(interpreter, SMOP_RI(interpreter), 44 79 SMOP__ID__loop, SMOP__NATIVE__capture_create(interpreter, 45 80 SMOP_REFERENCE(interpreter,interpreter), 46 81 NULL, NULL)); 47 printf("ok 3- interpreter loop.\n");82 printf("ok 5 - interpreter loop.\n"); 48 83 49 84 50 85 SMOP_RELEASE(SMOP__INTPTR__InterpreterInstance,interpreter); 51 86 52 printf("ok 4- Scalar destroyed should free the p6opaque object also.\n");87 printf("ok 6 - Scalar destroyed should free the p6opaque object also.\n"); 53 88 54 89 smop_destr();
