Fix start-context-and-delete sub-primitive (reported by Sascha Matzke)

db4
Slava Pestov 2010-08-02 20:28:23 -04:00
parent 39bcf7af6a
commit 451237a028
4 changed files with 37 additions and 11 deletions

View File

@ -335,7 +335,18 @@ IN: bootstrap.x86
jit-set-context
] \ (set-context-and-delete) define-sub-primitive
: jit-start-context-and-delete ( -- )
jit-load-vm
jit-load-context
ESP [] vm-reg MOV
ESP 4 [+] ctx-reg MOV
"reset_context" jit-call
jit-pop-quot-and-param
ctx-reg jit-switch-context
jit-push-param
jit-jump-quot ;
[
jit-delete-current-context
jit-start-context
jit-start-context-and-delete
] \ (start-context-and-delete) define-sub-primitive

View File

@ -230,9 +230,6 @@ IN: bootstrap.x86
: jit-switch-context ( reg -- )
-8 jit-scrub-return
! Save ds, rs registers
jit-save-context
! Make the new context the current one
ctx-reg swap MOV
vm-reg vm-context-offset [+] ctx-reg MOV
@ -257,6 +254,7 @@ IN: bootstrap.x86
: jit-set-context ( -- )
jit-pop-context-and-param
jit-save-context
arg1 jit-switch-context
RSP 8 ADD
jit-push-param ;
@ -269,17 +267,17 @@ IN: bootstrap.x86
ds-reg 16 SUB ;
: jit-start-context ( -- )
! Create the new context in return-reg
! Create the new context in return-reg. Have to save context
! twice, first before calling new_context() which may GC,
! and again after popping the two parameters from the stack.
jit-save-context
arg1 vm-reg MOV
"new_context" jit-call
jit-pop-quot-and-param
jit-save-context
return-reg jit-switch-context
jit-push-param
jit-jump-quot ;
[ jit-start-context ] \ (start-context) define-sub-primitive
@ -295,7 +293,17 @@ IN: bootstrap.x86
jit-set-context
] \ (set-context-and-delete) define-sub-primitive
: jit-start-context-and-delete ( -- )
jit-load-context
arg1 vm-reg MOV
arg2 ctx-reg MOV
"reset_context" jit-call
jit-pop-quot-and-param
ctx-reg jit-switch-context
jit-push-param
jit-jump-quot ;
[
jit-delete-current-context
jit-start-context
jit-start-context-and-delete
] \ (start-context-and-delete) define-sub-primitive

View File

@ -166,6 +166,12 @@ VM_C_API void delete_context(factor_vm *parent, context *old_context)
parent->delete_context(old_context);
}
VM_C_API void reset_context(factor_vm *parent, context *ctx)
{
ctx->reset();
parent->init_context(ctx);
}
cell factor_vm::begin_callback(cell quot_)
{
data_root<object> quot(quot_,this);

View File

@ -73,6 +73,7 @@ struct context {
VM_C_API context *new_context(factor_vm *parent);
VM_C_API void delete_context(factor_vm *parent, context *old_context);
VM_C_API void reset_context(factor_vm *parent, context *ctx);
VM_C_API cell begin_callback(factor_vm *parent, cell quot);
VM_C_API void end_callback(factor_vm *parent);