diff --git a/include/SWI-Prolog.h b/include/SWI-Prolog.h index 3eb92156e..d6f4e1749 100755 --- a/include/SWI-Prolog.h +++ b/include/SWI-Prolog.h @@ -683,6 +683,36 @@ PL_EXPORT(LRESULT) PL_win_message_proc(HWND hwnd, X_API intptr_t PL_query(int); /* get information from Prolog */ + /******************************* + * ERRORS * + *******************************/ + +PL_EXPORT(int) PL_get_atom_ex(term_t t, atom_t *a); +PL_EXPORT(int) PL_get_integer_ex(term_t t, int *i); +PL_EXPORT(int) PL_get_long_ex(term_t t, long *i); +PL_EXPORT(int) PL_get_int64_ex(term_t t, int64_t *i); +PL_EXPORT(int) PL_get_intptr_ex(term_t t, intptr_t *i); +PL_EXPORT(int) PL_get_size_ex(term_t t, size_t *i); +PL_EXPORT(int) PL_get_bool_ex(term_t t, int *i); +PL_EXPORT(int) PL_get_float_ex(term_t t, double *f); +PL_EXPORT(int) PL_get_char_ex(term_t t, int *p, int eof); +PL_EXPORT(int) PL_unify_bool_ex(term_t t, int val); +PL_EXPORT(int) PL_get_pointer_ex(term_t t, void **addrp); +PL_EXPORT(int) PL_unify_list_ex(term_t l, term_t h, term_t t); +PL_EXPORT(int) PL_unify_nil_ex(term_t l); +PL_EXPORT(int) PL_get_list_ex(term_t l, term_t h, term_t t); +PL_EXPORT(int) PL_get_nil_ex(term_t l); + +PL_EXPORT(int) PL_instantiation_error(term_t culprit); +PL_EXPORT(int) PL_representation_error(const char *resource); +PL_EXPORT(int) PL_type_error(const char *expected, term_t culprit); +PL_EXPORT(int) PL_domain_error(const char *expected, term_t culprit); +PL_EXPORT(int) PL_existence_error(const char *type, term_t culprit); +PL_EXPORT(int) PL_permission_error(const char *operation, + const char *type, term_t culprit); +PL_EXPORT(int) PL_resource_error(const char *resource); + + /******************************* * BLOBS * *******************************/ diff --git a/packages/PLStream/pl-error.c b/packages/PLStream/pl-error.c index a15da7b3d..2055e1daa 100644 --- a/packages/PLStream/pl-error.c +++ b/packages/PLStream/pl-error.c @@ -184,6 +184,76 @@ PL_unify_bool_ex(term_t t, bool val) return PL_error(NULL, 0, NULL, ERR_TYPE, ATOM_bool, t); } + /******************************* + * TYPICAL ERRORS * + *******************************/ + +int +PL_instantiation_error(term_t actual) +{ return PL_error(NULL, 0, NULL, ERR_INSTANTIATION); +} + +int +PL_representation_error(const char *resource) +{ atom_t r = PL_new_atom(resource); + int rc = PL_error(NULL, 0, NULL, ERR_RESOURCE, r); + PL_unregister_atom(r); + + return rc; +} + + +int +PL_type_error(const char *expected, term_t actual) +{ return PL_error(NULL, 0, NULL, ERR_CHARS_TYPE, expected, actual); +} + + +int +PL_domain_error(const char *expected, term_t actual) +{ atom_t a = PL_new_atom(expected); + int rc = PL_error(NULL, 0, NULL, ERR_DOMAIN, a, actual); + PL_unregister_atom(a); + + return rc; +} + + +int +PL_existence_error(const char *type, term_t actual) +{ atom_t a = PL_new_atom(type); + int rc = PL_error(NULL, 0, NULL, ERR_EXISTENCE, a, actual); + PL_unregister_atom(a); + + return rc; +} + + +int +PL_permission_error(const char *op, const char *type, term_t obj) +{ atom_t t = PL_new_atom(type); + atom_t o = PL_new_atom(op); + int rc = PL_error(NULL, 0, NULL, ERR_PERMISSION, o, t, obj); + + PL_unregister_atom(t); + PL_unregister_atom(o); + + return rc; +} + + +int +PL_resource_error(const char *resource) +{ atom_t r = PL_new_atom(resource); + int rc = PL_error(NULL, 0, NULL, ERR_RESOURCE, r); + + PL_unregister_atom(r); + + return rc; +} + + + word notImplemented(char *name, int arity) { return (word)PL_error(NULL, 0, NULL, ERR_NOT_IMPLEMENTED_PROC, name, arity);