2022-05-18 04:29:55 hello? 2022-05-18 04:30:05 hi 2022-05-18 04:30:18 oh hey sorry it's my first time on libera 2022-05-18 04:30:32 oh cool welcome 2022-05-18 04:31:00 you are on the channel for Forth the programming language 2022-05-18 04:31:46 so I got interested in forth some time ago and had some time to try it out today, I'm using gforth and was wondering what is the preferred way of obtaining standalone forth executables? 2022-05-18 04:32:06 since all forth environments I've encountered so far are interpreters 2022-05-18 04:32:44 i'm not sure! 2022-05-18 04:33:11 crc knows stuff 2022-05-18 04:33:38 other people too, but crc is my go-to guy :-) 2022-05-18 04:33:46 so do I just ask them? 2022-05-18 04:33:55 yup 2022-05-18 04:34:17 you might have to wait for a reply 2022-05-18 04:34:25 sure 2022-05-18 04:34:29 irc has gotten a little slower over the years :-) 2022-05-18 05:21:49 Hi janmaslo. 2022-05-18 05:21:55 Hey dave0. 2022-05-18 05:23:31 janmaslo: Forth is intended as an "interactive" language; it's one of its "core concepts" so to speak. The way interact with it is by telling the interpreter words. It looks them up and executes them. However, you can also define new words, which is how you "extend" the Forth system. 2022-05-18 05:24:11 I can't think of any real reason a forth "regular compiler" couldn't be written, but that would lose the interactivity that's such an important thing in the language. 2022-05-18 05:24:34 So it's not really that it "can't" be done - it just usually "isn't" done. 2022-05-18 05:25:09 You can load Forth source from a disk file or disk blocks - that's a form of "non-interactive compilation." 2022-05-18 05:25:22 But you usually do that from inside Forth, rather than from an operating system prompt. 2022-05-18 05:28:46 Getting a stand-alone executable; the method would vary from Forth to Forth, and some may not offer the feature. I'm not super familiar with the "population of Forths" out there, but my guess is that what you find more frequently is the ability to snapshot your "current system" to disk, which would give you an executable that loaded up as an interpreter but with stuff you added already built in. I.e., it 2022-05-18 05:28:48 would just write out a Forth with an expanded dictionary. 2022-05-18 05:30:16 An easy jump from there would be to offer you a mechanism to run a "default start-up word," which could be the application you wanted an executable for. But that would also include all the parts of the Forth system you hadn't needed to make your app go. Probably the least common thing you'll find will be a Forth that lets you make a stand-alone application that skins out all the pieces you didn't really 2022-05-18 05:30:18 need. 2022-05-18 05:32:30 Here is an old Google Groups thread that may be germane to what you're interested in: 2022-05-18 05:32:33 https://groups.google.com/g/comp.lang.forth/c/4SXd2euVE0g 2022-05-18 05:37:34 most forths don't have compilers to generate standalone executables 2022-05-18 05:39:30 You see, a typical Forth is put together as a "dictionary" of words; usually a few hundred of them. These words depend on one another, building up functionality as they go, which means that they "point to each other's location" within the file. 2022-05-18 05:40:05 Writing out a stripped down executable that excluded words unnecessary for your particular job would involve changing all those pointers, and that's just not how most Forths are written to work. 2022-05-18 05:40:38 Once a word is compiled, it never moves - it has a permanent fixed location within the system and that location can be used to refer to it. 2022-05-18 05:41:14 You could go "zero out" words that you didn't want to use, but that wouldn't re-locate the words you were using. 2022-05-18 05:41:34 Again, this isn't because "it can't be done" - it's just that it's not commonly done. 2022-05-18 05:41:57 for gforth, you can create turnkey images. These still need the main gforth executable to run. See https://gforth.org/manual/Modifying-the-Startup-Sequence.html and the various other pages in the images section of the manual. 2022-05-18 05:42:33 When you compile a standalone executable in a language like C, the same thing happens - all the C code in your source file gets machine code corresponding to it, and that code is put somewhere in the executable. The understanding is that you included only the C code that is needed. 2022-05-18 05:42:45 Some C compilers are smart enough to leave out functions that never get called. 2022-05-18 05:43:52 Most standalone forth compilers will be turnkey based, as KipIngram describes, with the majority (or all) of the actual Forth system present (though possibly hidden) in the resulting binary. 2022-05-18 05:44:09 Almost every Forth system, though, starts out with a collection of words, and you just add more. There is no mechanism for pruning words out. 2022-05-18 05:44:56 But Forth systems can be very small, so this is hardly much of a penalty these days. 2022-05-18 05:45:14 i guess if you could store the dictionary as a doubly linked list instead if you did want arbitrary word pruning 2022-05-18 05:45:54 You can also find Forth systems that crosscompile for some target microcontroller board or something like that. Those sometimes have a way of carefully controlling what winds up on the target, and often you don't even get a dictionary on the target - it resides on the host. 2022-05-18 05:46:23 whoelse: that doesn't account for the compiled code though 2022-05-18 05:46:28 It's not just the list structure - the issue is that if you move where a word "is" in the image, you have to then update every reference to that word. 2022-05-18 05:48:57 Once a word is compiled, it's not always easy to tell (except by executing the word) which bits of the word are references to other words, which are literal numbers, which are strings, etc. 2022-05-18 05:49:48 When you have a literal number or string in a compiled word, it's generally preceeed by an executable cell that expects to be followed by a number or a string and will properly jump the instruction pointer over it at run time. 2022-05-18 05:50:55 Usually, though, there won't be any "roadmap" information anywhere in the system that says "this word will be followed by a number." 2022-05-18 05:51:12 "This word" is just implemented by CODE that presumes there's a number following. 2022-05-18 05:51:33 So when you execute that word, the code does the right stuff. 2022-05-18 05:51:51 But that "structural fact" isn't "defined" in any orderly way in the system. 2022-05-18 05:52:35 You could imagine including a field in the header that described any inline arguments the word took, but that's not necessary and it's not common. 2022-05-18 05:54:14 You could also imagine having the header describe what the word expected to find on the stack, but that's not common either - once again, the implementing code just "does what it does," and you learn what each word expect on the stack and write your code in a way that provides that. 2022-05-18 05:56:47 janmaslo: I've recently taken an interest in the APL programming language and we've discussed it a bit here. One of our members (eris, I think) pointed out that you can't parse APL without executing it. So Forth isn't the only language you find around that's "naturally interpretive." 2022-05-18 05:56:59 might be easier to just keep an additional dictionary for preserving word sources, and then allowing your "standalone executable" compiler evaluate each word's source in this extra dictionary at "standlone compile" time 2022-05-18 05:58:31 Yeah, I was just sitting here thinking that the best way to get this would be to have some sort of "scriptable" *system* compilation. You'd pass over the user's source and note which words were going to be needed, and then you'd "make" a system that just compiled the original source for those words only. 2022-05-18 05:59:05 Combine that with a way to know how to "start up" the final result. 2022-05-18 05:59:38 You'd basically be creating a custom Forth, potentially severely whittled down and not even offering an interpreter, when you compiled your application. 2022-05-18 05:59:49 This probably wouldn't be that hard to do if you had it in mind from the very start. 2022-05-18 06:00:49 It would just be an automated version of me going through my nasm source, removing a bunch of words I wasn't going to need, and assembling something new. 2022-05-18 06:01:31 But you'd then be faced with the need to compile the additional application Forth the user supplied, and I'm not sure how you'd do that without a starting Forth that could compile. 2022-05-18 06:02:01 I'm sure it could be dealt with, but it would just use something very different from the "stock Forth system." 2022-05-18 06:02:23 It's just not really what Forth "is," so it's not floating around out there all over the place. 2022-05-18 06:03:19 janmaslo: What is your target system? If it's a "normal computer" like the ones we all use everyday, I'll just reiterate how small Forth systems usually are - that excess baggage you're not using isn't going to penalize you terribly much. 2022-05-18 06:04:08 If you're targeting some restricted environemtn microcontroller, then you're just going to have to see if a Forth-ish tool for it exists out there. Or write one. 2022-05-18 06:06:33 One of my goals for the Forth I'm working on is for it to be able to recompile itself. That will probably involve using the "host Forth" (the one actually running) to compile an image for the "target Forth" (the new one) - once I've got that I'll probably be pretty close to having something that could create small images for a totally different target. In that case the problems I alluded to above would be 2022-05-18 06:06:35 dodged by using the resources of the host Forth to do all the work. 2022-05-18 06:06:56 While creating an image that could then be separately saved off and run on whatever device it was intended for. 2022-05-18 06:07:56 But most Forths don't do that - they just offer the ability to extend the "host Forth." 2022-05-18 06:08:50 There's an old system out there called "forthos" that is intended to be a bare metal x86 Forth - it can run on a machine with no other operating system. It has the ability to rebuild itself. 2022-05-18 06:09:41 But it's not something you can "just run" on your notebook; you have to jump some hoops to "deploy it" on a machine. 2022-05-18 06:12:10 Anyway, if I were you I think I'd go look for a Forth that can write out an executable snapshot of itself and which has a mechanism for specifying that when it's executed some word you choose should be "auto run" at startup. 2022-05-18 06:12:50 That will let you get the behavior of a standalone executable. You'll have the excess baggage you're not using in there, but I think your chances of finding an existing system that avoids that are low. 2022-05-18 06:16:24 Here's a link to creating image files in gforth: 2022-05-18 06:16:25 https://gforth.org/manual/gforthmi.html 2022-05-18 06:17:26 It has an --application option that looks like it might be interesting to you. 2022-05-18 06:19:54 A common way of using Forth is to leverage the interpreter as the basis of your application's user interface. In cases like that, then you wind up actually *wanting* most of that "baggage" I've referred to above. 2022-05-18 06:20:47 The book "Thinking Forth" (available online in pdf form) talks more about this, and is generally a great reference on the "philosophy" of using Forth. 2022-05-18 11:33:39 Love that book 2022-05-18 11:34:09 It's how I learned the language yeeeears ago on.. The Amiga of all things :) 2022-05-18 11:48:41 pfCatch: Unrecognised token = 0x108 at 0x0 whoops 2022-05-18 12:02:11 Yeah, that one and Forth Fundamentals by McCabe are my faves. TF is better for "using the language", and FF for the "nuts and bolts."