Jump to content

Photo

Some System Limit Questions...

wiki values limits maximums scripting zscript zquest zasm lexer stack

  • Please log in to reply
29 replies to this topic

#1 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 07 December 2015 - 11:06 AM

I still have a few missing entries on system limits. I'm unsure of the values of these, and I'm not even certain if anyone knows at this point, but if any of you do, here's what's still a void in the Wiki entry.

 

Please note that some of these have greater value than others, but it would be nice to document all of them. Some are even...important.

 

Editor Values

  • Maximum strings in string editor: ( 65519 ) ?
  • Largest tile ID (ZQ Editors): 32767 ? (The largest value that can be referenced in the ZQ item, enemy, and other editors.)
                --> I seem to remember a problem calling high values.

Script Drawing

  • Maximum Z Height: ?

Objects

  • Maximum Z Height: ? (Link->Z, npc->Z, weapon->Z )

Stack Operation

  • Maximum number of concurrent stacks: ?
                --> Essentially, the maximum number of concurrent scripts; except that item 
                    scripts share one stack.
  • Maximum function calls per script ( 127* )
  • *Note: 255 variables will compile, but fail to run. A safe maximum is closer to 245, to allow instructions and function calls on the stack
  • *Note: Both variables, and function calls share registers (global variables are gd registers), and thus cumulatively count against their combined caps (within a register type). See: ZASM_Registers
                --> How are these tabulated at compilation, and is there a strict ratio 
                   ( function call:variable ) ?
                --> I presume here, that vars in the functions also use gd registers, when called. 
  • Maximum script buffer size: ?
                --> It is > 107,000 lines; and does this limit include code added via the import 
                    directive?!
  • Maximum number of instructions: ?
  • Maximum number of running instructions per frame: ?
  • Maximum instructions per script: ?
                --> Is this value affected by scope? Probably not, as statements would be 
                    instructions, too.
  • Maximum number of scripts ?
  • Max ffc scripts at compilation ?
  • Max Item scripts at compilation ?
  • Max global scripts at compilation ?
                --> I believe these exceed the number of slots to which you can assign them.
                --> I know this is unlikely to ever be reached.
  • Maximum function calls per script: ?
  • Maximum local function declarations per script: ?
                --> Do local function declarations, and global function declarations share the 
                    same space?
                --> Meaning, is a function declared at local scope, counted against the (2^32-1) 
                    total max global functions; or may each script declare (2^32-1) functions at 
                    its own local scope?

Script Registers

 

How are script registers handled, exactly? By this, I mean, what uses a script register, instead of a gd register? Are script registers used for anything other than holding vars at a scope local to a script? Function calls always seem to use gd regs, so...?


Edited by ZoriaRPG, 07 December 2015 - 11:13 AM.


#2 ywkls

ywkls

    Master

  • Members

Posted 07 December 2015 - 11:32 AM

  • Maximum script buffer size: ?
--> It is > 107,000 lines; and does this limit include code added via the import
directive?!

 


If it helps, the current script in the latest Zodiac demo runs to 107,853 lines; including spaces and std.zh.



#3 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 07 December 2015 - 12:12 PM

If it helps, the current script in the latest Zodiac demo runs to 107,853 lines; including spaces and std.zh.

 

That's where I got that value. :P

 

It tells me that is a safe number of lines, but not the true cap.


  • ywkls likes this

#4 cavthena

cavthena

    Apprentice

  • Members
  • Real Name:Clayton
  • Location:I wish I knew

Posted 07 December 2015 - 08:24 PM

I'm now 80% (and quickly dropping... Thanks Gleeok :badrazz: ) sure there is no cap on the amount of lines you can have and a huge size on the buffer (maybe ~19 million bytes?). Like i said before in a different post, lines normally don't mean anything. To prove my point I created a ffc that has a total of 1,238,563 lines of Waitframe() with a buffer size of 18,580,033 Bytes. It takes a few seconds longer to compile but other than that no problems.

 

However I also did the same with 4,189,929 lines and a buffer size of 67,038,841 bytes of  "a = Tan(268);" and caused ZC to crash while compiling. When I attempted it again this time with 1,238,563 lines and 19,816,998 bytes it still crashed and with 4,954,228 lines and 74,313,412 bytes of Waitframe() caused a crash on compile. I'm sure these crashes are from the buffer size and not the amount of lines as the amount is above 19 million bytes even when the line count is the same.

 

I also attempted to use a master import file. With a buffer size of 44 bytes. Still caused a crash on 4,954,228 lines of Waitframe() during compile.


Edited by cavthena, 07 December 2015 - 10:47 PM.


#5 Gleeok

Gleeok

    It's dangerous to dough alone, bake this.

  • Members
  • Real Name:Pillsbury
  • Location:Magical Land of Dough

Posted 07 December 2015 - 09:31 PM

The line count can't be greater than 2 billion or so in theory. However it wasn't really stress-tested and there's a few bugs in it that will pop up if you try to do ridiculous things beyond normal usage. These are really low priority though--certainly under my radar at least.

