remove nil/null: absence is an error, empty object is the only no-value
- delete the nil type; catscript has no nil and no null - add the empty object (Object with no members), exposed as the global 'empty'; it is a shared immutable singleton - 'nil' is no longer a keyword: it is an undefined global, which raises - undefined global -> error (consistent with a missing attribute) - only 'false' is falsy (numbers/objects are truthy); booleans kept - OP_NIL -> OP_EMPTY; compiler, VM, stdlib, toml, ffi, generator, file, list, selector, value all migrated - rename the table type to Object - std/ front-end and examples/tests migrated to 'empty' - 84/84 tests
This commit is contained in:
1 parent
e0bf102f2a
commit
d29b0706c9
36 files changed
+257
-244
No files matched your search
+11
-11
@@ -1,24 +1,24 @@
|
||||
-- tests/ffi.cat -- edge cases for the `ffi` library.
|
||||
--
|
||||
-- Deterministic output (no getpid): loads, symbol binding, signatures,
|
||||
-- return conversions, and the nil-on-error contract.
|
||||
-- return conversions, and the empty-on-error contract.
|
||||
|
||||
local m = ffi::load("libm.so.6")
|
||||
local c = ffi::load("libc.so.6")
|
||||
|
||||
-- load failure / bad library -> nil
|
||||
-- load failure / bad library -> empty
|
||||
local bad = ffi::load("no_such_library_xyz.so.999")
|
||||
print("bad load nil:", bad == nil)
|
||||
print("bad load empty:", bad == empty)
|
||||
print("bad load type:", type(bad))
|
||||
|
||||
-- symbol binding
|
||||
local pow = m:func("pow", "double(double,double)")
|
||||
print("pow bound:", pow ~= nil)
|
||||
print("missing sym nil:", m:func("no_such_symbol_xyz", "int()") == nil)
|
||||
print("pow bound:", pow ~= empty)
|
||||
print("missing sym empty:", m:func("no_such_symbol_xyz", "int()") == empty)
|
||||
|
||||
-- invalid signature -> nil
|
||||
print("bad sig nil:", m:func("pow", "not a signature") == nil)
|
||||
print("bad rettype nil:", m:func("pow", "nope(double)") == nil)
|
||||
-- invalid signature -> empty
|
||||
print("bad sig empty:", m:func("pow", "not a signature") == empty)
|
||||
print("bad rettype empty:", m:func("pow", "nope(double)") == empty)
|
||||
|
||||
-- return conversions
|
||||
print("pow 2,10:", pow(2, 10))
|
||||
@@ -37,13 +37,13 @@ local strlen = c:func("strlen", "long(string)")
|
||||
print("strlen abc:", strlen("abc"))
|
||||
print("strlen empty:", strlen(""))
|
||||
|
||||
-- void return -> nil
|
||||
-- void return -> empty
|
||||
local srand = c:func("srand", "void(uint32)")
|
||||
print("void ret nil:", srand(1) == nil)
|
||||
print("void ret empty:", srand(1) == empty)
|
||||
|
||||
-- pointer-ish spelling accepted
|
||||
local strchr = c:func("strchr", "string(string,int)")
|
||||
print("strchr bound:", strchr ~= nil)
|
||||
print("strchr bound:", strchr ~= empty)
|
||||
|
||||
-- library is callable like :func
|
||||
local cosf = m("cos", "double(double)")
|
||||
|
||||
+7
-7
@@ -69,7 +69,7 @@ check "file-hints" "n=3 buf=abc" "`echo "$out" | sed -n 5p`"
|
||||
out=`$BIN examples/generators.cat`
|
||||
check "gen-type" "type: generator" "`echo "$out" | sed -n 1p`"
|
||||
check "gen-next-1" "next: 1" "`echo "$out" | sed -n 2p`"
|
||||
check "gen-next-nil" "next: nil" "`echo "$out" | sed -n 5p`"
|
||||
check "gen-next-nil" "next: empty" "`echo "$out" | sed -n 5p`"
|
||||
check "gen-forin-sum" "sum 1..5 = 15" "`echo "$out" | sed -n 6p`"
|
||||
check "gen-break-lazy" "taken < 3: 3" "`echo "$out" | sed -n 7p`"
|
||||
|
||||
@@ -119,12 +119,12 @@ check "ffi-abs" "abs(-42) = 42" "`echo "$out" | sed -n 5p`"
|
||||
# ---- ffi edge cases (deterministic) ---------------------------------
|
||||
|
||||
out=`$BIN tests/ffi.cat`
|
||||
check "ffi-badload-nil" "bad load nil: true" "`echo "$out" | sed -n 1p`"
|
||||
check "ffi-badload-type" "bad load type: nil" "`echo "$out" | sed -n 2p`"
|
||||
check "ffi-badload-empty" "bad load empty: true" "`echo "$out" | sed -n 1p`"
|
||||
check "ffi-badload-type" "bad load type: Object" "`echo "$out" | sed -n 2p`"
|
||||
check "ffi-bound" "pow bound: true" "`echo "$out" | sed -n 3p`"
|
||||
check "ffi-missing-sym" "missing sym nil: true" "`echo "$out" | sed -n 4p`"
|
||||
check "ffi-badsig" "bad sig nil: true" "`echo "$out" | sed -n 5p`"
|
||||
check "ffi-badret" "bad rettype nil: true" "`echo "$out" | sed -n 6p`"
|
||||
check "ffi-missing-sym" "missing sym empty: true" "`echo "$out" | sed -n 4p`"
|
||||
check "ffi-badsig" "bad sig empty: true" "`echo "$out" | sed -n 5p`"
|
||||
check "ffi-badret" "bad rettype empty: true" "`echo "$out" | sed -n 6p`"
|
||||
check "ffi-pow-2-10" "pow 2,10: 1024" "`echo "$out" | sed -n 7p`"
|
||||
check "ffi-pow-3-4" "pow 3,4: 81" "`echo "$out" | sed -n 8p`"
|
||||
check "ffi-floor" "floor 3.7: 3" "`echo "$out" | sed -n 9p`"
|
||||
@@ -132,7 +132,7 @@ check "ffi-sqrt-144" "sqrt 144: 12" "`echo "$out" | sed -n 10p
|
||||
check "ffi-abs-neg" "abs -42: 42" "`echo "$out" | sed -n 11p`"
|
||||
check "ffi-strlen-abc" "strlen abc: 3" "`echo "$out" | sed -n 12p`"
|
||||
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-void-empty" "void ret empty: 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`"
|
||||
|
||||
|
||||
Reference in new issue
Block a user