[Commit] nickle ChangeLog,1.126,1.127 compile.c,1.161,1.162

Keith Packard commit at keithp.com
Thu Jun 16 13:48:36 PDT 2005


Committed by: keithp

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

Modified Files:
	ChangeLog compile.c 
Log Message:
2005-06-16  Keith Packard  <keithp at keithp.com>

	* compile.c: (CompileLvalue), (CompileCall), (_CompileExpr),
	(_CompileStat), (ObjUnFuncName):
	&poly foo() { ... };
	&poly x = &foo();
	Compiler generated 'Dereference, do_reference' in this
	call which caused the object referenced by foo() to be
	copied.  Notice case of call to reference value function
	followed by & operator and elide the Dereference/do_reference
	pair.


Index: ChangeLog
===================================================================
RCS file: /local/src/CVS/nickle/ChangeLog,v
retrieving revision 1.126
retrieving revision 1.127
diff -u -d -r1.126 -r1.127
--- ChangeLog	5 Jun 2005 01:03:42 -0000	1.126
+++ ChangeLog	16 Jun 2005 20:48:33 -0000	1.127
@@ -1,3 +1,15 @@
+2005-06-16  Keith Packard  <keithp at keithp.com>
+
+	* compile.c: (CompileLvalue), (CompileCall), (_CompileExpr),
+	(_CompileStat), (ObjUnFuncName):
+	&poly foo() { ... };
+	&poly x = &foo();
+	Compiler generated 'Dereference, do_reference' in this
+	call which caused the object referenced by foo() to be
+	copied.  Notice case of call to reference value function
+	followed by & operator and elide the Dereference/do_reference
+	pair.
+
 2005-06-04  Keith Packard  <keithp at keithp.com>
 
 	reviewed by: <delete if not using a buddy>

Index: compile.c
===================================================================
RCS file: /local/src/CVS/nickle/compile.c,v
retrieving revision 1.161
retrieving revision 1.162
diff -u -d -r1.161 -r1.162
--- compile.c	14 Jan 2005 16:58:53 -0000	1.161
+++ compile.c	16 Jun 2005 20:48:33 -0000	1.162
@@ -227,7 +227,7 @@
 ObjPtr	CompileAssignOp (ObjPtr obj, ExprPtr expr, BinaryOp op, ExprPtr stat, CodePtr code);
 ObjPtr	CompileAssignFunc (ObjPtr obj, ExprPtr expr, BinaryFunc func, ExprPtr stat, CodePtr code, char *name);
 ObjPtr	CompileArrayIndex (ObjPtr obj, ExprPtr expr, TypePtr indexType, ExprPtr stat, CodePtr code, int *ndimp);
-ObjPtr	CompileCall (ObjPtr obj, ExprPtr expr, Tail tail, ExprPtr stat, CodePtr code);
+ObjPtr	CompileCall (ObjPtr obj, ExprPtr expr, Tail tail, ExprPtr stat, CodePtr code, Bool auto_reference);
 ObjPtr	_CompileExpr (ObjPtr obj, ExprPtr expr, Bool evaluate, ExprPtr stat, CodePtr code);
 ObjPtr	_CompileBoolExpr (ObjPtr obj, ExprPtr expr, Bool evaluate, ExprPtr stat, CodePtr code);
 void	CompilePatchLoop (ObjPtr obj, int start,
@@ -610,6 +610,12 @@
 	    break;
 	}
 	break;
+    case OP:
+	if (auto_reference)
+	{
+	    obj = CompileCall (obj, expr, TailNever, stat, code, True);
+	    break;
+	}
     default:
 	if (auto_reference)
 	{
@@ -1101,7 +1107,7 @@
  */
 
 ObjPtr
-CompileCall (ObjPtr obj, ExprPtr expr, Tail tail, ExprPtr stat, CodePtr code)
+CompileCall (ObjPtr obj, ExprPtr expr, Tail tail, ExprPtr stat, CodePtr code, Bool auto_reference)
 {
     ENTER ();
     InstPtr inst;
@@ -1119,7 +1125,7 @@
     }
     expr->base.type = TypeCombineReturn (expr->tree.left->base.type);
     t = CompileRefType (obj, expr, expr->base.type);
-    if (t)
+    if ((t && !auto_reference) || (!t && auto_reference))
 	tail = TailNever;
     if ((tail == TailAlways &&
 	 !TypePoly (expr->base.type) &&
@@ -1134,12 +1140,18 @@
     {
 	BuildInst (obj, OpCall, inst, stat);
 	inst->ints.value = varactual ? -argc : argc;
-	if (t)
+	if (t && !auto_reference)
 	{
 	    BuildInst (obj, OpUnFunc, inst, stat);
 	    inst->unfunc.func = Dereference;
 	    expr->base.type = t;
 	}
+	else if (!t && auto_reference)
+	{
+	    BuildInst (obj, OpUnFunc, inst, stat);
+	    inst->unfunc.func = do_reference;
+	    expr->base.type = NewTypeRef (expr->base.type, True);
+	}
 	else
 	    BuildInst (obj, OpNoop, inst, stat);
     }
@@ -2413,7 +2425,7 @@
 	inst->ints.value = ndim;
 	break;
     case OP:	    /* function call */
-	obj = CompileCall (obj, expr, TailNever, stat, code);
+	obj = CompileCall (obj, expr, TailNever, stat, code, False);
 	break;
     case COLONCOLON:
 	obj = _CompileExpr (obj, expr->tree.right, evaluate, stat, code);
@@ -2814,7 +2826,7 @@
 							  expr->tree.left,
 							  (Expr *) 0)),
 			   TailNever,
-			   stat, code);
+			   stat, code, False);
 	expr->base.type = typePrim[rep_thread];
 	break;
     case DOLLAR:
@@ -3617,7 +3629,7 @@
 	    if (expr->tree.right->base.tag == OP && 
 		_CompileCanTailCall (obj, code))
 	    {
-		obj = CompileCall (obj, expr->tree.right, TailAlways, expr, code);
+		obj = CompileCall (obj, expr->tree.right, TailAlways, expr, code, False);
 	    }
 	    else
 	    {
@@ -3641,7 +3653,7 @@
 	break;
     case EXPR:
 	if (last && expr->tree.left->base.tag == OP && !profiling)
-	    obj = CompileCall (obj, expr->tree.left, TailVoid, expr, code);
+	    obj = CompileCall (obj, expr->tree.left, TailVoid, expr, code, False);
 	else
 	    obj = _CompileExpr (obj, expr->tree.left, False, expr, code);
 	break;
@@ -4277,6 +4289,7 @@
 	{ Lnot,		"Lnot" },
 	{ Not,		"Not" },
 	{ Factorial,	"Factorial" },
+	{ do_reference,	"do_reference" },
 	{ 0, 0 }
     };
     int	i;




More information about the Commit mailing list