1 ! Copyright (C) 2009 Joe Groff.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: accessors alien.c-types alien.parser alien.parser.private
4 alien.syntax compiler.units continuations debugger eval kernel
5 lexer namespaces parser sequences sets summary tools.test
11 : with-parsing ( lines quot -- )
12 [ <lexer> ] [ '[ _ with-compilation-unit ] ] bi* with-lexer ; inline
16 { "hello" } [ CREATE-C-TYPE name>> ] with-parsing
19 ! Check that it deletes from old-definitions
22 "hello" current-vocab create-word
23 old-definitions get first adjoin
24 "hello" (CREATE-C-TYPE) drop
25 old-definitions get first cardinality
32 void "what-type" f { } { } make-callback-type 2drop name>>
38 "hello" current-vocab create-word
39 old-definitions get first adjoin
40 void "hello" f { } { } make-callback-type 3drop
41 old-definitions get first cardinality
47 { "ayae" } [ parse-enum-name new-definitions get first in? ] with-parsing
50 ! validate-c-type-name
51 { "Cannot define a C type “hello*” that ends with an asterisk (*)" } [
52 [ "hello*" validate-c-type-name ] [ ] recover summary
64 "alien.parser.tests" use-vocab
65 "alien.c-types" use-vocab
67 [ int ] [ "int" parse-c-type ] unit-test
68 [ { int 5 } ] [ "int[5]" parse-c-type ] unit-test
69 [ { int 5 10 11 } ] [ "int[5][10][11]" parse-c-type ] unit-test
70 [ { int 5 10 eleven } ] [ "int[5][10][eleven]" parse-c-type ] unit-test
71 [ pointer: void ] [ "void*" 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*** ] [ "int****" parse-c-type ] unit-test
76 [ { pointer: int 3 } ] [ "int*[3]" parse-c-type ] unit-test
77 [ { pointer: void 3 } ] [ "void*[3]" parse-c-type ] unit-test
78 [ pointer: { int 3 } ] [ "int[3]*" parse-c-type ] unit-test
79 [ c-string ] [ "c-string" parse-c-type ] unit-test
80 [ char2 ] [ "char2" parse-c-type ] unit-test
81 [ pointer: char2 ] [ "char2*" parse-c-type ] unit-test
83 [ "void[3]" parse-c-type ] must-fail
84 [ "int[3" parse-c-type ] must-fail
85 [ "int[3][4" parse-c-type ] must-fail
86 [ "not-word" parse-c-type ] [ error>> no-word-error? ] must-fail-with
89 FUNCTION: void* alien-parser-function-effect-test ( int *arg1, float arg2 )
91 { ( arg1 arg2 -- void* ) } [
92 \ alien-parser-function-effect-test "declared-effect" word-prop
95 { t } [ \ alien-parser-function-effect-test inline? ] unit-test
97 FUNCTION-ALIAS: (alien-parser-function-effect-test) void* alien-parser-function-effect-test ( int *arg1, float arg2 )
99 { ( arg1 arg2 -- void* ) } [
100 \ (alien-parser-function-effect-test) "declared-effect" word-prop
103 { t } [ \ (alien-parser-function-effect-test) inline? ] unit-test
105 CALLBACK: void* alien-parser-callback-effect-test ( int *arg1 float arg2 )
107 { ( arg1 arg2 -- void* ) } [
108 \ alien-parser-callback-effect-test "callback-effect" word-prop
111 { t } [ \ alien-parser-callback-effect-test inline? ] unit-test
113 ! Reported by mnestic
114 TYPEDEF: int alien-parser-test-int ! reasonably unique name...
118 "USE: specialized-arrays SPECIALIZED-ARRAY: alien-parser-test-int" eval( -- )
119 ! after restart, we end up here
126 [ C-TYPE: hi TYPEDEF: void* hi ] with-compilation-unit