From c62a177aa01bba93b9f6a1f01cb95f26389d9668 Mon Sep 17 00:00:00 2001 From: Nakidai Date: Thu, 17 Jul 2025 16:29:24 +0300 Subject: Add some boilerplate for compiling --- b2cl.ccl | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) (limited to 'b2cl.ccl') diff --git a/b2cl.ccl b/b2cl.ccl index ffd2338..5942680 100755 --- a/b2cl.ccl +++ b/b2cl.ccl @@ -148,4 +148,76 @@ R/ead / -- token ... _ ( E?=_#;=_ ) } -@R/ead +\ + This function reads stack until EOP (end of parsing) with tokens and + prints compiled text to stdout +\ +P/arse loop / EOP token ... EOP -- +{ + &t/oken + &e=e/nd + _ ( + \ EOP \ e?=_#; + \ '^' \ T?@t#; + \ '+' \ I?@i#; + \ '-' \ J?@j#; + \ '*' \ H?@h#; + \ '~' \ X?@x#; + \ '#' \ B?@b#; + \ ':' \ K?@k#; + \ '%' \ D?@d#; + \ '=' \ N?@n#; + \ '!' \ A?@a#; + \ '$' \ C?@c#; + \ '&' \ E?@e#; + \ '<' \ M?@m#; + \ '>' \ O?@o#; + \ '@' \ Q?@q#; + / Otherwise we've got a parameter for a block instruction + / (or any of other 8 tokens which is an error b2cl doesn't + / handle rn) + / Maybe it's better to not consume EOP so caller can check for + / errors that way + @B/lock + ) +} + +\ + Main function for compiling. Takes full stack +\ +C/ompile / token ... -- +{ + %_^-=E$E%_$E / Insert s + + \ \&x / Setup instruction names + \ '!' \ ^ +++++++++++++++++++++++++++++++++ =A + \ '#' \ $A ++ =B + \ '$' \ $B + =C + \ '%' \ $C + =D + \ '&' \ $D + =E + \ '(' \ $E ++ =F + \ ')' \ $F + =G + \ '*' \ $G + =H + \ '+' \ $H + =I + \ '-' \ $I ++ =J + \ ':' \ $J +++++++++++++ =K + \ ';' \ $K + =L + \ '<' \ $L + =M + \ '=' \ $M + =N + \ '>' \ $N + =O + \ '?' \ $O + =P + \ '@' \ $P + =Q + \ '[' \ $Q +++++++++++++++++++++++++++ =R + \ ']' \ $R ++ =S + \ '^' \ $S + =T + \ '_' \ $T + =U + \ '{' \ $U ++++++++++++++++++++++++++++ =V + \ '}' \ $V ++ =W + \ '~' \ $W + =X + + / Emit boilerplate before + @P/arse loop + / Emit boilerplate after +} + +@R\ead and then\ @C\ompile\ -- cgit 1.4.1