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

+3 -3
View File
@@ -7,11 +7,11 @@
* a declared signature, using libffi to perform the ABI-correct call.
*
* local lib = ffi.load("libm.so.6")
* local pow = lib:func("pow", "double(double,double)")
* local pow = lib.func("pow", "double(double,double)")
* print(pow(2, 10)) -- 1024
*
* local c = ffi.load("libc.so.6")
* local pid = c:func("getpid", "int()")
* local pid = c.func("getpid", "int()")
*
* Signature grammar: "RET(ARG,ARG,...)" where each type is one of
* void, bool, char, int8/uint8, int16/uint16, int/long/int32/uint32,
@@ -24,7 +24,7 @@
#include "cat/value.h"
/* CAT_TYPES_FFI_Library -- a dlopen() handle as a first-class value.
* `lib:func(name, sig)` / `lib[name]` resolve a symbol. */
* `lib.func(name, sig)` / `lib[name]` resolve a symbol. */
typedef struct CAT_TYPES_FFI_Library {
CAT_VALUE_Value base;
void *handle;
+1 -1
View File
@@ -13,7 +13,7 @@
* BytesIO -- an in-memory byte buffer (read as bytes)
*
* `File` is also exposed to catscript as a class table so that
* `File::open(path)` / `File:open(path)` produce a `File` value.
* `File::open(path)` produces a `File` value (static, no self).
*/
#ifndef CAT_TYPES_FILE_H
#define CAT_TYPES_FILE_H
+4 -4
View File
@@ -14,10 +14,10 @@
* and for the whole VM run since values are not freed early).
*
* local m = memory(16)
* m:set_u32(0, 1234)
* print(m:u32(0)) -- 1234
* m:set_text(4, "hi") -- 7 bytes: "hi" + NUL is at 4..6
* print(m:text(4)) -- hi
* m.set_u32(0, 1234)
* print(m.u32(0)) -- 1234
* m.set_text(4, "hi") -- 7 bytes: "hi" + NUL is at 4..6
* print(m.text(4)) -- hi
*/
#ifndef CAT_TYPES_MEMORY_H
#define CAT_TYPES_MEMORY_H
+5 -5
View File
@@ -7,11 +7,11 @@
* compiler lowers surface syntax to ordinary method sends against a small
* set of well-known selector names:
*
* obj(a, b) -> obj:_parenthesis_(a, b)
* obj[i] -> obj:_squarebrackets_(i)
* obj[i] = v -> obj:_squarebrackets_set_(i, v)
* obj.k -> obj:_dot_("k")
* obj.k = v -> obj:_dot_set_("k", v)
* obj(a, b) -> obj._parenthesis_(a, b)
* obj[i] -> obj._squarebrackets_(i)
* obj[i] = v -> obj._squarebrackets_set_(i, v)
* obj.k -> obj._dot_("k")
* obj.k = v -> obj._dot_set_("k", v)
* { ... } -> _curlybrackets_ hook on the new object
*
* Every object bound to these names inherits a default implementation