-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstandard_endcase_fs
73 lines (52 loc) · 2.11 KB
/
standard_endcase_fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
\ standard_endcase_fs
\ This file is part of Sfera, a library for SuperForth
\ http://programandala.net/en.program.sfera.html
\ Author: Marcos Cruz (programandala.net), 2016.
\ ==============================================================
\ License
\ You may do whatever you want with this work, so long as you
\ retain the copyright/authorship/acknowledgment/credit
\ notice(s) and this license in all redistributed copies and
\ derived works. There is no warranty.
\ ==============================================================
\ Description
\ SuperForth's `endcase` is not the original Eaker's structure,
\ which become popular after being firt published in 1980, and
\ which was adopted by the Forth-94 Standard.
\
\ The difference is SuperForth's `endcase` does not consume the
\ case selector, but consumes it with a custom word called
\ `default`, which is mandatory even when there's no default
\ code in the structure. This implementation is versatile and
\ makes the coding of default case simple.
\ This file is provided as an alternative for compatibility with
\ standard Forth. It replaces the original `endcase` with a
\ standard version and modifies SuperForth's `default`
\ accordingly.
\ ==============================================================
\ Usage
\ SuperForth `case` structure:
\ n case
\ x1 of ... endof
\ x2 of ... endof
\ default ... \ *mandatory* default case, even empty
\ endcase
\ Modified version after standard Forth:
\ n case
\ x1 of ... endof
\ x2 of ... endof
\ default of ... endof \ *optional* default case
\ endcase
\ ==============================================================
\ History
\ 2016-01-15: Code extracted from the main file of the library.
\
\ 2016-02-08: Removed `end-of-file`. Fixed typo.
\ ==============================================================
\ Make `endcase` standard:
: endcase ( n -- )
?comp postpone drop postpone endcase ; immediate
\ Standard `endcase`.
\ Adapt SuperForth's `default` to the standard syntax:
' dup 38752 ! \ hack `default` to compile `dup` instead of `drop`
\ vim: filetype=superforthsfera