Stack machine is intended for questions related to using a stack data structure for the storage of both temporary values during calculations as well as stack frames during transfer of control to subroutines.
It is well known how to convert code from SSA representation to a register machine. (Basically, graph coloring register allocation is the core of such conversion.)
But what's the general method for converting from SSA to a stack machine? (CIL byte…
I'm working on a compiler for a stack machine (specifically CIL) and I've parsed the code into a graph of basic blocks. From here I'm looking to apply SSA to the methods, but it's not going too well. My first attempt (while working with a flat…
I am writing a compiler for a fairly standard stack machine. Now I want to add a garbage collector. I can see that I could generate some sort of 'stack maps' to know which variables are gc roots in each activation record. However, I have no idea how…
I've been playing around with a simple stack-based language, and one of the things that I've found myself doing repeatedly is manually optimizing chunks of code.
I figured "hey, this looks very much like something that a computer can do! Repetitive…
I'm building a toy compiler from a C like language to a stack machine and I'm at the point where I need to figure out what to do with functions and block local variables. Thinking through it abstractly it looks like I have two options at opposite…
I'm curious if anyone have any really good tutorials/articles/books for learning about stack machines in general, and the JVM in particular. I know these…
So I'm compiling a subset of C to a simple stack VM for learning purposes and I'd like to know how to best compile a switch statement, e.g.
switch (e) {
case 0: { ... }
case 1: { ... }
...
case k: { ... }
}
The book I'm going through offers…
So I've been learning about stack machines, interpreters, compilers and a few other things related to programming languages and their general theory. Most of the stuff I find in books and online are very specialized and talk about one specific…
I'm looking at some C++ code and it includes a stack machine for scripting. I learnt C++ years ago, but never used it in my day job, so I don't have any real idea if this is common practice, or is it only used under certain very specific…
Here’s my whole program. The reasoning behind it is the larger is the program on Ethereum, the more it costs money to load it (as the gas cost is per byte and quite high).
CALLER
CALLDATASIZE
ISZERO
PUSH1 0x07
JUMPI
PUSH3 0x5b6000
SSTORE
So I’m…
I read that ADD and MUL instructions when implemented in Stack are zero address instructions but there is no discussion anywhere as to PUSH and POP instruction are one address instruction or zero address instructions.
Here is an excerpt from…
Graham Hutton, in the 2nd edition of Programming in Haskell, spends the last 2 chapters on the topic of stack machine based implementation of an AST.
And he finishes by showing how to derive the correct implementation of that machine from the…
This is the assembly code:
ldc 5 // a
ldc 12 // b
bsr sumsquare
ajs -2 // delete parameters
ldr RR // result on the stack
stl 1 // store in a variable
....
sumsquare:
link 1 // 1 local variable
ldl -3 // a
…
For my class, I have to write a compiler for a tiny subset of Python:
This language has one method
There aren't functions, so I'm only dealing with one lexical scope
This Python subset will be translated to Java bytecode.
I've already done…