Getting .vm filenames from a directory

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Getting .vm filenames from a directory

Brad360
Since Chapter 7 when I read about how the full translator would have to handle translation of multiple files from a given directory, I was worried because I didn't know how to, say, iterate through files of a folder.  I am not that experienced of a programmer in C++, certainly not with the Windows API, so I am sure it would be possible, but not in a way I would know.

So, I thought, would it be a good idea to assume that if translating from a directory that contains the .vm files, to first look for Sys.vm, since that would contain Sys.init, which is required to run?  Then, assuming that is found, the job of Sys.init is to initiate things in the Hack platform and begin running the main function of the program.  Namely, it has to make a call to some other function to get further into the execution of the program.

So, this is my idea.  When calls are found in the .vm files, take note of the function name.  Since the functions are to be named in the format fileName.functionName, when a call is encountered, the fileName part of the function name could be said to imply the existence of a .vm file that contains it, correct?  Then, as translation goes on, it keeps discovering the .vm files that have functions in them that are used throughout the rest of the program.

Basically, is this overly complicated, or is this actually what is required of us?  Are there any foreseeable pitfalls that I have missed, like maybe circular dependencies that might lead to the missing of the discovery of a .vm file?  Or, is there a simple way I overlooked in C++ to gain access to the files of a directory?
Reply | Threaded
Open this post in threaded view
|

Re: Getting .vm filenames from a directory

ybakos
Not quite. For the first series of VM translator tasks, you merely translate all the .vm files in the particular directory. Toward the end, you then explicitly inject a small amount of code that represents the Sys.init call.
Reply | Threaded
Open this post in threaded view
|

Re: Getting .vm filenames from a directory

cadet1620
Administrator
In reply to this post by Brad360
Last time I looked (it's been a few years...) there was no cross platform support for directory searching in C++. The Windows API functions you want are FindFirstFile(), FindNextFile() and FindClose().

Email me if you need example code.

--Mark