Would it be a good idea to lower down (again) FPC so that it can be used easier for systems programming?
Mailing lists / fpc-pascal / 2008-11
Make FPC closer to hardware
8 messages · 4 people · –
- Lleledumbo 4
- FFrank Peelo 2
- FFlorian Klaempfl 1
- MMicha Nelissen 1
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
leledumbo wroteWould it be a good idea to lower down (again) FPC so that it can be used easier for systems programming?
....example?
Micha
Micha Nelissen wrote....example?
Let Write(Ln) work without file system support? Perhaps just by supplying a routine to write one character, and let other write routines use it.
Show quoted text 6 lines
Too slow in the common use case.
Let Write(Ln) work without file system support? Perhaps just by supplying a routine to…
leledumbo wrote 8 lines
I think it already has what you want there.
Doesn't call a function for each char, though. That was last seen in TurboPascal 3. TurboPascal v4 introduced Text File Device Drivers. These do the same thing, but much more efficiently and flexibly.
Basically, you write 4 functions for your device to handling opening the file, doing I/O, flushing any internal buffers and closing (e.g. if you were writing a device driver to send output via carrier pigeon, they might be called PigeonOpen, PigeonInOut, PigeonFlush and PigeonClose), and then an Assign... procedure (AssignPigeon) to associate these functions with a text file. Then use Write(Ln) to that text file, and the stuff goes through your driver procedures. If you want to just use Writeln('blablabla') instead of Writeln(f, 'blablabla') then your Assign procedure will assign the file the '' name.
You've already guessed from the name of the InOut function that this can be used to replace the keyboard input as well as screen output.
Googling for
Pascal "text file device driver" example
finds links like the following:
http://www.opensc.ws/ebooks/Delphi%205%20-%20Object%20Pascal%20Language%20Guide.pdf (see section 8.4)
Or here's an example of creating routines which take chars from Write(Ln) and sending them to somewhere else (to a stream): http://www.hu.freepascal.org/lists/fpc-pascal/2004-December/007763.html
There's the CRT unit source code, crt.pp, as well.
Frank
Well, it's just an example. I'm saying that because the need of file system support is quite frustrating that I need to write my own write routines.
leledumbo wroteWell, it's just an example. I'm saying that because the need of file system support is quite frustrating that I need to write my own write routines.
yes, but for example you /don't/ need to write your own write routines. (You *can't* write writeln in Pascal!) You can implement just the driver underneath. As the CRT unit does. It's not "one character at a time", it's "one bufferful at a time"; this is an efficiency thing. You /could/ write a tfdd that called your "one char at a time" functions.
The FreePascal people have written a portable compiler with this language, so it must be possible to do system stuff with it!
Frank
Frank Peelo wroteyes, but for example you /don't/ need to write your own write routines. (You *can't* write writeln in Pascal!)
I know, I'm just saying Write routines, doesn't have to be the same as Write(Ln) which has variable number of arguments. I'm writing one for each type (.i.e WriteString, WriteLong, etc).
Frank Peelo wrote 6 lines
What driver? Well, it's not difficult to have that "one bufferful at a time" thing. Perhaps I'll take a look at Crt unit source.
Frank Peelo wroteThe FreePascal people have written a portable compiler with this language, so it must be possible to do system stuff with it!
That's what I saw from other OSes, which already have everything needed. I guess I should ask them.