#6 Saffith

Saffith

    IPv7 user

  • ZC Developers

Posted 08 December 2015 - 12:34 AM

void f(){}
10 bytes. That's the smallest possible valid function. 2^32-1 functions would take, at minimum, about 40GB of disk space. The same number of scripts, more than twice that. Even if you generate them automatically, that's ridiculous.
Thoroughness is nice and all, but when is this ever going to come up?

#7 ywkls

ywkls

    Master

  • Members

Posted 08 December 2015 - 10:00 AM

The line count can't be greater than 2 billion or so in theory. However it wasn't really stress-tested and there's a few bugs in it that will pop up if you try to do ridiculous things beyond normal usage. These are really low priority though--certainly under my radar at least.

 

2 billion? Seriously? Unless you have some sort of program that writes code for you, that works out at writing one line of code every second, 24 hours a day, 365 days a year, for 63 years! If someone is going to that kind of effort in Zscript, heaven help them.

 

 2^32-1 functions would take, at minimum, about 40GB of disk space. 

 

See above note. The figure to do that using the same criteria is almost 136 years. Not happening without a team of coders working around the clock.


Edited by ywkls, 08 December 2015 - 10:00 AM.


#8 coolgamer012345

coolgamer012345

    🔸

  • Members
  • Location:Indiana, USA

Posted 08 December 2015 - 01:34 PM

void f(){}
10 bytes. That's the smallest possible valid function.

Wouldn't the smallest valid function be:

int f(){}

As 'int' would be smaller than 'void', correct?


Edited by Coolgamer012345, 08 December 2015 - 01:35 PM.


#9 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 08 December 2015 - 01:37 PM

Allow me to prioritise these, based on questions that people asked, to which I did not know the answer:

 

Compiler

 

    Maximum script buffer size: ?

 

From the above, this seems to be 32b signed for l/c, and 18MB for raw data; all including import directive files.

Is that a safe, and reasonably accurate limit?

 

18MB though, at least I will need to keep that in mind.



    Maximum number of instructions: ?

 

I'm going to guess that at compilation, this is purely based on per-script, and per-whatever limits, and that there is no pure limit here, unless it's a 32b count.

 

The next set are far more important:

    Maximum number of running instructions per frame: ?

 

    Maximum instructions per script: ?

 

    Maximum function calls per script: ?

 

