From 28dbb22aeea7cc0409bb61ce82e2c9dc41f81440 Mon Sep 17 00:00:00 2001 From: Jeremy Hughes Date: Wed, 15 Jul 2009 16:51:44 +1200 Subject: [PATCH] split alien.inline syntax into alien.inline.syntax --- extra/alien/inline/inline-docs.factor | 102 ------------------ extra/alien/inline/inline.factor | 26 ----- extra/alien/inline/syntax/authors.txt | 1 + extra/alien/inline/syntax/syntax-docs.factor | 100 +++++++++++++++++ .../syntax-tests.factor} | 4 +- extra/alien/inline/syntax/syntax.factor | 31 ++++++ 6 files changed, 134 insertions(+), 130 deletions(-) create mode 100644 extra/alien/inline/syntax/authors.txt create mode 100644 extra/alien/inline/syntax/syntax-docs.factor rename extra/alien/inline/{inline-tests.factor => syntax/syntax-tests.factor} (93%) create mode 100644 extra/alien/inline/syntax/syntax.factor diff --git a/extra/alien/inline/inline-docs.factor b/extra/alien/inline/inline-docs.factor index 260644e663..2c0cd28745 100644 --- a/extra/alien/inline/inline-docs.factor +++ b/extra/alien/inline/inline-docs.factor @@ -10,102 +10,6 @@ IN: alien.inline "Call " { $link POSTPONE: define-c-library } " to set them up." } print-element ; PRIVATE> -HELP: ;C-LIBRARY -{ $syntax ";C-LIBRARY" } -{ $description "Writes, compiles, and links code generated since previous invocation of " { $link POSTPONE: C-LIBRARY: } "." } -{ $see-also POSTPONE: compile-c-library } ; - -HELP: C-FRAMEWORK: -{ $syntax "C-FRAMEWORK: name" } -{ $description "OS X only. Link to named framework. Takes effect when " { $link POSTPONE: ;C-LIBRARY } " is called." } -{ $see-also POSTPONE: c-use-framework } ; - -HELP: C-FUNCTION: -{ $syntax "C-FUNCTION: return name ( args ... )\nbody\n;" } -{ $description "Appends a function to the C library in scope and defines an FFI word that calls it." } -{ $examples - { $example - "USING: alien.inline prettyprint ;" - "IN: cmath.ffi" - "" - "C-LIBRARY: cmathlib" - "" - "C-FUNCTION: int add ( int a, int b )" - " return a + b;" - ";" - "" - ";C-LIBRARY" - "" - "1 2 add ." - "3" } -} -{ $see-also POSTPONE: define-c-function } ; - -HELP: C-INCLUDE: -{ $syntax "C-INCLUDE: name" } -{ $description "Appends an include line to the C library in scope." } -{ $see-also POSTPONE: c-include } ; - -HELP: C-LIBRARY: -{ $syntax "C-LIBRARY: name" } -{ $description "Starts a new C library scope. Other " { $snippet "alien.inline" } " syntax can be used after this word." } -{ $examples - { $example - "USING: alien.inline ;" - "IN: rectangle.ffi" - "" - "C-LIBRARY: rectlib" - "" - "C-STRUCTURE: rectangle { \"int\" \"width\" } { \"int\" \"height\" } ;" - "" - "C-FUNCTION: int area ( rectangle c )" - " return c.width * c.height;" - ";" - "" - ";C-LIBRARY" - "" } -} -{ $see-also POSTPONE: define-c-library } ; - -HELP: C-LINK/FRAMEWORK: -{ $syntax "C-LINK/FRAMEWORK: name" } -{ $description "Equivalent to " { $link POSTPONE: C-FRAMEWORK: } " on OS X and " { $link POSTPONE: C-LINK: } " everywhere else." } -{ $see-also POSTPONE: c-link-to/use-framework } ; - -HELP: C-LINK: -{ $syntax "C-LINK: name" } -{ $description "Link to named library. Takes effect when " { $link POSTPONE: ;C-LIBRARY } " is called." } -{ $see-also POSTPONE: c-link-to } ; - -HELP: C-STRUCTURE: -{ $syntax "C-STRUCTURE: name pairs ... ;" } -{ $description "Like " { $snippet "C-STRUCT:" } " but also generates equivalent C code."} -{ $see-also POSTPONE: define-c-struct } ; - -HELP: C-TYPEDEF: -{ $syntax "C-TYPEDEF: old new" } -{ $description "Like " { $snippet "TYPEDEF:" } " but generates a C typedef statement too." } -{ $see-also POSTPONE: define-c-typedef } ; - -HELP: COMPILE-AS-C++ -{ $syntax "COMPILE-AS-C++" } -{ $description "Insert this word anywhere between " { $link POSTPONE: C-LIBRARY: } " and " { $link POSTPONE: ;C-LIBRARY } " and the generated code will be treated as C++ with " { $snippet "extern \"C\"" } " prepended to each function prototype." } ; - -HELP: DELETE-C-LIBRARY: -{ $syntax "DELETE-C-LIBRARY: name" } -{ $description "Deletes the shared library file corresponding to " { $snippet "name" } " . " } -{ $notes - { $list - { "Must be executed in the vocabulary where " { $snippet "name" } " is defined. " } - "This word is mainly useful for unit tests." - } -} -{ $see-also POSTPONE: delete-inline-library } ; - -HELP: RAW-C: -{ $syntax "RAW-C:" "body" ";" } -{ $description "Insert a string into the generated source file. Useful for macros and other details not implemented in " { $snippet "alien.inline" } "." } ; - HELP: compile-c-library { $description "Writes, compiles, and links code generated since last invocation of " { $link POSTPONE: define-c-library } ". " "Also calls " { $snippet "add-library" } ". " @@ -207,9 +111,3 @@ HELP: with-c-library HELP: raw-c { $values { "str" string } } { $description "Insert a string into the generated source file. Useful for macros and other details not implemented in " { $snippet "alien.inline" } "." } ; - -ARTICLE: "alien.inline" "Inline C" -{ $vocab-link "alien.inline" } -; - -ABOUT: "alien.inline" diff --git a/extra/alien/inline/inline.factor b/extra/alien/inline/inline.factor index 4582782c41..62c6102a86 100644 --- a/extra/alien/inline/inline.factor +++ b/extra/alien/inline/inline.factor @@ -124,29 +124,3 @@ PRIVATE> : raw-c ( str -- ) [ "\n" % % "\n" % ] "" make c-strings get push ; - -SYNTAX: C-LIBRARY: scan define-c-library ; - -SYNTAX: COMPILE-AS-C++ t library-is-c++ set ; - -SYNTAX: C-LINK: scan c-link-to ; - -SYNTAX: C-FRAMEWORK: scan c-use-framework ; - -SYNTAX: C-LINK/FRAMEWORK: scan c-link-to/use-framework ; - -SYNTAX: C-INCLUDE: scan c-include ; - -SYNTAX: C-FUNCTION: - function-types-effect parse-here define-c-function ; - -SYNTAX: C-TYPEDEF: scan scan define-c-typedef ; - -SYNTAX: C-STRUCTURE: - scan parse-definition define-c-struct ; - -SYNTAX: ;C-LIBRARY compile-c-library ; - -SYNTAX: DELETE-C-LIBRARY: scan delete-inline-library ; - -SYNTAX: RAW-C: parse-here raw-c ; diff --git a/extra/alien/inline/syntax/authors.txt b/extra/alien/inline/syntax/authors.txt new file mode 100644 index 0000000000..c45c6f3279 --- /dev/null +++ b/extra/alien/inline/syntax/authors.txt @@ -0,0 +1 @@ +Jeremy Hughes \ No newline at end of file diff --git a/extra/alien/inline/syntax/syntax-docs.factor b/extra/alien/inline/syntax/syntax-docs.factor new file mode 100644 index 0000000000..2453d98cf6 --- /dev/null +++ b/extra/alien/inline/syntax/syntax-docs.factor @@ -0,0 +1,100 @@ +! Copyright (C) 2009 Jeremy Hughes. +! See http://factorcode.org/license.txt for BSD license. +USING: help.markup help.syntax alien.inline ; +IN: alien.inline.syntax + +HELP: ;C-LIBRARY +{ $syntax ";C-LIBRARY" } +{ $description "Writes, compiles, and links code generated since previous invocation of " { $link POSTPONE: C-LIBRARY: } "." } +{ $see-also POSTPONE: compile-c-library } ; + +HELP: C-FRAMEWORK: +{ $syntax "C-FRAMEWORK: name" } +{ $description "OS X only. Link to named framework. Takes effect when " { $link POSTPONE: ;C-LIBRARY } " is called." } +{ $see-also POSTPONE: c-use-framework } ; + +HELP: C-FUNCTION: +{ $syntax "C-FUNCTION: return name ( args ... )\nbody\n;" } +{ $description "Appends a function to the C library in scope and defines an FFI word that calls it." } +{ $examples + { $example + "USING: alien.inline prettyprint ;" + "IN: cmath.ffi" + "" + "C-LIBRARY: cmathlib" + "" + "C-FUNCTION: int add ( int a, int b )" + " return a + b;" + ";" + "" + ";C-LIBRARY" + "" + "1 2 add ." + "3" } +} +{ $see-also POSTPONE: define-c-function } ; + +HELP: C-INCLUDE: +{ $syntax "C-INCLUDE: name" } +{ $description "Appends an include line to the C library in scope." } +{ $see-also POSTPONE: c-include } ; + +HELP: C-LIBRARY: +{ $syntax "C-LIBRARY: name" } +{ $description "Starts a new C library scope. Other " { $snippet "alien.inline" } " syntax can be used after this word." } +{ $examples + { $example + "USING: alien.inline ;" + "IN: rectangle.ffi" + "" + "C-LIBRARY: rectlib" + "" + "C-STRUCTURE: rectangle { \"int\" \"width\" } { \"int\" \"height\" } ;" + "" + "C-FUNCTION: int area ( rectangle c )" + " return c.width * c.height;" + ";" + "" + ";C-LIBRARY" + "" } +} +{ $see-also POSTPONE: define-c-library } ; + +HELP: C-LINK/FRAMEWORK: +{ $syntax "C-LINK/FRAMEWORK: name" } +{ $description "Equivalent to " { $link POSTPONE: C-FRAMEWORK: } " on OS X and " { $link POSTPONE: C-LINK: } " everywhere else." } +{ $see-also POSTPONE: c-link-to/use-framework } ; + +HELP: C-LINK: +{ $syntax "C-LINK: name" } +{ $description "Link to named library. Takes effect when " { $link POSTPONE: ;C-LIBRARY } " is called." } +{ $see-also POSTPONE: c-link-to } ; + +HELP: C-STRUCTURE: +{ $syntax "C-STRUCTURE: name pairs ... ;" } +{ $description "Like " { $snippet "C-STRUCT:" } " but also generates equivalent C code."} +{ $see-also POSTPONE: define-c-struct } ; + +HELP: C-TYPEDEF: +{ $syntax "C-TYPEDEF: old new" } +{ $description "Like " { $snippet "TYPEDEF:" } " but generates a C typedef statement too." } +{ $see-also POSTPONE: define-c-typedef } ; + +HELP: COMPILE-AS-C++ +{ $syntax "COMPILE-AS-C++" } +{ $description "Insert this word anywhere between " { $link POSTPONE: C-LIBRARY: } " and " { $link POSTPONE: ;C-LIBRARY } " and the generated code will be treated as C++ with " { $snippet "extern \"C\"" } " prepended to each function prototype." } ; + +HELP: DELETE-C-LIBRARY: +{ $syntax "DELETE-C-LIBRARY: name" } +{ $description "Deletes the shared library file corresponding to " { $snippet "name" } " . " } +{ $notes + { $list + { "Must be executed in the vocabulary where " { $snippet "name" } " is defined. " } + "This word is mainly useful for unit tests." + } +} +{ $see-also POSTPONE: delete-inline-library } ; + +HELP: RAW-C: +{ $syntax "RAW-C:" "body" ";" } +{ $description "Insert a string into the generated source file. Useful for macros and other details not implemented in " { $snippet "alien.inline" } "." } ; diff --git a/extra/alien/inline/inline-tests.factor b/extra/alien/inline/syntax/syntax-tests.factor similarity index 93% rename from extra/alien/inline/inline-tests.factor rename to extra/alien/inline/syntax/syntax-tests.factor index 09b76a4bb5..e6a0b8b7d8 100644 --- a/extra/alien/inline/inline-tests.factor +++ b/extra/alien/inline/syntax/syntax-tests.factor @@ -1,8 +1,8 @@ ! Copyright (C) 2009 Jeremy Hughes. ! See http://factorcode.org/license.txt for BSD license. -USING: alien.inline alien.inline.private io.directories io.files +USING: alien.inline alien.inline.syntax io.directories io.files kernel namespaces tools.test alien.c-types alien.structs ; -IN: alien.inline.tests +IN: alien.inline.syntax.tests DELETE-C-LIBRARY: test C-LIBRARY: test diff --git a/extra/alien/inline/syntax/syntax.factor b/extra/alien/inline/syntax/syntax.factor new file mode 100644 index 0000000000..6cef56f9b2 --- /dev/null +++ b/extra/alien/inline/syntax/syntax.factor @@ -0,0 +1,31 @@ +! Copyright (C) 2009 Jeremy Hughes. +! See http://factorcode.org/license.txt for BSD license. +USING: alien.inline lexer multiline namespaces parser ; +IN: alien.inline.syntax + + +SYNTAX: C-LIBRARY: scan define-c-library ; + +SYNTAX: COMPILE-AS-C++ t library-is-c++ set ; + +SYNTAX: C-LINK: scan c-link-to ; + +SYNTAX: C-FRAMEWORK: scan c-use-framework ; + +SYNTAX: C-LINK/FRAMEWORK: scan c-link-to/use-framework ; + +SYNTAX: C-INCLUDE: scan c-include ; + +SYNTAX: C-FUNCTION: + function-types-effect parse-here define-c-function ; + +SYNTAX: C-TYPEDEF: scan scan define-c-typedef ; + +SYNTAX: C-STRUCTURE: + scan parse-definition define-c-struct ; + +SYNTAX: ;C-LIBRARY compile-c-library ; + +SYNTAX: DELETE-C-LIBRARY: scan delete-inline-library ; + +SYNTAX: RAW-C: parse-here raw-c ;