On Saturday, 12 February 2022 at 16:48:26 UTC, user1234 wrote:
> On Saturday, 12 February 2022 at 13:17:19 UTC, rempas wrote:
> On Wednesday, 9 February 2022 at 02:07:05 UTC, user1234 wrote:
> std.file.readText() is just fine... your really want to do an os with call fgetc for every single byte that has to be read ?
Good point! I was really wondering if "fgetc" does a system call every single time that it is called or if the text is buffered just like with "printf". I will use "read" in any case just to be sure tho. I don't want to use Phobos tho so I cannot use "file.readText". Thank you for your time!
I think that nowadays fgetc does not make sense anymore, maybe in the past when the amount of memory available was very reduced... source files are 100 kb top. You can load 100 of them, the fingerprint is still small. What will likely consume the more is the AST.
Otherwise readText is easy to translate, it's just fopen then fread then fclose, + a few checks for the errors, not a big deal to translate.
The problem with phobos and if used to program a compiler is dynamic arrays, because of how they are managed.
With Styx I had used phobos because I knew the memory management was designed to work similarly with arrays, i.e functions can return arrays, but using the "sink" style would have not caused any problem (by "sink" style I mean when the buffer is owned by the calling frame, and passed as parameter, e.g like in many C-style APIs)
Then the amount of phobos code to translate in order to bootstrap was minimal:
std.paths:
- isAbsolute
- isDir
- isFile
- dirName
- baseName
- exists
- cwd
- dirEntries
- setExtension
std.files:
- read (or readText)
- write (not even used I realize now)
std.process
- pipeProcess (actually just used to optionally --run after compile)
std.getopt
- getopt (tho libc functions for that could have been used... dmd itself doesnt have any special functions for the arg processing in the driver IIRC)
Add to this a few things from libc and unistd and you're good. You dont need more.