From b6dfdcb9095e3087e7aa657377f82d0a5a2b5218 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sat, 27 Mar 2010 08:13:57 -0400 Subject: [PATCH] set-context and start-context primitives can now pass parameters around --- basis/cpu/x86/32/bootstrap.factor | 16 ++++++++++------ basis/cpu/x86/64/bootstrap.factor | 18 ++++++++++-------- .../known-words/known-words.factor | 4 ++-- core/bootstrap/primitives.factor | 4 ++-- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/basis/cpu/x86/32/bootstrap.factor b/basis/cpu/x86/32/bootstrap.factor index 6fab8769d5..dde800760e 100644 --- a/basis/cpu/x86/32/bootstrap.factor +++ b/basis/cpu/x86/32/bootstrap.factor @@ -269,12 +269,11 @@ IN: bootstrap.x86 ESP [] vm-reg MOV "new_context" jit-call - ! Save pointer to quotation and parameter, pop them off the - ! datastack + ! Save pointer to quotation and parameter EBX ds-reg MOV ds-reg 8 SUB - ! Make the new context the active context + ! Make the new context active EAX jit-set-context ! Push parameter @@ -288,16 +287,21 @@ IN: bootstrap.x86 ] \ (start-context) define-sub-primitive [ - ! Load context from datastack + ! Load context and parameter from datastack EAX ds-reg [] MOV EAX EAX alien-offset [+] MOV - ds-reg 4 SUB + EBX ds-reg -4 [+] MOV + ds-reg 8 SUB - ! Make it the active context + ! Make the new context active EAX jit-set-context ! Twiddle stack for return ESP 4 ADD + + ! Store parameter to datastack + ds-reg 4 ADD + ds-reg [] EBX MOV ] \ (set-context) define-sub-primitive << "vocab:cpu/x86/bootstrap.factor" parse-file suffix! >> diff --git a/basis/cpu/x86/64/bootstrap.factor b/basis/cpu/x86/64/bootstrap.factor index e8fa026a49..9eb59e2c86 100644 --- a/basis/cpu/x86/64/bootstrap.factor +++ b/basis/cpu/x86/64/bootstrap.factor @@ -242,15 +242,12 @@ IN: bootstrap.x86 arg1 vm-reg MOV "new_context" jit-call - ! Load quotation from datastack + ! Load quotation and parameter from datastack arg1 ds-reg [] MOV - - ! Load parameter from datastack arg2 ds-reg -8 [+] MOV - ds-reg 16 SUB - ! Make the new context the active context + ! Make the new context active return-reg jit-set-context ! Push parameter @@ -262,16 +259,21 @@ IN: bootstrap.x86 ] \ (start-context) define-sub-primitive [ - ! Load context from datastack + ! Load context and parameter from datastack temp0 ds-reg [] MOV temp0 temp0 alien-offset [+] MOV - ds-reg 8 SUB + temp1 ds-reg -8 [+] MOV + ds-reg 16 SUB - ! Make it the active context + ! Make the new context active temp0 jit-set-context ! Twiddle stack for return RSP 8 ADD + + ! Store parameter to datastack + ds-reg 8 ADD + ds-reg [] temp1 MOV ] \ (set-context) define-sub-primitive << "vocab:cpu/x86/bootstrap.factor" parse-file suffix! >> diff --git a/basis/stack-checker/known-words/known-words.factor b/basis/stack-checker/known-words/known-words.factor index a625eedb3a..a95456cdc6 100644 --- a/basis/stack-checker/known-words/known-words.factor +++ b/basis/stack-checker/known-words/known-words.factor @@ -513,9 +513,9 @@ M: bad-executable summary \ delete-context { c-ptr } { } define-primitive -\ (start-context) { object quotation } { } define-primitive +\ (start-context) { object quotation } { object } define-primitive -\ (set-context) { alien } { } define-primitive +\ (set-context) { object alien } { object } define-primitive \ special-object { fixnum } { object } define-primitive \ special-object make-flushable diff --git a/core/bootstrap/primitives.factor b/core/bootstrap/primitives.factor index 9971c00e1d..38e1a380ee 100644 --- a/core/bootstrap/primitives.factor +++ b/core/bootstrap/primitives.factor @@ -369,8 +369,8 @@ tuple { "fixnum<=" "math.private" (( x y -- z )) } { "fixnum>" "math.private" (( x y -- ? )) } { "fixnum>=" "math.private" (( x y -- ? )) } - { "(set-context)" "threads.private" (( context -- )) } - { "(start-context)" "threads.private" (( obj quot -- )) } + { "(set-context)" "threads.private" (( obj context -- obj' )) } + { "(start-context)" "threads.private" (( obj quot -- obj' )) } } [ first3 make-sub-primitive ] each ! Primitive words