Sign in to follow this  
255

Stack depth question

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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!"

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Quote:
Original post by tychon
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!"
OMFG!
I find it quite hard to believe that someone could even intentionally reach that. It would probably use almost every 3-letter variable name possible!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this