Phase 7a: bitwise operators & | ^ << >> ~ (retire band/bor/shl/…)
First step of the "stop feeling like C" pass. Bitwise ops were functions (`band(x, MASK)`, `shl(a, 3)`); they are now real operators: band -> & bor -> | bxor -> ^ shl -> << shr -> >> bnot -> ~ Precedence is Go-style so the C footgun is gone: `<<`/`>>`/`&` bind like `*`, `|`/`^` like `+`, both tighter than comparison — `flags & MASK == 0` parses as `(flags & MASK) == 0`. `>>` is logical (lshr), matching the old `shr`. Mechanics: lexer tokenizes `<< >> & | ^ ~`; p_mul takes `<< >> &`, p_add takes `| ^`, p_unary takes `~`; emit_bin routes them through the existing int arith path (arith_code gains and/or/xor/shl/lshr) and E_UN handles `~`. The six intrinsics are deleted. Delivered as two reseeds: (A) add the operators keeping the intrinsics, (B) migrate every call site to operator form (85 lines across compiler + runtime, via a balanced-paren call->operator script; two multi-line big-endian reads in image/truetype done by hand) and delete the intrinsics. Vocabulary drops the six from LUDIC_INTRINSICS (ludic_syntax.h, grammar, LudicTokens.kt) and the grammar gains a bitwise-operator rule. LANGUAGE.md precedence table rewritten. Reseeded (21724 lines); C-free fixpoint holds; goldens byte-identical (the PNG and TrueType decoders lean on these ops); 17/17; vocab + doc-fences clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
0e0c58519d
commit
fcada23eba
18 changed files with 3417 additions and 3403 deletions
|
|
@ -14,7 +14,6 @@ fn is_intrinsic(name: ptr) -> bool {
|
|||
if streq(name,"print_str") or streq(name,"print_int") { return true }
|
||||
if streq(name,"os_argc") or streq(name,"os_arg") or streq(name,"os_exit") or streq(name,"file_stderr") { return true }
|
||||
if streq(name,"os_system") or streq(name,"os_getenv") { return true }
|
||||
if streq(name,"shl") or streq(name,"shr") or streq(name,"band") or streq(name,"bor") or streq(name,"bxor") or streq(name,"bnot") { return true }
|
||||
if streq(name,"peek32") or streq(name,"poke32") { return true }
|
||||
return false
|
||||
}
|
||||
|
|
@ -114,16 +113,7 @@ fn emit_intrinsic(name: ptr, e: Node) -> Val {
|
|||
let n = arg_code(e, 0)
|
||||
return val(emit_bind(sconcat("call ptr @getenv(ptr ", sconcat(n, ")"))), "str")
|
||||
}
|
||||
if streq(name, "bnot") { let a = arg_code(e, 0); return val(emit_bind(sconcat("xor i32 ", sconcat(a, ", -1"))), "int") }
|
||||
if streq(name,"shl") or streq(name,"shr") or streq(name,"band") or streq(name,"bor") or streq(name,"bxor") {
|
||||
let a = arg_code(e, 0); let b = arg_code(e, 1)
|
||||
var opc = "shl"
|
||||
if streq(name,"shr") { opc = "lshr" }
|
||||
if streq(name,"band") { opc = "and" }
|
||||
if streq(name,"bor") { opc = "or" }
|
||||
if streq(name,"bxor") { opc = "xor" }
|
||||
return val(emit_bind(sconcat(opc, sconcat(" i32 ", sconcat(a, sconcat(", ", b))))), "int")
|
||||
}
|
||||
# bitwise ops are the operators & | ^ << >> ~ now (see emit_bin / p_mul).
|
||||
if streq(name, "peek32") {
|
||||
let p = arg_code(e, 0); let i = arg_code(e, 1)
|
||||
let g = nreg()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue