Questions tagged [stack-machine]

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.

References

27 questions
18
votes
2 answers

Converting SSA to stack machine

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…
rwallace
  • 31,405
  • 40
  • 123
  • 242
10
votes
1 answer

SSA for stack machine code

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…
Serafina Brocious
  • 30,433
  • 12
  • 89
  • 114
8
votes
0 answers

How does a register machine differ from a stack machine?

How does a register machine differ from a stack machine?
yazz.com
  • 57,320
  • 66
  • 234
  • 385
7
votes
2 answers

How to find gc roots in a stack machine?

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…
6
votes
1 answer

How to optimize simple stack-machine code?

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…
TLW
  • 1,373
  • 9
  • 22
5
votes
1 answer

Compiling local variables for a stack machine

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…
David K.
  • 6,153
  • 10
  • 47
  • 78
4
votes
2 answers

Learning resources - stack machines, JVM especially

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…
Lars Westergren
  • 2,119
  • 15
  • 25
3
votes
1 answer

Compiling switch statements for a simple VM

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…
3
votes
1 answer

Theory of interpreters, partial evaluators, and compilers

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…
3
votes
1 answer

How common is stack machine use in C++ code?

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…
T9b
  • 3,312
  • 5
  • 31
  • 50
2
votes
1 answer

Why jumping into an instruction even if containing a JUMPDEST does not work?

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…
user2284570
  • 2,891
  • 3
  • 26
  • 74
1
vote
1 answer

Is PUSH instruction in assembly language a zero address instruction or one address instruction?

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…
1
vote
1 answer

How to use Data.SBV to help derive correct stack machine implementation?

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…
dbanas
  • 1,707
  • 14
  • 24
1
vote
1 answer

How can I pass the result of a method back to the stack in assembly programming?

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 …
John Hm
  • 21
  • 3
1
vote
1 answer

How to store variables from Symbol Table Compilers

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…
1
2