mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-24 20:45:06 +02:00
Added more type checking
This commit is contained in:
parent
4631081e3a
commit
c8591e4473
1 changed files with 13 additions and 3 deletions
16
runtime.c
16
runtime.c
|
@ -49,6 +49,7 @@ const char *tag_names[20] = { \
|
||||||
#define Cyc_check_cons(obj) Cyc_check_type(Cyc_is_cons, cons_tag, obj);
|
#define Cyc_check_cons(obj) Cyc_check_type(Cyc_is_cons, cons_tag, obj);
|
||||||
#define Cyc_check_num(obj) Cyc_check_type(Cyc_is_number, integer_tag, obj);
|
#define Cyc_check_num(obj) Cyc_check_type(Cyc_is_number, integer_tag, obj);
|
||||||
#define Cyc_check_int(obj) Cyc_check_type(Cyc_is_integer, integer_tag, obj);
|
#define Cyc_check_int(obj) Cyc_check_type(Cyc_is_integer, integer_tag, obj);
|
||||||
|
#define Cyc_check_str(obj) Cyc_check_type(Cyc_is_string, string_tag, obj);
|
||||||
|
|
||||||
void Cyc_invalid_type_error(int tag, object found) {
|
void Cyc_invalid_type_error(int tag, object found) {
|
||||||
char buf[256];
|
char buf[256];
|
||||||
|
@ -56,6 +57,12 @@ void Cyc_invalid_type_error(int tag, object found) {
|
||||||
Cyc_rt_raise2(buf, found);
|
Cyc_rt_raise2(buf, found);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Cyc_check_obj(int tag, object obj) {
|
||||||
|
if (!is_object_type(obj)) {
|
||||||
|
Cyc_invalid_type_error(tag, obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Funcall section, these are hardcoded here to support
|
/* Funcall section, these are hardcoded here to support
|
||||||
functions in this module. */
|
functions in this module. */
|
||||||
#define funcall1(cfn,a1) if (type_of(cfn) == cons_tag || prim(cfn)) { Cyc_apply(0, (closure)a1, cfn); } else { ((cfn)->fn)(1,cfn,a1);}
|
#define funcall1(cfn,a1) if (type_of(cfn) == cons_tag || prim(cfn)) { Cyc_apply(0, (closure)a1, cfn); } else { ((cfn)->fn)(1,cfn,a1);}
|
||||||
|
@ -870,6 +877,8 @@ void __string2list(const char *str, cons_type *buf, int buflen){
|
||||||
common_type Cyc_string2number(object str){
|
common_type Cyc_string2number(object str){
|
||||||
common_type result;
|
common_type result;
|
||||||
double n;
|
double n;
|
||||||
|
Cyc_check_obj(string_tag, str);
|
||||||
|
Cyc_check_str(str);
|
||||||
if (type_of(str) == string_tag &&
|
if (type_of(str) == string_tag &&
|
||||||
((string_type *) str)->str){
|
((string_type *) str)->str){
|
||||||
n = atof(((string_type *) str)->str);
|
n = atof(((string_type *) str)->str);
|
||||||
|
@ -951,9 +960,10 @@ string_type Cyc_string_append_va_list(int argc, object str1, va_list ap) {
|
||||||
}
|
}
|
||||||
|
|
||||||
integer_type Cyc_string_length(object str) {
|
integer_type Cyc_string_length(object str) {
|
||||||
make_int(len, strlen(string_str(str)));
|
Cyc_check_obj(string_tag, str);
|
||||||
return len;
|
Cyc_check_str(str);
|
||||||
}
|
{ make_int(len, strlen(string_str(str)));
|
||||||
|
return len; }}
|
||||||
|
|
||||||
object Cyc_string_ref(object str, object k) {
|
object Cyc_string_ref(object str, object k) {
|
||||||
const char *raw = string_str(str);
|
const char *raw = string_str(str);
|
||||||
|
|
Loading…
Add table
Reference in a new issue