Skip to content

Commit

Permalink
Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-serrano committed Apr 26, 2024
1 parent 80a407a commit c3ac820
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
8 changes: 8 additions & 0 deletions doc/staging.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ In the second example:

The `emit` statements uses generated signal names.

This last example illustrates many of the staging features, included
those described in the next sections. It shows how to generate a `fork`
construct with as many branches as values contained in a JavaScript
array. It shows how to wait for and emit signals whose names are generated.

<span class="hiphop">&#x2605;</span> [staging-fork.hh.js](../test/staging-fork.hh.js)
<!-- ${doc.includeCode("../test/staging-fork.hh.js", "hiphop")} -->


Dynamic Signal Names in Delay Expressions
-----------------------------------------
Expand Down
3 changes: 0 additions & 3 deletions test/staging-emit-if2.hh.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
"use @hop/hiphop";
"use hopscript";

import * as hh from "@hop/hiphop";
import { format } from "util";

Expand Down
29 changes: 29 additions & 0 deletions test/staging-fork.hh.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as hh from "@hop/hiphop";
import { format } from "util";

const Instruments = [ "violin", "piano", "trumpet", "sax" ];

function makeAwait(instruments) {
return hiphop fork ${ instruments.map(val => hiphop {
await (this[`${val}IN`].nowval);
emit ${`${val}OUT`}(${val});
}) }
}

hiphop module prg() {
in ... ${ Instruments.map(i => `${i}IN`) };
out ... ${ Instruments.map(i => `${i}OUT`) };

${ makeAwait(Instruments) }
}

export const mach = new hh.ReactiveMachine(prg);
mach.outbuf = "";
mach.debug_emitted_func = emitted => {
mach.outbuf += format(emitted) + "\n";
}

mach.react();
mach.react({ violinIN: true, saxIN: true });
mach.react({ pianoIN: true });
mach.react()
4 changes: 4 additions & 0 deletions test/staging-fork.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[]
[ 'violinOUT("violin")', 'saxOUT("sax")' ]
[ 'pianoOUT("piano")' ]
[]

0 comments on commit c3ac820

Please sign in to comment.