rev 646 - in trunk: include/prothon pr/test src

SVN User <[email protected]> Sat, 19 Jun 2004 21:07:31 -0400
Newsgroups gmane.comp.lang.prothon.cvs
Message-ID <[email protected]>
Author: mark
Date: 2004-06-19 21:07:28 -0400 (Sat, 19 Jun 2004)
New Revision: 646

Modified:
   trunk/include/prothon/prothon.h
   trunk/pr/test/test.pr
   trunk/src/builtins-time.c
Log:
simplified constructor for simple case of DateTime(usecs)

Modified: trunk/include/prothon/prothon.h
===================================================================
--- trunk/include/prothon/prothon.h	2004-06-20 00:42:44 UTC (rev 645)
+++ trunk/include/prothon/prothon.h	2004-06-20 01:07:28 UTC (rev 646)
@@ -989,12 +989,13 @@
 	(var) = (index > 0 ? parms[((index)-1)*2+1] : list_item(ist, parms[1], -index)); }
 
 #define INT_32_PARAM(index, var)	/* i32_t var; */						\
-{	if (!has_proto(ist, (index > 0 ? parms[((index)-1)*2+1] : list_item(ist, parms[1], -index)), OBJ(INT_PROTO))) {						\
+do {	if (!has_proto(ist, (index > 0 ? parms[((index)-1)*2+1] : list_item(ist, parms[1], -index)), OBJ(INT_PROTO))) {						\
 		raise_exception(ist, OBJ(TYPE_EXC),									\
 				"expected a integer in parameter " #index);					\
 		return (index > 0 ? parms[((index)-1)*2+1] : list_item(ist, parms[1], -index));														\
 	}																		\
-	(var) = int2i32t(ist, index > 0 ? parms[((index)-1)*2+1] : list_item(ist, parms[1], -index)); }
+	(var) = int2i32t(ist, index > 0 ? parms[((index)-1)*2+1] : list_item(ist, parms[1], -index)); \
+} while (FALSE)
 i32_t int2i32t(isp ist, obj_p self);
 
 #define INT_64_PARAM(index, var)	/* i64_t var; */						\

Modified: trunk/pr/test/test.pr
===================================================================
--- trunk/pr/test/test.pr	2004-06-20 00:42:44 UTC (rev 645)
+++ trunk/pr/test/test.pr	2004-06-20 01:07:28 UTC (rev 646)
@@ -1,3 +1,3 @@
 #!/usr/bin/env prothon
 
-print DateTime(1975, 10, 19)
+print DateTime(1000000000000000000)

Modified: trunk/src/builtins-time.c
===================================================================
--- trunk/src/builtins-time.c	2004-06-20 00:42:44 UTC (rev 645)
+++ trunk/src/builtins-time.c	2004-06-20 01:07:28 UTC (rev 646)
@@ -89,35 +89,42 @@
 	DateTime_OBJ->data.i64     = apr_time_now();
 }
 
-DEF(DateTime, init_, FPARM8( year,        NEW_INT(0), month,  NEW_INT(0), 
-	                         day,         NEW_INT(0), hour,   NEW_INT(0),      
-						     minute,      NEW_INT(0), second, NEW_INT(0), 
-						     microsecond, NEW_INT(0), tzinfo, OBJ(NONE) ) ) {
+DEF(DateTime, init_, FPARM8( year,        OBJ(NONE), month,  OBJ(NONE), 
+	                         day,         OBJ(NONE), hour,   OBJ(NONE),      
+						     minute,      OBJ(NONE), second, OBJ(NONE), 
+						     microsecond, OBJ(NONE), tzinfo, OBJ(NONE) ) ) {
 	apr_status_t aprerr;
 	apr_time_t result;
 	apr_time_exp_t aprxt;
-	i32_t year,month,day,hour,minute,second;
-	i64_t microsecond; 
+	i32_t month=0, day=0, hour=0, minute=0, second=0;
+	i64_t year=0, microsecond=0; 
 	obj_p tzinfo;
+	int have_yr = FALSE, have_mo = FALSE, have_dy = FALSE;
+	int have_hr = FALSE, have_mi = FALSE, have_sc = FALSE, have_us = FALSE;
 
 	BIN_EMPTY_CHK();
-	INT_32_PARAM(1, year);
-	INT_32_PARAM(2, month);
-	INT_32_PARAM(3, day);
-	INT_32_PARAM(4, hour);
-	INT_32_PARAM(5, minute);
-	INT_32_PARAM(6, second);
-	INT_64_PARAM(7, microsecond);
+	if (parms[1]  != OBJ(NONE)) { have_yr = TRUE; INT_64_PARAM(1, year); }
+	if (parms[3]  != OBJ(NONE)) { have_mo = TRUE; INT_32_PARAM(2, month); }
+	if (parms[5]  != OBJ(NONE)) { have_dy = TRUE; INT_32_PARAM(3, day); }
+	if (parms[7]  != OBJ(NONE)) { have_hr = TRUE; INT_32_PARAM(4, hour); }
+	if (parms[9]  != OBJ(NONE)) { have_mi = TRUE; INT_32_PARAM(5, minute); }
+	if (parms[11] != OBJ(NONE)) { have_sc = TRUE; INT_32_PARAM(6, second); }
+	if (parms[13] != OBJ(NONE)) { have_us = TRUE; INT_64_PARAM(7, microsecond); }
 	tzinfo = parms[15];
 
 	SET_TYPE_IF_EXC(DateTime_OBJ, self, DATA_TYPE_IMMDATA) return NULL;
 	self->imm_data_len = 8;
-	if ( !year && !month && !day && !hour && 
-		!minute && !second && !microsecond ) {
+	if ( !have_yr && !have_mo && !have_dy &&
+		 !have_hr && !have_mi && !have_sc && !have_us ) {
 		self->data.i64 = apr_time_now();
 		return OBJ(NONE);
 	}
-	if (!year && !month) {
+	if (  have_yr && !have_mo && !have_dy &&
+		 !have_hr && !have_mi && !have_sc && !have_us ) {
+		self->data.i64 = year;
+		return OBJ(NONE);
+	}
+	if (!have_yr && !have_mo) {
 		self->data.i64 = 
 			(((i64_t)day)*24*60*60*1000000) + 
 		    (((i64_t)hour)*60*60*1000000) + 
@@ -126,7 +133,7 @@
 		return OBJ(NONE);
 	}
 	memset(&aprxt, 0, sizeof(aprxt));
-	aprxt.tm_year = year-1900;
+	aprxt.tm_year = ((i32_t)year)-1900;
 	aprxt.tm_mon  = month-1;
 	aprxt.tm_mday = day;
 	aprxt.tm_hour = hour;