functions are objects: closures carry a member table (_doc_)

- CAT_TYPES_FUNCTION_Closure gains an attrs table; get/set_attribute
  give closures real members, so a function can hold _doc_ and any other
  attribute like a table
- cat_types_function_attrs() accessor; attributes() enumerates a
  closure's members; help() reads a function's _doc_
- compiler: generalise dotted assignment to chains (name.a.b = v), so a
  method can be documented (Calc.add._doc_ = ...)
- tests/functions_as_objects.cat + 7 assertions (84 total, all green)
- README: 'funcoes tambem sao objetos' + reflection sections
This commit is contained in:
Minus committed 2026-11-16 03:50:54 +00:00
1 parent 1203acd64b
commit e0bf102f2a
7 files changed
+183 -18

No files matched your search

+4
View File
@@ -17,11 +17,15 @@ typedef struct CAT_TYPES_FUNCTION_Closure {
struct CAT_BYTECODE_Function *proto;
CAT_VALUE_Value **upvals; /* captured values */
int nupvals;
CAT_VALUE_Value *attrs; /* optional member table (e.g. `_doc_`) */
} CAT_TYPES_FUNCTION_Closure;
/* Wrap a prototype as a callable closure. */
CAT_VALUE_Value *cat_types_function_new(struct CAT_BYTECODE_Function *proto);
/* The closure's own member table (created lazily; may be NULL). */
CAT_VALUE_Value *cat_types_function_attrs(CAT_VALUE_Value *fn);
CAT_VALUE_Vtable *cat_types_function_vtable(void);
#endif /* CAT_TYPES_FUNCTION_H */