rev 627 - trunk/src

SVN User <[email protected]> Tue, 15 Jun 2004 22:31:05 -0400
Newsgroups gmane.comp.lang.prothon.cvs
Message-ID <[email protected]>
Author: mark
Date: 2004-06-15 22:31:01 -0400 (Tue, 15 Jun 2004)
New Revision: 627

Added:
   trunk/src/builtins-time.c
Modified:
   trunk/src/builtins-file.c
   trunk/src/builtins-float.c
   trunk/src/object.c
   trunk/src/src.vcproj
Log:
added Time builtin object with init_, str_, hash_, eq_?, and cmp_ methods

Modified: trunk/src/builtins-file.c
===================================================================
--- trunk/src/builtins-file.c	2004-06-15 22:39:40 UTC (rev 626)
+++ trunk/src/builtins-file.c	2004-06-16 02:31:01 UTC (rev 627)
@@ -80,9 +80,10 @@
 #define OPEN(obj)    (((obj) != File_OBJ) && STREAM(obj))
 
 MODULE_DECLARE(Dir);
-MODULE_DECLARE(TempDir);
 MODULE_DECLARE(File);
+MODULE_DECLARE(TempFile);
 MODULE_DECLARE(TextFile);
+MODULE_DECLARE(TempTextFile);
 
 //*************************** set_file_obj_data *******************************
 static void set_file_obj_data( isp ist, obj_p file_obj, obj_p filename, obj_p mode,
@@ -502,64 +503,6 @@
 	return parms[1];
 }
 
-//*************************** MODULE TempDir **********************************
-
-MODULE_START(TempDir) {
-	apr_pool_t *subpool;
-	char* temp_dir_path;
-
-	TempDir_OBJ = NEW_OBJ(Dir_OBJ);
-	set_obj_doc(TempDir_OBJ, "Temporary directory object prototype");
-
-	apr_pool_create(&subpool, get_pr_head_pool());
-	apr_temp_dir_get(&temp_dir_path, subpool);
-	set_file_obj_data( ist, TempDir_OBJ, NEW_STRING(temp_dir_path), 
-		               NULL, NULL, 0, APR_READ );
-	SET_TYPE_IF_EXC(Dir_OBJ, TempDir_OBJ, DATA_TYPE_DATAPTR) return;
-	MODULE_ADD_TO_BASE(TempDir);
-	set_unclonable(TempDir_OBJ);
-}
-
-DEF(TempDir, init_, NULL) {
-	BIN_EMPTY_CHK();
-	set_immutable(TempDir_OBJ);
-	return TempDir_OBJ;
-}
-
-DEF(TempDir, str_, NULL) {
-	char buf[300], *path;
-	BIN_STR_CHK(TempDir);
-	path = pr2c_strptr(ist, get_attr(ist, self, sym(ist, "path")));
-	apr_snprintf(buf, sizeof(buf), "<TempDir:'%s'>", path);
-	pr_free(path);
-	return NEW_STRING(buf);
-}
-
-DEF(TempDir, make, FPARM1(uperms, NEW_INT(APR_UREAD|APR_UWRITE|APR_UEXECUTE))) {
-	raise_exception(ist, OBJ(TYPE_EXC), "make() not allowed on TempDir");
-	return NULL;
-}
-DEF(TempDir, rename, FPARM1(name, NULL)) {
-	raise_exception(ist, OBJ(TYPE_EXC), "rename() not allowed on TempDir");
-	return NULL;
-}
-DEF(TempDir, move, FPARM1(dir, NULL)) {
-	raise_exception(ist, OBJ(TYPE_EXC), "move() not allowed on TempDir");
-	return NULL;
-}
-DEF(TempDir, delete, NULL) {
-	raise_exception(ist, OBJ(TYPE_EXC), "delete() not allowed on TempDir");
-	return NULL;
-}
-DEF(TempDir, setUPerms, FPARM1(uperms, NEW_INT(APR_UREAD|APR_UWRITE|APR_UEXECUTE))) {
-	raise_exception(ist, OBJ(TYPE_EXC), "setUPerms() not allowed on TempDir");
-	return NULL;
-}
-DEF(TempDir, setAttrs, FPARM3(readOnly, OBJ(NONE), executable, OBJ(NONE), hidden, OBJ(NONE))) {
-	raise_exception(ist, OBJ(TYPE_EXC), "setAttrs() not allowed on TempDir");
-	return NULL;
-}
-
 //*************************** MODULE File *************************************
 
 MODULE_START(File)
