2022-03-20 00:19:29 So, on a related note, running a word that executes BL WORD will skip the next line of input. I wonder if maybe a nice set of features along the line of #ifdef could be rolled up using these input stream munging ideas. 2022-03-20 00:20:10 Might be useful for loading tools that can be configured different ways. 2022-03-20 00:21:14 In FIG the ( word did this kind of thing - it would just drop everything up to and including the closeing ) 2022-03-20 00:22:53 Or, as early as FIG, rather. 2022-03-20 15:02:32 Ugh. Not the next *line* of input - the next *word*. 2022-03-20 15:34:36 I think I'll steal this forth again 2022-03-20 15:34:38 https://gist.githubusercontent.com/lbruder/10007431/raw/4b87f81da0adddbf38c7531d6325f6b513cb5e47/lbForth.c 2022-03-20 15:35:03 I have to make an xlib game in order to reproduce an old amiga game 2022-03-20 15:35:18 but I have to use C for that 2022-03-20 15:35:38 https://www.youtube.com/watch?v=_X3u8Y3MQNc&ab_channel=Spillhistorie.no 2022-03-20 15:37:15 https://imgur.com/a/svRFNN6 this is what I have in C 2022-03-20 15:38:00 it's a window with the shape of the image 2022-03-20 15:38:36 I could just add builtins to this forth and use that instead of C 2022-03-20 15:48:45 hmm I'll run into problems I guess 2022-03-20 15:49:11 the stack only understands numbers and I need to manage some structs 2022-03-20 15:49:37 should I make it from scratch 2022-03-20 15:49:41 Yes. 2022-03-20 15:49:46 ACTION cries 2022-03-20 15:49:56 Keep pointers to structs on the stack and write words to do the struct operations. 2022-03-20 15:50:31 Once you've done that, though, then you've got the source and can load it up and use it whenever you need to. 2022-03-20 15:50:39 So it's worth thinking through a "nice" implementation. 2022-03-20 15:50:54 didn't want to take so much time for making this simple game 2022-03-20 15:51:08 I'm only doing it because I want to please an old amiga fan 2022-03-20 15:51:23 but I could end with a nice forth 2022-03-20 15:52:24 I'll try from scratch 2022-03-20 15:52:34 I don't like to have code that's not mine 2022-03-20 15:52:59 *uses libraries while saying this* 2022-03-20 15:57:15 ok I'll make a very dirty non forth 2022-03-20 16:10:02 I like writing my own stuff too. Satisfying. 2022-03-20 16:36:29 I cry because I just wanted to make a very little game and end making my own language instead 2022-03-20 16:36:50 I always do this kind of stuff and that's why I never finish anything 2022-03-20 16:37:40 I'll just make a reverse polish notation language with a stack 2022-03-20 16:37:57 don't know if I really want the return stack 2022-03-20 16:38:26 I think I could make a transpiler instead but I'd like something interactive 2022-03-20 16:39:58 didn't touch C in a long time 2022-03-20 16:40:07 need to relearn basic stuff 2022-03-20 16:40:53 Oh, I hear you man, and feel your pain. I'm the worst about not following through. 2022-03-20 16:42:01 Back around 2000, which I regard as the high point of my career, I had a team of engineers to assign the piddly little details to, and we got tons of good stuff done. When it's just me I still have a lot of fun planning everything and hammering through all the little "architecture niceties," but then I get bogged down in all the tedious implementation details and never finish. 2022-03-20 16:42:34 "Imagining" complex systems if fun. Doing all the work to make them real often isn't. 2022-03-20 16:42:49 Because to make something real even the boring work has to be done. 2022-03-20 16:43:39 I don't know why I like to do that but I cannot "stop" it 2022-03-20 16:43:50 Same here - it's just a part of who I am. 2022-03-20 16:44:03 it's for example if I want to make a website I end wanting to make a framework to make the website on that 2022-03-20 16:44:19 and to make the framework I want to create a language for it first 2022-03-20 16:44:32 and so on xD 2022-03-20 16:44:36 I once started on an online chat system, that was intended to be totally end-to-end encrypted, peer to peer, etc. 2022-03-20 16:44:41 and this is why I have no website :/ 2022-03-20 16:45:02 I did manage to slam through enough CSS to make it look nice in a browser, but never "finished." 2022-03-20 16:45:15 but somehow forth seems to be the solution to our problem 2022-03-20 16:45:28 I knew "how" it would do everything, but that's a far cry from having it actually do it. 2022-03-20 16:45:49 And sometimes that planning part is big and involves a lot of work, and I'll stick to that like glue. 2022-03-20 16:46:10 anyways maybe it's just better to make gforth work with ffi here 2022-03-20 16:46:15 When the boring work comes, though, I try, but usually find myself lured off into some other arena of interest before very long. 2022-03-20 16:46:37 but then I'll add a dependency I'm not sure the guy will be able to satisfy 2022-03-20 16:47:02 and even if it's able to, I'd prefer something that just compiles in a fresh system install 2022-03-20 16:47:24 anyways, I'll start trying 2022-03-20 16:47:57 I'd like the stack to be able to manage all the kinds of data I need in Xlib 2022-03-20 16:48:19 but does not sound nice 2022-03-20 16:48:39 maybe just some words for those structs or idk 2022-03-20 16:50:49 and I still have to learn forth XD 2022-03-20 16:51:22 ACTION blames himself 2022-03-20 16:54:26 KipIngram: I also jump to another thing constantly 2022-03-20 16:54:47 how do you end finishing stuff? 2022-03-20 16:55:09 I loose interest so fast I just jump to another thing 2022-03-20 16:57:39 Some things I wind up coming back around to. 2022-03-20 16:58:10 When I picked this nasm Forth up a week and a half ago or so, it had been sitting untouched for like 10 months or something like that. 2022-03-20 16:58:26 Took a few days to get back up on top of it - little details to remember and so on. 2022-03-20 16:58:38 I've kind of got it back in hand now. 2022-03-20 16:58:58 yes I think the key is to save the code 2022-03-20 16:59:21 I end rewriting stuff I wrote time ago a lot of time 2022-03-20 16:59:56 And it was oh so close to being "quite functional" too. Mostly just needed number printing (which I've done a quick temporary implementation of now) and disk I/O, which I did the last three days or so. Now it can BLOCK and LOAD, so it's all set for me to move development out of nasm and into "itself." 2022-03-20 17:00:21 I would say typical feature wise it's like 97% or something complete. 2022-03-20 17:00:33 I need to implement VOCABULARY and its supporting words. 2022-03-20 17:00:56 FIND already knows how to search a list of vocabularies, and CURRENT already exists to specify where new dictionary entries go. 2022-03-20 17:01:06 But at the moment there's only the FORTH vocabulary. 2022-03-20 17:01:33 Other than that it's basically already a full Forth. 2022-03-20 17:01:36 well you don't have to stick to the standard, but it seems you want 2022-03-20 17:01:57 seems a wise choice anyways 2022-03-20 17:01:59 Well, I don't know if my particular way of doing vocabularies is standard - probably not. 2022-03-20 17:02:04 I didn't consult any standards. 2022-03-20 17:02:16 I just wrote it. :-) 2022-03-20 17:02:45 My thinking is probably more FIG Forth than it is anything since then, but there may be an influence or two from later in it as well. 2022-03-20 17:03:22 My FIND doesn't have a variant return, depending on whether or it succeeds or not, the way FIG FIND did. 2022-03-20 17:03:33 It just returns either the CFA of the sought word or zero. 2022-03-20 17:03:58 I don't really like words that don't have a consistent return structure. 2022-03-20 17:04:16 Unless that's the whole point, like it is with ?DUP. 2022-03-20 17:04:26 If I make a forth, the only "forth" thing will have it's rpn and a stack 2022-03-20 17:04:58 and I'm wondering if the stack will just manage numbers or several kind of data 2022-03-20 17:05:02 Well, just try to understand how common Forths work. I didn't when I wrote my very first one ever and it was horrid. 2022-03-20 17:05:14 It behaved like a Forth, but internally it was a mess. 2022-03-20 17:05:32 And this stuff has been very well thought through, as I later learned. 2022-03-20 17:05:33 and that's another thing, I have to learn forth 2022-03-20 17:05:53 this is why I crt 2022-03-20 17:05:54 cry 2022-03-20 17:06:02 ACTION wants to make a game 2022-03-20 17:06:03 That first one was in 6809 assembly, on a TRS-80 Color Computer. 2022-03-20 17:06:12 ACTION has to implement a forth 2022-03-20 17:06:17 ACTION has to learn forth first 2022-03-20 17:06:23 That would have been in, like, 1983 or 84 or so. 2022-03-20 17:06:44 I was born in 93 2022-03-20 17:07:00 :-) 2022-03-20 17:07:11 63 for me. 2022-03-20 17:07:17 1963, that is. 2022-03-20 17:07:56 ok I'll make a forth in perl and use it to learn forth 2022-03-20 17:07:58 XD 2022-03-20 17:08:28 maybe I'll get things clearer later in order to do the C version 2022-03-20 17:09:04 I don't know Perl. I do know that you can build a "real" Forth, (in that it operates like a real Forth) in GNU C. 2022-03-20 17:09:27 That C has non-standard extensions (pointers to labels) that let you make a real inner interpreter vm. 2022-03-20 17:09:34 I've learn perl because I thought as a unix user I should learn awk 2022-03-20 17:09:39 With primitives little C one-liners. 2022-03-20 17:09:48 I think awk can be a handy tool to have 2022-03-20 17:10:02 Yeah, a lot of those Linux tools are handy. 2022-03-20 17:10:14 I admire how Linux lets you accomplish things. 2022-03-20 17:10:14 but then saw perl was like an evolution of awk + a general purpose language 2022-03-20 17:10:27 so I had some time wondering which one to choose 2022-03-20 17:10:29 By piping together a bunch of those little utilities. 2022-03-20 17:10:56 awk is posix so it's a nice "feature" and the learning curve is much easier than the perl one 2022-03-20 17:10:56 Ah, I didn't realize that. I've heard of them both but didn't know they were related in any way. 2022-03-20 17:11:19 but on the other side, perl is much more powerful and it's almost omnipresent 2022-03-20 17:11:25 I've gotten pretty good with sed, but still basically have to look up anything I do in awk. 2022-03-20 17:11:37 choose perl and resulted to be much more useful than what I thought 2022-03-20 17:11:59 I know people brag about how terse perl code can be. 2022-03-20 17:12:07 It does sound awfully powerful. 2022-03-20 17:12:07 specially for a person like me who can't stop jumping from one thing to another, perl at least let's me have some little script done before I jump 2022-03-20 17:12:35 Sure, yes - there's something to be said for having a "working foundation" to start with. 2022-03-20 17:12:55 it's weird but I think I wrote more code in perl than any other language, so it seems I've made a good choice 2022-03-20 17:13:25 I want something like Linux streams and "pipes" in this Forth, but I don't have any sort of clear picture about how that should work yet. 2022-03-20 17:13:43 but I want to be able to use it similar to the way I use bash. 2022-03-20 17:13:55 I'd really like it if I could make the Forth my Linux shell. 2022-03-20 17:14:01 KipIngram: hmm 2022-03-20 17:14:17 well idk in asm, in C you have pipe and dup 2022-03-20 17:14:25 you could just use that 2022-03-20 17:14:32 I figure I need a file system first, to have a place to keep up with the stream content. 2022-03-20 17:14:50 but as you don't seem to have an operating system on top of that forth... 2022-03-20 17:15:01 then you have to start by creating exec 2022-03-20 17:15:06 But it's kind of alien concept in Forth - Forth wants to grab direct hold of the keyboard, screen, etc. 2022-03-20 17:15:07 exec and fork I suppose 2022-03-20 17:15:34 Yeah, I would need to do that if I intend to actually launch stuff from that "shell." 2022-03-20 17:15:51 once you have those making pipes should be easy 2022-03-20 17:16:03 Well, and a file system. 2022-03-20 17:16:19 could be just temporary memory space, but yes 2022-03-20 17:16:23 But thing is, if it's a Linux shell I'd have to use Linux files, wouldn't I? 2022-03-20 17:16:43 But I'd like to have streams even if the Forth is the full OS, so I'm really talking about two different targets here. 2022-03-20 17:16:54 Linux shell is probably within easier reach. 2022-03-20 17:17:05 depends if you plan to run your forth on top of linux or as standalone "operating system" 2022-03-20 17:17:09 Because yeah, I'd really just be using the streams it already supports. 2022-03-20 17:17:19 if you go for standalone then you have a lot of work to do 2022-03-20 17:17:24 I'm interested in both. 2022-03-20 17:17:32 But like I said, they're "different." 2022-03-20 17:17:35 if you go for linux you could use some syscalls I guess 2022-03-20 17:17:47 Most of the thinking I've put into it has been oriented around it being a standalone OS. 2022-03-20 17:18:09 but if I were you and focused in linux I think I'd add some c code 2022-03-20 17:18:29 then you have a lot of libraries that make your life easier 2022-03-20 17:18:48 if you refuse to use C, then some syscalls 2022-03-20 17:18:56 I don't really have the Linux shell target thought through well enough to define it much yet. 2022-03-20 17:19:00 idk how would you "cooperate" with linux if not 2022-03-20 17:19:23 if you want standalone, you'll make an operating system 2022-03-20 17:19:44 Right now it uses Linux syscalls to do all of its device I/O, and to do an initial allocation of RAM (which I then manage from internally). 2022-03-20 17:20:04 Uses a couple of termios syscalls, but that's just to get initialized and restore on exit. 2022-03-20 17:20:40 At the Forth level, KEY still is associated in a hard-wired way with the keyboard, and I know if I want it to have any sort of native stream capability (stand-alone os picture), I'll have to relax that. 2022-03-20 17:20:46 I think I would add C code and just make bindings for exec fork pipe dup etc 2022-03-20 17:20:50 KEY and EMIT will need to be vectors that I can re-target. 2022-03-20 17:20:56 but maybe you don't want to add C 2022-03-20 17:21:02 I'd prefer not to. 2022-03-20 17:21:23 A major goal still waiting for me is to get it to be able to re-build itself. 2022-03-20 17:21:28 never used syscalls so I have no idea then 2022-03-20 17:21:38 Then in theory I put nasm away for good and maintain it using it. 2022-03-20 17:21:53 Which means I'll need enough of an assembler to write the primitives with. 2022-03-20 17:22:05 That turns out to be not much of an assembler, though. 2022-03-20 17:22:24 what do the forths that let you add asm code? 2022-03-20 17:22:41 they compile it to binary directly? 2022-03-20 17:22:42 And it mostly uses a portion of the x86_64 instruction set that is very sensibly encoded and doesn't require a lot of hoop jumping to output. 2022-03-20 17:22:54 I've got some work toward that goal from the last implementation already done. 2022-03-20 17:23:13 Yes, they generate the machine code directly. 2022-03-20 17:23:24 You have some Forth words that are basically assembly opcodes. 2022-03-20 17:23:47 and that's how you'll do? 2022-03-20 17:23:49 For the main instructions you need for writing a Forth it's fairly straightforward. The monstrous nature of the full x86_64 instruction set isn't a problem. 2022-03-20 17:24:00 That's the goal, yes. 2022-03-20 17:24:09 :0 nice 2022-03-20 17:24:17 I actually plan to interpose an additional layer that you could think of as assembly macros. 2022-03-20 17:24:26 you're a masochist like me I think 2022-03-20 17:24:35 Those macros would be designed to be the only thing that had to port to go to a new instruction set. 2022-03-20 17:24:43 but you have more experience so you can suffer more 2022-03-20 17:24:46 :D 2022-03-20 17:24:47 The primitives would be written USING those macros, and would be portable. 2022-03-20 17:25:25 Picking the right macros, so that I can wind up with efficient primitives for either x86_64 or ARM - that's an ongoing task for me. 2022-03-20 17:25:50 as long as you get fun doing it and you learn it's a big win always 2022-03-20 17:25:56 That might mean having some macros that are "empty" on the x86_64 but not empty on ARM, or vice versa. 2022-03-20 17:26:21 Since x86_64 is CISC and ARM is RISC, there are some differences in the power of the instructions. 2022-03-20 17:26:33 Like you can't do arithmetic directly using RAM operands on ARM. 2022-03-20 17:26:44 Gotta use MOV to bring it into a register first. 2022-03-20 17:28:34 I feel like this "recompile" ability isn't horribly far away for me. Once I have my old editor ported and working, it's really sort of the first thing I should start addressing. 2022-03-20 17:29:20 I just want a forth with c ffi 2022-03-20 17:29:29 Some of the plumbing is already in place - like, I have two versions of HERE, one for the "running system" and one for the "target system." Normally they match, but if I'm recompiling the system the target version will be pointing off somewhere into a disk buffer. 2022-03-20 17:29:42 and that works in netbsd 2022-03-20 17:29:47 The compiler uses that second one already. 2022-03-20 17:30:16 but I need a temporary forth to learn forth first 2022-03-20 17:30:20 ffi sounds interesting. I've seen some references to it, but have never "dug in." 2022-03-20 17:30:45 KipIngram: idk how gforth does, I was socked to see how easy is to add bindings 2022-03-20 17:31:01 bindings? 2022-03-20 17:31:06 I suppose it creates some c code and just compiles it (I have no other idea) 2022-03-20 17:31:07 Sounds like some fancy thing. 2022-03-20 17:31:09 c ffi bindings 2022-03-20 17:31:12 Oh, I see. 2022-03-20 17:31:38 https://rosettacode.org/wiki/Draw_a_pixel#Forth 2022-03-20 17:31:44 look at this example 2022-03-20 17:31:46 Well, as I said, most of my thinking has been in terms of this being a standalone OS, so I've paid almost no attention to "wiring it to outside tools." 2022-03-20 17:32:01 it uses the c sdl library 2022-03-20 17:32:09 Except where I had to, like keyboard input, screen output, etc. 2022-03-20 17:32:21 my reason is Xlib 2022-03-20 17:32:39 I need Xlib.h Xpm.h and shape.h 2022-03-20 17:32:52 no language will give me the 3 bindings except C 2022-03-20 17:33:12 Right now it opens a file blk.dat at startup and saves the handle for the block stuff to use. It would be easy enough for me to add an ability to switch that to arbitrary other files, but I haven't. 2022-03-20 17:33:51 well I've done the same with common lisp clx as it provided xshape extension and used an image format very easy to parse so I was able to translate it to a pixmap 2022-03-20 17:34:08 We talked about list here in channel a year ago or so, for several days. 2022-03-20 17:34:11 but my algorithm was slow 2022-03-20 17:34:17 I got interested enough to dig into how lisp works inside. 2022-03-20 17:34:29 I love it 2022-03-20 17:34:43 I decided that it would be fairly trivial to allocate a second big slug of RAM and have a simple lisp engine live "concurrently" with the Forth. 2022-03-20 17:34:52 Forth could pump strings into it and get strings back from it. 2022-03-20 17:34:54 but I have some interest in forth 2022-03-20 17:35:06 some people had tried to convince me to learn prolog 2022-03-20 17:35:17 but forth interests me more, idk why but I like it 2022-03-20 17:35:20 I don't know about "fancy powerful" LISPs, but the basics looked fairly straightforward to build. 2022-03-20 17:35:33 it's easy to make a lisp 2022-03-20 17:35:46 even to implement macros is easy as long as it's an interpreter 2022-03-20 17:36:16 Neat thing about running those side-by-side is that it would be a good thing to devote a second core to. 2022-03-20 17:36:17 the interpreter just looks if a function name correspond to a macro, then calls that macro and evaluates whatever the macro returned 2022-03-20 17:36:37 Just be careful with the interface, but the insides of the lisp would be the other core's business. 2022-03-20 17:37:10 but I think there is no need for lisp macros if you have forth 2022-03-20 17:37:23 and even that you can make a forth with macro-like features 2022-03-20 17:37:25 And that brings up another thing - I do want the Forth to be able to multi-task and make use of multiple cores. 2022-03-20 17:37:38 oh 2022-03-20 17:37:43 But right now my I/O is blocking - I'll need to relax that to move in that direction. 2022-03-20 17:38:09 That's a reason I was happy to find that ostep book the other day - looks like it's got some good info in that direction. 2022-03-20 17:38:25 sounds like hard stuff 2022-03-20 17:38:25 It's been decades since I've really studied operating systems in any deep way. 2022-03-20 17:38:41 but anyways you'll end making an operating system 2022-03-20 17:38:48 Well, I think of it as "involved" stuff - not really hard ideas, but a lot of details to get right. 2022-03-20 17:39:09 And a lot of ways to step in poo. 2022-03-20 17:39:10 for me it sounds like it adds a nice level of complexity 2022-03-20 17:39:29 but I suppose it depends on how you tackle it 2022-03-20 17:40:12 I'm lazy to make a forth in C 2022-03-20 17:40:41 but making it in perl has no sense as what I want is C libraries 2022-03-20 17:41:01 btw KipIngram if you're kind of interested in lisp I liked a scheme implementation a lot 2022-03-20 17:41:13 I don't like scheme but it's an exception for me 2022-03-20 17:41:14 For a little while I thought my stack frames would make a nice way for a child task to "help out" with some primary task - just by sharing the frame pointer and working on parts of the frame. But that would be likely to run into cache sharing issues that would clobber performance. 2022-03-20 17:41:32 it's written in ansi C and you can add your own stuff very easily 2022-03-20 17:41:34 The two tasks would be diddling around with RAM too close to the same spot. 2022-03-20 17:41:48 https://ccrma.stanford.edu/software/snd/snd/s7.html 2022-03-20 17:41:54 Oh, cool - thanks. 2022-03-20 17:42:04 ACTION opens a browser tab... 2022-03-20 17:42:12 it's s7 scheme I've had so much fun playing with it 2022-03-20 17:42:43 basically you just add s7.h and s7.c to your C code and it's like "take this scheme and do whatever you want with it" 2022-03-20 17:42:47 That's a pretty extensive webpage. 2022-03-20 17:42:56 yes, it needs documentation 2022-03-20 17:43:14 the documentation is enough for almost all you'll want to do with that scheme 2022-03-20 17:43:31 Another thing I want to do someday is do my own processor in an FPGA. A native Forth processor, so to speak. 2022-03-20 17:43:56 it has several examples for adding C data types and alike 2022-03-20 17:44:10 I've got some notes somewhere on the innermost parts of that, and a decent encoding for 32 instructions. 2022-03-20 17:44:18 it's nice cause you can make C data structures behave like native scheme types 2022-03-20 17:45:01 actually is an implementation with the only goal of being a lisp with c ffi library 2022-03-20 17:45:15 you just take it and add your own stuff 2022-03-20 17:45:24 but meh, you have your own forth 2022-03-20 17:47:09 I had fun with it, but won't be my own language 2022-03-20 17:47:27 Well, my own Forth that doesn't necessarily play well with others. :-) 2022-03-20 17:47:48 Knowing a lot of inter-operatble tools is a good thing. 2022-03-20 17:48:12 s/operatble/operable/ 2022-03-20 17:48:47 I aim for C ffi more than a standalone thing 2022-03-20 17:49:07 I'd like to be able to add whatever libraries I'll later need 2022-03-20 17:49:24 which forces me to write it in C 2022-03-20 17:49:44 well I can embed perl in C :D 2022-03-20 17:49:53 and extend perl with C 2022-03-20 17:53:19 Well, sounds to me like you're closer to accomplishing useful things than I am. I'm kind of off in a little esoteric mind space just "hobby-ing around." 2022-03-20 17:53:25 But, I have fun. 2022-03-20 17:57:56 KipIngram: not really 2022-03-20 17:58:08 and I'm kind of cheating if we compare what we do 2022-03-20 17:58:27 anyways if I want to have a useful forth I can implement it in perl 2022-03-20 17:58:48 I'm able to do the stuff you want to add like pipes and alike for free 2022-03-20 17:59:18 `command executed in shell` if you type this in perl it will get executed as a shell command 2022-03-20 17:59:42 and you have open able to "open" a command so you can write to the input and read output 2022-03-20 18:00:18 actually for me perl is the best scripting language I know 2022-03-20 18:00:36 and yes people use python instead but that does not mean is better suited than perl for this task 2022-03-20 18:01:17 so if you want a "scripting" forth if you make it in perl you have it for free 2022-03-20 18:01:35 but that's not what you really want knowing you don't even want to add C xD 2022-03-20 18:02:12 and the knowledge you need for what you're doing can't be compared to the knowledge needed for what I am doing 2022-03-20 18:02:38 I'm basically cheating 2022-03-20 18:07:46 btw this is how you make a perl interpreter in C 2022-03-20 18:07:48 https://termbin.com/e6vr 2022-03-20 18:08:00 cc pl.c `perl -MExtUtils::Embed -e ccopts -e ldopts` and compile it with this 2022-03-20 18:08:33 this way you have the whole perl embedded in your C program 2022-03-20 18:09:28 yet you need perl installed :D 2022-03-20 18:16:30 I think it would be better to just make gforth work here 2022-03-20 18:17:02 idk if I can but should be able to 2022-03-20 21:11:19 should I use function pointers or a big switch case for primitive words? 2022-03-20 21:11:46 function pointers seem cleaner than having a fucking big switch case, but meh 2022-03-20 21:12:19 I'll do it as dirty as I can :D 2022-03-20 21:12:24 so a switch case 2022-03-20 21:14:58 hmm now does not seem nice to do a strcmp for every possible word 2022-03-20 21:15:13 do you convert the word to an index? 2022-03-20 21:15:20 I think I'll do that 2022-03-20 22:30:33 ahahahah 2022-03-20 22:30:44 https://termbin.com/gbbm 2022-03-20 22:30:57 it's a shame to show this code but idc 2022-03-20 22:31:13 the whole code is a joke and I need to start again from scratch 2022-03-20 22:31:28 and there's not even a dictionary or alike 2022-03-20 22:31:36 Well, when I did it in GNU C I used pointers to labels, and built a proper indirect threaded interpreter. 2022-03-20 22:31:51 it just "executes" hardcoded strings 2022-03-20 22:32:16 and the best feature is I don't fucking care if the word is not all numbers 2022-03-20 22:32:20 Yeah - most Forths that people write up in HLL's like that aren't "really Forth." They just bear a superficial functional reemblance. 2022-03-20 22:32:32 if I find a number in the first char I assume it's a number :D 2022-03-20 22:32:38 so 3fhrejsdnf is a number 2022-03-20 22:33:05 Well, Forth just first tries to look the number up in the dictionary. If that fails, it then tries to convert it to a number. And only if that fails also does it throw an error. 2022-03-20 22:33:22 KipIngram: this is what I'll do, just steal concepts from forth, but won't be a forth 2022-03-20 22:33:26 Which means numbers are expensive - the whole dictionary has to be searched before you start thinking "number." 2022-03-20 22:33:31 anyways this code sucks so much I cannot continue 2022-03-20 22:33:45 and I think pop and push are fucking broken 2022-03-20 22:33:56 I need to implement a proper circular stack 2022-03-20 22:34:17 KipIngram: I do that too 2022-03-20 22:34:22 I first check for a number 2022-03-20 22:34:30 but anyways there only exist 3 words 2022-03-20 22:34:42 My inner interpreter for that C version was something like "w=*(ip++); tmp=*(w++); goto tmp;" 2022-03-20 22:34:42 ahahaha 2022-03-20 22:34:46 Or close to that. 2022-03-20 22:34:53 Don't have it in front of me. 2022-03-20 22:35:14 I need to rewrite it and fix everything 2022-03-20 22:35:29 but I suppose it helped me a bit to get an initial idea 2022-03-20 22:35:33 Then the primitives were little bits of C that ended in that sequence. 2022-03-20 22:35:41 anyways I'm not thinking in the return stack or the dictionary 2022-03-20 22:36:01 but I'll do it that way, shit code and incrementally improve it 2022-03-20 22:36:01 I used "register" for the important performance variables, but have no idea whether the compiler honored that or not. 2022-03-20 22:36:20 That was one motivation for going to nasm - to be 100% that what was happening was as good as I could make it. 2022-03-20 22:36:41 KipIngram: I liked the register feature, but I've read usually the compiler knows better than the rpogrammer and that sometimes was even ignored 2022-03-20 22:36:59 Given the relocatability requirements MacOS imposed, my guess is that it was NOT using registers in as good a way as possible. 2022-03-20 22:37:09 I use 12 of the 16 registers in my architecture. 2022-03-20 22:37:25 And I don't touch rsp at all, so that's a 13th. 2022-03-20 22:37:55 I only have rax, rbx, and rdx that aren't used at all. 2022-03-20 22:38:12 Well, except for scratch - I certainly *use* them. But they don't have any "persistent meaning." 2022-03-20 22:38:54 I have to think about the dictionary 2022-03-20 22:39:08 I suppose I'll have an array of function pointers 2022-03-20 22:39:26 and convert words to their corresponding number 2022-03-20 22:39:53 KipIngram: I always wanted to learn asm, but never had a real usage case 2022-03-20 22:40:02 maybe except now (forth is a use case) 2022-03-20 22:44:46 KipIngram: what if I make the stack accept an union of types? 2022-03-20 22:45:43 I liked the perl implementation as the stack was able to receive any scalar value 2022-03-20 22:48:00 well it's better to just add fetch and store at least for strings 2022-03-20 22:48:18 but I have no idea about how will I operate with structures and alike 2022-03-20 22:49:39 Yes, Forth is definitely a valid use case. 2022-03-20 22:49:50 It's the only way to take full control of the processor resources. 2022-03-20 22:50:33 Well, you can certainly do something like that. I think if I were setting out to do that I'd have the stack contain pointers only - pointers to "things" that themselves could be anything. 2022-03-20 22:50:44 I'm kind of headed that way now, except not "universally." 2022-03-20 22:51:15 hmm 2022-03-20 22:51:21 I need to relearn C 2022-03-20 22:51:22 I'll still keep the usual stuff on the stack. But once I get this new memory management stuff up and going then one possible stack item will be a 64-bit "typed pointer." 2022-03-20 22:51:44 The built-in Forth words won't know what to do with that, but I'll be able to write words that do. 2022-03-20 22:51:50 and want a circular stack 2022-03-20 22:52:01 The stack item will be a pointer and the items themselves will live in the memory allocation structure. 2022-03-20 22:52:22 And there's room in a 64-bit address for plenty of address and type information. 2022-03-20 22:52:33 I've played with apache a bit and saw the apache portable runtime 2022-03-20 22:52:47 it's a library apache uses but not tied to apache 2022-03-20 22:53:03 I always thought a language implementor could benefit from that library 2022-03-20 22:53:21 I usually find tight little portable vms interesting. 2022-03-20 22:53:26 as it gives a lot of "portable" implementations of stuff usually a language dos 2022-03-20 22:54:03 some of them are circular buffers, hashes memory pools, threads, sockets 2022-03-20 22:54:15 does* 2022-03-20 22:54:42 but I want something tiny with no dependencies 2022-03-20 22:54:44 Yeah. I ultimately want to be able to write things that will have the sort of functionality that Octave has - handle vectors, matrices, that type of thing. 2022-03-20 22:54:55 Stuff that will not ever "live on the stack." 2022-03-20 22:55:04 But yet I want the "base system" to be essentially pure Forth. 2022-03-20 22:55:29 For that Octive type thing I'll write a whole replacement interpreter, which I use when I want to do numeric processing and then quit out of when I'm done. 2022-03-20 22:55:30 apr is nice as it has memory pools which ensure stuff will have a lifetime and then free accordingly 2022-03-20 22:55:47 and learning apr is learning apache internals 2022-03-20 22:56:05 bucket brigades are circular buffers and the memory pools are apr pools 2022-03-20 22:56:16 ACTION hates the bucket brigades 2022-03-20 22:56:20 :D 2022-03-20 22:57:36 KipIngram: you really don't fear having lots of stuff to do 2022-03-20 22:57:44 :-) 2022-03-20 22:57:59 I generally don't go in for self-deallocating RAM. 2022-03-20 22:58:06 I don't mind knowing when to free things. 2022-03-20 22:58:32 Having the system able to figure out when no one's looking at something any more implies some overhead I'd rather do without. 2022-03-20 22:58:41 yes I don't think you'd like the apr anyways 2022-03-20 22:59:10 knowing you prefer to implement everything for yourself it's like going the opposite way 2022-03-20 22:59:34 but always think a language implementor could benefit a lot from the apr 2022-03-20 22:59:50 you get a lot of stuff for free and the same portability as apache 2022-03-20 22:59:52 Yeah, I love absorbing ideas. 2022-03-20 23:00:20 if you just rely on the apr it's likely you won't have machine dependent code 2022-03-20 23:00:59 I should use it as I'm trying to get a C forth 2022-03-20 23:01:11 but at least not for now 2022-03-20 23:07:24 If your stack contains pointers to structured objects, then you can have type information either in the stack cell itself or in the object pointed to by the stack - at any rate, you have access to it. And if you are replacing the interpreter/compiler, you can replace it with one that considers the "type structure" of the top stack items when searching for a word match. 2022-03-20 23:07:32 Raises the possibility of overloading word names. 2022-03-20 23:07:55 * with a pair of reals on top of the stack would be a different word from * with a real and a vector. 2022-03-20 23:08:00 Etc. 2022-03-20 23:08:23 The nice thing about that is it's a compile-time decision process - once a word is compiled, it's still fast. 2022-03-20 23:09:19 I've contemplated having that more advanced interpreter have a separate "type stack," so that I could know the type even when the stack item was just an int or whatever. 2022-03-20 23:09:35 oh 2022-03-20 23:09:37 You'd have to keep up, though, with what the type effects of words were as you compiled. 2022-03-20 23:09:45 I was wondering if having several stacks 2022-03-20 23:10:01 a type stack looks like a good idea 2022-03-20 23:10:11 The type effect of a new definition could be computed from the type effects of the words in that definition. 2022-03-20 23:10:17 but you could have one stack with type info 2022-03-20 23:10:38 You could. More to keep up with, so I don't want it in my "base system." 2022-03-20 23:10:46 But as an "add on"? Sure. 2022-03-20 23:10:55 i don't think I will 2022-03-20 23:11:16 I'm not fan of types 2022-03-20 23:11:35 Over time I've learned that trying to get too fancy from the ground floor using winds up not turning out well. 2022-03-20 23:11:35 but idk if make the stack handle more than numbers 2022-03-20 23:11:45 So I've been brutally simple with this new one so far. 2022-03-20 23:12:03 and having several stacks is an idea sometimes comes to me 2022-03-20 23:12:33 but it looks like a wrong decision 2022-03-20 23:12:50 I did one thing that isn't pretty "standard." I have a lot of "conditional jump" words. Basically several for each of the basic conditional - a plain one, one with a 0 default argument, etc. 2022-03-20 23:13:05 And all of those need an offset immediately following the compiled code word. 2022-03-20 23:13:29 The compiler doesn't know to put that in a normal Forth, so you wind up needing a corresponding immediate word for each one that will compile it and put the offset. 2022-03-20 23:13:59 I added a bit identifying those words to my header, and made my compiler just a little smarter - if that bit is set, then it adds the offset following the compiled word. 2022-03-20 23:14:40 The only place I ever jump to is back to the beginning of the current definition, so it can figure that out. 2022-03-20 23:15:02 So they're conditional recursions - only kind of jump in my system. 2022-03-20 23:20:00 hahaha 2022-03-20 23:20:09 I think I'll add macros to this one 2022-03-20 23:20:30 well not sure, it was weird 2022-03-20 23:21:11 I've tried with a perl implementation it had lists by pushing delimiters on the stack 2022-03-20 23:21:29 and if you put 'word the word was pushed on the stack as a string 2022-03-20 23:21:36 There's a very old book Chuck once wrote, talking about an early vision of Forth. It something more akin to macros than to definitions. 2022-03-20 23:21:54 there was also an evaluation_list of words that acted of some sort of return stack 2022-03-20 23:22:10 it just had all the words of the program and went executing them one by one 2022-03-20 23:22:17 you could add words to that list 2022-03-20 23:22:32 I mean lisp macros 2022-03-20 23:22:44 It also talked about some rather interesting virtualization techniques using disk blocks. 2022-03-20 23:22:54 the implementation of a lisp macro is very easy as long as you have an interpreter 2022-03-20 23:23:39 but I didn't saw the reason of having lisp macros in that forth 2022-03-20 23:23:53 I could add words to the current execution and quote words 2022-03-20 23:24:11 and you could put several quotes in a word XD 2022-03-20 23:24:15 like '''''word 2022-03-20 23:24:40 every time the interpreter saw a quoted word just removed one ' of it 2022-03-20 23:25:05 so 'word being evaluated would remove the ' and the next time the word would get executed 2022-03-20 23:25:11 http://exemark.com/FORTH/ChuckMooreBook.pdf 2022-03-20 23:28:37 I may have to look through that again. Clearly the language evolved a lot after that was written - in a lot of ways what we've got now is a lot better. But there are still some interesting tidbits that are "ideas to consider." 2022-03-20 23:37:15 I've downloaded it 2022-03-20 23:38:43 xd I like how starts 2022-03-20 23:38:56 "Im not sure why you are reading this book" 2022-03-20 23:47:33 I've read it a bit some time before 2022-03-20 23:48:04 I remember the phrase "conspire to add features" 2022-03-20 23:48:24 but what is the book about KipIngram 2022-03-20 23:48:32 it's about how to implement forth? 2022-03-20 23:53:17 It's about some very early thoughts Chuck had on what became Forth. 2022-03-20 23:53:23 Something you said up above reminded me of it. 2022-03-20 23:53:34 I wouldn't use it as a how-to for writing a Forth. 2022-03-20 23:53:41 For that use that McCabe book.