2008-03-20 21:11:45 -04:00
|
|
|
! Copyright (C) 2005, 2008 Slava Pestov, Alex Chapman.
|
2007-09-20 18:09:08 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2008-07-01 17:33:45 -04:00
|
|
|
USING: accessors arrays alien alien.c-types alien.structs
|
|
|
|
alien.arrays alien.strings kernel math namespaces parser
|
|
|
|
sequences words quotations math.parser splitting grouping
|
|
|
|
effects prettyprint prettyprint.sections prettyprint.backend
|
|
|
|
assocs combinators lexer strings.parser ;
|
2007-09-20 18:09:08 -04:00
|
|
|
IN: alien.syntax
|
|
|
|
|
|
|
|
<PRIVATE
|
|
|
|
|
|
|
|
: parse-arglist ( return seq -- types effect )
|
2008-03-20 21:11:45 -04:00
|
|
|
2 group dup keys swap values [ "," ?tail drop ] map
|
2007-09-20 18:09:08 -04:00
|
|
|
rot dup "void" = [ drop { } ] [ 1array ] if <effect> ;
|
|
|
|
|
|
|
|
: function-quot ( type lib func types -- quot )
|
|
|
|
[ alien-invoke ] 2curry 2curry ;
|
|
|
|
|
|
|
|
: define-function ( return library function parameters -- )
|
2008-11-29 14:37:38 -05:00
|
|
|
[ pick ] dip parse-arglist
|
2007-09-20 18:09:08 -04:00
|
|
|
pick create-in dup reset-generic
|
2008-11-29 14:37:38 -05:00
|
|
|
[ function-quot ] 2dip
|
2007-09-20 18:09:08 -04:00
|
|
|
-rot define-declared ;
|
|
|
|
|
|
|
|
PRIVATE>
|
|
|
|
|
2008-03-18 19:02:24 -04:00
|
|
|
: DLL" lexer get skip-blank parse-string dlopen parsed ; parsing
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
: ALIEN: scan string>number <alien> parsed ; parsing
|
|
|
|
|
2008-07-01 17:33:45 -04:00
|
|
|
: BAD-ALIEN <bad-alien> parsed ; parsing
|
|
|
|
|
2007-09-20 18:09:08 -04:00
|
|
|
: LIBRARY: scan "c-library" set ; parsing
|
|
|
|
|
|
|
|
: FUNCTION:
|
|
|
|
scan "c-library" get scan ";" parse-tokens
|
2008-04-26 00:12:44 -04:00
|
|
|
[ "()" subseq? not ] filter
|
2007-09-20 18:09:08 -04:00
|
|
|
define-function ; parsing
|
|
|
|
|
|
|
|
: TYPEDEF:
|
|
|
|
scan scan typedef ; parsing
|
|
|
|
|
2008-01-13 03:09:08 -05:00
|
|
|
: TYPEDEF-IF:
|
|
|
|
scan-word execute scan scan rot [ typedef ] [ 2drop ] if ; parsing
|
|
|
|
|
2007-09-20 18:09:08 -04:00
|
|
|
: C-STRUCT:
|
|
|
|
scan in get
|
|
|
|
parse-definition
|
2008-11-29 14:37:38 -05:00
|
|
|
[ 2dup ] dip define-struct-early
|
2007-09-20 18:09:08 -04:00
|
|
|
define-struct ; parsing
|
|
|
|
|
|
|
|
: C-UNION:
|
|
|
|
scan in get parse-definition define-union ; parsing
|
|
|
|
|
|
|
|
: C-ENUM:
|
|
|
|
";" parse-tokens
|
|
|
|
dup length
|
2008-11-29 14:37:38 -05:00
|
|
|
[ [ create-in ] dip 1quotation define ] 2each ;
|
2007-09-20 18:09:08 -04:00
|
|
|
parsing
|
|
|
|
|
|
|
|
M: alien pprint*
|
2007-11-07 19:26:39 -05:00
|
|
|
{
|
2008-07-01 17:33:45 -04:00
|
|
|
{ [ dup expired? ] [ drop \ BAD-ALIEN pprint-word ] }
|
2007-11-07 19:26:39 -05:00
|
|
|
{ [ dup pinned-c-ptr? not ] [ drop "( displaced alien )" text ] }
|
2008-04-11 13:53:22 -04:00
|
|
|
[ \ ALIEN: [ alien-address pprint* ] pprint-prefix ]
|
2007-11-07 19:26:39 -05:00
|
|
|
} cond ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2007-12-03 19:19:18 -05:00
|
|
|
M: dll pprint* dll-path dup "DLL\" " "\"" pprint-string ;
|