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

SVN User <[email protected]> Fri, 04 Jun 2004 18:00:57 -0400
Newsgroups gmane.comp.lang.prothon.cvs
Message-ID <[email protected]>
Author: mark
Date: 2004-06-04 18:00:54 -0400 (Fri, 04 Jun 2004)
New Revision: 576

Modified:
   trunk/include/prothon/prothon.h
   trunk/pr/test/adict.pr
   trunk/pr/test/test.pr
   trunk/src/builtins-int.c
Log:
fixed bug in Int.init_

Modified: trunk/include/prothon/prothon.h
===================================================================
--- trunk/include/prothon/prothon.h	2004-06-04 20:36:02 UTC (rev 575)
+++ trunk/include/prothon/prothon.h	2004-06-04 22:00:54 UTC (rev 576)
@@ -606,7 +606,7 @@
 // (usually parms[1])
 #define CHECK_TYPE_EXC(__obj, __proto_obj, name)			\
 do {														\
-	if (!has_proto(ist, __obj, __proto_obj)) {			\
+	if (!(__obj) || !has_proto(ist, __obj, __proto_obj)) {	\
 		raise_exception(ist, OBJ(TYPE_EXC),					\
 				"object is not of type " #name);			\
 		return NULL;										\

Modified: trunk/pr/test/adict.pr
===================================================================
--- trunk/pr/test/adict.pr	2004-06-04 20:36:02 UTC (rev 575)
+++ trunk/pr/test/adict.pr	2004-06-04 22:00:54 UTC (rev 576)
@@ -4,7 +4,7 @@
 	print "failure number",n
 	Sys.exit(1)
 
-x = 1
+x = [1]
 if Len(x.attrs_) != 0: err(0)
 x.attrs_ = {`a:1, `b:2}
 if x.a != 1 or x.b != 2: err(1)
Modified: trunk/pr/test/test.pr
===================================================================
--- trunk/pr/test/test.pr	2004-06-04 20:36:02 UTC (rev 575)
+++ trunk/pr/test/test.pr	2004-06-04 22:00:54 UTC (rev 576)
@@ -1,6 +1,31 @@
 #!/usr/bin/env prothon
 
-print [2] == ["222"]
+# bin.pr
 
-print 2 == "222"
+x = Exception
 
+object obj(String, Int):
+    Int.init_{obj}(99)      # inits using second proto
+    print Int.str_{obj}()   # prints 99
+
+try:
+    with obj: Int.init_{obj}(99)   # init Int a second time
+except x,e: print e    # throws "object has binary data, expected none"
+
+try:
+    obj.init_('abc')    # init as String
+except x,e: print e     # throws "object has binary data, expected none"
+
+L = Proto(List) # L is uninitialized list
+
+L.init_(1,2,3)
+print L             # prints [1, 2, 3] 
+
+L.init_(4,5,6)
+print L             # prints [4, 5, 6] 
+
+d = {1:2, 'a':'b'}
+print d             # prints {1:2, 'a':'b'}
+
+d.init_(c = 'd', f = 'g')
+print d             # prints {f:'g', c:'d'} 
\ No newline at end of file

Modified: trunk/src/builtins-int.c
===================================================================
--- trunk/src/builtins-int.c	2004-06-04 20:36:02 UTC (rev 575)
+++ trunk/src/builtins-int.c	2004-06-04 22:00:54 UTC (rev 576)
@@ -2080,11 +2080,19 @@
 }
 
 DEF(Int, init_, FORM_STAR_PARAM) {
-	obj_p i;
+	obj_p i = NULL;
 	BIN_EMPTY_CHK();
 	if (list_len(ist, parms[1]))
 		INT____PARAM(0, i);
-	copy_object_data(ist, self, i);
+	CHECK_TYPE_EXC(i, OBJ(INT_PROTO), integer);
+	if (i->data_type == DATA_TYPE_IMMDATA) {
+		self->data_type = DATA_TYPE_IMMDATA;
+		self->imm_data_len = 8;
+		self->data.i64 = i->data.i64;
+	} else {
+		self->data_type = DATA_TYPE_DATAPTR;
+		self->data.ptr  = copy_longp(i->data.ptr, 0);
+	}
 	return OBJ(NONE);
 }