rev 233 - trunk/include/prothon
SVN User <[email protected]>
| Newsgroups | gmane.comp.lang.prothon.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: bcollins
Date: 2004-03-31 11:37:59 -0500 (Wed, 31 Mar 2004)
New Revision: 233
Modified:
trunk/include/prothon/prothon.h
Log:
Add CHECK_PROTO() and CHECK_TYPE_EXC() convenience macros.
Modified: trunk/include/prothon/prothon.h
===================================================================
--- trunk/include/prothon/prothon.h 2004-03-31 15:39:21 UTC (rev 232)
+++ trunk/include/prothon/prothon.h 2004-03-31 16:37:59 UTC (rev 233)
@@ -483,6 +483,23 @@
// or have a circular reference. See section "INTERPRETER STATE" below.
int has_proto_QUES(isp ist, obj_p obj, obj_p obj_proto);
+// CHECK_PROTO: Convenience macro to check that an object has a certain
+// prototype. If not, the exception type will be thrown with message, and
+// return the value ret.
+#define CHECK_PROTO(__obj, __proto_obj, __exc_obj, __ret, __msg, args...) \
+do { \
+ if (!has_proto_QUES(ist, __obj, __proto_obj)) { \
+ raise_exception(ist, __exc_obj, __msg, ## args); \
+ return __ret; \
+ } \
+} while(0)
+
+// CHECK_TYPE_EXC: Even more specific than CHECK_PROTO, it does the common
+// type validation for objects (usually self).
+#define CHECK_TYPE_EXC(__obj, __proto_obj, name) \
+ CHECK_PROTO(__obj, __proto_obj, OBJ(TYPE_EXC), NULL, \
+ "object is not of type " #name)
+
// SWITCH_PROTO_TO: Replace all old protos with a new single proto object
void switch_proto_to(isp ist, obj_p obj, obj_p new_proto);