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.
This commit is contained in:
1 parent
a73600e221
commit
7cdf388bf4
10 files changed
+18
-18
No files matched your search
@@ -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}
|
||||
|
||||
+2
-2
@@ -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)
|
||||
|
||||
|
||||
+1
-1
@@ -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"))
|
||||
|
||||
+1
-1
@@ -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`"
|
||||
|
||||
+1
-1
@@ -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)
|
||||
|
||||
|
||||
Reference in new issue
Block a user