selectors: a.b sends with self, a::b without; drop a:b

The `.` and `::` selectors swap meaning and `a:b` is removed, so every
access is one of:

  a.b          read the member
  a.b(args)    call the member WITH a as self
  a::b         static read (no self)
  a::b(args)   call the member WITHOUT self

- compiler: postfix `.` emits CALLMETHOD (with self) when followed by
  `(`, else GETATTR; `::` emits GETATTR + CALL (no self); the `:` form
  is gone (with a helpful error suggesting `.`/`::`).
- `:` remains only for type hints (local x : int), unchanged.
- ffi: `lib.func(...)` (with self) and `ffi::load(...)` (no self); the
  native loaders no longer skip a receiver.
- file: `File::open` is static, so cm_open reads args[0]/args[1].
- lexer: fix cat_lexer_kind_name, whose table had drifted from the enum
  (missing `nil`), mislabelling tokens.
- self-hosted parser (std/lang/parser.cat): `.name(` -> method (self),
  `::name(` -> call (no self); compiler/checker unchanged.
- tools/migrate_selectors.py: one-pass migration of the call forms.
- regenerated std/glfw and std/vulkan; migrated examples/tests/std and
  the README; new tests/selectors.cat (130 green).

Verified live: GLFW window + Vulkan device still work; `a:b` now errors.
This commit is contained in:
Minus committed 2026-11-17 18:55:18 +00:00
1 parent 04009c3c5e
commit 6f6f444beb
35 files changed
+1114 -964

No files matched your search

