feat(stdlib): 2D Vector type + Vector.* namespace (issue #25)
Some checks failed
docs / build-and-deploy (push) Has been cancelled
Some checks failed
docs / build-and-deploy (push) Has been cancelled
Implement the Vec.* half of #25 under the proper (de-abbreviated) name Vector, unblocking it with a self-contained value type instead of waiting on the full #1 type system. A Vector is two Q16.16 fixed components (x, y) packed into one i64 — a true by-value type that lives in a register and never allocates (reuses the new `long`/i64 support; llty maps `Vector` to i64). Fifteen operations, all deterministic fixed-point reusing fx_mul/fx_div/fx_lerp and the @fn_fx_* prelude: make/zero/x/y, add/sub/scale/dot, length/distance/normalize/lerp, rotate/angle/from_angle. New selfhost/emit_vector.ludic (wired into emit_ns_call + the frag list), the `Vector` primitive type in llty and the grammars/LSP/JetBrains tokens, docs (type-vector + 15 Vector.* pages + section), and a registered test. Reseeded; C-free fixpoint holds; all suites green (45/25/29); site + check.py OK. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
2e0047514b
commit
121053e179
30 changed files with 13740 additions and 11881 deletions
|
|
@ -204,7 +204,7 @@ program LudicLsp {
|
|||
return c == 43 or c == 45 or c == 42 or c == 47 or c == 37 or c == 60 or c == 62 or c == 61 or c == 40 or c == 41 or c == 123 or c == 125 or c == 91 or c == 93 or c == 44 or c == 58 or c == 46 or c == 33 or c == 64 or c == 59
|
||||
}
|
||||
function is_type_word(w: pointer) -> bool {
|
||||
return (w == "int") or (w == "long") or (w == "fixed") or (w == "bool") or (w == "entity") or (w == "string") or (w == "pointer") or (w == "byte") or (w == "words") or (w == "fixeds") or (w == "pointers") or (w == "void")
|
||||
return (w == "int") or (w == "long") or (w == "fixed") or (w == "bool") or (w == "entity") or (w == "string") or (w == "pointer") or (w == "byte") or (w == "words") or (w == "fixeds") or (w == "pointers") or (w == "Vector") or (w == "void")
|
||||
}
|
||||
function is_phase_word(w: pointer) -> bool {
|
||||
return (w == "Start") or (w == "Input") or (w == "FixedUpdate") or (w == "Update") or (w == "LateUpdate") or (w == "Render")
|
||||
|
|
@ -1301,6 +1301,23 @@ program LudicLsp {
|
|||
if (meth == "fnv1a_64") { return "Hash.fnv1a_64(s) -> long" }
|
||||
if (meth == "mix64") { return "Hash.mix64(x) -> long" }
|
||||
}
|
||||
if (ns == "Vector") {
|
||||
if (meth == "make") { return "Vector.make(x, y) -> Vector" }
|
||||
if (meth == "zero") { return "Vector.zero() -> Vector" }
|
||||
if (meth == "x") { return "Vector.x(v) -> fixed" }
|
||||
if (meth == "y") { return "Vector.y(v) -> fixed" }
|
||||
if (meth == "add") { return "Vector.add(a, b) -> Vector" }
|
||||
if (meth == "sub") { return "Vector.sub(a, b) -> Vector" }
|
||||
if (meth == "scale") { return "Vector.scale(v, s) -> Vector" }
|
||||
if (meth == "dot") { return "Vector.dot(a, b) -> fixed" }
|
||||
if (meth == "length") { return "Vector.length(v) -> fixed" }
|
||||
if (meth == "distance") { return "Vector.distance(a, b) -> fixed" }
|
||||
if (meth == "normalize") { return "Vector.normalize(v) -> Vector" }
|
||||
if (meth == "lerp") { return "Vector.lerp(a, b, t) -> Vector" }
|
||||
if (meth == "rotate") { return "Vector.rotate(v, angle) -> Vector" }
|
||||
if (meth == "angle") { return "Vector.angle(v) -> fixed" }
|
||||
if (meth == "from_angle") { return "Vector.from_angle(a) -> Vector" }
|
||||
}
|
||||
if (ns == "List") {
|
||||
if (meth == "len") { return "List.len(s) -> int" }
|
||||
if (meth == "push") { return "List.push(s, v)" }
|
||||
|
|
@ -2287,7 +2304,7 @@ program LudicLsp {
|
|||
}
|
||||
function comp_types(o: Buf) -> void {
|
||||
comp_item(o, "int", 14, "built-in type"); comp_item(o, "long", 14, "built-in type"); comp_item(o, "fixed", 14, "built-in type"); comp_item(o, "bool", 14, "built-in type")
|
||||
comp_item(o, "entity", 14, "built-in type"); comp_item(o, "string", 14, "built-in type"); comp_item(o, "pointer", 14, "built-in type"); comp_item(o, "void", 14, "built-in type")
|
||||
comp_item(o, "entity", 14, "built-in type"); comp_item(o, "string", 14, "built-in type"); comp_item(o, "pointer", 14, "built-in type"); comp_item(o, "Vector", 14, "built-in type"); comp_item(o, "void", 14, "built-in type")
|
||||
}
|
||||
function comp_builtins(o: Buf) -> void { var i = 0; while i < len(g_builtins) { comp_item(o, g_builtins[i], 3, g_bsigs[i]); i = i + 1 } }
|
||||
function on_completion(msg: JVal, id: JVal) -> void {
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ static const char* LUDIC_KW_STMT[] = {
|
|||
"and","or","not","break","continue","new","emit","cancel", 0
|
||||
};
|
||||
static const char* LUDIC_TYPES[] = {
|
||||
"int","long","fixed","bool","entity","string","pointer","byte","words","fixeds","pointers","void", 0
|
||||
"int","long","fixed","bool","entity","string","pointer","byte","words","fixeds","pointers","Vector","void", 0
|
||||
};
|
||||
static const char* LUDIC_PHASES[] = {
|
||||
"Start","Input","FixedUpdate","Update","LateUpdate","Render", 0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue