[Commit] nickle ChangeLog, 1.141, 1.142 builtin.5c, 1.10, 1.11 compile.c, 1.164, 1.165 execute.c, 1.95, 1.96 gram.y, 1.146, 1.147 lex.l, 1.83, 1.84 opcode.h, 1.28, 1.29 pretty.c, 1.71, 1.72 process.5c, 1.1, 1.2 type.c, 1.65, 1.66

Bart Massey commit at keithp.com
Sat Dec 10 14:11:49 PST 2005


Committed by: bart

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

Modified Files:
	ChangeLog builtin.5c compile.c execute.c gram.y lex.l opcode.h 
	pretty.c process.5c type.c 
Log Message:
2005-12-10  Bart Massey <bart at cs.pdx.edu>
version 2.51

	* debian/changelog:
	Update for version 2.51
	
        * builtin.5c:
	Don't load every random library; make the user autoload or
	autoimport them if they want them instead.
	
	* process.5c:
	Replaced putc and getc in copy function.

	* compile.c:
	* lex.l:
	* gram.y:
	* pretty.c:
	* type.c:
	Added &&= and ||= operators.

	* execute.c:
	* opcode.h:
	Added Drop opcode needed for short-circuit code for &&= and ||=.



Index: ChangeLog
===================================================================
RCS file: /local/src/CVS/nickle/ChangeLog,v
retrieving revision 1.141
retrieving revision 1.142
diff -u -d -r1.141 -r1.142
--- ChangeLog	7 Dec 2005 04:32:27 -0000	1.141
+++ ChangeLog	10 Dec 2005 22:11:45 -0000	1.142
@@ -1,3 +1,27 @@
+2005-12-10  Bart Massey <bart at cs.pdx.edu>
+version 2.51
+
+	* debian/changelog:
+	Update for version 2.51
+	
+        * builtin.5c:
+	Don't load every random library; make the user autoload or
+	autoimport them if they want them instead.
+	
+	* process.5c:
+	Replaced putc and getc in copy function.
+
+	* compile.c:
+	* lex.l:
+	* gram.y:
+	* pretty.c:
+	* type.c:
+	Added &&= and ||= operators.
+
+	* execute.c:
+	* opcode.h:
+	Added Drop opcode needed for short-circuit code for &&= and ||=.
+	
 2005-12-06  Keith Packard  <keithp at keithp.com>
 version 2.50
 

Index: builtin.5c
===================================================================
RCS file: /local/src/CVS/nickle/builtin.5c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- builtin.5c	1 Aug 2005 09:20:29 -0000	1.10
+++ builtin.5c	10 Dec 2005 22:11:45 -0000	1.11
@@ -122,9 +122,11 @@
 library "socket.5c";
 
 # Now autoload/autoimport the bonus stuff
-autoload Mutex;
-autoload ARC4;
-autoload PRNG;
+# (But why?  Let the users do it.)
+#autoload Mutex;
+#autoload ARC4;
+#autoload PRNG;
+#autoload Process;
 
 # parse the command line
 extend namespace Command {

Index: compile.c
===================================================================
RCS file: /local/src/CVS/nickle/compile.c,v
retrieving revision 1.164
retrieving revision 1.165
diff -u -d -r1.164 -r1.165
--- compile.c	1 Aug 2005 09:20:29 -0000	1.164
+++ compile.c	10 Dec 2005 22:11:45 -0000	1.165
@@ -2799,6 +2799,96 @@
     case ASSIGNLXOR:	obj = CompileAssignFunc (obj, expr, Lxor, stat, code, "^"); break;
     case ASSIGNLAND:	obj = CompileAssignOp (obj, expr, LandOp, stat, code); break;
     case ASSIGNLOR:	obj = CompileAssignOp (obj, expr, LorOp, stat, code); break;
+    case ASSIGNAND:
+	/*
+	 * a &&= b
+	 *
+	 * a ASSIGNAND b
+	 *   +--------+
+	 */
+	top_inst = obj->used;
+	obj = CompileLvalue (obj, expr->tree.left, stat, code,
+			     False, False, False, False, False);
+	SetPush (obj);
+	NewInst (obj, OpFetch, middle_inst, stat);
+	NewInst (obj, OpBranchFalse, test_inst, stat);
+	/* no short circuit */
+	obj = _CompileBoolExpr (obj, expr->tree.right, True, stat, code);
+	if (test_inst >= 0)
+	{
+	    inst = ObjCode (obj, test_inst);
+	    inst->branch.offset = obj->used - test_inst;
+	    inst->branch.mod = BranchModNone;
+	    BuildInst (obj, OpAssign, inst, stat);
+	    NewInst(obj, OpBranch, test_inst, stat);
+	} else {
+	    NewInst (obj, OpAssign, middle_inst, stat);
+	    NewInst(obj, OpBranch, test_inst, stat);
+	}
+	/* short circuit */
+	NewInst(obj, OpDrop, middle_inst, stat);
+	inst = ObjCode(obj, test_inst);
+	inst->branch.offset = obj->used - test_inst;
+	inst->branch.mod = BranchModNone;
+	/* exit: is this Noop necessary? */
+	BuildInst (obj, OpNoop, inst, stat);
+	expr->base.type = TypeCombineBinary (expr->tree.left->base.type,
+					     AND,
+					     expr->tree.right->base.type);
+	if (!expr->base.type)
+	{
+	    CompileError (obj, stat, "Incompatible types, left '%T', right '%T', for &&= operation",
+			  expr->tree.left->base.type,
+			  expr->tree.right->base.type);
+	    expr->base.type = typePoly;
+	    break;
+	}
+	break;
+    case ASSIGNOR:
+	/*
+	 * a ||= b
+	 *
+	 * a ASSIGNOR b
+	 *   +--------+
+	 */
+	top_inst = obj->used;
+	obj = CompileLvalue (obj, expr->tree.left, stat, code,
+			     False, False, False, False, False);
+	SetPush (obj);
+	NewInst (obj, OpFetch, middle_inst, stat);
+	NewInst (obj, OpBranchTrue, test_inst, stat);
+	/* no short circuit */
+	obj = _CompileBoolExpr (obj, expr->tree.right, True, stat, code);
+	if (test_inst >= 0)
+	{
+	    inst = ObjCode (obj, test_inst);
+	    inst->branch.offset = obj->used - test_inst;
+	    inst->branch.mod = BranchModNone;
+	    BuildInst (obj, OpAssign, inst, stat);
+	    NewInst(obj, OpBranch, test_inst, stat);
+	} else {
+	    NewInst (obj, OpAssign, middle_inst, stat);
+	    NewInst(obj, OpBranch, test_inst, stat);
+	}
+	/* short circuit */
+	NewInst(obj, OpDrop, middle_inst, stat);
+	inst = ObjCode(obj, test_inst);
+	inst->branch.offset = obj->used - test_inst;
+	inst->branch.mod = BranchModNone;
+	/* exit: is this Noop necessary? */
+	BuildInst (obj, OpNoop, inst, stat);
+	expr->base.type = TypeCombineBinary (expr->tree.left->base.type,
+					     OR,
+					     expr->tree.right->base.type);
+	if (!expr->base.type)
+	{
+	    CompileError (obj, stat, "Incompatible types, left '%T', right '%T', for ||= operation",
+			  expr->tree.left->base.type,
+			  expr->tree.right->base.type);
+	    expr->base.type = typePoly;
+	    break;
+	}
+	break;
     case EQ:	    obj = CompileBinOp (obj, expr, EqualOp, stat, code); break;
     case NE:	    obj = CompileBinFunc (obj, expr, NotEqual, stat, code,"!="); break;
     case LT:	    obj = CompileBinOp (obj, expr, LessOp, stat, code); break;
@@ -4258,6 +4348,7 @@
     "AssignOp",
     "AssignFunc",
     "End",
+    "Drop",
 };
 
 static char *

Index: execute.c
===================================================================
RCS file: /local/src/CVS/nickle/execute.c,v
retrieving revision 1.95
retrieving revision 1.96
diff -u -d -r1.95 -r1.96
--- execute.c	14 Jan 2005 05:44:00 -0000	1.95
+++ execute.c	10 Dec 2005 22:11:45 -0000	1.96
@@ -1422,6 +1422,9 @@
 		case OpEnd:
 		    SetSignalFinished ();
 		    break;
+		case OpDrop:
+		    stack = 1;
+		    break;
 		default:
 		    break;
 		}

Index: gram.y
===================================================================
RCS file: /local/src/CVS/nickle/gram.y,v
retrieving revision 1.146
retrieving revision 1.147
diff -u -d -r1.146 -r1.147
--- gram.y	2 Oct 2005 18:30:19 -0000	1.146
+++ gram.y	10 Dec 2005 22:11:45 -0000	1.147
@@ -163,6 +163,7 @@
 		ASSIGNDIV ASSIGNMOD ASSIGNPOW
 		ASSIGNSHIFTL ASSIGNSHIFTR
 		ASSIGNLXOR ASSIGNLAND ASSIGNLOR
+                ASSIGNOR ASSIGNAND
 %right		FORK
 %right		QUEST COLON
 %left		OR
@@ -1478,6 +1479,8 @@
 		| ASSIGNLXOR
 		| ASSIGNLAND
 		| ASSIGNLOR
+		| ASSIGNOR
+		| ASSIGNAND
 		| ASSIGN
 		;
 integer		: TEN_NUM