@@ -1566,16 +1509,6 @@
 	MODULE_ADD_SYM(Dir, setAttrs);
 	MODULE_ADD_SYM(Dir, objList_);
 
-	MODULE_SUB_INIT(TempDir);
-	MODULE_ADD_SYM(TempDir, init_);
-	MODULE_ADD_SYM(TempDir, str_);
-	MODULE_ADD_SYM(TempDir, make);
-	MODULE_ADD_SYM(TempDir, rename);
-	MODULE_ADD_SYM(TempDir, move);
-	MODULE_ADD_SYM(TempDir, delete);
-	MODULE_ADD_SYM(TempDir, setUPerms);
-	MODULE_ADD_SYM(TempDir, setAttrs);
-
 	MODULE_SUB_INIT(File);
 	MODULE_ADD_SYM(File, init_);
 	MODULE_ADD_SYM(File, str_);
Modified: trunk/src/builtins-float.c
===================================================================
--- trunk/src/builtins-float.c	2004-06-15 22:39:40 UTC (rev 626)
+++ trunk/src/builtins-float.c	2004-06-16 02:31:01 UTC (rev 627)
@@ -312,7 +312,7 @@
 		}
 	}
 	if (Float_value(self) == float_other)
-		return NEW_FLOAT(0);
+		return NEW_INT(0);
 	else if (Float_value(self) > float_other)
 		return NEW_INT(1);
 	else

