My purpose is to debug the Clojure Compiler to understand more about it. (My project code is an aid to this purpose.).
I've got both the Clojure Compiler source and my project test
set up in my IntelliJ IDE.
I've got the the clojure
project as the primary project, and the test
project is on the classpath.
I'm triggering the Clojure REPL in the debugger by running the clojure.main
class in the clojure
project.
My test
project has the following source in the test.core
core.clj
file:
(ns test.core
(:gen-class))
(deftype SquarePeg [width length])
(deftype RoundHole [radius])
(def square-peg (SquarePeg. 5 50))
(defn insert-peg [^test.core.RoundHole peg]
(println "insert-peg inserted with: " peg))
(defn -main
"Insert a square peg in a round hole"
[& args]
(insert-peg square-peg)
(println "Done."))
I've set the following breakpoints:
Compiler.java
L4709 (Handling vars when emitting values)AFn.java
L154 (Invoking a function with a single argument)Now what I'm doing is pasting in the following function invocation into the REPL after I've switched the breakpoints on:
(insert-peg square-peg)
Now what I see is that the println
(as pr
) in the code above runs through the AFn.java
single arg invoke, but the call to insert-peg
does not. (This is what I want to debug).
(First breakpoint tripped after breakpoints switched on).
I do see the declarations of insert-peg
and square-peg
running through the emit code in the Compiler.java
- but what I'm looking for is the function application. I want to see square-peg
be applied to insert-peg
running in the compiler code in the debugger. (Perhaps I'm missing a breakpoint, or looking in the wrong place).
Assumptions:
My question is: How do I debug the application of arguments to my function in the Clojure Compiler?
The trick was the function InvokeExpr(...)
in Compiler.java
.
In particular the VarExpr
section.