[Commit] nickle ChangeLog, 1.113, 1.114 array.c, 1.26, 1.27 builtin.c, 1.22, 1.23 builtin.h, 1.11, 1.12 file.c, 1.65, 1.66 float.c, 1.25, 1.26 foreign.c, 1.1, 1.2 pretty.c, 1.70, 1.71 union.c, 1.11, 1.12 value.h, 1.109, 1.110

Keith Packard commit at keithp.com
Thu Dec 16 18:05:24 PST 2004


Committed by: keithp

Update of /local/src/CVS/nickle
In directory home.keithp.com:/tmp/cvs-serv4753

Modified Files:
	ChangeLog array.c builtin.c builtin.h file.c float.c foreign.c 
	pretty.c union.c value.h 
Log Message:
2004-12-16  Keith Packard  <keithp at keithp.com>

	* builtin.c: (BuiltinSetUserdefType), (BuiltinType):
	* builtin.h:
	Add support for up to 100 user-defined types for builtin functions
	
	* file.c: (FileCheckBlocked):
	Fixed an execution ordering bug which should have caused
	an infinite loop in some weird file blocking cases.
	
	* float.c: (FloatPrint):
	Don't print fractional part if it rounds to zero. Still
	need to trim trailing zeros from fractions.
	
	* foreign.c: (ForeignFree):
	Best return 1 or the object will not actually be freed.
	
	* pretty.c: (PrettyDoc):
	Doc strings with multi-byte chars were broken.
	
	* array.c: (BuildArrayType):
	* union.c: (BuildUnionType), (BuildEnumType):
	* value.h:
	Add type construction helpers for foreign libraries


Index: ChangeLog
===================================================================
RCS file: /local/src/CVS/nickle/ChangeLog,v
retrieving revision 1.113
retrieving revision 1.114
diff -u -d -r1.113 -r1.114
--- ChangeLog	11 Dec 2004 17:42:18 -0000	1.113
+++ ChangeLog	17 Dec 2004 02:05:20 -0000	1.114
@@ -1,3 +1,28 @@
+2004-12-16  Keith Packard  <keithp at keithp.com>
+
+	* builtin.c: (BuiltinSetUserdefType), (BuiltinType):
+	* builtin.h:
+	Add support for up to 100 user-defined types for builtin functions
+	
+	* file.c: (FileCheckBlocked):
+	Fixed an execution ordering bug which should have caused
+	an infinite loop in some weird file blocking cases.
+	
+	* float.c: (FloatPrint):
+	Don't print fractional part if it rounds to zero. Still
+	need to trim trailing zeros from fractions.
+	
+	* foreign.c: (ForeignFree):
+	Best return 1 or the object will not actually be freed.
+	
+	* pretty.c: (PrettyDoc):
+	Doc strings with multi-byte chars were broken.
+	
+	* array.c: (BuildArrayType):
+	* union.c: (BuildUnionType), (BuildEnumType):
+	* value.h:
+	Add type construction helpers for foreign libraries
+	
 2004-12-11  Keith Packard  <keithp at keithp.com>
 
 	* builtin-foreign.c: (do_Foreign_load), (import_Foreign_namespace):

Index: array.c
===================================================================
RCS file: /local/src/CVS/nickle/array.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- array.c	18 Sep 2004 05:04:17 -0000	1.26
+++ array.c	17 Dec 2004 02:05:20 -0000	1.27
@@ -7,6 +7,7 @@
  */
 
 #include	"nickle.h"
+#include    	"gram.h"
 
 int
 ArrayInit (void)
@@ -421,3 +422,23 @@
     for (i = 0; i < a->ndim; i++)
 	ArrayResize (av, i, dims[i]);
 }
