Working on alien-indirect
parent
1313d68dc1
commit
5f8856b56b
|
@ -17,7 +17,6 @@
|
||||||
- we need to optimize [ dup array? [ array? ] [ array? ] if ]
|
- we need to optimize [ dup array? [ array? ] [ array? ] if ]
|
||||||
- better way of dealing with compiler errors
|
- better way of dealing with compiler errors
|
||||||
- track individual method usages
|
- track individual method usages
|
||||||
- track a list of assets loaded from each module's file
|
|
||||||
- variable width word wrap
|
- variable width word wrap
|
||||||
- add-gadget, model-changed, set-model should compile
|
- add-gadget, model-changed, set-model should compile
|
||||||
- graphical module manager tool
|
- graphical module manager tool
|
||||||
|
@ -28,9 +27,11 @@
|
||||||
space
|
space
|
||||||
- we have trouble drawing rectangles
|
- we have trouble drawing rectangles
|
||||||
- UI dataflow visualizer
|
- UI dataflow visualizer
|
||||||
- tool help
|
|
||||||
- browser: show currently selected vocab & words
|
- browser: show currently selected vocab & words
|
||||||
|
|
||||||
- doc sweep
|
- doc sweep
|
||||||
|
- tool help
|
||||||
|
- perhaps commands window should sort by gesture
|
||||||
|
|
||||||
+ ui:
|
+ ui:
|
||||||
|
|
||||||
|
@ -38,7 +39,6 @@
|
||||||
because of grafting and ungrafting
|
because of grafting and ungrafting
|
||||||
- set-model set-model* and control-changed: its a hack, clean it up
|
- set-model set-model* and control-changed: its a hack, clean it up
|
||||||
- x11: scroll up/down wiggles caret
|
- x11: scroll up/down wiggles caret
|
||||||
- perhaps commands window should sort by gesture
|
|
||||||
- roundoff is still not quite right with tracks
|
- roundoff is still not quite right with tracks
|
||||||
- fix top level window positioning
|
- fix top level window positioning
|
||||||
- merge keyboard help with help in some way
|
- merge keyboard help with help in some way
|
||||||
|
@ -71,10 +71,11 @@
|
||||||
- horizontal wheel scrolling
|
- horizontal wheel scrolling
|
||||||
- polish OS X menu bar code
|
- polish OS X menu bar code
|
||||||
- structure editor
|
- structure editor
|
||||||
- loading space invaders slows the UI down
|
|
||||||
|
|
||||||
+ module system:
|
+ module system:
|
||||||
|
|
||||||
|
- convention for main entry point of a module
|
||||||
|
- track a list of assets loaded from each module's file
|
||||||
- generic 'define ( asset def -- )'
|
- generic 'define ( asset def -- )'
|
||||||
- C types should be words
|
- C types should be words
|
||||||
- TYPEDEF: float { ... } { ... } ; ==> \ float T{ c-type ... } "c-type" swp
|
- TYPEDEF: float { ... } { ... } ; ==> \ float T{ c-type ... } "c-type" swp
|
||||||
|
@ -85,6 +86,7 @@
|
||||||
|
|
||||||
+ compiler/ffi:
|
+ compiler/ffi:
|
||||||
|
|
||||||
|
- stdcall callbacks
|
||||||
- see if alien calls can be made faster
|
- see if alien calls can be made faster
|
||||||
- [ r> ] infer should throw an inference error
|
- [ r> ] infer should throw an inference error
|
||||||
- compiler tests are not as reliable now because of try-compile usage
|
- compiler tests are not as reliable now because of try-compile usage
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
! Copyright (C) 2006 Slava Pestov.
|
||||||
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
|
IN: alien
|
||||||
|
USING: compiler errors generic hashtables inference
|
||||||
|
kernel namespaces sequences strings words parser prettyprint ;
|
||||||
|
|
||||||
|
TUPLE: alien-indirect return parameters abi ;
|
||||||
|
C: alien-indirect make-node ;
|
||||||
|
|
||||||
|
TUPLE: alien-indirect-error ;
|
||||||
|
|
||||||
|
: alien-indirect ( funcptr args... return parameters abi -- )
|
||||||
|
<alien-indirect-error> throw ;
|
||||||
|
|
||||||
|
M: alien-indirect-error summary
|
||||||
|
drop "Words calling ``alien-indirect'' cannot run in the interpreter. Compile the caller word and try again." ;
|
||||||
|
|
||||||
|
\ alien-indirect [ string object string ] [ ] <effect>
|
||||||
|
"infer-effect" set-word-prop
|
||||||
|
|
||||||
|
\ alien-indirect [
|
||||||
|
empty-node <alien-indirect>
|
||||||
|
pop-literal nip over set-alien-indirect-abi
|
||||||
|
pop-literal nip over set-alien-indirect-parameters
|
||||||
|
pop-literal nip over set-alien-indirect-return
|
||||||
|
node,
|
||||||
|
] "infer" set-word-prop
|
||||||
|
|
||||||
|
: generate-indirect-cleanup ( node -- )
|
||||||
|
dup alien-indirect-abi "stdcall" = [
|
||||||
|
drop
|
||||||
|
] [
|
||||||
|
alien-indirect-parameters stack-space %cleanup
|
||||||
|
] if ;
|
||||||
|
|
||||||
|
: %shuffle "shuffle" word-prop phantom-shuffle end-basic-block ;
|
||||||
|
|
||||||
|
M: alien-indirect generate-node
|
||||||
|
end-basic-block compile-gc
|
||||||
|
dup alien-indirect-parameters objects>registers
|
||||||
|
%alien-indirect
|
||||||
|
dup generate-indirect-cleanup
|
||||||
|
alien-indirect-return box-return
|
||||||
|
iterate-next ;
|
||||||
|
|
||||||
|
M: alien-indirect stack-reserve*
|
||||||
|
alien-indirect-parameters stack-space ;
|
|
@ -52,10 +52,10 @@ M: alien-invoke-error summary
|
||||||
dup unbox-parameters "save_stacks" f %alien-invoke
|
dup unbox-parameters "save_stacks" f %alien-invoke
|
||||||
\ %stack>freg move-parameters ;
|
\ %stack>freg move-parameters ;
|
||||||
|
|
||||||
: box-return ( node -- )
|
: box-return ( ctype -- )
|
||||||
alien-invoke-return [ ] [ f swap box-parameter ] if-void ;
|
[ ] [ f swap box-parameter ] if-void ;
|
||||||
|
|
||||||
: generate-cleanup ( node -- )
|
: generate-invoke-cleanup ( node -- )
|
||||||
dup alien-invoke-library library-abi "stdcall" = [
|
dup alien-invoke-library library-abi "stdcall" = [
|
||||||
drop
|
drop
|
||||||
] [
|
] [
|
||||||
|
@ -66,7 +66,8 @@ M: alien-invoke generate-node
|
||||||
end-basic-block compile-gc
|
end-basic-block compile-gc
|
||||||
dup alien-invoke-parameters objects>registers
|
dup alien-invoke-parameters objects>registers
|
||||||
dup alien-invoke-dlsym %alien-invoke
|
dup alien-invoke-dlsym %alien-invoke
|
||||||
dup generate-cleanup box-return
|
dup generate-invoke-cleanup
|
||||||
|
alien-invoke-return box-return
|
||||||
iterate-next ;
|
iterate-next ;
|
||||||
|
|
||||||
M: alien-invoke stack-reserve*
|
M: alien-invoke stack-reserve*
|
||||||
|
|
|
@ -23,9 +23,6 @@ kernel-internals math namespaces sequences words ;
|
||||||
[ dup class get swap inc-reg-class ] keep ;
|
[ dup class get swap inc-reg-class ] keep ;
|
||||||
|
|
||||||
: alloc-parameter ( parameter -- reg reg-class )
|
: alloc-parameter ( parameter -- reg reg-class )
|
||||||
#! Allocate a register and stack frame location.
|
|
||||||
#! n is a stack location, and the value of the class
|
|
||||||
#! variable is a register number.
|
|
||||||
c-type "reg-class" swap hash dup reg-class-full?
|
c-type "reg-class" swap hash dup reg-class-full?
|
||||||
[ spill-param ] [ fastcall-param ] if
|
[ spill-param ] [ fastcall-param ] if
|
||||||
[ fastcall-regs nth ] keep ;
|
[ fastcall-regs nth ] keep ;
|
||||||
|
|
|
@ -48,6 +48,9 @@ M: stack-params %freg>stack
|
||||||
: %alien-invoke ( symbol dll -- )
|
: %alien-invoke ( symbol dll -- )
|
||||||
reset-sse compile-c-call ;
|
reset-sse compile-c-call ;
|
||||||
|
|
||||||
|
: %alien-indirect ( -- )
|
||||||
|
"unbox_alien" f %alien-invoke RAX CALL ;
|
||||||
|
|
||||||
: %alien-callback ( quot -- )
|
: %alien-callback ( quot -- )
|
||||||
RDI load-indirect "run_callback" f compile-c-call ;
|
RDI load-indirect "run_callback" f compile-c-call ;
|
||||||
|
|
||||||
|
|
|
@ -112,6 +112,8 @@ DEFER: %alien-callback ( quot -- )
|
||||||
|
|
||||||
DEFER: %callback-value ( reg-class func -- )
|
DEFER: %callback-value ( reg-class func -- )
|
||||||
|
|
||||||
|
DEFER: %alien-indirect ( -- )
|
||||||
|
|
||||||
M: stack-params fastcall-regs drop 0 ;
|
M: stack-params fastcall-regs drop 0 ;
|
||||||
|
|
||||||
GENERIC: reg-size ( register-class -- n )
|
GENERIC: reg-size ( register-class -- n )
|
||||||
|
|
|
@ -25,6 +25,7 @@ sequences words parser ;
|
||||||
dup shuffle-in-d swap shuffle-out-d <effect> ;
|
dup shuffle-in-d swap shuffle-out-d <effect> ;
|
||||||
|
|
||||||
: define-shuffle ( word shuffle -- )
|
: define-shuffle ( word shuffle -- )
|
||||||
|
[ "shuffle" set-word-prop ] 2keep
|
||||||
[ shuffle>effect "infer-effect" set-word-prop ] 2keep
|
[ shuffle>effect "infer-effect" set-word-prop ] 2keep
|
||||||
[ , \ infer-shuffle , ] [ ] make "infer" set-word-prop ;
|
[ , \ infer-shuffle , ] [ ] make "infer" set-word-prop ;
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ PROVIDE: library/compiler {
|
||||||
"alien/compiler.factor"
|
"alien/compiler.factor"
|
||||||
"alien/alien-invoke.factor"
|
"alien/alien-invoke.factor"
|
||||||
"alien/alien-callback.factor"
|
"alien/alien-callback.factor"
|
||||||
|
"alien/alien-indirect.factor"
|
||||||
"alien/syntax.factor"
|
"alien/syntax.factor"
|
||||||
|
|
||||||
"alien/alien-callback.facts"
|
"alien/alien-callback.facts"
|
||||||
|
|
|
@ -195,6 +195,9 @@ M: stack-params %freg>stack
|
||||||
: %alien-callback ( quot -- )
|
: %alien-callback ( quot -- )
|
||||||
0 <int-vreg> load-literal "run_callback" f %alien-invoke ;
|
0 <int-vreg> load-literal "run_callback" f %alien-invoke ;
|
||||||
|
|
||||||
|
: %alien-indirect ( -- )
|
||||||
|
"unbox_alien" f %alien-invoke 3 MTLR BLRL ;
|
||||||
|
|
||||||
: save-return 0 swap [ return-reg ] keep %freg>stack ;
|
: save-return 0 swap [ return-reg ] keep %freg>stack ;
|
||||||
: load-return 0 swap [ return-reg ] keep %stack>freg ;
|
: load-return 0 swap [ return-reg ] keep %stack>freg ;
|
||||||
|
|
||||||
|
|
|
@ -73,3 +73,15 @@ FUNCTION: foo ffi_test_14 int x int y ;
|
||||||
cpu "x86" = macosx? and [
|
cpu "x86" = macosx? and [
|
||||||
[ 11 6 ] [ 11 6 ffi_test_14 dup foo-x swap foo-y ] unit-test
|
[ 11 6 ] [ 11 6 ffi_test_14 dup foo-x swap foo-y ] unit-test
|
||||||
] when
|
] when
|
||||||
|
|
||||||
|
: indirect-test-1
|
||||||
|
"int" { } "cdecl" alien-indirect ;
|
||||||
|
|
||||||
|
[ 3 ] [ "ffi_test_1" f dlsym <alien> indirect-test-1 ] unit-test
|
||||||
|
|
||||||
|
: indirect-test-2
|
||||||
|
"int" { "int" "int" } "cdecl" alien-indirect ;
|
||||||
|
|
||||||
|
[ 5 ]
|
||||||
|
[ 2 3 "ffi_test_2" f dlsym <alien> indirect-test-2 ]
|
||||||
|
unit-test
|
||||||
|
|
|
@ -55,4 +55,7 @@ kernel-internals math memory namespaces words ;
|
||||||
! Restore return register
|
! Restore return register
|
||||||
pop-return-reg ;
|
pop-return-reg ;
|
||||||
|
|
||||||
|
: %alien-indirect ( -- )
|
||||||
|
"unbox_alien" f %alien-invoke EAX CALL ;
|
||||||
|
|
||||||
: %cleanup ( n -- ) dup zero? [ drop ] [ ESP swap ADD ] if ;
|
: %cleanup ( n -- ) dup zero? [ drop ] [ ESP swap ADD ] if ;
|
||||||
|
|
Loading…
Reference in New Issue