added styles for gh md extensions, worked on generators post

This commit is contained in:
Parker TenBroeck 2026-04-29 13:43:55 -04:00
parent bd7eaeec38
commit d5fa5f0608
5 changed files with 193 additions and 36 deletions

View file

@ -37,6 +37,7 @@ render_emoji = true
bottom_footnotes = true
github_alerts = true
# insert_anchor_links = "heading"
[markdown.highlighting]
light_theme = "github-light-high-contrast"

View file

@ -8,10 +8,70 @@ tags = ["java", "bytecode"]
category = ["project"]
+++
With the release of Java 24 came the official Class-File API giving a stable and (relatively) ergonomic interface for reading, modifying, and writing java classes/bytecode at runtime with no external dependencies. Seeing this I decided to play around with it and see what fun I could have.
# Bytecode, Stack Machines, and Registers
Java (and other JVM languages) are compiled to a set of [bytecode instructions](https://en.wikipedia.org/wiki/List_of_JVM_bytecode_instructions).
These instructions primarily operate on a stack (fifo) using 0-n operands from the top and pushing 0-1 values back onto the stack.
An example would be the `iadd` instruction which pops two integers off the stack and pushes the sum of them.
A more complex example would be something like `invokevirtual <methodref_index>` which calls a method on a class.
`methodref_index` is an index (in this case a 2 byte index) into the class files `constant_pool`[^1]
[^1]: https://docs.oracle.com/javase/specs/jvms/se23/html/jvms-4.html#jvms-4.1
> [!NOTE]
> Highlights information that users should take into account, even when skimming.
> [!TIP]
> Optional information to help a user be more successful.
> [!IMPORTANT]
> Crucial information necessary for users to succeed.
> [!WARNING]
> Critical content demanding immediate user attention due to potential risks.
> [!CAUTION]
> Negative potential consequences of an action.
## Stack manipulation
Sometimes it's
## Registers
# Stack Machine and Registers
# Decompilation
# Interlude, what's a stack map?
# Tracking everything everywhere
# Putting everything together
# Injection
Take a look at the [GitHub](https://github.com/ParkerTenBroeck/generators)
```java,linenos
public static Future<Void, IOException> echo(@Cancellation("close") Socket socket) throws IOException {
public static Future<Void, IOException> echo(
@Cancellation("close") Socket socket
) throws IOException {
try(socket){
var buffer = ByteBuffer.allocate(4096*2);
while(true){
@ -24,4 +84,17 @@ public static Future<Void, IOException> echo(@Cancellation("close") Socket socke
}
```
Java (and other languages which compile for the JVM) operate on a
```java,linenos
public static Gen<Long, Void> primes() {
long number = 1;
Gen.yield(2L);
outer: while(true){
number += 2;
for(long i=2; i <= Math.sqrt(number); i ++){
if(number%i==0)continue outer;
}
Gen.yield(number);
}
}
```

View file

@ -60,37 +60,37 @@ Take a look at the [GitHub](https://github.com/ParkerTenBroeck/MyCPU_16bit)
| No Operation | 00 | 30000 | 1044000 | 800000 | | | | |
| Bit | Function |
| --- | --- |
| 31 | NA |
| 30 | NA |
| 29 | NA |
| 28 | NA |
| 27 | NA |
| 26 | NA |
| 25 | NA |
| 24 | Instruction Register In |
| 23 | Micro Instruction Counter Reset |
| 22 | Conditional Instruction Type Select Bit 3 |
| 21 | Conditional Instruction Type Select Bit 2 |
| 20 | Conditional Instruction Type Select Bit 1 |
| 19 | Program Counter In |
| 18 | Program Counter Count |
| 17 | Program Counter Out |
| 16 | Update Memory Address Register |
| 15 | Memory In |
| 14 | Memory Out |
| 13 | Internal Screen Register In |
| 12 | Jump Register Out |
| 11 | Jump Register In |
| 10 | B Register Out |
| 9 | B Register In |
| 8 | A Register Out |
| 7 | A Register In |
| 6 | Y Register Out |
| 5 | Y Register In |
| 4 | X Register Out |
| 3 | X Register In |
| 2 | ALU mode select bit 3 |
| 1 | ALU mode select bit 2 |
| 0 | ALU mode select bit 1 |
| Bit | Function |
| -- | ------------------------------------------ |
| 31 | NA |
| 30 | NA |
| 29 | NA |
| 28 | NA |
| 27 | NA |
| 26 | NA |
| 25 | NA |
| 24 | Instruction Register In |
| 23 | Micro Instruction Counter Reset |
| 22 | Conditional Instruction Type Select Bit 3 |
| 21 | Conditional Instruction Type Select Bit 2 |
| 20 | Conditional Instruction Type Select Bit 1 |
| 19 | Program Counter In |
| 18 | Program Counter Count |
| 17 | Program Counter Out |
| 16 | Update Memory Address Register |
| 15 | Memory In |
| 14 | Memory Out |
| 13 | Internal Screen Register In |
| 12 | Jump Register Out |
| 11 | Jump Register In |
| 10 | B Register Out |
| 9 | B Register In |
| 8 | A Register Out |
| 7 | A Register In |
| 6 | Y Register Out |
| 5 | Y Register In |
| 4 | X Register Out |
| 3 | X Register In |
| 2 | ALU mode select bit 3 |
| 1 | ALU mode select bit 2 |
| 0 | ALU mode select bit 1 |

View file

@ -172,3 +172,80 @@ th {
}
.markdown-alert-note {
border-left: solid 3px var(--blue);
padding-left: 20px;
margin-left: 10px;
::before{
content: "Note";
display: block;
font-weight: bold;
color: var(--blue);
}
}
.markdown-alert-note {
border-left: solid 3px var(--blue);
padding-left: 20px;
margin-left: 10px;
::before{
content: "Note";
display: block;
font-weight: bold;
color: var(--blue);
}
}
.markdown-alert-tip {
border-left: solid 3px var(--green);
padding-left: 20px;
margin-left: 10px;
::before{
content: "Tip";
display: block;
font-weight: bold;
color: var(--green);
}
}
.markdown-alert-important {
border-left: solid 3px var(--purple);
padding-left: 20px;
margin-left: 10px;
::before{
content: "Important";
display: block;
font-weight: bold;
color: var(--purple);
}
}
.markdown-alert-warning {
border-left: solid 3px var(--yellow);
padding-left: 20px;
margin-left: 10px;
::before{
content: "Warning";
display: block;
font-weight: bold;
color: var(--yellow);
}
}
.markdown-alert-caution {
border-left: solid 3px var(--red);
padding-left: 20px;
margin-left: 10px;
::before{
content: "Caution";
display: block;
font-weight: bold;
color: var(--red);
}
}

View file

@ -62,6 +62,12 @@
--primary: light-dark(#ffd979, #daa520);
--text-highlight: color-mix(in srgb-linear, var(--primary) 50%, transparent);
--blue: light-dark(#0969da, #1f6feb);
--green: light-dark(#1a7f37, #3fb950);
--purple: light-dark(#8250df, #ab7df8);
--yellow: light-dark(#9a6700, #d29922);
--red: light-dark(#d1242f, #f85149);
}
* {