Added: trunk/src/builtins-time.c
===================================================================
--- trunk/src/builtins-time.c	2004-06-15 22:39:40 UTC (rev 626)
+++ trunk/src/builtins-time.c	2004-06-16 02:31:01 UTC (rev 627)
@@ -0,0 +1,150 @@
+/* ====================================================================
+ * The Prothon License Agreement, Version 1.1
+ *
+ * Copyright (c) 2004 Hahn Creative Applications, http://hahnca.com.
+ * All rights reserved. 
+ *
+ * 1. This LICENSE AGREEMENT is between Hahn Creative Applications ("HCA"),
+ * and the Individual or Organization ("Licensee") accessing and otherwise
+ * using Prothon software in source or binary form and its associated
+ * documentation.
+ * 
+ * 2. Subject to the terms and conditions of this License Agreement, HCA
+ * hereby grants Licensee a nonexclusive, royalty-free, world-wide license
+ * to reproduce, analyze, test, perform and/or display publicly, prepare
+ * derivative works, distribute, and otherwise use Prothon alone or in any
+ * derivative version, provided, however, that HCA's License Agreement and
+ * HCA's notice of copyright, i.e., "Copyright (c) 2004 Hahn Creative
+ * Applications; All Rights Reserved" are retained in Prothon alone or
+ * in any derivative version prepared by Licensee.
+ * 
+ * 3. In the event Licensee prepares a derivative work that is based on or
+ * incorporates Prothon or any part thereof, and wants to make the
+ * derivative work available to others as provided herein, then Licensee
+ * hereby agrees to include in any such work a brief summary of the
+ * changes made to Prothon.
+ * 
+ * 4. HCA is making Prothon available to Licensee on an "AS IS" basis.
+ * HCA MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED.  BY WAY
+ * OF EXAMPLE, BUT NOT LIMITATION, HCA MAKES NO AND DISCLAIMS ANY
+ * REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS FOR ANY
+ * PARTICULAR PURPOSE OR THAT THE USE OF PROTHON WILL NOT INFRINGE ANY
+ * THIRD PARTY RIGHTS.
+ * 
+ * 5. HCA SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PROTHON
+ * FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS A
+ * RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PROTHON, OR ANY
+ * DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
+ * 
+ * 6. This License Agreement will automatically terminate upon a material
+ * breach of its terms and conditions.
+ * 
+ * 7. Nothing in this License Agreement shall be deemed to create any
+ * relationship of agency, partnership, or joint venture between HCA and
+ * Licensee.  This License Agreement does not grant permission to use HCA
+ * trademarks or trade name in a trademark sense to endorse or promote
+ * products or services of Licensee, or any third party.
+ * 
+ * 8. By copying, installing or otherwise using Prothon, Licensee agrees
+ * to be bound by the terms and conditions of this License Agreement.
+ * ====================================================================
+ */
+
+// builtins-time.c
+
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+
+#include <apr_time.h>
+#include <apr_strings.h>
+
+#include <prothon/prothon.h>
+#include "object.h"
+#include <prothon/prothon_dll.h>
+
+MODULE_DECLARE(Time);
+
+//********************************* new_time_obj *****************************
+obj_p new_time_obj(isp ist, i64_t usecs){
+	obj_p obj = NEW_OBJ(Time_OBJ);
+	SET_TYPE_IF_EXC(Time_OBJ, obj, DATA_TYPE_IMMDATA) return NULL;
+	obj->imm_data_len = 8;
+	obj->data.i64 = usecs;
+	obj->immutable = TRUE;
+	return obj;
+}
+
+MODULE_START(Time)
+{
+	Time_OBJ = NEW_OBJ(NULL);
+
+	set_obj_doc(Time_OBJ, "Time object prototype");
+	set_obj_id(Time_OBJ, *, Time);
+
+	set_attr(ist, OBJ(OBJECT), sym(ist, "Time"), Time_OBJ);
+
+	SET_TYPE_IF_EXC(Time_OBJ, Time_OBJ, DATA_TYPE_IMMDATA) return;
+	Time_OBJ->imm_data_len = 8;
+	Time_OBJ->data.i64     = apr_time_now();
+}
+
+DEF(Time, init_, FPARM1(usecs, NEW_INT(-1))) { 
+	apr_time_t usecs;
+	BIN_EMPTY_CHK();
+	INT_64_PARAM(1, usecs);
+	SET_TYPE_IF_EXC(Time_OBJ, self, DATA_TYPE_IMMDATA) return NULL;
+	self->imm_data_len = 8;
+	if (usecs < 0)
+		self->data.i64 = apr_time_now();
+	else
+		self->data.i64 = usecs;
+	return OBJ(NONE);
+}
+
+DEF(Time, hash_, NULL) { 
+	BIN_CONTENT_CHK(Time);
+	return new_hash_obj(ist, self->data.i32[0]+self->data.i32[1]);
+}
+
+DEF(Time, cmp_, FORM_RPARAM){
+	BIN_CONTENT_CHK(Time);
+	CHECK_TYPE_EXC(parms[1], Time_OBJ, Time);
+	if (self->data.i64 == parms[1]->data.i64)
+		return NEW_INT(0);
+	else if (self->data.i64 > parms[1]->data.i64)
+		return NEW_INT(1);
+	else
+		return NEW_INT(-1);
+}
+
+DEF(Time, eq__QUES, FORM_RPARAM){
+	BIN_CONTENT_CHK(Time);
+	CHECK_TYPE_EXC(parms[1], Time_OBJ, Time);
+	if (self->data.i64 == parms[1]->data.i64) return OBJ(PR_TRUE);
+	else                                      return OBJ(PR_FALSE);
+}
+
+DEF(Time, str_, FPARM1(spec, NEW_STRING(""))) {
+	char buf[APR_RFC822_DATE_LEN], *spec;
+	BIN_STR_CHK(Time);
+	STRING_PARAM(1, spec);
+	if (strlen(spec) > 0) {
+		raise_exception(ist, OBJ(OVERFLOW_EXC), "time str_ spec not supported yet");
+		return NULL;
+	}
+	apr_rfc822_date(buf, self->data.i64);
+	return NEW_STRING(buf);
+}
+
+MAIN_MODULE_INIT(Time)
+{
+	MODULE_SUB_INIT(Time);
+	MODULE_ADD_SYM(Time, init_);
+	MODULE_ADD_SYM(Time, str_);
+	MODULE_ADD_SYM(Time, hash_);
+	MODULE_ADD_SYM(Time, eq__QUES);
+	MODULE_ADD_SYM(Time, cmp_);
+
+	check_exceptions(ist);
+}


Property changes on: trunk/src/builtins-time.c
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: trunk/src/object.c
===================================================================
--- trunk/src/object.c	2004-06-15 22:39:40 UTC (rev 626)
+++ trunk/src/object.c	2004-06-16 02:31:01 UTC (rev 627)
@@ -256,6 +256,7 @@
 	BUILTIN_LOAD(String);
 	BUILTIN_LOAD(Thread);
 	BUILTIN_LOAD(Tuple);
+	BUILTIN_LOAD(Time);
 }
 
 //********************************* debug_object ******************************

Modified: trunk/src/src.vcproj
===================================================================
--- trunk/src/src.vcproj	2004-06-15 22:39:40 UTC (rev 626)
+++ trunk/src/src.vcproj	2004-06-16 02:31:01 UTC (rev 627)
@@ -167,6 +167,9 @@
 				RelativePath=".\builtins-thread.c">
 			</File>
 			<File
+				RelativePath=".\builtins-time.c">
+			</File>
+			<File
 				RelativePath=".\builtins-tuple.c">
 			</File>
 			<File