CObey
Pages: 1 2
Julie Stamp (8365) 474 posts |
I have translated Obey from assembler to C. The zip is available here, kindly hosted by Rick. It contains the compiled CObey module and its source. If someone could take a look and give guidance as to getting the code up to standard thanks. In the spirit of stripping out assembler, I have used a slightly different mechanism to Obey for handling environments. Obey creates a small piece of code to be executed for each Obey file as the exit handler. I have not done this, but it can be put in if people think this is important. Maybe it will also be useful for anyone looking to add experimental features. |
Alan Robertson (52) 420 posts |
I’m not a good programmer unlike a lot of people here, but I’ll take a look later tonight and see what I think. So is Obey, the first of many planned ARM>C conversions? |
Ronald (387) 195 posts |
Maybe it will also be useful for anyone looking to add experimental features. Fantastic that someone is taking an interest in the Obey language. I think the first step would be to get the replacement module doing everything the old one does so nothing complains. Having said that, Obey files are much simpler to update than the large files in other languages. |
Paolo Fabio Zaino (28) 1882 posts |
@ Julie
Had a very quick look at the source and found a little thing you may want to change: on main/c in read_from_file at the end of the function
Unless you’re planning to add some code between the two statements then “if(error) return error;” appears redundant right now, you’ll return error anyway and even if cache is false. thanks and really nice job! :) |
Colin (478) 2433 posts |
The first problem I would envisage is that the code is compiled with GCC and the roms are compiled using Norcroft. AcornDDE provides skeletons for creating modules in C so that compilation can switch between ram versions and rom versions. This skeleton has macros for all libraries including ${OSLIB}. There is also debuglib available which will output debug text to various destinations if needed. s.veneer won’t compile with ObjASM. If you have the rom sources and have compiled them then after running !builder set it up to your rom sources and a suitable environment then the libraries in the rom sources are available for you to include in your program as they would be if your program was put into the rom. So you would be writing your program ready to go in the rom. So then when you have sources that would slot into the rom you need to work out how to use git, get a GitLab account with ROOL, fork the ‘obey’ project in GitLab, clone the ‘obey’ project , replace it with your version on a separate branch, push your branch to gitlab and request a merge with the master ‘obey’ project. Detailed instructions are in ‘Documents’ in this site but if you are new to it all your eyes can glaze over fairly quickly. Hopefully I haven’t put you off it is worth persevering and I would have thought a C version of the Obey module would be most welcome. ROOL were offering free copies of AcornC/C++ to new developers it may be worth getting a copy. I’d practice with AcornC/C++ by compiling a rom – the instructions are in ‘Documents’ on this site. Alternatively send it to ROOL and hope they are willing to port it to fit in the roms. If you are struggling to start, If you got Norcroft I could do the makefile for you so you could see how I would do it. Not that that would guarantee it would get accepted unchanged. |
Colin (478) 2433 posts |
As to introducing new features I would get it accepted replicating existing features first. Then think about adding features. It may be decided that adding new features may break something and a separate command for extended features may be a better way to go. |
Rick Murray (539) 13840 posts |
Yes, I noticed that. I think the first thing, at this stage, is for a few people to (early on in startup) replace the default Obey with this, and see if things behave “as expected”. Then it can be tested with a wider range of people (as part of the ROM). And then…
This. Get current features fully working first. I’m sure somebody somewhere has a real Gonzo Obey file to throw at it. A feature I’d love to see is some sort of “-noerror” option. In that case, errors will be quietly written to Obey$Error (or whatever) and Obey will continue. But, that’s for another day. For now, testing what’s there does all the same things as Obey.
I’d be surprised if GCC didn’t throw a warning for “stuff that looks like coffee outside of a function”. I meant to write “code”. Autocorrect changed it to “coffee”. Not really my cup of tea, but hang on, I guess that’s as good a reason as any to go put the kettle on… :-) |
Timothy Baldwin (184) 242 posts |
On a per command basis, that already exist is the form of X, in the BootCommands module. } That’s because it is in a function. |
Paolo Fabio Zaino (28) 1882 posts |
Yup Rick, the code is in a function and it’s correct. It’s just a bit redundant the way it is now, however if Julie is planning to add extra logic between the 2 returns then it’s perfectly fine. I did not comment about GCC because even if it’s compiled with GCC the source does not appear to be using any gnu C dialect, so I pretty sure it’ll compile fine in DDE (obviously Makefile needs some changes for that). The ROM related statements/info from Colin are obviously correct (and also useful to know, so thanks for sharing!), but by the way I saw the source it doesn’t appear to be finished and ready for that conversion IMHO. So I assumed Julie wants feedback on the way the Module works and if we found any Obey file that failed working with CObey. Hope this helps |
Ronald (387) 195 posts |
. The first problem I would envisage is that the code is compiled with GCC and the roms are compiled using NorcroftI thought compiling with -mlibscl was the equivalent of norcroft. There must be other problems that stops GCC from compiling RiSC OS though. If it was just makefiles/build systems you’d think it could be done. a separate command for extended features may be a better way to go.Thats the way I see it too, luckily there are not many already used. The If Then Else is pretty limited, but adding a Case of cmd would fill the gap. I think it could even be useful in the convention of doing it one line, because it would be more compact, but more importantly would cope reliably and predictably with a lot of cases. The one line convention may be linked with the exec-ing another file? user input could be done with ReadLine32 either internally or in an external C program returning it’s argument as a system variable containing the line and sys$returncode could have the number of characters. It could be that you could just return a string in sys$returncode for a compact version. You would need something else for grabbing stdout from another program. That is one place where the rules are different between unixlib and libscl and it could be tricky. Possibly would need a scrap/tmp interface to work across the board. |
Colin (478) 2433 posts |
I don’t use gcc so don’t know it’s details. The assembler file in Julie’s code is not like those in the rom sources so unless the asm compiler can compile those files it would take some work. Judging by the changes to makefiles related to GCC I occasionally see in the repository I suspect someone is trying to get gcc to work.
I meant it may be better to leave Obey alone for legacy programs (you don’t know if adding more key words will break anything) and introduce an ExObey command/file with more features – if more features are wanted. It would be difficult to write an obey file for your program with the extended features as you would be concerned that some one else may not have a version of the module with extended features so you just end up not using them. BASIC has the same problem. |
Steve Fryatt (216) 2105 posts |
It should be possible1 to use ObjAsm format .s files with AsAsm, however, and that’s part of the GCCSDK. I’ve no idea if it’s included with the native GCC, though. 1 In the sense that I do, for all of my ASM-based projects. It’s been a while since I’ve assembled on on RISC OS, but they used to work. |
Jeffrey Lee (213) 6048 posts |
It is. |
Rick Murray (539) 13840 posts |
Does GCC support all the flexibility of the Norcroft macros? I am under the impression that the main issue isn’t so much what the code looks like, but what the macros look like. |
Ronald (387) 195 posts |
If the Arm cpu development as ended as far as RISC OS is concerned, and if the existing assembler version works, it could be a good reason not to introduce a C version, and do it another way. Sticking to one line (new) commands I guess Obey would try to run the non keyword as a program, and the remaining line would go as argument(s) when one is found. |
Timothy Baldwin (184) 242 posts |
It erroneously sets Obey$Dir before opening the obey file which means commands like “ |
Rick Murray (539) 13840 posts |
About bloody time! https://unicode.org/emoji/charts-13.0/emoji-released.html#1fad6
Sounds suspiciously like a workaround for something architecturally lacking. |
Julie Stamp (8365) 474 posts |
Good spot Timothy. I know someone here mentioned Obey$File before. You might want an Obey$ErrorFile to go with Obey$Error so you know where it came from. Thanks for all your comments guys :-) I will have to bite the bullet and cross into DDE land :-/ I wanted to get reassurance that it had a chance of being accepted before I go to all that effort, so the response is encouraging. |
Charles Ferguson (8243) 427 posts |
I’ve ported the makefile and some of the code to work with the ancient stuff I work with, and… well, it works. I haven’t sorted out the running of tests just yet, but the result is up at: https://github.com/gerph/cobey You can find the built version by following the green tick and going to the artifacts off the RISC OS build linked there. Tiny proof that it works: https://asciinema.org/a/345529 I’m not convinced that you should have any of the NewApplication stuff in there, because you don’t want Obey to deregister its handlers when another application starts. However, I’ve only skimmed the code, so I could be wrong about what that’s doing. Also, there’s a lot of faffing with OS file handles. Why not just use C file handles? Whilst you can use C as a meta-assembler, it’s a lot nicer to actually use it the way that it’s meant to be. Plus it means you can re-use that code in unit tests. |
Chris Hall (132) 3554 posts |
Also, there’s a lot of faffing with OS file handles. Why not just use C file handles? Do C file handles respond correctly to the *Close and *Shut commands? |
Stuart Swales (1481) 351 posts |
I’ve always used OS file handles (on all platforms) in commercial products (as opposed to internal tools) as you treat them like any other OS syscall interface, expecting to get sensible errors back to present to the user, rather than unhelpful C errno values |
Steve Fryatt (216) 2105 posts |
In what way? They’re just a wrapper around an OS filehandle, with some additional bits required by the C library. |
Julie Stamp (8365) 474 posts |
Charles, Obey has to remove its environment temporarily when an application starts because it isn’t an application itself, and the actual application needs to get a chance to remove its handlers. The example given in the original source is calling an Obey file from BASIC. More explicitly, if you go Supervisor → BASIC → Obey, then running an application, say *Repeat, should cause it to end with an OS_Exit going to Supervisor. Hopefully one day the kernel will be able to do this itself, without the old handler addresses being hidden away inside somebody’s app slot. Interesting addresses you have there for the workspace block?! |
Charles Ferguson (8243) 427 posts |
Yup, that’s right. I’d assumed it was because you were unthreading the obey module as if it were an application, but I see that’s not the case itself. BASIC has always been a somewhat ugly case, because it expects to only ever be the thing that’s running. Moving to a more process-based system would remove the need for the ugliness that the C libraries use to ensure that they can run sub tasks, and allow BASIC to be freed from its BBC-like heritage. As for the workspace block, the RMA lives (by default) at &7000000 on the OS I’m running for testing 1. 1 Amusingly, it’s found at least 3 bugs in the OS and environment, by just running the CObey module and its tests, so yay for that. |
Charles Ferguson (8243) 427 posts |
I turned on Fortify, and ran a simple one line test, and it showed up a warning about possible free twice: https://asciinema.org/a/345702 Line 306 is here: https://github.com/gerph/cobey/blob/fortify/c/main#L306
I suspect this is because in process_lines you call `close_obey(this, TRUE);` which will `free(this);`, but when you return back to main_command, you then check this and free it if it’s valid. If you really are handing off ownership of this to process_lines, then you should insert a `this = NULL;` immediately before the call to process_lines (and obviously pass the correct this value). |
Pages: 1 2