iamleeg / Amiga-Smalltalk

An implementation of Blue Book Smalltalk-80
European Union Public License 1.2
17 stars 0 forks source link

Native Amiga filesystem access #10

Open iamleeg opened 4 years ago

iamleeg commented 4 years ago

It would be helpful to be able to filein/fileout sources using Amiga files, and read/write Amiga data files.

acf commented 4 years ago

I’ll start looking at this but it may take some time 😂

acf commented 4 years ago

So at first glance the Stream APIs are all in Smalltalk (Page 195), and I can't see how the ties into anything I can find in part 4, where I expected to find some primitive syscalls. I'll keep digging but thought I'd keep progress notes here in case you see me heading down a wrong track.

acf commented 4 years ago

Notes for future me:

https://github.com/gnu-smalltalk/smalltalk/blob/dfe4b5660037c4d178853ee00458a75e51a88563/kernel/FileDescr.st

https://github.com/gnu-smalltalk/smalltalk/blob/dfe4b5660037c4d178853ee00458a75e51a88563/libgst/prims.def#L5503

So GNU smalltalk implements the file operations as primitives but does seem to call them out in places “Smalltalk primitives and files”. Looking at BlueBook chapter 29, file handling is not listed as a primitive specifically. The closest seems to be ReadStream and WriteStream (65 and 66). Interestingly GNU Smalltalk does not seem to implement WriteStreams nextPut method as a primitive.

Conclusion is that file operations are not part of the blue book specification. Page 209 suggests that ExternalStream and FileStream exist to build a file system in Smalltalk where a file system can be created, which also suggests that Smalltalk can run in a universe of no file system at all. The VM does not need to provide anything in particular so it seems we’re free to go our own way, using FileStream, FileDirectory, FilePage and File as the basics, and implementing those Smalltalk classes however we choose.

Squeak File Handling https://github.com/OpenSmalltalk/opensmalltalk-vm/blob/8f731e5896e819c831636e9a3ac74132f40f72f9/platforms/Cross/plugins/FilePlugin/sqFilePluginBasicPrims.c

Another BlueBook Smalltalk that implements file operations as a primitive

https://github.com/dbanay/Smalltalk/blob/master/src/interpreter.cpp#L2538

This is nice... https://github.com/dbanay/Smalltalk/blob/6a7619cba3d7a3bd3d9807e429bf00d6c6886061/src/interpreter.cpp#L2487. same as the rest of primitive dispatch but called out as private

acf commented 4 years ago

I’m going to start adding in some primitives from page 617 and work towards adding the stream primitives. From there I’ll try and build out the File classes.

iamleeg commented 4 years ago

Thanks for investigating that! I think there are a few places where the blue book doesn't tell us what Smalltalk-80 did, for example I haven't worked out whether there's a run loop in the VM, or an entry point for an event loop implemented in the image.

acf commented 4 years ago

On the run loop thing I also saw this https://github.com/dbanay/Smalltalk/blob/6a7619cba3d7a3bd3d9807e429bf00d6c6886061/src/main.cpp#L846

acf commented 4 years ago

Just a note that progress is being made, albeit slowly, through other PRs adding more and more primitives. See, for example, https://github.com/iamleeg/Amiga-Smalltalk/pull/19

acf commented 3 years ago

I've been working on a branch to try and read and write ST-80 images but I am increasingly frustrated by the poor tooling. My initial approach was just to try and transliterate the stuff in the dbanay C++ BlueBook into our Amiga C but that just means there's tons of code all at once that either works or doesn't (and currently doesn't). So I think I'll start again and build it the same way he does, but incrementally.