Index: lex.l
===================================================================
RCS file: /local/src/CVS/nickle/lex.l,v
retrieving revision 1.83
retrieving revision 1.84
diff -u -d -r1.83 -r1.84
--- lex.l	3 Aug 2005 06:34:05 -0000	1.83
+++ lex.l	10 Dec 2005 22:11:45 -0000	1.84
@@ -393,6 +393,8 @@
 ">>="		{ yylval.ints = ASSIGNSHIFTR; return ASSIGNSHIFTR; }
 "⪢="		{ yylval.ints = ASSIGNSHIFTR; return ASSIGNSHIFTR; }
 "^="		{ yylval.ints = ASSIGNLXOR; return ASSIGNLXOR; }
+"&&="           { yylval.ints = ASSIGNAND; return ASSIGNAND; }
+"||="           { yylval.ints = ASSIGNOR; return ASSIGNOR; }
 "&="		{ yylval.ints = ASSIGNLAND; return ASSIGNLAND; }
 "|="		{ yylval.ints = ASSIGNLOR; return ASSIGNLOR; }
 "="		{ yylval.ints = ASSIGN; return ASSIGN; }

Index: opcode.h
===================================================================
RCS file: /local/src/CVS/nickle/opcode.h,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- opcode.h	11 Apr 2004 02:30:22 -0000	1.28
+++ opcode.h	10 Dec 2005 22:11:45 -0000	1.29
@@ -84,6 +84,7 @@
     OpAssignOp,
     OpAssignFunc,
     OpEnd,
+    OpDrop
 } __attribute__ ((packed)) OpCode;
 
 #endif /* _CODE_H_ */

Index: pretty.c
===================================================================
RCS file: /local/src/CVS/nickle/pretty.c,v
retrieving revision 1.71
retrieving revision 1.72
diff -u -d -r1.71 -r1.72
--- pretty.c	17 Dec 2004 02:05:20 -0000	1.71
+++ pretty.c	10 Dec 2005 22:11:45 -0000	1.72
@@ -104,6 +104,8 @@
     case ASSIGNLXOR:
     case ASSIGNLAND:
     case ASSIGNLOR:
+    case ASSIGNAND:
+    case ASSIGNOR:
 	return 1;
     case QUEST: case COLON:
 	return 2;
@@ -467,6 +469,8 @@
     case ASSIGNLXOR:
     case ASSIGNLAND:
     case ASSIGNLOR:
+    case ASSIGNAND:
+    case ASSIGNOR:
     case COMMA:
 	PrettyExpr (f, e->tree.left, selfPrec, level, nest, pd);
 	switch (e->base.tag) {
@@ -503,6 +507,8 @@
 	case ASSIGNLXOR:FilePuts (f, " ^= "); break;
 	case ASSIGNLAND:FilePuts (f, " &= "); break;
 	case ASSIGNLOR:	FilePuts (f, " |= "); break;
+	case ASSIGNAND:FilePuts (f, " &&= "); break;
+	case ASSIGNOR:	FilePuts (f, " ||= "); break;
 	case COMMA:	FilePuts (f, ", "); break;
 	}
 	PrettyExpr (f, e->tree.right, selfPrec, level, nest, pd);

Index: process.5c
===================================================================
RCS file: /local/src/CVS/nickle/process.5c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- process.5c	20 Nov 2005 08:49:33 -0000	1.1
+++ process.5c	10 Dec 2005 22:11:45 -0000	1.2
@@ -25,7 +25,7 @@
 	   in process manipulation. */
     {
 	while (!end(readfd))
-	    putc(getc(readfd), writefd);
+	    putb(getb(readfd), writefd);
     }
 
     public typedef void(file) agent;

Index: type.c
===================================================================
RCS file: /local/src/CVS/nickle/type.c,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -d -r1.65 -r1.66
--- type.c	20 Oct 2005 18:24:22 -0000	1.65
+++ type.c	10 Dec 2005 22:11:45 -0000	1.66
@@ -811,6 +811,21 @@
     return 0;
 }
 
+/*
+ * Return the least-upper bound for a boolean computation
+ */
+static Type *
+TypeBinaryBool (Type *left, Type *right)
+{
+    if (TypePoly (left))
+	left = typePrim[rep_bool];
+    if (TypePoly (right))
+	right = typePrim[rep_bool];
+    if (TypeBool (left) && TypeBool (right))
+	return left;
+    return 0;
+}
+
 static void
 TypeEltMark (void *object)
 {
@@ -984,6 +999,11 @@
 	if ((type = TypeBinaryIntegral (left, right)))
 	    ret = TypeAdd (ret, type);
 	break;
+    case ASSIGNAND:
+    case ASSIGNOR:
+	if ((type = TypeBinaryBool (left, right)))
+	    ret = TypeAdd (ret, type);
+	break;
     case COLON:
 	if (TypePoly (left) || TypePoly (right))
 	    ret = TypeAdd (ret, typePoly);



More information about the Commit mailing list