1 ! (c)2009 Joe Groff bsd license
2 USING: accessors alien.c-types alien.parser alien.parser.private
3 alien.syntax compiler.units continuations debugger eval fry kernel
4 lexer namespaces parser sequences sets summary tools.test
10 : with-parsing ( lines quot -- )
11 [ <lexer> ] [ '[ _ with-compilation-unit ] ] bi* with-lexer ; inline
15 { "hello" } [ CREATE-C-TYPE name>> ] with-parsing
18 ! Check that it deletes from old-definitions
21 "hello" current-vocab create-word
22 old-definitions get first adjoin
23 "hello" (CREATE-C-TYPE) drop
24 old-definitions get first cardinality
31 void "what-type" f { } { } make-callback-type 2drop name>>
37 "hello" current-vocab create-word
38 old-definitions get first adjoin
39 void "hello" f { } { } make-callback-type 3drop
40 old-definitions get first cardinality
46 { "ayae" } [ parse-enum-name new-definitions get first in? ] with-parsing
49 ! validate-c-type-name
50 { "Cannot define a C type “hello*” that ends with an asterisk (*)" } [
51 [ "hello*" validate-c-type-name ] [ ] recover summary
63 "alien.parser.tests" use-vocab
64 "alien.c-types" use-vocab
66 [ int ] [ "int" parse-c-type ] unit-test
67 [ { int 5 } ] [ "int[5]" parse-c-type ] unit-test
68 [ { int 5 10 11 } ] [ "int[5][10][11]" parse-c-type ] unit-test
69 [ { int 5 10 eleven } ] [ "int[5][10][eleven]" parse-c-type ] unit-test
70 [ pointer: void ] [ "void*" parse-c-type ] unit-test
71 [ pointer: int ] [ "int*" parse-c-type ] unit-test
72 [ pointer: int* ] [ "int**" parse-c-type ] unit-test
73 [ pointer: int** ] [ "int***" parse-c-type ] unit-test
74 [ pointer: int*** ] [ "int****" parse-c-type ] unit-test
75 [ { pointer: int 3 } ] [ "int*[3]" parse-c-type ] unit-test
76 [ { pointer: void 3 } ] [ "void*[3]" parse-c-type ] unit-test
77 [ pointer: { int 3 } ] [ "int[3]*" parse-c-type ] unit-test
78 [ c-string ] [ "c-string" parse-c-type ] unit-test
79 [ char2 ] [ "char2" parse-c-type ] unit-test
80 [ pointer: char2 ] [ "char2*" parse-c-type ] unit-test
82 [ "void[3]" parse-c-type ] must-fail
83 [ "int[3" parse-c-type ] must-fail
84 [ "int[3][4" parse-c-type ] must-fail
85 [ "not-word" parse-c-type ] [ error>> no-word-error? ] must-fail-with
88 FUNCTION: void* alien-parser-function-effect-test ( int *arg1, float arg2 )
90 { ( arg1 arg2 -- void* ) } [
91 \ alien-parser-function-effect-test "declared-effect" word-prop
94 { t } [ \ alien-parser-function-effect-test inline? ] unit-test
96 FUNCTION-ALIAS: (alien-parser-function-effect-test) void* alien-parser-function-effect-test ( int *arg1, float arg2 )
98 { ( arg1 arg2 -- void* ) } [
99 \ (alien-parser-function-effect-test) "declared-effect" word-prop
102 { t } [ \ (alien-parser-function-effect-test) inline? ] unit-test
104 CALLBACK: void* alien-parser-callback-effect-test ( int *arg1 float arg2 )
106 { ( arg1 arg2 -- void* ) } [
107 \ alien-parser-callback-effect-test "callback-effect" word-prop
110 { t } [ \ alien-parser-callback-effect-test inline? ] unit-test
112 ! Reported by mnestic
113 TYPEDEF: int alien-parser-test-int ! reasonably unique name...
117 "USE: specialized-arrays SPECIALIZED-ARRAY: alien-parser-test-int" eval( -- )
118 ! after restart, we end up here
125 [ C-TYPE: hi TYPEDEF: void* hi ] with-compilation-unit