灵符lingfu
L

ling-miao

↓ 0 下载

miao: a Ling-native version control system — temples, souls, rites and talismans instead of repos, branches, commits and tags; adaptive whole/delta/chunk storage; SSH temple fairs for sharing; a LingStationX-themed GUI; ROYGBIV everywhere

Windows · x86-64macOS · Intel x86-64Linux · x86-64LingOS · Pi 5 ARM64
关键词 vcs, version-control, git, miao, ling
lingfu install ling-miao
许可证Apache-2.0 OR MIT
作者ling-lin
README代码 / 文件版本依赖关系图依赖此包的项目安全构建设置

代码 / 文件 (268)

tools/smoke.ling
# smoke.ling — validates runtime assumptions before building miao. Run:
#   ling run --interp tools/smoke.ling alpha beta
fn is_bad(r) {
    match r { bad(e) => { return true } ok(v) => { return false } }
}

bind start = do {
    # 1. print_color + VT enable
    print_color(2, "[1] print_color green ok")

    # 2. raw ANSI truecolor after VT enabled
    bind er = hex_text("1b")
    if is_bad(er) { print("[2] FAIL hex_text") }
    bind E = er.unwrap()
    print(E + "[38;2;247;148;30m" + "[2] truecolor orange ok" + E + "[0m")

    # 3. st_ store headless
    st_set("k", 42.0)
    print("[3] st_get=" + st_get("k", 0.0) + " (want 42)")

    # 4. blake3 string vs file equivalence
    bind txt = "hello temple\n"
    bind h1 = hash_hex(txt)
    write_file("tools/_smoke_tmp.txt", txt)
    bind h2 = file_hash("tools/_smoke_tmp.txt")
    if h1 == h2 { print("[4] hash_hex==file_hash ok " + str_slice(h1, 0.0, 8.0)) }
    if h1 != h2 { print("[4] FAIL hash mismatch " + h1 + " vs " + h2) }

    # 5. file_read_hex / file_write_hex roundtrip + text detect
    bind hr = file_read_hex("tools/_smoke_tmp.txt")
    if is_bad(hr) { print("[5] FAIL file_read_hex") }
    bind hx = hr.unwrap()
    bind tr = hex_text(hx)
    if is_bad(tr) { print("[5] FAIL hex_text on text file") }
    if tr.unwrap() == txt { print("[5] hex roundtrip ok len=" + len(hx)) }
    bind wr = file_write_hex("tools/_smoke_tmp2.bin", hx)
    print("[5b] write_hex -> hash match: " + sel(file_hash("tools/_smoke_tmp2.bin") == h1, "ok", "FAIL"))

    # 6. split keeps trailing empty segment
    bind parts = split("a\nb\n", "\n")
    print("[6] split len=" + len(parts) + " (want 3) last='" + list_get(parts, 2.0) + "' (want empty)")
    bind rejoin = list_join(parts, "\n")
    print("[6b] rejoin exact: " + sel(rejoin == "a\nb\n", "ok", "FAIL"))

    # 7. get_args shape
    bind a = get_args()
    bind i = 0.0
    bind shown = ""
    while i < len(a) {
        bind shown = shown + "|" + list_get(a, i)
        bind i = i + 1.0
    }
    print("[7] argv=" + shown)

    # 8. recursion
    print("[8] fact(6)=" + smoke_fact(6.0) + " (want 720)")

    # 9. list_dir entries
    bind es = list_dir("tools")
    print("[9] list_dir tools -> " + len(es) + " entries, first=" + list_get(es, 0.0))

    # 10. str_find / str_slice semantics
    bind s = "soul: main"
    bind idx = str_find(s, ": ")
    print("[10] find=" + idx + " slice=" + str_slice(s, idx + 2.0, 99.0) + " (want main)")

    # 11. now_unix + env
    print("[11] now_unix=" + now_unix() + " user=" + env_get("USERNAME", "?"))

    # 12. absolute_path
    print("[12] abs=" + absolute_path("."))

    # 13. sel helper evaluates both — define locally
    print("[13] sel ok=" + sel(true, "yes", "no"))

    # cleanup
    remove_file("tools/_smoke_tmp.txt")
    remove_file("tools/_smoke_tmp2.bin")
    print_color(4, "[done] smoke complete")
}

fn smoke_fact(n) {
    if n < 1.5 { return 1.0 }
    return n * smoke_fact(n - 1.0)
}

fn sel(c, a, b) {
    if c { return a }
    return b
}

← 返回索引