+
+Type *
+BuildArrayType (Type *type, int ndim, ...)
+{
+    ENTER ();
+    Expr    *dims = 0;
+    int	    i;
+    int	    dim;
+    va_list ap;
+
+    va_start (ap, ndim);
+    for (i = 0; i < ndim; i++)
+    {
+	dim = va_arg (ap, int);
+	dims = NewExprTree (COMMA, NewExprConst (TEN_FLOAT, NewInt (dim)),
+			    dims);
+    }
+    va_end (ap);
+    RETURN (NewTypeArray (type, dims, False));
+}

Index: builtin.c
===================================================================
RCS file: /local/src/CVS/nickle/builtin.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- builtin.c	11 Dec 2004 07:46:49 -0000	1.22
+++ builtin.c	17 Dec 2004 02:05:20 -0000	1.23
@@ -120,12 +120,12 @@
 					     type)));
 }
 
-static Type *typeUserdef;
+static Type *typeUserdef[100];
 
 void
-BuiltinSetUserdefType (Type *type)
+BuiltinSetUserdefType (Type *type, int n)
 {
-    typeUserdef = type;
+    typeUserdef[n] = type;
 }
 
 static char *
@@ -138,6 +138,8 @@
     Bool    resizable = False;
     Expr    *dims = 0;
     Type    *k;
+    char    f;
+    int	    i;
     
     ref = False;
     if (*format == '*')
@@ -162,7 +164,7 @@
 	hash = True;
 	format = BuiltinType (format + 1, &k);
     }
-    switch (*format++) {
+    switch (f = *format++) {
     case 'p': t = typePoly; break;
     case 'n': t = typePrim[rep_float]; break;
     case 'N': t = typePrim[rep_float]; break;
@@ -179,7 +181,12 @@
     case 'v': t = typePrim[rep_void]; break;
     case 'F': t = typePrim[rep_foreign]; break;
     case 'a': t = typeSockaddr; break;
-    case 'u': t = typeUserdef; break;
+    case '0': case '1': case '2': case '3': case '4':
+    case '5': case '6': case '7': case '8': case '9':
+	i = (f - '0') * 10 + (*format++) - '0';
+	t = typeUserdef[i];
+	if (t)
+	    break;
     default: 
 	t = 0;
 	write (2, "Invalid builtin argument type\n", 30);

Index: builtin.h
===================================================================
RCS file: /local/src/CVS/nickle/builtin.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- builtin.h	11 Dec 2004 07:46:49 -0000	1.11
+++ builtin.h	17 Dec 2004 02:05:20 -0000	1.12
@@ -32,7 +32,7 @@
 		  char		*string);
 
 void
-BuiltinSetUserdefType (Type *type);
+BuiltinSetUserdefType (Type *type, int n);
 
 SymbolPtr
 BuiltinException (NamespacePtr  *namespacep,

Index: file.c
===================================================================
RCS file: /local/src/CVS/nickle/file.c,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -d -r1.65 -r1.66
--- file.c	11 Dec 2004 06:02:23 -0000	1.65
+++ file.c	17 Dec 2004 02:05:20 -0000	1.66
@@ -1869,6 +1869,7 @@
 	    *prev = blocked->file.next;
 	    continue;
 	}
+	prev = &blocked->file.next;
 	if (fd < 3 && !ownTty[fd])
 	    continue;
 	if (blocked->file.flags & FileInputBlocked)
@@ -1877,7 +1878,6 @@
 	    FD_SET (fd, &writable);
 	if (fd >= n)
 	    n = fd + 1;
-	prev = &blocked->file.next;
     }
     if (n > 0)
     {

Index: float.c
===================================================================
RCS file: /local/src/CVS/nickle/float.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- float.c	11 Dec 2004 04:53:43 -0000	1.25
+++ float.c	17 Dec 2004 02:05:20 -0000	1.26
@@ -914,12 +914,13 @@
 	frac_width = 0;
     frac_buffer = 0;
     frac_string = 0;
+    if (frac_width)
+	frac_part = Floor (Times (frac_part, Pow (NewInt (base), 
+						  NewInt (frac_width - 1))));
     if (frac_width && (!Zerop (frac_part) || orig_prec > 0))
     {
 	int	frac_wrote;
 	
-	frac_part = Floor (Times (frac_part, Pow (NewInt (base), 
-						  NewInt (frac_width - 1))));
 	if (ValueIsInteger(frac_part))
 	    frac_n = IntegerMag(frac_part);
 	else

Index: foreign.c
===================================================================
RCS file: /local/src/CVS/nickle/foreign.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- foreign.c	11 Dec 2004 17:42:18 -0000	1.1
+++ foreign.c	17 Dec 2004 02:05:20 -0000	1.2
@@ -41,7 +41,7 @@
 
     if (foreign->free)
 	(*foreign->free) (foreign->data);
-    return 0;
+    return 1;
 }
 
 ValueRep ForeignRep = {

Index: pretty.c
===================================================================
RCS file: /local/src/CVS/nickle/pretty.c,v
retrieving revision 1.70
retrieving revision 1.71
diff -u -d -r1.70 -r1.71
--- pretty.c	8 Jun 2004 09:30:54 -0000	1.70
+++ pretty.c	17 Dec 2004 02:05:20 -0000	1.71
@@ -835,7 +835,7 @@
 	    FilePuts (f, " *");
 	    newline = False;
 	}
-	FileOutput (f, c);
+	FileOutchar (f, c);
 	if (c == '\n')
 	    newline = True;
     }

