2005-06-12 03:38:57 -04:00
|
|
|
! Copyright (C) 2005 Alex Chapman.
|
|
|
|
! See http://factor.sf.net/license.txt for BSD license.
|
|
|
|
IN: alien
|
|
|
|
USING: compiler kernel lists namespaces parser sequences words ;
|
|
|
|
|
|
|
|
! usage of 'LIBRARY:' and 'FUNCTION:' :
|
|
|
|
!
|
|
|
|
! LIBRARY: gl
|
|
|
|
! FUNCTION: void glTranslatef ( GLfloat x, GLfloat y, GLfloat z ) ;
|
|
|
|
!
|
|
|
|
! should be the same as doing:
|
|
|
|
!
|
|
|
|
! : glTranslatef ( x y z -- )
|
|
|
|
! "void" "gl" "glTranslatef" [ "GLfloat" "GLfloat" "GLfloat" ] alien-invoke ;
|
|
|
|
! \ glTranslatef compile
|
|
|
|
!
|
|
|
|
! other forms:
|
|
|
|
!
|
|
|
|
! FUNCTION: void glEnd ( ) ; -> : glEnd ( -- ) "void" "gl" "glEnd" [ ] alien-invoke ;
|
|
|
|
!
|
|
|
|
! TODO: show returns in the stack effect
|
|
|
|
|
|
|
|
: LIBRARY: scan "c-library" set ; parsing
|
|
|
|
|
2005-08-22 16:39:01 -04:00
|
|
|
: unpair ( seq -- odds evens )
|
|
|
|
2 swap group flip dup empty?
|
|
|
|
[ drop { } { } ] [ 2unseq ] ifte ;
|
|
|
|
|
2005-06-12 03:38:57 -04:00
|
|
|
: parse-arglist ( lst -- types stack effect )
|
2005-08-22 16:39:01 -04:00
|
|
|
unpair [
|
2005-06-12 03:38:57 -04:00
|
|
|
" " % [ "," ?tail drop % " " % ] each "-- " %
|
|
|
|
] make-string ;
|
|
|
|
|
|
|
|
: (define-c-word) ( type lib func types stack-effect -- )
|
|
|
|
>r over create-in >r
|
|
|
|
[ alien-invoke ] cons cons cons cons r> swap define-compound
|
|
|
|
word r> "stack-effect" set-word-prop ;
|
|
|
|
|
|
|
|
: define-c-word ( type lib func function-args -- )
|
|
|
|
[ "()" subseq? not ] subset parse-arglist (define-c-word) ;
|
|
|
|
|
|
|
|
: FUNCTION:
|
|
|
|
scan "c-library" get scan string-mode on
|
|
|
|
[ string-mode off define-c-word ] [ ] ; parsing
|
|
|
|
|
|
|
|
: TYPEDEF:
|
|
|
|
#! TYPEDEF: old new
|
|
|
|
scan scan typedef ; parsing
|
|
|
|
|
|
|
|
: DLL" skip-blank parse-string dlopen swons ; parsing
|