Stack depth question

Started by
9 comments, last by iMalc 18 years, 4 months ago
I'm writing a VM/JIT-based programming language. I've decided to allow 255 virtual registers in a function for each primitive datatype so the register numbers can be stored in bytes. My question: is 255 enough or should I use 16-bit register numbers? Have you ever needed more than 255 integers (including local structs) in one function? Have you ever met a code generator that might need that many?
Advertisement
It sounds resonable, but people will always use your language in ways you can't conceive. Old C++ compiles had 64K limits on cpp file sizes that some programs( Microsoft Office ) broke.

Why not try to make it dynamic( std::vector ) and let the availalbe memory dictate the size??

CHeers
Chris
CheersChris
Making a restriction like this is both good and bad.

Good: Because it encourages more thought into the code you are writing for the language. You can't simply be care-free.

Bad: Because it is a restriction.

Now i don't think using a vector is a good idea for this because you don't actually have any control on how it bloats. It largely depends on the platform but if its a desktop pc then there is no harm in allowing code bloat.

ace
Some hard limit has to be placed because the VM instructions will have to have a fixed argument size. The storage space can be allocated dynamically. 8-bit arguments to most instructions would produce smaller intermediate code, which is a meaningless micro-optimization, I know, but nice nevertheless.

I intend to spread local C struct-like entities over the same registers. Perhaps it's easier to find an example of a struct that has over a hundred members?
Quote:Original post by 255
I intend to spread local C struct-like entities over the same registers. Perhaps it's easier to find an example of a struct that has over a hundred members?
What about local arrays? Those can easily go over a hundred (or 255 even) 'members'. Or are (local) arrays not allowed in your language?
Arrays will always be on the heap and behave like other reference-objects by default. I'm not sure yet whether they even need special language constructs.
Quote:Original post by 255
I'm writing a VM/JIT-based programming language. I've decided to allow 255 virtual registers in a function for each primitive datatype so the register numbers can be stored in bytes.

My question: is 255 enough or should I use 16-bit register numbers? Have you ever needed more than 255 integers (including local structs) in one function? Have you ever met a code generator that might need that many?
I think 255 would be quite enough, and you could quite happily throw a compile-time error if the programmer exceeds that. No one should ever write functions that big.
Just make sure you aren't going to allocate space for 255 of each data type on every level of the stack, when they might only use 2 or 3. Otherwise you're going to have a worse limit when it comes to the number of recursive calls / stack depth allowed.
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms
Go with the 16-bit value. If it later turns out to be a problem or a good optimization, then switch to 8-bit. You don't want to restrict the compiler and/or the user unnecessarily.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
To quote another site:

Quote:At my previous job, we were porting a UNIX system to Windows NT using Microsoft VC++. A colleague of mine, that was in the process of porting his portion of the code, came to me, looking really upset.

* Colleague: "Hey! I hate these Microsoft guys! What a rotten compiler! It only accepts 16,384 local variables in a function!"
Thank you for your answers. 16 bits it is then, for now. Still, it'd be interesting to hear why someone or some code generator would need so many variables.

This topic is closed to new replies.

Advertisement