Question

I'm making a stack based virtual machine in RPython using the PyPy toolchain to convert the RPython to C. So far I have 4 instructions.

  1. EOP - End of Program
  2. EOI - End of Instruction
  3. PUSH - Push item onto the stack
  4. PRINT - Print the top of the stack

My question is, how do you push a String to the top of the stack. Is it the same as when you push a number to the top of the stack or do I have to do something else when working with strings?

Was it helpful?

Solution

That depends. Do you want to push the string, or a pointer to a string? If it's the former, you have a problem, because the string will have variable length, unlike a pointer or a number. If it's the latter, you have to consider memory management aside from your stack.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top