[Commit] nickle Makefile.am,1.32,1.33 builtin.5c,1.2,1.3
compile.c,1.138,1.139 printf.5c,1.4,1.5 scanf.5c,1.15,1.16
struct.c,1.19,1.20 value.h,1.85,1.86
Keith Packard
commit at keithp.com
Tue Jun 10 23:01:58 PDT 2003
- Previous message: [Commit]
RRbot game1.gm,NONE,1.1 game2.gm,NONE,1.1 game3.gm,NONE,1.1
game4.gm,NONE,1.1 game5.gm,NONE,1.1 game6.gm,NONE,1.1
solutions.txt,NONE,1.1
- Next message: [Commit] nickle/builtin builtin.c,1.10,1.11 namespaces.h,1.2,1.3
sockets.c,1.10,1.11
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Committed by: keithp
Update of /local/src/CVS/nickle
In directory home.keithp.com:/tmp/cvs-serv10033
Modified Files:
Makefile.am builtin.5c compile.c printf.5c scanf.5c struct.c
value.h
Log Message:
Allow declarations to be lvalues.
Typecheck printf arguments against format string.
Do correct base conversions in scanf for b, o, x formats.
Include only appropriate characters for each numeric scanf format.
Rename Sockets namespace to Socket
Add Socket::gethostname and Socket::getsockname.
Index: Makefile.am
===================================================================
RCS file: /local/src/CVS/nickle/Makefile.am,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- Makefile.am 7 Jun 2003 18:21:18 -0000 1.32
+++ Makefile.am 11 Jun 2003 05:01:55 -0000 1.33
@@ -7,7 +7,7 @@
SUBDIRS = builtin bench test
NICKLEFILES = builtin.5c math.5c scanf.5c mutex.5c arc4.5c prng.5c command.5c abort.5c \
- printf.5c history.5c ctype.5c string.5c
+ printf.5c history.5c ctype.5c string.5c socket.5c
EXAMPLES = examples/circle.5c examples/comb.5c examples/kaiser.5c \
examples/miller-rabin.5c examples/numbers.5c examples/prime.5c \
examples/qbrating.5c examples/roman.5c examples/rsa-demo.5c \
Index: builtin.5c
===================================================================
RCS file: /local/src/CVS/nickle/builtin.5c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- builtin.5c 1 Nov 2002 20:47:51 -0000 1.2
+++ builtin.5c 11 Jun 2003 05:01:55 -0000 1.3
@@ -88,6 +88,7 @@
library "math.5c";
import Math;
library "scanf.5c";
+library "socket.5c"
# Now autoload/autoimport the bonus stuff
autoimport Abort;
autoload Mutex;
Index: compile.c
===================================================================
RCS file: /local/src/CVS/nickle/compile.c,v
retrieving revision 1.138
retrieving revision 1.139
diff -u -d -r1.138 -r1.139
--- compile.c 5 Jun 2003 23:51:23 -0000 1.138
+++ compile.c 11 Jun 2003 05:01:55 -0000 1.139
@@ -395,9 +395,19 @@
TypePtr t;
switch (expr->base.tag) {
+ case VAR:
+ obj = CompileDecl (obj, expr, False, stat, code);
+ {
+ DeclListPtr decl;
+ s = 0;
+ for (decl = expr->decl.decl; decl; decl = decl->next)
+ s = decl->symbol;
+ }
+ goto isName;
case NAME:
s = CompileCheckSymbol (obj, stat, expr, code,
&depth, createIfNecessary);
+isName:
if (!s)
{
expr->base.type = typePoly;
Index: printf.5c
===================================================================
RCS file: /local/src/CVS/nickle/printf.5c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- printf.5c 2 Nov 2002 21:34:50 -0000 1.4
+++ printf.5c 11 Jun 2003 05:01:55 -0000 1.5
@@ -147,16 +147,45 @@
}
/*
- * format
+ * typecheck and select base
*/
- int base = 10;
- switch (fmt::c()) {
- case 'b': case 'B': base = 2; break;
- case 'x': case 'X': base = 16; break;
- case 'o': case 'O': base = 8; break;
- }
- print (f, arg::next(), String::new(fmt::c()), base,
- width, prec, fill);
+
+ const struct {
+ string formats;
+ bool(poly) test;
+ string message;
+ int base;
+ }[*] fmts = {
+ { formats = "s", test = is_string,
+ message = "string", base = 10 },
+ { formats = "dD", test = is_int,
+ message = "int", base = 10 },
+ { formats = "bB", test = is_int,
+ message = "int", base = 2 },
+ { formats = "oO", test = is_int,
+ message = "int", base = 8 },
+ { formats = "xX", test = is_int,
+ message = "int", base = 16 },
+ { formats = "efEF", test = is_number,
+ message = "real", base = 10 }
+ };
+
+ poly this_arg = arg::next();
+ string this_fmt = String::new (fmt::c());
+ int this_base = 10;
+
+ for (int i = 0; i < dim (fmts); i++)
+ if (String::index (fmts[i].formats, this_fmt) >= 0)
+ {
+ if (!fmts[i].test (this_arg))
+ raise invalid_argument (fmts[i].message +
+ "format with non-" +
+ fmts[i].message,
+ 1, this_arg);
+ this_base = fmts[i].base;
+ break;
+ }
+ print (f, this_arg, this_fmt, this_base, width, prec, fill);
} else
putc (fmt::c(), f);
fmt::step ();
Index: scanf.5c
===================================================================
RCS file: /local/src/CVS/nickle/scanf.5c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- scanf.5c 2 Nov 2002 21:34:50 -0000 1.15
+++ scanf.5c 11 Jun 2003 05:01:55 -0000 1.16
@@ -28,7 +28,34 @@
File::ungetc (c, f);
}
- bool isnumber (int c)
+ bool isbinary (int c)
+ {
+ if ('0' <= c && c <= '1')
+ return true;
+ if (c == '-')
+ return true;
+ return false;
+ }
+
+ bool isoctal (int c)
+ {
+ if ('0' <= c && c <= '7')
+ return true;
+ if (c == '-')
+ return true;
+ return false;
+ }
+
+ bool isdecimal (int c)
+ {
+ if ('0' <= c && c <= '9')
+ return true;
+ if (c == '-')
+ return true;
+ return false;
+ }
+
+ bool ishex (int c)
{
if ('0' <= c && c <= '9')
return true;
@@ -38,20 +65,45 @@
return true;
if (c == '-')
return true;
+ return false;
+ }
+
+ bool isfloat (int c)
+ {
+ if ('0' <= c && c <= '9')
+ return true;
+ if (c == 'e')
+ return true;
+ if (c == '-')
+ return true;
if (c == '.')
return true;
return false;
}
+ /* return next integer in input */
+ int integer (bool(int c) test, int base)
+ {
+ int c;
+ string s;
+
+ whitespace();
+ s = "";
+ while (test (c = File::getc (f)))
+ s = s + String::new(c);
+ File::ungetc (c, f);
+ return string_to_integer (s, base);
+ }
+
/* return next number in input */
- real number ()
+ real number (bool(int c) test)
{
int c;
string s;
whitespace();
s = "";
- while (isnumber (c = File::getc (f)))
+ while (test (c = File::getc (f)))
s = s + String::new(c);
File::ungetc (c, f);
return string_to_real (s);
@@ -84,10 +136,22 @@
case '%':
i++;
switch (format[i]) {
- case 'd':
- case 'e':
- case 'f':
- *args[argc++] = number();
+ case 'b': case 'B':
+ *args[argc++] = integer (isbinary, 2);
+ break;
+ case 'o': case 'O':
+ *args[argc++] = integer (isoctal, 8);
+ break;
+ case 'd': case 'D':
+ *args[argc++] = integer (isdecimal, 10);
+ break;
+ case 'x': case 'X':
+ *args[argc++] = integer (ishex, 16);
+ break;
+ case 'e': case 'E':
+ case 'f': case 'F':
+ case 'g': case 'G':
+ *args[argc++] = number(isfloat);
break;
case 'c':
*args[argc++] = File::getc(f);
Index: struct.c
===================================================================
RCS file: /local/src/CVS/nickle/struct.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- struct.c 16 Mar 2003 22:49:26 -0000 1.19
+++ struct.c 11 Jun 2003 05:01:55 -0000 1.20
@@ -196,3 +196,26 @@
EXIT ();
return 1;
}
+
+Type *
+BuildStructType (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 (NewTypeStruct (st));
+}
Index: value.h
===================================================================
RCS file: /local/src/CVS/nickle/value.h,v
retrieving revision 1.85
retrieving revision 1.86
diff -u -d -r1.85 -r1.86
--- value.h 3 Jun 2003 06:03:56 -0000 1.85
+++ value.h 11 Jun 2003 05:01:55 -0000 1.86
@@ -857,6 +857,7 @@
#endif
Value NewStruct (StructType *type, Bool constant);
StructType *NewStructType (int nelements);
+Type *BuildStructType (int nelements, ...);
Type *StructMemType (StructType *st, Atom name);
Value StructMemRef (Value sv, Atom name);
Value StructMemValue (Value sv, Atom name);
- Previous message: [Commit]
RRbot game1.gm,NONE,1.1 game2.gm,NONE,1.1 game3.gm,NONE,1.1
game4.gm,NONE,1.1 game5.gm,NONE,1.1 game6.gm,NONE,1.1
solutions.txt,NONE,1.1
- Next message: [Commit] nickle/builtin builtin.c,1.10,1.11 namespaces.h,1.2,1.3
sockets.c,1.10,1.11
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Commit
mailing list