reflection: attributes() (dir-like) and help() with _doc_
- new list type (iterable, indexable) backing attributes() - attributes(obj): member names of a table/object, follows __index inheritance, includes native and slot members (like Python dir()) - help(obj): prints the value's _doc_ documentation, else its type and attributes - natives carry an optional _doc_ string (cat_types_native_new_doc); stdlib builtins documented - len() handles lists - examples/reflect.cat + 8 assertions wired into run_tests.sh (77 total)
This commit is contained in:
1 parent
4dae4ee1cd
commit
1203acd64b
8 files changed
+381
-14
No files matched your search
@@ -135,6 +135,18 @@ check "ffi-strlen-empty" "strlen empty: 0" "`echo "$out" | sed -n 13p
|
||||
check "ffi-void-nil" "void ret nil: true" "`echo "$out" | sed -n 14p`"
|
||||
check "ffi-strchr-bound" "strchr bound: true" "`echo "$out" | sed -n 15p`"
|
||||
check "ffi-lib-callable" "cos 0: 1" "`echo "$out" | sed -n 16p`"
|
||||
|
||||
# ---- reflection: attributes() / help() ------------------------------
|
||||
|
||||
out=`$BIN examples/reflect.cat`
|
||||
check "attr-count" "point attrs: 4" "`echo "$out" | sed -n 1p`"
|
||||
check "attr-x" " - x" "`echo "$out" | sed -n 2p`"
|
||||
check "attr-y" " - y" "`echo "$out" | sed -n 3p`"
|
||||
check "attr-name" " - name" "`echo "$out" | sed -n 4p`"
|
||||
check "attr-doc" " - _doc_" "`echo "$out" | sed -n 5p`"
|
||||
check "attr-method" "animal has speak: true" "`echo "$out" | sed -n 6p`"
|
||||
check "help-doc" "A 2D point with x, y coordinates." "`echo "$out" | sed -n 8p`"
|
||||
check "help-native" "print(a, ...) -- escreve os argumentos em stdout." "`echo "$out" | sed -n 10p`"
|
||||
# ---- bytecode dump ---------------------------------------------------
|
||||
|
||||
out=`$BIN --dump examples/hello.cat`
|
||||
|
||||
Reference in new issue
Block a user