(This one is reached more often than I'd like to hear about.)
    
    What uses a script register, instead of a gd register? Are script registers used for anything other than holding vars at a scope local to a script?
        

Script Drawing

        Maximum Z Height (3D drawing): ?

Objects

    Maximum Z Height: ? (Link->Z, npc->Z, weapon->Z )

 

Notes on Object Z:

AFAIK, Z is only valid when not in sideview gravity, and Link's Z is treated as upwards in one plane; whereas in sideview, Link's Y and Z are identical. I have no idea if npcs and other objects in sideview share these traits.

 

Other objects, such as npcs, or weapons, seem to be slightly different (overhead view) than Link. I have no idea what constraints exist per type, and I don't remember if negative Z is valid.

 

 

 

Wouldn't the smallest valid function be:

int f(){}

As 'int' would be smaller than 'void', correct?

 

If we want to be hyper-technical, the function count limit is artificially constrained by the filesystem type. Few filesystems support a single file of that size, and would be limited to 4GB, or 2GB file size limits. These remain ultimately unrealistically huge numbers.

 

Besides, if the maximum buffer size is 18MB, that would similarly, and severely limit this, would it not? I'm pretty shocked at that value too, as it seems extremely arbitrary.

 

I remind at least one person a month that they can realistically create as many functions as they want. Keep that in mind. Even if the number is absurdly large, the fact that it is absurdly large becomes a permanent part of their memory; or I would hope.

 

The values not in this post, have extremely low priority.

 

---

 

Also, this error:

Stack over or underflow, stack pointer = 0

 

What usually causes that?


Edited by ZoriaRPG, 08 December 2015 - 03:09 PM.


#10 Saffith

Saffith

    IPv7 user

  • ZC Developers

Posted 09 December 2015 - 02:37 PM

Maximum number of instructions: ?

Total? Just the per-script limit times the number of scripts.
 

Maximum number of running instructions per frame: ?

No limit.
 

Maximum instructions per script: ?

2^32, at least effectively. I don't know if there's actually a limit on the number of instructions a script can compile to, but the program counter is an unsigned int, so any instructions beyond 2^32-1 can't possibly run.
 

Maximum function calls per script: ?

Only limited by the number of instructions, as far as I know.
 

What uses a script register, instead of a gd register? Are script registers used for anything other than holding vars at a scope local to a script?

Script registers are d0..d7, a0, a1, the stack pointer, status flags, and one reference each to the different object types (npc, item, etc.). The compiler does with them as it sees fit. The d registers are used for data it's working with at the moment, stack addresses, return values, and probably other things. The compiler doesn't use a0 and a1 at all, as far as I know. I don't think they serve any purpose at all, in fact.
gd registers are totally different. Those are where global variables are stored.
 

Script Drawing        Maximum Z Height (3D drawing): ?

Greater than can be reached by scripts.
 

Objects
    Maximum Z Height: ? (Link->Z, npc->Z, weapon->Z )

32767. Above that wraps around to -32768, and negative values are adjusted to 0.
 

Stack over or underflow, stack pointer = 0

What usually causes that?

Too many local variables and/or nested function calls.
 

Wouldn't the smallest valid function be:

int f(){}
As 'int' would be smaller than 'void', correct?

That isn't valid; it needs a return statement. It will compile and run, but that should be considered a bug.

#11 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 10 December 2015 - 10:42 AM

...maximum instructions...

 
2^32, at least effectively. I don't know if there's actually a limit on the number of instructions a script can compile to, but the program counter is an unsigned int, so any instructions beyond 2^32-1 can't possibly run.


I have no idea then, how people claimed to have received errors regarding too many instructions at either compilation, or at script execution. I suspect that their claims of reaching an 'instruction limit' must have been related to function calls, and var declarations. Of course, the ZScript needed to create that many ZASM instructions wouldn't fit inside the script buffer anyway.
 
 

Stack over or underflow, stack pointer = 0

Too many local variables and/or nested function calls.



Don't function calls pop off as each returns, and thus, any given nest should pop off once the last function call in its scope returns?

Then again, I also thought that variables inside statements would pop off once the scope of the statement exits, which is apparently not true. That's why I didn't believe this was the cause, when doing some script debugging for other people.


Anyhow, thank you. I updated the Wiki Entry for this. If I can fill in the gaps in the future, that would be good. Further, if there is anything that is probably important, and missing from that page, please inform me.

Edited by ZoriaRPG, 10 December 2015 - 10:44 AM.


#12 Saffith

Saffith

    IPv7 user

  • ZC Developers

Posted 10 December 2015 - 11:26 AM

Don't function calls pop off as each returns, and thus, any given nest should pop off once the last function call in its scope returns?

Nested function calls. They do get popped off when they're finished.

#13 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 10 December 2015 - 01:24 PM

 

Don't function calls pop off as each returns, and thus, any given nest should pop off once the last function call in its scope returns?

Nested function calls. They do get popped off when they're finished.

 


I got that. I even acknowledged it, and asked specifically about nest behaviour. ?

 

What I mean, is this:

void multiFoo(){
    foo1();
    foo2();
    foo3();
}

How do these pop off?

 

  • Do foo1, and foo2 pop off when foo3 is called, as both have exited;
  • or do all three pop together off when multiFoo() exits?

 

I thought it was the former, but there could be some simultaneity quirk that I don't know about.

 

Did you mean, too many cascading nests?

 

---

 

I'm also shocked that vars declared in statements persist:

void bunk(){
    for ( int q = 0; q < 10; q++ ) {
        int x = Rand(20);
        Trace(x);
    } 
 
    for ( int w  =1; w < 20; w++ ) {
        int y = Rand(10);
        Trace(y);
    }
}

Apparently, the ten declarations of x, do not pop when the for loop completes. Instead, they wait to pop until the function exits, and thus accrue with the declarations of y... I would have thought that they popped when their for statement fell out of scope, but apparently not. 


Edited by ZoriaRPG, 10 December 2015 - 01:25 PM.


#14 Saffith

Saffith

    IPv7 user

  • ZC Developers

Posted 10 December 2015 - 01:34 PM

Did you mean, too many cascading nests?

Yes. Function A calling function B, which calls function C, which calls function D...
Each one is popped as soon as it completes.
 

I'm also shocked that vars declared in statements persist:

void bunk(){
    for ( int q = 0; q < 10; q++ ) {
        int x = Rand(20);
        Trace(x);
    } 
 
    for ( int w  =1; w < 20; w++ ) {
        int y = Rand(10);
        Trace(y);
    }
}
Apparently, the ten declarations of x, do not pop when the for loop completes.

Variables declared in a loop don't count as multiple variables. Each new instance of x and each new instance of y occupy the same place in the stack.

#15 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 11 December 2015 - 02:23 PM

Yes. Function A calling function B, which calls function C, which calls function D...
Each one is popped as soon as it completes.
 
Variables declared in a loop don't count as multiple variables. Each new instance of x and each new instance of y occupy the same place in the stack.

 

That is precisely what I would expect here, but according to Evan, and in actual tests, an enemy script that does this in multiple instances, will generate an overflow. That could be a bug, and I'll get you the script, so that you may see what it's doing.

 

Edit: I replied to our last PM conversation with the information/scripts for you to test this error.


Edited by ZoriaRPG, 11 December 2015 - 02:31 PM.




Also tagged with one or more of these keywords: wiki, values, limits, maximums, scripting, zscript, zquest, zasm, lexer, stack

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users