Whoa, thanks for your suggestions!! it supports recursion now, basically for each script function I store:
-information about its local data(local variables and function parameters), how many local vars, how many bytes needed for those local vars.
-its instructions....
-its return type
then when the script calls a function, it will:
-allocate bytes needed for the function's local data + request storage for return value
-point the function to the allocated bytes
-'push' to the call stack (make it the current function)
-execute its instructions
upon returning, it will:
-store any return value it has to store
-release all data it has
-restore call stack or 'pop'
and it worked nicely, I've tested it by making a factorial function inside the script.....now I only need to 'FIX' the stack size (I want to allocate some bytes at the beginning that acts as a stack 'pool', but that's not hard to do)
many many thanks guys !!
Is any recursive function can be translated into its iterative form?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement