Skip to content

Commit

Permalink
#362 Add invoke behavior to replicator
Browse files Browse the repository at this point in the history
Fix bug with respect to passing sequences to a function, and a bug in
the parser that did not correctly generate updatebegin/updateend pairs.
  • Loading branch information
SanderMertens committed Oct 3, 2015
1 parent 576ff77 commit f82db99
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
5 changes: 4 additions & 1 deletion components/vm/src/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,10 @@ typedef union Di2f_t {
cx_error("Exception: null dereference in updateFrom");\
goto STOP;\
}\
cx_update((cx_object)op1_##code);\
if (cx_update((cx_object)op1_##code)) {\
cx_error("Exception: %s", cx_lasterr());\
goto error;\
}\
next();\

#define UPDATEBEGIN(type,code)\
Expand Down
2 changes: 1 addition & 1 deletion packages/corto/ast/src/ast_Update.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ static void ast_Update_begin(ast_Update this, ic_program program, ic_node expr)
}

static void ast_Update_end(ast_Update this, ic_program program, ic_node expr, ic_node from) {
IC_3(program, ast_Node(this)->line, ic_update, expr, from, NULL,
IC_3(program, ast_Node(this)->line, ic_updateend, expr, from, NULL,
IC_DEREF_ADDRESS, IC_DEREF_VALUE, IC_DEREF_VALUE);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/corto/lang/src/cx_call.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void cx_callb(cx_function f, cx_void* result, void* args) {
cx_object instance = *(cx_object*)args;
cx_object owner = cx_ownerof(instance);

if (instance && cx_instanceof(cx_replicator_o, instance)) {
if (owner && cx_instanceof(cx_replicator_o, owner)) {
cx_octetseq argbuff = {f->size, args};
cx_replicator_invoke(owner, instance, f, argbuff);
return;
Expand Down
5 changes: 5 additions & 0 deletions packages/corto/lang/src/cx_function.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ cx_int16 _cx_function_bind(cx_function this) {
case CX_PRIMITIVE:
this->size += cx_type_sizeof(paramType);
break;
case CX_COLLECTION:
if (cx_collection(paramType)->kind == CX_SEQUENCE) {
this->size += sizeof(cx_objectseq);
break;
}
default:
this->size += sizeof(void*);
break;
Expand Down
14 changes: 7 additions & 7 deletions packages/corto/lang/src/cx_replicator.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ cx_void _cx_replicator_destruct(cx_replicator this) {
/* ::corto::lang::replicator::invoke(object instance,function proc,octetseq args) */
cx_void _cx_replicator_invoke(cx_replicator this, cx_object instance, cx_function proc, cx_octetseq args) {
/* $begin(::corto::lang::replicator::invoke) */
cx_object owner = cx_ownerof(instance);

if (this->onInvoke._parent.procedure) {
if (cx_ownerof(instance) == this) {
if (owner == this) {
if (this->onInvoke._parent.procedure) {
cx_octetseq argbuff = args;
argbuff.buffer = cx_alloc(args.length * sizeof(cx_octet));
memcpy(argbuff.buffer, args.buffer, args.length * sizeof(cx_octet));
cx_invokeEvent e = cx_invokeEventCreate(this, instance, proc, argbuff);
cx_dispatcher_post(this, e);
} else {
cx_id id1, id2;
cx_error("invalid invoke: replicator %s does not own object '%s'",
cx_fullname(this, id1),
cx_fullname(instance, id2));
}
} else {
cx_object prevowner = cx_setOwner(cx_ownerof(instance));
cx_callb(proc, NULL, args.buffer);
cx_setOwner(prevowner);
}

/* $end */
Expand Down

0 comments on commit f82db99

Please sign in to comment.