]> gitweb.factorcode.org Git - factor.git/blob - basis/alien/syntax/syntax.factor
use a "pointer" wrapper tuple to indicate pointer types instead of the current slipsh...
[factor.git] / basis / alien / syntax / syntax.factor
1 ! Copyright (C) 2005, 2010 Slava Pestov, Alex Chapman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays alien alien.c-types
4 alien.arrays alien.strings kernel math namespaces parser
5 sequences words quotations math.parser splitting grouping
6 effects assocs combinators lexer strings.parser alien.parser 
7 fry vocabs.parser words.constant alien.libraries ;
8 IN: alien.syntax
9
10 SYNTAX: DLL" lexer get skip-blank parse-string dlopen suffix! ;
11
12 SYNTAX: ALIEN: 16 scan-base <alien> suffix! ;
13
14 SYNTAX: BAD-ALIEN <bad-alien> suffix! ;
15
16 SYNTAX: LIBRARY: scan "c-library" set ;
17
18 SYNTAX: FUNCTION:
19     (FUNCTION:) define-declared ;
20
21 SYNTAX: CALLBACK:
22     (CALLBACK:) define-inline ;
23
24 SYNTAX: TYPEDEF:
25     scan-c-type CREATE-C-TYPE dup save-location typedef ;
26
27 SYNTAX: C-ENUM:
28     ";" parse-tokens
29     [ [ create-in ] dip define-constant ] each-index ;
30
31 SYNTAX: C-TYPE:
32     void CREATE-C-TYPE typedef ;
33
34 ERROR: no-such-symbol name library ;
35
36 : address-of ( name library -- value )
37     2dup load-library dlsym [ 2nip ] [ no-such-symbol ] if* ;
38
39 SYNTAX: &:
40     scan "c-library" get '[ _ _ address-of ] append! ;
41
42 : global-quot ( type word -- quot )
43     name>> "c-library" get '[ _ _ address-of 0 ]
44     swap c-type-getter-boxer append ;
45
46 : define-global ( type word -- )
47     [ nip ] [ global-quot ] 2bi (( -- value )) define-declared ;
48
49 SYNTAX: C-GLOBAL: scan-c-type CREATE-WORD define-global ;
50
51 SYNTAX: pointer:
52     scan-c-type <pointer> suffix! ;