/unmaintained/alien/inline/syntax/syntax-docs.factor

http://github.com/abeaumont/factor · Factor · 100 lines · 86 code · 12 blank · 2 comment · 0 complexity · cd7ad845765fdbd4664a968e328b32f8 MD5 · raw file

  1. ! Copyright (C) 2009 Jeremy Hughes.
  2. ! See http://factorcode.org/license.txt for BSD license.
  3. USING: help.markup help.syntax alien.inline ;
  4. IN: alien.inline.syntax
  5. HELP: ;C-LIBRARY
  6. { $syntax ";C-LIBRARY" }
  7. { $description "Writes, compiles, and links code generated since previous invocation of " { $link POSTPONE: C-LIBRARY: } "." }
  8. { $see-also POSTPONE: compile-c-library } ;
  9. HELP: C-FRAMEWORK:
  10. { $syntax "C-FRAMEWORK: name" }
  11. { $description "OS X only. Link to named framework. Takes effect when " { $link POSTPONE: ;C-LIBRARY } " is called." }
  12. { $see-also POSTPONE: c-use-framework } ;
  13. HELP: C-FUNCTION:
  14. { $syntax "C-FUNCTION: return name ( args ... )\nbody\n;" }
  15. { $description "Appends a function to the C library in scope and defines an FFI word that calls it." }
  16. { $examples
  17. { $example
  18. "USING: alien.inline.syntax prettyprint ;"
  19. "IN: cmath.ffi"
  20. ""
  21. "C-LIBRARY: cmathlib"
  22. ""
  23. "C-FUNCTION: int add ( int a, int b )"
  24. " return a + b;"
  25. ";"
  26. ""
  27. ";C-LIBRARY"
  28. ""
  29. "1 2 add ."
  30. "3" }
  31. }
  32. { $see-also POSTPONE: define-c-function } ;
  33. HELP: C-INCLUDE:
  34. { $syntax "C-INCLUDE: name" }
  35. { $description "Appends an include line to the C library in scope." }
  36. { $see-also POSTPONE: c-include } ;
  37. HELP: C-LIBRARY:
  38. { $syntax "C-LIBRARY: name" }
  39. { $description "Starts a new C library scope. Other " { $snippet "alien.inline" } " syntax can be used after this word." }
  40. { $examples
  41. { $example
  42. "USING: alien.inline.syntax ;"
  43. "IN: rectangle.ffi"
  44. ""
  45. "C-LIBRARY: rectlib"
  46. ""
  47. "C-STRUCTURE: rectangle { \"int\" \"width\" } { \"int\" \"height\" } ;"
  48. ""
  49. "C-FUNCTION: int area ( rectangle c )"
  50. " return c.width * c.height;"
  51. ";"
  52. ""
  53. ";C-LIBRARY"
  54. "" }
  55. }
  56. { $see-also POSTPONE: define-c-library } ;
  57. HELP: C-LINK/FRAMEWORK:
  58. { $syntax "C-LINK/FRAMEWORK: name" }
  59. { $description "Equivalent to " { $link POSTPONE: C-FRAMEWORK: } " on OS X and " { $link POSTPONE: C-LINK: } " everywhere else." }
  60. { $see-also POSTPONE: c-link-to/use-framework } ;
  61. HELP: C-LINK:
  62. { $syntax "C-LINK: name" }
  63. { $description "Link to named library. Takes effect when " { $link POSTPONE: ;C-LIBRARY } " is called." }
  64. { $see-also POSTPONE: c-link-to } ;
  65. HELP: C-STRUCTURE:
  66. { $syntax "C-STRUCTURE: name pairs ... ;" }
  67. { $description "Like " { $snippet "C-STRUCT:" } " but also generates equivalent C code."}
  68. { $see-also POSTPONE: define-c-struct } ;
  69. HELP: C-TYPEDEF:
  70. { $syntax "C-TYPEDEF: old new" }
  71. { $description "Like " { $snippet "TYPEDEF:" } " but generates a C typedef statement too." }
  72. { $see-also POSTPONE: define-c-typedef } ;
  73. HELP: COMPILE-AS-C++
  74. { $syntax "COMPILE-AS-C++" }
  75. { $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." } ;
  76. HELP: DELETE-C-LIBRARY:
  77. { $syntax "DELETE-C-LIBRARY: name" }
  78. { $description "Deletes the shared library file corresponding to " { $snippet "name" } " . " }
  79. { $notes
  80. { $list
  81. { "Must be executed in the vocabulary where " { $snippet "name" } " is defined. " }
  82. "This word is mainly useful for unit tests."
  83. }
  84. }
  85. { $see-also POSTPONE: delete-inline-library } ;
  86. HELP: <RAW-C
  87. { $syntax "<RAW-C code RAW-C>" }
  88. { $description "Insert a (multiline) string into the generated source file. Useful for macros and other details not implemented in " { $snippet "alien.inline" } "." } ;