| | 255 | |
| | 256 | |
| | 257 | Components |
| | 258 | ---------- |
| | 259 | |
| | 260 | Components are similar to functions, but they operate via a dataflow model. |
| | 261 | They have inputs, outputs which are connected to the inputs of other |
| | 262 | components, and a body which is evaluated when all inputs are set. |
| | 263 | |
| | 264 | Components must have at least one input, but they don't require any outputs. |
| | 265 | |
| | 266 | Here is an example of how to create and connect components:: |
| | 267 | |
| | 268 | [a b -- out] [a b mul :out] component :c1 |
| | 269 | [val] [val .] component :probe |
| | 270 | 'c1/out 'probe/val connect |
| | 271 | |
| | 272 | Now, when the inputs to *c1* are set, *probe* will automatically be invoked:: |
| | 273 | |
| | 274 | 3 :c1/a |
| | 275 | 5 :c1/b |
| | 276 | 15 |
| | 277 | |
| | 278 | Further changes to the inputs will continue to invoke the *probe* component:: |
| | 279 | |
| | 280 | 5 :c1/a |
| | 281 | 25 |
| | 282 | |
| | 283 | *Connect* also accepts components as arguments. This is short-hand for |
| | 284 | refering to the first input or output. |
| | 285 | The following call makes the same connection as the example above:: |
| | 286 | |
| | 287 | c1 probe connect |
| | 629 | Extending The System |
| | 630 | ==================== |
| | 631 | |
| | 632 | Adding C Functions |
| | 633 | ------------------ |
| | 634 | |
| | 635 | C functions are defined with the *UR_CALL* macro. |
| | 636 | |
| | 637 | The function is responsible for checking that arguments are of the correct |
| | 638 | type and for reporting any errors. If type checking were built into the |
| | 639 | evaluator there would be redundant checks for the typical case where the |
| | 640 | function accepts multiple types for a given argument or pattern of |
| | 641 | arguments. |
| | 642 | |
| | 643 | Always access and check stack arguments starting with *tos* and work down. |
| | 644 | Since the bottom of the stack contains *UT_UNSET*, checking in this order |
| | 645 | avoids an extra check to make sure that the stack holds at least the number |
| | 646 | of expected arguments. |
| | 647 | |
| | 648 | |