+4 -4
View File
@@ -19,13 +19,13 @@ class Dog extends Animal
end
local a = Animal("cat")
print(a:speak())
print(a:get_name())
print(a.speak())
print(a.get_name())
-- subclassing: Dog inherits init/get_name, overrides speak
local d = Dog("Rex")
print(d:speak())
print(d:get_name())
print(d.speak())
print(d.get_name())
-- use: import another catscript file (its definitions become global here)
use "std/math/math.cat"
+5 -5
View File
@@ -4,19 +4,19 @@
-- signature, and call it. libffi performs the ABI-correct call.
local m = ffi::load("libm.so.6")
local pow = m:func("pow", "double(double,double)")
local pow = m.func("pow", "double(double,double)")
print("pow(2,10) =", pow(2, 10))
local sqrt = m:func("sqrt", "double(double)")
local sqrt = m.func("sqrt", "double(double)")
print("sqrt(144) =", sqrt(144))
local c = ffi::load("libc.so.6")
local getpid = c:func("getpid", "int()")
local getpid = c.func("getpid", "int()")
local pid = getpid()
print("getpid > 0:", pid > 0)
local strlen = c:func("strlen", "long(string)")
local strlen = c.func("strlen", "long(string)")
print("strlen:", strlen("catscript"))
local abs = c:func("abs", "int(int)")
local abs = c.func("abs", "int(int)")
print("abs(-42) =", abs(-42))
+8 -8
View File
@@ -6,23 +6,23 @@
-- in-memory text stream
local s = StringIO("hello, catscript")
print("stringio:", s:read())
print("stringio:", s.read())
-- in-memory byte stream, written then read back
local b = BytesIO()
b:write("bytes ")
b:write("io")
print("bytesio:", b:read())
b.write("bytes ")
b.write("io")
print("bytesio:", b.read())
-- a real file, opened with the File::open classmethod
local path = "/tmp/catscript_demo.txt"
local w = File::open(path, "w")
w:write("line one\n")
w:close()
w.write("line one\n")
w.close()
local r = File::open(path, "r")
print("file:", r:read())
r:close()
print("file:", r.read())
r.close()
-- type hints: advisory, including DynSized() and sentinel_sized
function describe(n : cint, buf : cbyte[sentinel_sized<0>]) -> ascii_text
+4 -4
View File
@@ -13,10 +13,10 @@ print("type:", type(count_up(3)))
-- manual iteration with next
local g = count_up(3)
print("next:", g:next())
print("next:", g:next())
print("next:", g:next())
print("next:", g:next()) -- empty: exhausted
print("next:", g.next())
print("next:", g.next())
print("next:", g.next())
print("next:", g.next()) -- empty: exhausted
-- for..in drives any iterator automatically
local sum = 0
+11 -11
View File
@@ -8,26 +8,26 @@
use glfw
local version = memory(12)
glfw.get_version(version, version:ptr() + 4, version:ptr() + 8)
print("glfw:", version:u32(0), version:u32(4), version:u32(8))
glfw::get_version(version, version.ptr() + 4, version.ptr() + 8)
print("glfw:", version.u32(0), version.u32(4), version.u32(8))
local ok = glfw.init()
local ok = glfw::init()
print("init:", ok)
-- a hidden window with no client API (for Vulkan surfaces)
glfw.window_hint(glfw.visible, glfw.false)
glfw.window_hint(0x00022001, 0) -- CLIENT_API = NO_API
local win = glfw.create_window(320, 240, "cat", 0, 0)
glfw::window_hint(glfw.visible, glfw.false)
glfw::window_hint(0x00022001, 0) -- CLIENT_API = NO_API
local win = glfw::create_window(320, 240, "cat", 0, 0)
print("window:", win > 0)
if win > 0 then
local fw = memory(8)
local fh = memory(8)
glfw.get_framebuffer_size(win, fw, fh)
print("framebuffer:", fw:u32(0), fh:u32(0))
print("should close:", glfw.window_should_close(win) == glfw.true)
glfw.destroy_window(win)
glfw::get_framebuffer_size(win, fw, fh)
print("framebuffer:", fw.u32(0), fh.u32(0))
print("should close:", glfw::window_should_close(win) == glfw.true)
glfw::destroy_window(win)
end
glfw.terminate()
glfw::terminate()
print("done")
+3 -3
View File
@@ -13,6 +13,6 @@ local counter = {
end
}
counter:increment(1)
counter:increment(2)
print("counter:", counter:get()) -- 3
counter.increment(1)
counter.increment(2)
print("counter:", counter.get()) -- 3
+2 -2
View File
@@ -9,6 +9,6 @@ local f = File::open("/tmp/catscript_slots_demo.txt", "w")
print("path:", f.path)
print("mode:", f.mode)
print("closed:", f.closed)
f:write("slots")
f:close()
f.write("slots")
f.close()
print("closed:", f.closed)
+10 -10
View File
@@ -9,23 +9,23 @@ use vulkan
-- VkApplicationInfo
local ai = memory(vulkan.size_vk_application_info)
ai:fill(0)
ai:set_u32(0, vulkan.structure_type_application_info)
ai:set_u32(24, 0x00400000) -- apiVersion 1.0.0
ai.fill(0)
ai.set_u32(0, vulkan.structure_type_application_info)
ai.set_u32(24, 0x00400000) -- apiVersion 1.0.0
-- VkInstanceCreateInfo
local ci = memory(vulkan.size_vk_instance_create_info)
ci:fill(0)
ci:set_u32(0, vulkan.structure_type_instance_create_info)
ci:set_u64(24, ai:ptr()) -- pApplicationInfo
ci.fill(0)
ci.set_u32(0, vulkan.structure_type_instance_create_info)
ci.set_u64(24, ai.ptr()) -- pApplicationInfo
local inst = memory(8)
local r = vulkan.create_instance(ci, 0, inst)
local r = vulkan::create_instance(ci, 0, inst)
print("create_instance:", r == vulkan.success)
local n = memory(4)
vulkan.enumerate_physical_devices(inst:u64(0), n, 0)
print("devices > 0:", n:u32(0) > 0)
vulkan::enumerate_physical_devices(inst.u64(0), n, 0)
print("devices > 0:", n.u32(0) > 0)
vulkan.destroy_instance(inst:u64(0), 0)
vulkan::destroy_instance(inst.u64(0), 0)
print("done")