macro librarylib/Ffi.xtlm
Ffi.xtlm -- the binding macro: a facade function written from the signature of a native function (docs/ffi-macro.md). Import: "ffi:" u_se< "Ffi" (xetal-x puts this directory on XETAL_PATH)
"s_hout : text -> text" ᶠᶠⁱb̲ind< "hello/shout"
expands to the facade function l:s_hout, which speaks the ext: channel (docs/bridge.md). Kinds: unit (no argument), text, chars, int, float (an argument of any rank; as a result, a scalar), and as results also floats and ints (any rank, reshaped by the reply's shape).
ʰw̲ords : Char -> Box Char
private: the words of a text, and the i-th of them
ʰw̲ords ← { s → (n̲ot s = f̲irst " ") p̲artition s }
ʰv̲alue : Char -> Char -> Char
private: what an argument a of kind k is sent as, and the query that says its kind (and shape)
ʰv̲alue ← { k a → k m̲atch "text" ? a k m̲atch "chars" ? "(r_avel " c̲at a c̲at ")" k m̲atch "int" ? "(f_ormat r_avel f_loor " c̲at a c̲at ")" "(f_ormat r_avel f_loat " c̲at a c̲at ")" }
ʰq̲uery : Char -> Char -> Char
ʰq̲uery ← { k a → k m̲atch "text" ? "?text\"" k m̲atch "chars" ? "?chars=\" c_at f_ormat s_hape " c̲at a k m̲atch "int" ? "?int=\" c_at f_ormat s_hape " c̲at a "?float=\" c_at f_ormat s_hape " c̲at a }
ʰp̲ut : Char -> Char -> Char
private: the line putting argument a (kind k) for the native function t
ʰp̲ut ← { ka t → k ← 1 ʰw̲ord ʰw̲ords ka a ← 2 ʰw̲ord ʰw̲ords ka " p" c̲at a c̲at " := " c̲at (k ʰv̲alue a) c̲at " []N_PUT \"ext:" c̲at t c̲at (k ʰq̲uery a) c̲at "\n" }
ʰg̲et : Char -> Char -> Char
private: the lines getting the reply of t as kind k
ʰg̲et ← { k t → call ← "[]N_GET \"ext:" c̲at t c̲at "\"" shape ← "(f_loor n_umbers []N_GET \"ext:" c̲at t c̲at "?shape\") r_eshape v\n" k m̲atch "text" ? " " c̲at call c̲at "\n" k m̲atch "float" ? " f_irst n_umbers " c̲at call c̲at "\n" k m̲atch "int" ? " f_loor f_irst n_umbers " c̲at call c̲at "\n" k m̲atch "floats" ? " v := n_umbers " c̲at call c̲at "\n " c̲at shape k m̲atch "ints" ? " v := f_loor n_umbers " c̲at call c̲at "\n " c̲at shape " v := " c̲at call c̲at "\n " c̲at shape }
ʰp̲arams : (Any a, Num b) => a -> b -> Char
private: the parameters and the put lines, by how many arguments there are
ʰp̲arams ← { w n → n = 0 ? "@" n = 1 ? "a" "a b" }
ʰp̲uts : Box Char -> Char -> Char
ʰp̲uts ← { w t → n ← (t̲ally w) − 4 (n = 1) × (3 ʰw̲ord w) m̲atch "unit" ? "" n = 1 ? ((3 ʰw̲ord w) c̲at " a") ʰp̲ut t (((3 ʰw̲ord w) c̲at " a") ʰp̲ut t) c̲at ((4 ʰw̲ord w) c̲at " b") ʰp̲ut t }
ᵐb̲ind< : Char -> Char -> Char
ᵐb̲ind< ← { sig target → w ← ʰw̲ords sig n ← t̲ally w args ← (n − 4) − (3 ʰw̲ord w) m̲atch "unit" "l:" c̲at (1 ʰw̲ord w) c̲at " := { " c̲at (w ʰp̲arams args) c̲at " ->\n" c̲at (w ʰp̲uts target) c̲at ((n ʰw̲ord w) ʰg̲et target) c̲at "}" }