From 7cdf388bf45f11c4c054ed439be015ecc9849bfa Mon Sep 17 00:00:00 2001 From: Minus Date: Tue, 17 Nov 2026 23:14:17 +0000 Subject: [PATCH] object, not table: fix user-facing terminology The language is OOP with a single compound value, the object (an anonymous `{...}` or a class instance); it is not Lua and has no "tables". The visible type name was already `object`; this fixes the remaining user-facing wording: - error messages: "object has no member 'x'", "object is not callable". - README: drop the "Lua-like" phrasing; describe member objects, not tables. - self-hosted front-end AST node `t="object"` (was "table"), updated across parser/compiler/checker. - test comments/expected output aligned ("object:"). The internal C symbols keep the cat_types_table_* naming convention. Suite stays 130 green. --- README.md | 8 ++++---- src/cat/types/table.c | 6 +++--- std/lang/checker.cat | 2 +- std/lang/compiler.cat | 2 +- std/lang/parser.cat | 4 ++-- tests/functions_as_objects.cat | 4 ++-- tests/module.cat | 4 ++-- tests/repr.cat | 2 +- tests/run_tests.sh | 2 +- tests/selectors.cat | 2 +- 10 files changed, 18 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 5c8beea..a6b71f3 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # catscript Uma linguagem de scripting pequena, escrita em C, **100% orientada a -objetos**, com sintaxe parecida com Lua e **tipagem estrutural**. +objetos**, com sintaxe enxuta e **tipagem estrutural**. Este repositório contém: @@ -64,7 +64,7 @@ parser, o checker e o compiler são programas catscript**: - `src/catscript/compiler.cat` — gera bytecode a partir da AST. O runtime C expõe primitivas (`bc_run`, `bc_dump`) que transformam uma -"chunk" (uma tabela catscript: `{name, nparams, nlocals, consts, protos, +"chunk" (um objeto catscript: `{name, nparams, nlocals, consts, protos, code}`) em bytecode executável. Assim, código catscript compila e executa código catscript. @@ -339,8 +339,8 @@ Vulkan roda **headless** (lavapipe/llvmpipe); GLFW precisa de um display ## Funções também são objetos -Uma closure tem sua própria tabela de membros, então carrega `_doc_` (e -qualquer outro atributo) como uma tabela: +Uma closure tem seu próprio objeto de membros, então carrega `_doc_` (e +qualquer outro atributo) como um objeto: ```lua function add(a, b) return a + b end diff --git a/src/cat/types/table.c b/src/cat/types/table.c index 0537592..f8d2355 100644 --- a/src/cat/types/table.c +++ b/src/cat/types/table.c @@ -39,7 +39,7 @@ static int table_get_attribute(CAT_VALUE_Value *self, const char *name, return 0; } } - return (cat_error_raise(err, "table has no key '%s'", name), -1); + return (cat_error_raise(err, "object has no member '%s'", name), -1); } static int table_set_attribute(CAT_VALUE_Value *self, const char *name, @@ -62,7 +62,7 @@ static int table_call(CAT_VALUE_Value *self, CAT_VALUE_Value **args, int nargs, cat_error_clear(&e); if (cat_value_get_attribute(self, "new", &ctor, &e) != 0 || ctor == NULL) return (cat_error_raise(err, - "table is not callable (no 'new')"), -1); + "object is not callable (no 'new')"), -1); callargs[0] = self; for (i = 0; i < nargs && i < 257; i++) callargs[i + 1] = args[i]; @@ -156,7 +156,7 @@ int cat_types_table_get(CAT_VALUE_Value *tbl, const char *key, *out = t->pairs[idx].value; return 0; } - return (cat_error_raise(err, "table has no key '%s'", key), -1); + return (cat_error_raise(err, "object has no member '%s'", key), -1); } int cat_types_table_count(CAT_VALUE_Value *tbl) diff --git a/std/lang/checker.cat b/std/lang/checker.cat index 0b85315..cca5149 100644 --- a/std/lang/checker.cat +++ b/std/lang/checker.cat @@ -60,7 +60,7 @@ function chk_expr(e) chk_expr(e.idx) elseif t == "attr" then chk_expr(e.obj) - elseif t == "table" then + elseif t == "object" then local i = 1 while i <= len(e.fields) do chk_expr(e.fields[i].v) diff --git a/std/lang/compiler.cat b/std/lang/compiler.cat index 56c34ba..c6c3dbd 100644 --- a/std/lang/compiler.cat +++ b/std/lang/compiler.cat @@ -145,7 +145,7 @@ function cmp_expr(e) elseif t == "attr" then cmp_expr(e.obj) cmp_emit(22, cmp_addstr(e.name), 0, 0) - elseif t == "table" then + elseif t == "object" then cmp_emit(24, 0, 0, 0) local pos = 1 local i = 1 diff --git a/std/lang/parser.cat b/std/lang/parser.cat index 3645405..a1ed64a 100644 --- a/std/lang/parser.cat +++ b/std/lang/parser.cat @@ -11,7 +11,7 @@ -- { t="method", obj=O, name="m", args={...} } -- { t="index", obj=O, idx=I } -- { t="attr", obj=O, name="a" } --- { t="table", fields={ {k=..., v=...}, ... } } -- positional k is empty +-- { t="object", fields={ {k=..., v=...}, ... } } -- positional k is empty -- { t="func", name=..., params={...}, body={stats} } -- -- Statements: @@ -125,7 +125,7 @@ function par_table() par_advance() end par_expect("}", "'}'") - return { t = "table", fields = fields } + return { t = "object", fields = fields } end function par_args() diff --git a/tests/functions_as_objects.cat b/tests/functions_as_objects.cat index 4b0f126..cf204a2 100644 --- a/tests/functions_as_objects.cat +++ b/tests/functions_as_objects.cat @@ -1,7 +1,7 @@ -- tests/functions_as_objects.cat -- functions are objects too. -- --- A closure carries a member table, so it can hold `_doc_` (and any --- other attribute) exactly like a table. `help()` reads it; a dotted +-- A closure carries a member object, so it can hold `_doc_` (and any +-- other attribute) exactly like an object. `help()` reads it; a dotted -- assignment can reach an attribute of a nested object (a method). local t = {x = 1, y = 2} diff --git a/tests/module.cat b/tests/module.cat index 48d5de9..ff60f38 100644 --- a/tests/module.cat +++ b/tests/module.cat @@ -1,6 +1,6 @@ -- tests/module.cat -- the `module` global reflects the current unit. -- --- `module` is a global table: `name` is the basename of the running +-- `module` is a global object: `name` is the basename of the running -- file, `path` its path and `dir` its directory. Importing another -- file (use/dofile) swaps `module` for the duration of that file and -- restores the caller's afterwards. @@ -8,7 +8,7 @@ print("name:", module.name) print("dir:", module.dir) --- a user may mutate it like any table +-- a user may mutate it like any object module.extra = "tagged" print("extra:", module.extra) diff --git a/tests/repr.cat b/tests/repr.cat index ae2f242..355e1d6 100644 --- a/tests/repr.cat +++ b/tests/repr.cat @@ -19,7 +19,7 @@ class Point end local p = Point(3, 4) -print("table:", tostring(t)) +print("object:", tostring(t)) print("point:", tostring(p)) print("int:", tostring(42)) print("str:", tostring("hi")) diff --git a/tests/run_tests.sh b/tests/run_tests.sh index b49ccc1..25d92d8 100644 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -162,7 +162,7 @@ check "fn-help" "add(a, b) -- soma dois numeros." "`echo "$out" | sed -n # ---- _repr_ protocol ------------------------------------------------- out=`$BIN tests/repr.cat` -check "repr-value" "table: a custom point" "`echo "$out" | sed -n 1p`" +check "repr-value" "object: a custom point" "`echo "$out" | sed -n 1p`" check "repr-method" "point: Point(3, 4)" "`echo "$out" | sed -n 2p`" check "repr-int" "int: 42" "`echo "$out" | sed -n 3p`" check "repr-str" "str: hi" "`echo "$out" | sed -n 4p`" diff --git a/tests/selectors.cat b/tests/selectors.cat index f706588..620346d 100644 --- a/tests/selectors.cat +++ b/tests/selectors.cat @@ -17,7 +17,7 @@ counter.bump(3) counter.bump(4) print("with self:", counter.n) --- a plain table field +-- a plain object field local point = { x = 10, y = 20 } print("field x:", point.x)