[Nickle] nickle: Branch 'master' - 3 commits

Keith Packard keithp at keithp.com
Tue Jun 12 22:15:00 PDT 2012


 compile.c |   34 ++++++++++++++++++++++++++--------
 execute.c |    2 +-
 2 files changed, 27 insertions(+), 9 deletions(-)

New commits:
commit 7654ceb8b892ce483b8480755485888ef2402420
Author: Keith Packard <keithp at keithp.com>
Date:   Tue Jun 12 21:55:04 2012 -0700

    Handle OpFarJump in CompileReachable
    
    A FarJump within a catch block references instructions one or more
    frames outside of the instruction context. When checking for reachable
    code, look down inside the catch blocks to see if any of the FarJumps
    within them touch the target instruction.
    
    Fixes this example:
    
    void foo() {
    	for (;;)
    		try {
    		} catch uninitialized_value(string x) {
    			break;
    		}
    }
    
    Without this fix, the 'break' will not get noticed and no ReturnVoid
    will be appended to the object code for 'foo', leaving the break
    dangling in space.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/compile.c b/compile.c
index 418bbe1..2c0640d 100644
--- a/compile.c
+++ b/compile.c
@@ -246,7 +246,7 @@ ObjPtr	CompileFuncCode (CodePtr	code,
 			 CodePtr	previous,
 			 NonLocalPtr	nonLocal);
 void	CompileError (ObjPtr obj, ExprPtr stat, char *s, ...);
-static Bool CompileIsReachable (ObjPtr obj, int i);
+static Bool CompileIsReachable (ObjPtr obj, int i, int frame);
 static ObjPtr
 CompileArrayDimValue (ObjPtr obj, TypePtr type, Bool lvalue, ExprPtr stat, CodePtr code);
 static ObjPtr
@@ -3309,7 +3309,7 @@ _CompileStat (ObjPtr obj, ExprPtr expr, Bool last, CodePtr code)
 	    /*
 	     * Branch around else if reachable
 	     */
-	    if (CompileIsReachable (obj, obj->used))
+	    if (CompileIsReachable (obj, obj->used, 0))
 	    {
 		NewInst (obj, OpBranch, middle_inst, expr);
 	    }
@@ -3694,7 +3694,7 @@ _CompileStat (ObjPtr obj, ExprPtr expr, Bool last, CodePtr code)
 		     * Make sure there's no fall-through
 		     */
 		    if (icase > 0 && pair->tree.right &&
-			CompileIsReachable (obj, obj->used))
+			CompileIsReachable (obj, obj->used, 0))
 		    {
 			CompileError (obj, expr, 
 				      "Fall-through case with variant value");
@@ -3863,7 +3863,6 @@ CompileIsBranch (InstPtr inst)
     case OpBranch:
     case OpBranchFalse:
     case OpBranchTrue:
-    case OpFarJump:
     case OpCase:
     case OpTagCase:
     case OpDefault:
@@ -3875,7 +3874,7 @@ CompileIsBranch (InstPtr inst)
 }
 
 static Bool
-CompileIsReachable (ObjPtr obj, int target)
+CompileIsReachable (ObjPtr obj, int target, int frame)
 {
     InstPtr inst;
     int	    i;
@@ -3883,9 +3882,19 @@ CompileIsReachable (ObjPtr obj, int target)
     for (i = 0; i < obj->used; i++)
     {
 	inst = ObjCode (obj, i);
-	if (CompileIsBranch (inst) && i + inst->branch.offset == target)
+	if (frame == 0 && CompileIsBranch (inst) && i + inst->branch.offset == target)
+	    return True;
+	if (inst->base.opCode == OpObj &&
+	    !inst->code.code->base.builtin &&
+	    inst->code.code->func.body.obj->nonLocal) {
+	    if (CompileIsReachable(inst->code.code->func.body.obj, target, frame + 1))
+		return True;
+	}
+	if (inst->base.opCode == OpFarJump &&
+	    inst->farJump.farJump->frame == frame &&
+	    inst->farJump.farJump->inst == target)
 	    return True;
-	if (i == target - 1 && !CompileIsUnconditional (inst))
+	if (frame == 0 && i == target - 1 && !CompileIsUnconditional (inst))
 	    return True;
     }
     return False;
@@ -3907,7 +3916,7 @@ CompileFuncCode (CodePtr	code,
     obj->nonLocal = nonLocal;
     obj = _CompileStat (obj, code->func.code, True, code);
     needReturn = False;
-    if (!obj->used || CompileIsReachable (obj, obj->used))
+    if (!obj->used || CompileIsReachable (obj, obj->used, 0))
 	needReturn = True;
     if (needReturn)
     {
@@ -4694,6 +4703,13 @@ ObjDump (ObjPtr obj, int indent)
 		if (!branch[j])
 		    branch[j] = ++b;
 	}
+	if (inst->base.opCode == OpFarJump)
+	{
+	    j = inst->farJump.farJump->inst;
+	    if (0 <= j && j < obj->used)
+		if (!branch[j])
+		    branch[j] = ++b;
+	}
 	if (inst->base.opCode == OpTwixt)
 	{
 	    j = i + inst->twixt.enter;
commit 86456a8a2a7ae92da7c082a93d4ccf40c740f879
Author: Keith Packard <keithp at keithp.com>
Date:   Tue Jun 12 21:54:31 2012 -0700

    New instructions IsType and HasMember need entries in OpNames
    
    Otherwise, the array no longer matches the enum
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/compile.c b/compile.c
index e718d0e..418bbe1 100644
--- a/compile.c
+++ b/compile.c
@@ -4424,6 +4424,8 @@ const char *const OpNames[] = {
     "Assign",
     "AssignOp",
     "AssignFunc",
+    "IsType",
+    "HasMember",
     "End",
     "Drop",
 };
commit 9364ad117ab8cb6828fc308e99fd854a6029e277
Author: Keith Packard <keithp at keithp.com>
Date:   Tue Jun 12 21:53:46 2012 -0700

    Fix VALIDATE_EXECUTION test code
    
    Needed ObjType defined.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/execute.c b/execute.c
index 00b2a2e..4329798 100644
--- a/execute.c
+++ b/execute.c
@@ -920,7 +920,7 @@ int dump_inst = 0;
 
 #ifdef VALIDATE_EXECUTION
 
-extern DataType FrameType, BoxType, stackType, stackChunkType;
+extern DataType FrameType, BoxType, stackType, stackChunkType, ObjType;
 
 static void
 ObjValid(ObjPtr obj, InstPtr pc)


More information about the Nickle mailing list