let a method call one written below it

Each method was registered just before its own body was walked, so an
earlier one could not find it. All are registered first now, and one
called above its definition is declared ahead of the bodies, which C
needs as well.

Fixes #44.
This commit is contained in:
2026-10-09 17:37:03 +03:00
parent acd7010e6b
commit 24f11cdcba
3 changed files with 63 additions and 8 deletions

View File

@@ -2,7 +2,8 @@
(input)
(output "5.0 5.0 10.0 14.0 14.0 6.0"
"struct receiver: 14"
"private: 8.0")
"private: 8.0"
"forward call: 28.0")
(return 0)
;;; An ops block is mangled fns plus a registry entry, so a method is
@@ -22,6 +23,10 @@
(record vec2 ((x float) (y float)))
(ops vec2
;; a method may call one written below it
(fn twice-sum ((self vec2)) float
(return (* 2.0 (.sum-of self))))
(pub fn length ((self (* const vec2))) float
"Pointer self, so (.length v) has to take the address."
(return (sqrtf (+ (* (. self x) (. self x))
@@ -55,4 +60,5 @@
(var u vec2 #(vec2 : 8.0 0.0))
(printf "private: %.1f\n" (vec2/sum-of u))
(printf "forward call: %.1f\n" (.twice-sum v))
(return 0))