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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//! Dataflow combinators for Seq
//!
//! Higher-order words that manage value flow on the stack,
//! reducing the need for explicit stack shuffling (swap/rot/pick)
//! or auxiliary stack usage (>aux / aux>).
//!
//! These follow the concatenative tradition from Factor/Joy:
//! - `dip` — hide top value, run quotation, restore value
//! - `keep` — run quotation on top value, but preserve the original
//! - `bi` — apply two quotations to the same value
//! - `if` — branch on a Bool, invoking one of two quotations
use crateinvoke_callable;
use crate;
use crateValue;
/// `dip`: Hide top value, run quotation on the rest, restore value.
///
/// Stack effect: ( ..a x quot -- ..b x )
/// where quot : ( ..a -- ..b )
///
/// Equivalent to: `swap >aux call aux>`
///
/// # Safety
/// - Stack must have at least 2 values (quotation on top, preserved value below)
/// - Top of stack must be a Quotation or Closure
pub unsafe extern "C"
/// `keep`: Run quotation on top value, but preserve the original.
///
/// Stack effect: ( ..a x quot -- ..b x )
/// where quot : ( ..a x -- ..b )
///
/// Like `dip`, but the quotation also receives the preserved value.
/// Equivalent to: `over >aux call aux>`
///
/// # Safety
/// - Stack must have at least 2 values (quotation on top, value below)
/// - Top of stack must be a Quotation or Closure
pub unsafe extern "C"
/// `bi`: Apply two quotations to the same value.
///
/// Stack effect: ( ..a x quot1 quot2 -- ..c )
/// where quot1 : ( ..a x -- ..b )
/// quot2 : ( ..b x -- ..c )
///
/// Equivalent to: `>aux keep aux> call`
///
/// # Safety
/// - Stack must have at least 3 values (quot2 on top, quot1 below, value below that)
/// - Top two stack values must be Quotations or Closures
pub unsafe extern "C"
/// `if`: Branch on a Bool, invoking one of two quotations.
///
/// Stack effect: ( ..a Bool [..a -- ..b] [..a -- ..b] -- ..b )
/// The two quotations must have identical effects (the typechecker
/// enforces this); whichever runs leaves the stack in the same shape.
///
/// Layout at entry (top → bottom): else-quot, then-quot, cond.
///
/// # Safety
/// - Stack must have at least 3 values (else-quot on top, then-quot below,
/// Bool below that).
/// - The top two values must be Quotations or Closures.
/// - The third value must be a Bool.
pub unsafe extern "C"
// Public re-exports with short names for internal use.
// `if_combinator` rather than `if` because `if` is a Rust keyword.
pub use patch_seq_bi as bi;
pub use patch_seq_dip as dip;
pub use patch_seq_if as if_combinator;
pub use patch_seq_keep as keep;