Index: union.c
===================================================================
RCS file: /local/src/CVS/nickle/union.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- union.c	27 Feb 2004 03:50:16 -0000	1.11
+++ union.c	17 Dec 2004 02:05:20 -0000	1.12
@@ -123,3 +123,47 @@
     ret->unions.value = NewBox (constant, False, 1, 0);
     RETURN (ret);
 }
+
+Type *
+BuildUnionType (int nelements, ...)
+{
+    ENTER ();
+    StructType	*st;
+    int		i;
+    char	*name;
+    Type	*type;
+    va_list	ap;
+
+    st = NewStructType (nelements);
+    va_start (ap, nelements);
+    for (i = 0; i < nelements; i++)
+    {
+	type = va_arg (ap, Type *);
+	name = va_arg (ap, char *);
+	AddBoxType (&st->types, type);
+	StructTypeAtoms (st)[i] = AtomId (name);
+    }
+    va_end (ap);
+    RETURN (NewTypeUnion (st, False));
+}
+
+Type *
+BuildEnumType (int nelements, ...)
+{
+    ENTER ();
+    StructType	*st;
+    int		i;
+    char	*name;
+    va_list	ap;
+
+    st = NewStructType (nelements);
+    va_start (ap, nelements);
+    for (i = 0; i < nelements; i++)
+    {
+	name = va_arg (ap, char *);
+	AddBoxType (&st->types, typePrim[rep_void]);
+	StructTypeAtoms (st)[i] = AtomId (name);
+    }
+    va_end (ap);
+    RETURN (NewTypeUnion (st, True));
+}

Index: value.h
===================================================================
RCS file: /local/src/CVS/nickle/value.h,v
retrieving revision 1.109
retrieving revision 1.110
diff -u -d -r1.109 -r1.110
--- value.h	11 Dec 2004 06:02:23 -0000	1.109
+++ value.h	17 Dec 2004 02:05:20 -0000	1.110
@@ -1026,8 +1026,11 @@
 Value	StructMemRef (Value sv, Atom name);
 Value	StructMemValue (Value sv, Atom name);
 Value	NewUnion (StructType *type, Bool constant);
+Type	*BuildUnionType (int nelements, ...);
+Type	*BuildEnumType (int nelements, ...);
 Value	UnionValue (Value uv, Atom name);
 Value	UnionRef (Value uv, Atom name);
+Type	*BuildArrayType (Type *type, int ndim, ...);
 
 Value	BinaryOperate (Value av, Value bv, BinaryOp operator);
 Value	UnaryOperate (Value v, UnaryOp operator);




More information about the Commit mailing list