Skip to content

Commit 64c1bdb

Browse files
committed
Fix a few typos, start draft of fn-star-talkin-bout-my-generation
1 parent a1ee7d4 commit 64c1bdb

File tree

5 files changed

+67
-2
lines changed

5 files changed

+67
-2
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
layout: post
3+
title: C4 - fn*: talkin' 'bout my generation
4+
date: 2025-09-07 00:00:00 -0500
5+
categories: general
6+
---
7+
8+
We look at code generation for functions in ClojureCLR.
9+
10+
In a previous post ([C4: Functional anatomy]({{site.baseurl}}{% post_url 2025-09-04-functional-anatomy %})), we looked at how functions are represented in ClojureCLR. That post focused on the interfaces and classes that form the basis of the representation of functions. When we generate a function in ClojureCLR, though we are deriving a class from one of the base classes (typically `AFunction` or `RestFn`), there is a significant amount of support structure that gets added. That is the topic of this post.
11+
12+
## Our playground
13+
14+
The primary classes involved in function code generation are:
15+
16+
<img src="{{site.baseurl | prepend: site.url}}/assets/images/objexpr.png" alt="Graph of all types related to ObjExpr" />
17+
18+
I have no idea why `ObjExpr` and `ObjMethod` are named what they are.
19+
`FnExpr` is the AST node that represents an `fn*` form. `FnMethod` represents an `invoke` method of the generated class.
20+
`NewInstanceExpr` represents a `deftype` or `reify` form; `NewInstanceMethod` represents a method of the generated class.
21+
For these, a significant amount of code lies in the base classes `ObjExpr` and `ObjMethod`. We will focus here on `FnExpr` and `FnMethod`. Most of this analysis applies to `NewInstanceExpr` and `NewInstanceMethod` as well.
22+
23+
Note: Do not confuse `NewInstanceExpr` with `NewExpr` -- the latter represents a `new` form that creates an instance of a class.
24+
25+
## Let me count the lines
26+
27+
| File | Source lines | Executable lines |
28+
|------|--------------:|------------------:|
29+
| ObjExpr.cs | 1,195 | 450 |
30+
| FnExpr.cs | 362 | 102 |
31+
| NewInstanceExpr.cs | 681 | 227 |
32+
| ObjMethod.cs | 176 | 50 |
33+
| FnMethod.cs | 458 | 157 |
34+
| NewInstanceMethod.cs | 321 | 117 |
35+
36+
Doesn't seem like much? It's packed. And dependent on a some other goodies that we will get to shortly.
37+
38+
##

_posts/2025-08-31-classic-clojure-compiler-contemplation.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ The other posts in the series are:
1414
- [C4: Symbolic of what?]({{site.baseurl}}{% post_url 2025-09-02-symbolic-of-what %}) - A little digression on what symbols represent
1515
- [C4: ISeq clarity]({{site.baseurl}}{% post_url 2025-09-03-iseq-clarity %}) - How to analyze an `ISeq`
1616
- [C4: Functional anatomy]({{site.baseurl}}{% post_url 2025-09-04-functional-anatomy %}) - How functions are implemented in Clojure
17-
- __C4: The fn*: talkin' 'bout my generation__ - Code-gen for functions
17+
- __C4: fn*: talkin' 'bout my generation__ - Code-gen for functions
1818
- __C4: How type-ical__ - Type analysis by the compiler
1919
- __C4: I have something to emit__ - More on code generation
2020
- __C4: A time for reflection__ -- Reflection and dynamic callsites
2121
- __C4: Is there a protocol for that?__ -- Protocols
22+
- __C4: Out of control__ -- Some points about flow of control and data in the compiler
2223

2324
## The terms of discussion
2425

_posts/2025-09-04-functional-anatomy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ date: 2025-09-04 00:00:00 -0500
55
categories: general
66
---
77

8-
We look at the implementation of functions in ClojureCLR and how evaluation/compilation translates a source code definition of a function to the underlying class representation.
8+
We look at the implementation of functions in ClojureCLR and how evaluation/compilation translates a source code definition of a function to the underlying class representation. (The first of several posts on this topic.)
99

1010
## The universe, and everything
1111

assets/images/objexpr.png

11.8 KB
Loading

assets/objexpr.dot

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
strict digraph G {
2+
3+
rankdir = RL;
4+
5+
node [shape=box];
6+
7+
subgraph objexprrelated {
8+
node [shape=box];
9+
10+
Expr;
11+
ObjExpr -> { Expr };
12+
NewInstanceExpr -> { ObjExpr };
13+
FnExpr -> { ObjExpr };
14+
15+
}
16+
17+
subgraph objmethodrelated {
18+
node [shape=box];
19+
20+
ObjMethod;
21+
NewInstanceMethod -> { ObjMethod };
22+
FnMethod -> { ObjMethod };
23+
}
24+
25+
26+
}

0 commit comments

Comments
 (0)