Checking number of arguments

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Checking number of arguments

SomeGuy
I'm looking for a way to make sure that every call in class1 to a subroutine in class2 uses the correct number of arguments.
As the Jack compiler is meant to compile each .jack file independently, I can't just check class2's file.
I could try detecting it in the resulting vm code, but I don't know of an easy way to find out the number of arguments that a vm function uses.

One solution I came up with is to compile each jack subroutine to a vm function whose identifier includes the number of arguments eg: function int foo(int i, int j) -> function file.foo2 ...
This way, using the incorrect number of arguments will result in a call to an undefined function in the vm translator.
However, this isn't compatible with the jack OS vm files.

Is there a better way?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Checking number of arguments

cadet1620
Administrator
There isn't much you can do when compiling a single source file. If your compiler detects when you pass it a directory name and then compiles all the files in that directory, you could do a prepass through the files to get the number of arguments in all the functions.

Alternatively, you could build tables of function definitions and function calls and validate that their argument counts match and report any errors after all the files are compiled.

--Mark
Loading...