/* It works like: * 1 - boot smop, * 2 - init a new object, and set the methods * 3 - get a stack * 4 - call method 1 * 5 - lower the refcount (should init destruction) * 6 - call method 2 * 7 - call stack loop */ int main(int argc, char** argv) { printf("1..6\n"); smop_init(); SMOP__Object* obj = smop_lowlevel_alloc(sizeof(SMOP__ResponderInterface)); if (!obj) { printf("not "); } printf("ok 1 - object allocated successfully.\n"); SMOP__ResponderInterface* ri = (SMOP__ResponderInterface*)obj; ri->MESSAGE = custom_MESSAGE; ri->REFERENCE = smop_lowlevel_refcnt_inc; ri->RELEASE = smop_lowlevel_refcnt_dec; SMOP__Object* intrp = SMOP_DISPATCH(SMOP__INTPTR__InterpreterInstance, SMOP_RI(SMOP__INTPTR__InterpreterInstance), SMOP__ID__new, SMOP__NATIVE__capture_create(SMOP__INTPTR__InterpreterInstance, SMOP__INTPTR__InterpreterInstance, NULL, NULL)); if (!intrp) { printf("not "); } printf("ok 2 - got new interp successfully %p.\n",intrp); SMOP_DISPATCH(intrp, ri, SMOP__ID__new, NULL); /* At this point, the destruction code for the object will be put in * the stack. That's why we still can call the second method just * below that. The object will only be invalidated when the stack * loop is called. */ SMOP_RELEASE(intrp, obj); SMOP_DISPATCH(intrp, ri, SMOP__ID__invocant, NULL); SMOP_DISPATCH(intrp, SMOP_RI(intrp), SMOP__ID__loop, SMOP__NATIVE__capture_create(intrp, SMOP_REFERENCE(intrp,intrp), NULL, NULL)); SMOP_RELEASE(SMOP__INTPTR__InterpreterInstance, intrp); printf("ok 6 - finished succesfully.\n"); smop_destr(); return 0; }
SMOP__Object* interpreter = SMOP_interpreter_create(SMOP__EmptyInterpreter); smop_native_init(interpreter); smop_s1p_init(interpreter); printf("1..1\nok 1 - memory test only... look for valgrind output...\n"); SMOP_DISPATCH(interpreter, SMOP_RI(interpreter), SMOP__NATIVE__idconst_create("loop"), SMOP__NATIVE__capture_create( interpreter, (SMOP__Object*[]) {SMOP_REFERENCE(interpreter,interpreter),NULL} ,(SMOP__Object*[]) {NULL})); SMOP_DISPATCH(interpreter, SMOP_RI(interpreter), SMOP__NATIVE__idconst_create("goto"), SMOP__NATIVE__capture_create( interpreter, (SMOP__Object*[]) {SMOP_REFERENCE(interpreter,interpreter),SMOP__NATIVE__bool_false,NULL} ,(SMOP__Object*[]) {NULL})); SMOP_DISPATCH(interpreter, SMOP_RI(interpreter), SMOP__NATIVE__idconst_create("loop") , SMOP__NATIVE__capture_create( interpreter, (SMOP__Object*[]) {SMOP_REFERENCE(interpreter,interpreter),NULL}, (SMOP__Object*[]) {NULL})); smop_s1p_destr(interpreter); SMOP_DISPATCH(interpreter, SMOP_RI(interpreter),
smop_interpreter_init(); SMOP__NAGC__ResponderInterface ri; ri.RI = NULL; ri.MESSAGE = custom_message; ri.REFERENCE = smop_nagc_reference; ri.RELEASE = smop_nagc_release; ri.WEAKREF = smop_nagc_weakref; ri.id = "test ri"; ri.DESTROYALL = custom_destroyall; SMOP__Object* obj = smop_nagc_alloc(sizeof(SMOP__NAGC__Object)); obj->RI = (SMOP__ResponderInterface*)&ri; SMOP__Object* interpreter = SMOP_interpreter_create(SMOP__EmptyInterpreter); printf("ok 1 # lives after interpreter creation\n"); SMOP_DISPATCH(SMOP__EmptyInterpreter, SMOP_RI(interpreter), SMOP__NATIVE__idconst_createn("goto",4),SMOP__NATIVE__capture_create(interpreter,(SMOP__Object*[]) {SMOP_REFERENCE(interpreter,interpreter), obj, NULL}, (SMOP__Object*[]) {NULL})); SMOP_DISPATCH(SMOP__EmptyInterpreter, SMOP_RI(interpreter), SMOP__NATIVE__idconst_createn("loop",4),SMOP__NATIVE__capture_create(interpreter,(SMOP__Object*[]) {interpreter, NULL}, (SMOP__Object*[]) {NULL})); smop_interpreter_destr(); smop_capture_destr(); smop_nagc_destr(); smop_s0native_destr(); return 0; }