Skip to content

Commit

Permalink
Trace loops and lets and protocols returning expression
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmonettas committed Nov 15, 2023
1 parent 047d26f commit 1848732
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
22 changes: 18 additions & 4 deletions src/jvm/clojure/lang/Compiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -3854,6 +3854,7 @@ public void emitProto(C context, ObjExpr objx, GeneratorAdapter gen){
Method m = new Method(onMethod.getName(), Type.getReturnType(onMethod), Type.getArgumentTypes(onMethod));
gen.invokeInterface(Type.getType(protocolOn), m);
HostExpr.emitBoxReturn(objx, gen, onMethod.getReturnType());
Emitter.emitExprTrace(gen,objx,coord,OBJECT_TYPE);
}
gen.mark(endLabel);
}
Expand Down Expand Up @@ -6701,7 +6702,11 @@ public void doEmit(C context, ObjExpr objx, GeneratorAdapter gen, boolean emitUn
if(emitUnboxed)
((MaybePrimitiveExpr)body).emitUnboxed(context, objx, gen);
else
body.emit(context, objx, gen);
{
body.emit(context, objx, gen);
if (context == C.EXPRESSION || context == C.RETURN)
Emitter.emitExprTrace(gen, objx, coord, OBJECT_TYPE);
}
}
finally
{
Expand All @@ -6711,9 +6716,14 @@ public void doEmit(C context, ObjExpr objx, GeneratorAdapter gen, boolean emitUn
else
{
if(emitUnboxed)
((MaybePrimitiveExpr)body).emitUnboxed(context, objx, gen);
((MaybePrimitiveExpr)body).emitUnboxed(context, objx, gen);
else
body.emit(context, objx, gen);
{
body.emit(context, objx, gen);
if (context == C.EXPRESSION || context == C.RETURN)
Emitter.emitExprTrace(gen, objx, coord, OBJECT_TYPE);
}

}
Label end = gen.mark();
// gen.visitLocalVariable("this", "Ljava/lang/Object;", null, loopLabel, end, 0);
Expand Down Expand Up @@ -7439,7 +7449,11 @@ else if((form instanceof IType) ||
Expr expr = analyze(C.EVAL, form);
return expr.eval();
}
}
} catch (Exception e)
{
System.out.println("Error processing form. Ns: " + currentNS().toString() + " file: " + (String)file + " form: " + origForm);
throw e;
}
finally
{
if (formCoords != null)
Expand Down
6 changes: 3 additions & 3 deletions test/clojure/test_clojure/pprint/test_pretty.clj
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,10 @@ It is implemented with a number of custom enlive templates.\"
(deftest test-print-meta
(let [r (with-meta (range 24) {:b 2})]
(are [expected val] (= (platform-newlines expected) (with-out-str (binding [*print-meta* true] (pprint val))))
"^{:b 2, :a 1} {:x 1, :y 2}\n"
"^{:a 1, :b 2} {:x 1, :y 2}\n"
^{:a 1 :b 2} {:x 1 :y 2}

"^{:b 2, :a 1}\n{:x\n ^{:b 2}\n (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23),\n :y 1}\n"
"^{:a 1, :b 2}\n{:x\n ^{:b 2}\n (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23),\n :y 1}\n"
^{:a 1 :b 2} {:x r :y 1}

"^{:a 1} {:x ^{:foo true} {:y 2}}\n"
Expand All @@ -405,7 +405,7 @@ It is implemented with a number of custom enlive templates.\"
"^{:a 1}\n[[[1\n ^{:b 2}\n (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23)]]]\n"
^{:a 1} [[[1 ^{:b 2} r]]]

"^{:column 16, :line 409} (1 2 3 4)\n"
"^{:line 409, :column 16} (1 2 3 4)\n"
^{:a 1} '(1 2 3 4)

"^{:a 1} (0 1 2 3)\n"
Expand Down
5 changes: 4 additions & 1 deletion test/clojure/test_clojure/storm_bodies.clj
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@
[:expr-exec 0 "3,2,1,1" -2008026743]
[:expr-exec 3 "3,2,2" -2008026743]
[:expr-exec 3 "3,2" -2008026743]
[:expr-exec 3 "3" -2008026743]
[:fn-return 3 "" -2008026743]]
(u/capture)) "captured traces should match.")))

(deftest let-test
(let [r (b/letter)]
(is (= 15 r) "function return should be right.")
Expand All @@ -74,6 +75,7 @@
[:expr-exec 15 "3,1,5,2" 1755477002]
[:bind "c" 15 "3"]
[:expr-exec 15 "3,2" 1755477002]
[:expr-exec 15 "3" 1755477002]
[:fn-return 15 "" 1755477002]]
(u/capture)) "captured traces should match.")))

Expand All @@ -84,6 +86,7 @@
[:bind "x" ":first" ""]
[:expr-exec ":first" "3,1" 1958052943]
[:expr-exec 42 "3,3" 1958052943]
[:expr-exec 42 "3" 1958052943]
[:fn-return 42 "" 1958052943]]
(u/capture)) "captured traces should match.")))

Expand Down

0 comments on commit 1848732

Please sign in to comment.