uCBQN/cc.bqn
2021-05-07 19:41:07 +03:00

56 lines
2.3 KiB
BQN
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#! /usr/bin/env dbqn
# Modified version of https://github.com/mlochbaum/BQN/blob/master/src/cjs.bqn, which is under the ISC license (https://github.com/mlochbaum/BQN/blob/master/LICENSE)
args•args
"Usage: ./cc.bqn path/to/mlochbaum/BQN <one of [rcfe] or an expression>"!2args
return 1args
args˜ return
path(args)"/src/"
args˜1
L {"m_caB(" (𝕩)",(B[]){" (1","¨𝕩)"})"}
LI {"m_cai32("(𝕩)",(i32[]){"(1","¨𝕩)"})"}
# Escape the special characters that appear in BQN sources.
Esc{
in (@+091013)"'""" # Null, Tab, LF, CR, and quotes
out "0tnr" # Whitespace characters changed to letters
i in𝕩
𝕩 i out((i<out)/) 𝕩 # Replace
(i<in) /"\"¨ 𝕩 # Insert \
}
Str "m_str32(U"""Esc""")"˙ # A BQN string
Char {"m_c32(U'"(Esc𝕩)"')"} # A BQN character
Num {s"-"/˜𝕩<0 =|"m_f64("")"˜s| "m_f64("s"1.0/0.0)"𝕩} # Format number
F # Format number
Import {𝕨•Import path𝕩}
FChars {𝕨•FChars path𝕩}
FLines {𝕨•FLines path𝕩}
glyphs Import "glyphs.bqn"
_getComp { (3+useInd) (𝕗 Import "c.bqn"){𝔽} }
useInd "-i"args args˜useInd
Comp ((<"inc(runtime[""])"˙)¨62) glyphs _getComp
J \n¨
Fconst @NumChar, Str,
Fout {((𝕩)LI F¨,L Fconst¨,L (LI ·F¨ 4)¨,L (L F¨)¨) {𝕎𝕩}¨ 𝕩}
Frun 1Fout
Long {¯2𝕩¨<","\n}
RT {
srcneedinputs𝕩Import"pr.bqn"
pr"runtime_0""provide"{(𝕨<(<{"inc("𝕨"["𝕩"])"}F¨)()¨𝕩)˜(𝕩)need}((-1+1=𝕩))inputs
Long Fout pr need _getComp src
}
CArg {J (¯5𝕩˙) FLines "c.bqn"}
LFC LongFoutComp
•Out(¬return) ("r""r0""r1""c""cc""f""e""p")
RT2, RT0, RT1
{𝕩LFC CArg "⟨""⟩"«","¨'"'(˜)¨glyphs}
{𝕩LFC "{""}"˜CArg"𝕩"}
{𝕩LFC FChars "f.bqn"}
{𝕩LFC SVG "e"}
{𝕩LFC SVG "p"}
¯1 · J LFoutComp¨
args