<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: routine code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 07 Aug 2008 23:36:47 GMT</pubDate>
    <description>DZone Snippets: routine code</description>
    <item>
      <title>Library interface dialect</title>
      <link>http://snippets.dzone.com/posts/show/1146</link>
      <description>&lt;code&gt;&lt;br /&gt;REBOL [&lt;br /&gt;    Title:  "Library Interface Dialect"&lt;br /&gt;    File:   %lib-dialect.r&lt;br /&gt;    Author: "Gregg Irwin"&lt;br /&gt;    Purpose: {&lt;br /&gt;        Allow for a more concise way to define library routine &lt;br /&gt;        interfaces.&lt;br /&gt;    }&lt;br /&gt;]&lt;br /&gt;&lt;br /&gt;lib-dialect-ctx: context [&lt;br /&gt;;     lib-ctx: make object! [file: lib: none free: does [free lib]]&lt;br /&gt;;     lib-spec: none&lt;br /&gt;&lt;br /&gt;    lib: none&lt;br /&gt;    def-rtn-type: none&lt;br /&gt;&lt;br /&gt;    name-mods: copy []&lt;br /&gt;    mod-name: func [name] [do join name-mods name]&lt;br /&gt;&lt;br /&gt;    ; dump/trace option to show generated code?&lt;br /&gt;&lt;br /&gt;    ;has-rtn-type?: does [all [rtn-type  'none &lt;&gt; rtn-type]]&lt;br /&gt;    ; lib is a global word reference in this func.&lt;br /&gt;    make-dll-func: func [reb-name spec rtn-type name] [&lt;br /&gt;        spec: copy any [spec []]&lt;br /&gt;        if all [rtn-type  'none &lt;&gt; rtn-type] [&lt;br /&gt;            append spec compose/deep [return: [(rtn-type)]]&lt;br /&gt;        ]&lt;br /&gt;        ;print ['make-dll-func reb-name mold spec rtn-type mold  mod-name any [name  form reb-name]]&lt;br /&gt;        set reb-name make routine! spec lib  mod-name any [name  form reb-name]&lt;br /&gt;    ]&lt;br /&gt;&lt;br /&gt;    data-type: [&lt;br /&gt;        'none | 'char | 'short | 'long | 'integer! | 'string! | 'decimal!&lt;br /&gt;        ; TBD add struct support ?&lt;br /&gt;    ]&lt;br /&gt;&lt;br /&gt;    func-decl: [&lt;br /&gt;        (spec: name: none  rtn-type: def-rtn-type)&lt;br /&gt;        set reb-name word!          ;(print reb-name)&lt;br /&gt;        any [&lt;br /&gt;              [set spec block!]     ;(print mold spec)&lt;br /&gt;            | [opt ['returns | 'as] set rtn-type data-type]  ;(print rtn-type)&lt;br /&gt;            | [opt 'calls set name string!]    ;(print name)&lt;br /&gt;        ]&lt;br /&gt;        (make-dll-func reb-name spec rtn-type name)&lt;br /&gt;    ]&lt;br /&gt;&lt;br /&gt;    ; You can use this multiple times, e.g. grouping functions by return&lt;br /&gt;    ; type and using it before each group.&lt;br /&gt;    set-def-rtn-type: [&lt;br /&gt;        opt 'set ['def-rtn-type | 'default-return-type]&lt;br /&gt;        set def-rtn-type data-type&lt;br /&gt;    ]&lt;br /&gt;&lt;br /&gt;    rules: [&lt;br /&gt;        ['lib | 'library] set file file! (lib: load/library file) ;append lib-spec compose [file: (file)]&lt;br /&gt;        opt [&lt;br /&gt;            ['modify-import-names | 'mod-imports] set name-mods block!&lt;br /&gt;        ]&lt;br /&gt;        any [set-def-rtn-type | func-decl]&lt;br /&gt;    ]&lt;br /&gt;&lt;br /&gt;    set 'make-routines func [spec [any-block!]] [&lt;br /&gt;        clear name-mods&lt;br /&gt;        parse spec rules&lt;br /&gt;    ]&lt;br /&gt;&lt;br /&gt;;     set 'make-library-interface func [spec] [&lt;br /&gt;;         lib-spec: copy []&lt;br /&gt;;         clear name-mods&lt;br /&gt;;         parse spec rules&lt;br /&gt;;     ]&lt;br /&gt;&lt;br /&gt;]&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 13 Jan 2006 04:11:40 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1146</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
  </channel>
</rss>
