2009-09-27 13:03:23 -04:00
|
|
|
! (c)2009 Joe Groff bsd license
|
2016-05-28 10:49:14 -04:00
|
|
|
USING: accessors alien.c-types alien.parser alien.parser.private
|
|
|
|
alien.syntax compiler.units continuations debugger eval fry kernel
|
2016-08-13 09:49:33 -04:00
|
|
|
lexer namespaces parser sequences sets summary tools.test
|
|
|
|
vocabs.parser words ;
|
2009-09-27 13:03:23 -04:00
|
|
|
IN: alien.parser.tests
|
|
|
|
|
2016-05-28 13:01:54 -04:00
|
|
|
<<
|
|
|
|
|
2016-05-28 10:49:14 -04:00
|
|
|
: with-parsing ( lines quot -- )
|
|
|
|
[ <lexer> ] [ '[ _ with-compilation-unit ] ] bi* with-lexer ; inline
|
|
|
|
|
2016-05-27 14:54:52 -04:00
|
|
|
! (CREATE-C-TYPE)
|
|
|
|
{ "hello" } [
|
2016-05-28 10:49:14 -04:00
|
|
|
{ "hello" } [ CREATE-C-TYPE name>> ] with-parsing
|
2016-05-27 14:54:52 -04:00
|
|
|
] unit-test
|
|
|
|
|
|
|
|
! Check that it deletes from old-definitions
|
|
|
|
{ 0 } [
|
2016-05-28 10:49:14 -04:00
|
|
|
{ } [
|
2016-05-27 14:54:52 -04:00
|
|
|
"hello" current-vocab create-word
|
|
|
|
old-definitions get first adjoin
|
|
|
|
"hello" (CREATE-C-TYPE) drop
|
|
|
|
old-definitions get first cardinality
|
2016-05-28 10:49:14 -04:00
|
|
|
] with-parsing
|
2016-05-27 14:54:52 -04:00
|
|
|
] unit-test
|
|
|
|
|
|
|
|
! make-callback-type
|
|
|
|
{ "what-type" } [
|
2016-05-28 10:49:14 -04:00
|
|
|
{ } [
|
|
|
|
void "what-type" f { } { } make-callback-type 2drop name>>
|
|
|
|
] with-parsing
|
2016-05-27 14:54:52 -04:00
|
|
|
] unit-test
|
|
|
|
|
2016-05-28 11:22:45 -04:00
|
|
|
{ 1 } [
|
2016-05-28 10:49:14 -04:00
|
|
|
{ } [
|
2016-05-27 14:54:52 -04:00
|
|
|
"hello" current-vocab create-word
|
|
|
|
old-definitions get first adjoin
|
2016-05-28 10:49:14 -04:00
|
|
|
void "hello" f { } { } make-callback-type 3drop
|
2016-05-27 14:54:52 -04:00
|
|
|
old-definitions get first cardinality
|
2016-05-28 10:49:14 -04:00
|
|
|
] with-parsing
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
! parse-enum-name
|
|
|
|
{ t } [
|
|
|
|
{ "ayae" } [ parse-enum-name new-definitions get first in? ] with-parsing
|
2016-05-27 14:54:52 -04:00
|
|
|
] unit-test
|
|
|
|
|
2016-08-13 09:49:33 -04:00
|
|
|
! validate-c-type-name
|
|
|
|
{ "Cannot define a C type “hello*” that ends with an asterisk (*)" } [
|
|
|
|
[ "hello*" validate-c-type-name ] [ ] recover summary
|
|
|
|
] unit-test
|
|
|
|
|
2016-05-28 13:01:54 -04:00
|
|
|
>>
|
|
|
|
|
2009-09-27 13:03:23 -04:00
|
|
|
TYPEDEF: char char2
|
|
|
|
|
|
|
|
SYMBOL: not-c-type
|
|
|
|
|
2009-10-16 13:27:16 -04:00
|
|
|
CONSTANT: eleven 11
|
|
|
|
|
2009-09-28 06:42:41 -04:00
|
|
|
[
|
|
|
|
"alien.parser.tests" use-vocab
|
|
|
|
"alien.c-types" use-vocab
|
|
|
|
|
|
|
|
[ int ] [ "int" parse-c-type ] unit-test
|
|
|
|
[ { int 5 } ] [ "int[5]" parse-c-type ] unit-test
|
|
|
|
[ { int 5 10 11 } ] [ "int[5][10][11]" parse-c-type ] unit-test
|
2009-10-16 13:27:16 -04:00
|
|
|
[ { int 5 10 eleven } ] [ "int[5][10][eleven]" parse-c-type ] unit-test
|
2010-02-21 19:27:36 -05:00
|
|
|
[ pointer: void ] [ "void*" parse-c-type ] unit-test
|
|
|
|
[ pointer: int ] [ "int*" parse-c-type ] unit-test
|
|
|
|
[ pointer: int* ] [ "int**" parse-c-type ] unit-test
|
|
|
|
[ pointer: int** ] [ "int***" parse-c-type ] unit-test
|
|
|
|
[ pointer: int*** ] [ "int****" parse-c-type ] unit-test
|
2010-08-15 04:51:55 -04:00
|
|
|
[ { pointer: int 3 } ] [ "int*[3]" parse-c-type ] unit-test
|
|
|
|
[ { pointer: void 3 } ] [ "void*[3]" parse-c-type ] unit-test
|
2010-08-15 05:37:17 -04:00
|
|
|
[ pointer: { int 3 } ] [ "int[3]*" parse-c-type ] unit-test
|
2010-02-23 14:42:02 -05:00
|
|
|
[ c-string ] [ "c-string" parse-c-type ] unit-test
|
2009-09-28 06:42:41 -04:00
|
|
|
[ char2 ] [ "char2" parse-c-type ] unit-test
|
2010-02-23 14:59:53 -05:00
|
|
|
[ pointer: char2 ] [ "char2*" parse-c-type ] unit-test
|
2009-09-28 06:42:41 -04:00
|
|
|
|
2010-08-15 05:37:17 -04:00
|
|
|
[ "void[3]" parse-c-type ] must-fail
|
|
|
|
[ "int[3" parse-c-type ] must-fail
|
|
|
|
[ "int[3][4" parse-c-type ] must-fail
|
2009-09-28 06:42:41 -04:00
|
|
|
[ "not-word" parse-c-type ] [ error>> no-word-error? ] must-fail-with
|
2009-10-09 05:25:25 -04:00
|
|
|
] with-file-vocabs
|
|
|
|
|
2015-07-19 19:24:47 -04:00
|
|
|
FUNCTION: void* alien-parser-function-effect-test ( int *arg1, float arg2 )
|
2010-07-28 03:05:14 -04:00
|
|
|
|
2015-07-03 12:39:59 -04:00
|
|
|
{ ( arg1 arg2 -- void* ) } [
|
2010-02-22 03:45:54 -05:00
|
|
|
\ alien-parser-function-effect-test "declared-effect" word-prop
|
|
|
|
] unit-test
|
|
|
|
|
2015-07-03 12:39:59 -04:00
|
|
|
{ t } [ \ alien-parser-function-effect-test inline? ] unit-test
|
2010-07-28 03:05:14 -04:00
|
|
|
|
2015-07-19 19:24:47 -04:00
|
|
|
FUNCTION-ALIAS: (alien-parser-function-effect-test) void* alien-parser-function-effect-test ( int *arg1, float arg2 )
|
2010-07-28 03:05:14 -04:00
|
|
|
|
2015-07-03 12:39:59 -04:00
|
|
|
{ ( arg1 arg2 -- void* ) } [
|
2010-07-28 03:05:14 -04:00
|
|
|
\ (alien-parser-function-effect-test) "declared-effect" word-prop
|
|
|
|
] unit-test
|
|
|
|
|
2015-07-03 12:39:59 -04:00
|
|
|
{ t } [ \ (alien-parser-function-effect-test) inline? ] unit-test
|
2010-07-28 03:05:14 -04:00
|
|
|
|
2015-07-19 19:24:47 -04:00
|
|
|
CALLBACK: void* alien-parser-callback-effect-test ( int *arg1 float arg2 )
|
2010-07-28 03:05:14 -04:00
|
|
|
|
2015-07-03 12:39:59 -04:00
|
|
|
{ ( arg1 arg2 -- void* ) } [
|
2010-02-22 03:45:54 -05:00
|
|
|
\ alien-parser-callback-effect-test "callback-effect" word-prop
|
2010-02-21 00:15:47 -05:00
|
|
|
] unit-test
|
|
|
|
|
2015-07-03 12:39:59 -04:00
|
|
|
{ t } [ \ alien-parser-callback-effect-test inline? ] unit-test
|
2010-07-28 03:05:14 -04:00
|
|
|
|
2009-10-09 05:25:25 -04:00
|
|
|
! Reported by mnestic
|
|
|
|
TYPEDEF: int alien-parser-test-int ! reasonably unique name...
|
|
|
|
|
2015-07-03 12:39:59 -04:00
|
|
|
{ "OK!" } [
|
2009-10-09 05:25:25 -04:00
|
|
|
[
|
|
|
|
"USE: specialized-arrays SPECIALIZED-ARRAY: alien-parser-test-int" eval( -- )
|
|
|
|
! after restart, we end up here
|
|
|
|
"OK!"
|
|
|
|
] [ :1 ] recover
|
2009-10-16 13:27:16 -04:00
|
|
|
] unit-test
|
2016-05-28 11:22:45 -04:00
|
|
|
|
|
|
|
! Redefinitions
|
|
|
|
{ } [
|
|
|
|
[ C-TYPE: hi TYPEDEF: void* hi ] with-compilation-unit
|
|
|
|
] unit-test
|