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
+12
-12
@@ -14,7 +14,7 @@
|
||||
--
|
||||
-- All state lives in globals prefixed CMP_ (closures capture no locals).
|
||||
|
||||
CMP_CHUNK = nil
|
||||
CMP_CHUNK = empty
|
||||
CMP_CONSTS = {}
|
||||
CMP_NC = 0
|
||||
CMP_PROTOS = {}
|
||||
@@ -80,7 +80,7 @@ function cmp_restore(s)
|
||||
end
|
||||
|
||||
function cmp_newchunk(name)
|
||||
CMP_CHUNK = nil
|
||||
CMP_CHUNK = empty
|
||||
CMP_CONSTS = {}
|
||||
CMP_NC = 0
|
||||
CMP_PROTOS = {}
|
||||
@@ -99,7 +99,7 @@ end
|
||||
|
||||
function cmp_expr(e)
|
||||
local t = e.t
|
||||
if t == "nil" then cmp_emit(2, 0, 0, 0)
|
||||
if t == "empty" then cmp_emit(2, 0, 0, 0)
|
||||
elseif t == "true" then cmp_emit(3, 0, 0, 0)
|
||||
elseif t == "false" then cmp_emit(4, 0, 0, 0)
|
||||
elseif t == "int" then cmp_emit(1, cmp_addconst(e.v), 0, 0)
|
||||
@@ -151,7 +151,7 @@ function cmp_expr(e)
|
||||
local i = 1
|
||||
while i <= len(e.fields) do
|
||||
local f = e.fields[i]
|
||||
if f.k ~= nil then
|
||||
if f.k ~= empty then
|
||||
cmp_emit(37, 0, 0, 0) -- DUP obj
|
||||
cmp_expr(f.v)
|
||||
cmp_emit(23, cmp_addstr(f.k), 0, 0)
|
||||
@@ -207,7 +207,7 @@ end
|
||||
-- ---- statements ------------------------------------------------------
|
||||
|
||||
function cmp_block(stats)
|
||||
if stats == nil then
|
||||
if stats == empty then
|
||||
return
|
||||
end
|
||||
local i = 1
|
||||
@@ -220,7 +220,7 @@ end
|
||||
function cmp_stat(s)
|
||||
local k = s.t
|
||||
if k == "local" then
|
||||
if s.init ~= nil then
|
||||
if s.init ~= empty then
|
||||
cmp_expr(s.init)
|
||||
else
|
||||
cmp_emit(2, 0, 0, 0)
|
||||
@@ -267,7 +267,7 @@ function cmp_stat(s)
|
||||
elseif k == "for" then
|
||||
cmp_for(s)
|
||||
elseif k == "return" then
|
||||
if s.e ~= nil then
|
||||
if s.e ~= empty then
|
||||
cmp_expr(s.e)
|
||||
cmp_emit(30, 0, 0, 0)
|
||||
else
|
||||
@@ -295,7 +295,7 @@ function cmp_if(s)
|
||||
cmp_block(s.conds[i].body)
|
||||
i = i + 1
|
||||
end
|
||||
if s.els ~= nil then
|
||||
if s.els ~= empty then
|
||||
nends = nends + 1
|
||||
ends[nends] = cmp_emit(27, 0, 0, 0)
|
||||
cmp_patch(jf, CMP_NI)
|
||||
@@ -317,7 +317,7 @@ function cmp_while(s)
|
||||
CMP_LOOPS[len(CMP_LOOPS) + 1] = { breaks = {} }
|
||||
cmp_block(s.body)
|
||||
local loop = CMP_LOOPS[len(CMP_LOOPS)]
|
||||
CMP_LOOPS[len(CMP_LOOPS)] = nil
|
||||
CMP_LOOPS[len(CMP_LOOPS)] = empty
|
||||
cmp_emit(27, jcond, 0, 0)
|
||||
cmp_patch(jend, CMP_NI)
|
||||
local i = 1
|
||||
@@ -332,7 +332,7 @@ function cmp_repeat(s)
|
||||
CMP_LOOPS[len(CMP_LOOPS) + 1] = { breaks = {} }
|
||||
cmp_block(s.body)
|
||||
local loop = CMP_LOOPS[len(CMP_LOOPS)]
|
||||
CMP_LOOPS[len(CMP_LOOPS)] = nil
|
||||
CMP_LOOPS[len(CMP_LOOPS)] = empty
|
||||
cmp_expr(s.cond)
|
||||
cmp_emit(29, jtop, 0, 0)
|
||||
local i = 1
|
||||
@@ -344,7 +344,7 @@ end
|
||||
|
||||
function cmp_for(s)
|
||||
cmp_expr(s.from)
|
||||
if s.step ~= nil then
|
||||
if s.step ~= empty then
|
||||
cmp_expr(s.step)
|
||||
else
|
||||
cmp_emit(1, cmp_addconst(1), 0, 0)
|
||||
@@ -365,7 +365,7 @@ function cmp_for(s)
|
||||
CMP_LOOPS[len(CMP_LOOPS) + 1] = { breaks = {} }
|
||||
cmp_block(s.body)
|
||||
local loop = CMP_LOOPS[len(CMP_LOOPS)]
|
||||
CMP_LOOPS[len(CMP_LOOPS)] = nil
|
||||
CMP_LOOPS[len(CMP_LOOPS)] = empty
|
||||
cmp_emit(5, slot, 0, 0)
|
||||
cmp_emit(5, slot + 2, 0, 0)
|
||||
cmp_emit(9, 0, 0, 0)
|
||||
|
||||
Reference in new issue
Block a user