Created
November 29, 2019 12:21
-
-
Save vladpazych/4eb290a6041c4dbc0ed9cdf4c88460d8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ( | |
| This is a small test example for the funnel script. | |
| Funnel is the script-language use in the tagion network | |
| ) | |
| : test ( add test ) | |
| .s | |
| 3 1 + | |
| .s | |
| ; | |
| num x | |
| : global_var ( global variable test ) | |
| .v | |
| X @ 7 + X ! | |
| .v | |
| X @ 4 * X ! | |
| .v | |
| ; | |
| : local_var ( local variable test ) | |
| num local | |
| .l | |
| local @ 7 + local ! | |
| .l | |
| local @ 4 * local ! | |
| .l | |
| ; | |
| : loop_example ( from to -- count ) | |
| num count | |
| do | |
| count @ 1+ count ! | |
| loop | |
| count @ | |
| .l | |
| ; | |
| : if_else_then ( high low -- text ) | |
| if | |
| if | |
| "ONE-ONE" | |
| else | |
| "ONE-ZERO" | |
| then | |
| else | |
| if | |
| "ZERO-ONE" | |
| else | |
| "ZERO-ZERO" | |
| then | |
| then | |
| .s | |
| ; | |
| : recursive ( iteration -- ) | |
| 1- | |
| dup | |
| .s | |
| if | |
| recursive | |
| else | |
| 2drop | |
| .s | |
| then | |
| ; | |
| : while_loop | |
| num local | |
| local ! | |
| begin | |
| local @ | |
| while | |
| local @ 1- local ! | |
| .l | |
| repeat | |
| ; | |
| : begin_until | |
| num local | |
| local ! | |
| begin | |
| local @ 1- local ! | |
| local @ 0 == | |
| .l | |
| until | |
| ; | |
| : main ( Default main function ) | |
| trace_on | |
| global_var | |
| local_var | |
| 10 0 loop_example | |
| 0 0 if_else_then | |
| 0 1 if_else_then | |
| 1 0 if_else_then | |
| 1 1 if_else_then | |
| 5 recursive | |
| 4 while_loop | |
| 3 begin_until | |
| trace_off | |
| ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment