diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2022-04-04 07:23:54 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2022-04-04 07:23:54 -0700 |
commit | 60095ceba927559a1ed226f8923327a1bb52f5c8 (patch) | |
tree | 1b14ca532636df226133f0048b193ea1d54e9a89 /cppawk-include/cons-priv.h | |
parent | 309cb40e0feaf77d547edeccce7bc07f4ff01ad0 (diff) | |
download | cppawk-60095ceba927559a1ed226f8923327a1bb52f5c8.tar.gz cppawk-60095ceba927559a1ed226f8923327a1bb52f5c8.tar.bz2 cppawk-60095ceba927559a1ed226f8923327a1bb52f5c8.zip |
Handle undefined value in type system.
New type code U indicates boxed undefined value.
Diffstat (limited to 'cppawk-include/cons-priv.h')
-rw-r--r-- | cppawk-include/cons-priv.h | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/cppawk-include/cons-priv.h b/cppawk-include/cons-priv.h index 95c8cee..1e32624 100644 --- a/cppawk-include/cons-priv.h +++ b/cppawk-include/cons-priv.h @@ -172,8 +172,15 @@ function __symbolp(__obj) #define __symbolp(obj) (substr(obj, 1, 1) ~ /^S?$/) function __box(__raw, + __check, __case_temps) { + if (!__present(__raw)) + return "U"; + + if (__present(__check)) + __error("box; excess argument %s", __check) + __case (__typecode(__raw)) { __of ("T", "S", "C") __cret ("T" __raw) // represent as unescaped string @@ -183,17 +190,25 @@ function __box(__raw, } function __unbox(__obj, + __check, __case_temps) { + if (__present(__check)) + __error("unbox; excess argument %s", __check) + __case (__typecode(__obj)) { __of ("T", "S") __cret (substr(__obj, 2)) __of ("C") - __error("unbox: %s looks like a cons", __obj, i) + __error("unbox: %s looks like a cons", __obj) __cbreak + __of ("U") + __cret(__check) __of ("") __cret("nil") __otherwise + if (!__numberp(__obj)) + __error("unbox: %s isn't symbol, number or boxed string", __obj) __cret (__obj) } } @@ -246,6 +261,9 @@ function __cdr(__cell, function __sexp(__obj, __d, __x, __y, __case_temps) { + if (!__present(__obj)) + __error("sexp: missing or undefined argument") + __case (__typecode(__obj)) { __of ("C") __d = __cdr(__obj) @@ -264,6 +282,8 @@ function __sexp(__obj, __cret ("\"" __bs_esc(substr(__obj, 2)) "\"") __of ("S") __cret (__bs_esc(substr(__obj, 2))) + __of ("U") + __cret ("#U") } if (__numberp(__obj)) { |