2022-03-24 00:29:41 Well, I caught gdb pretty red-handed failing to properly step away from the breakpoint. It of course replaces the byte at the break address with the 0xCC opcode. But when I then "step," it's supposed to put the original byte back and a new 0xCC at the first byte of the next instruction, and RUN THE FIRST INSTRUCTION. It's not doing that properly - I can tell from inspecting the registers. 2022-03-24 00:30:13 To get a clear picture of what was going on I had to add a new label at the end of the handler and break there, and inspect the final results. 2022-03-24 00:30:38 Also, dings on gdb for not allowing a breakpoint to be set at an ADDRESS. 2022-03-24 00:31:20 I shouldn't have had to add a label - I should be able to slap a break anywhere I want, and I'd be taking responsibility for making sure it was at the first byte of an instruction. 2022-03-24 00:31:53 dollars to donuts that when it was written it was written with C in mind. 2022-03-24 00:33:50 So, where am I as the day ends. I found a reference that gave the offsets for each register in that context structure. I used those to write my code - what it's trying to do is aim the context rip at NEXT and the context r13 (the Forth IP) at ERR, and load an 8 error code into context rcx (top of stack). So I'm just trying to return to 8 ERR. 2022-03-24 00:34:21 That "doesn't fail." It doesn't do 8 ERR, and it inserts a bogus character into the input stream, but the system continues to run. 2022-03-24 00:35:07 However, I can tell by looking at the RAM region pointed to by rdx that those offsets aren't right. It LOOKS like the offsets should all be 0x28 higher. But if I change the code to do that (and confirm that the block was changed in all the right ways), I segfault. 2022-03-24 00:35:24 So, further along than this afternoon, but... ugh. 2022-03-24 00:35:30 Doesn't feel like a near thing yet. 2022-03-24 00:39:18 It really bothers me to see the docs and what I see in gdb fail so completely to mesh. 2022-03-24 00:45:58 Ah... here: 2022-03-24 00:46:01 https://stackoverflow.com/questions/18913859/what-is-the-right-way-to-operate-ucontext-t 2022-03-24 00:46:33 There is some description of the context structure, and it shows five 8-byte items PRIOR TO the general registers in the structure. That's 0x28 bytes. 2022-03-24 00:46:53 That makes what I see in RAM match with the offsets I found - the offsets would then be within the register part of the structure. 2022-03-24 00:47:19 Unfortunately, that works "less well" than the other, though that may just be becaue I'm therefore messing with more innocuous registers. 2022-03-24 00:47:39 I mean, it doesn't get much less innocuous than rip and Forth IP. 2022-03-24 01:18:01 You know, one possible issue here, which isn't really long-term relevant given what I'm ultimately trying to do (catch faults that occur while I'm executing my self-contained primitives), might be the fact that when I get these SIGINT signals I'm running a syscall. Though I don't think the interrupt actually occurs until I return to user space. But specifically I'm in key, so that might explain why I get a 2022-03-24 01:18:04 ghost character. 2022-03-24 01:18:23 But I never run the code that actually responds to that, so I don't know. 2022-03-24 01:18:44 I really think I'm doing exactly what I thought I wanted to do to the context. 2022-03-24 01:19:05 Not seeing any reason yet why it shouldn't work. 2022-03-24 01:35:15 Well, I'll be damned. 2022-03-24 01:35:41 I shifted tack - I abandoned the SIGINT and tried SIGFPE instead (floating point error). That's a goal anyway. 2022-03-24 01:35:50 And... it *works*. Flawlessly. 2022-03-24 01:36:03 12345 ok 2022-03-24 01:36:05 ok 2022-03-24 01:36:07 ok 2022-03-24 01:36:09 ok 2022-03-24 01:36:11 ok 2022-03-24 01:36:13 1 2 3 4 5 0 / /: floating point error 2022-03-24 01:36:15 . 12345 ok 2022-03-24 01:36:34 That is EXACTLY what it's supposed to do - it's supposed to revert away the earlier part of the line. 2022-03-24 01:37:03 nice KipIngram ! 2022-03-24 01:37:47 It works for SIGSEGV too now. 2022-03-24 01:38:05 There's just something about being in the middle or aftermath of a syscall that fouls it up. 2022-03-24 01:38:13 but that's not even where I really wanted it. 2022-03-24 01:38:24 DAMN IT WORKS!!!!!! 2022-03-24 01:38:31 lol 2022-03-24 01:38:32 What a nice gift to go to bed on. 2022-03-24 01:38:41 you got the programmer's high :-) 2022-03-24 01:38:42 This was a deep dive day, man. 2022-03-24 01:38:49 Absolutely. :-) 2022-03-24 01:39:14 Ok, well, now I need another one - I want floating point errors and addressing errors. Those were the goals. 2022-03-24 01:39:17 But... tomorrow. 2022-03-24 01:39:22 Heh heh heh... 2022-03-24 01:42:57 well, I guess that's not a FLOATING point error. 2022-03-24 01:43:00 Arithmetic error. 2022-03-24 01:46:27 Night guys. Time to rest. 2022-03-24 02:02:10 nite KipIngram 2022-03-24 04:10:56 KipIngram: You never leave user space 2022-03-24 04:11:28 The signal is invoked and the main thread halts, the signal runs on a new stack but is running in userspace 2022-03-24 04:11:58 The ghost character for ^C I would guess is the character code of ^C being forwarded to the program's stdin 2022-03-24 04:12:48 Also nice, yeah when I get back to my FORTH I have plans to do the same thing: catch errors like divide by zero and segfaults 2022-03-24 04:14:30 I am going to implement exceptions so I will have it cause an exception throw 2022-03-24 04:14:54 And I shall probably steal your code to do this lol 2022-03-24 06:09:52 The starting forth editor is actually quite usable, a few minor modifications to the preview words at the end of a command and it is not far off from using vi with only basic string matching 2022-03-24 06:37:46 BCPL seems to have some nicer stuff than B or C 2022-03-24 06:43:09 oh? 2022-03-24 06:50:55 eris[m]: The ternary in BCPL is written -> , so you can write e.g. https://pastebin.com/raw/37U2W1hZ 2022-03-24 06:51:45 https://www.cl.cam.ac.uk/~mr10/bcplman.pdf 2022-03-24 06:52:14 Some example programs pp.245- 2022-03-24 06:53:32 Seems to have implicit end-of-line semicolon as well 2022-03-24 07:03:32 Unfortunately it suffers from B's problem of "what are bytes lol" 2022-03-24 08:03:12 @ gets an address and ! dereferences 2022-03-24 09:51:14 So is there some prohibition on x86_64 / Linux against loading the processor stack pointer? At one point yesterday I tried to write it, using a value that I had earlier read from it, and that didn't seem to want to work. 2022-03-24 09:51:21 It was late - I didn't follow up on it. 2022-03-24 09:51:56 I don't use rsp myself - generally it keeps whatever value it starts out with all the way through, except for when I do syscalls. 2022-03-24 09:52:25 The idea was to restore it to that value on error recovery, just in case it had "grown some" during the handler shenanigans. 2022-03-24 09:54:23 I may have just had some silly mistake. I just wrote a quick primitive that just copies rsp to rax and then copies it back - that didn't give any problem. So it's not some specially enforced restriction. 2022-03-24 09:56:22 Must have just been a slip up - it seems to work fine this morning. 2022-03-24 10:05:56 KipIngram: Some signals don't allow changing the stack 2022-03-24 10:06:27 Which makes sense, signals that just notify of something shouldn't, signals that indicate the thread crashed should 2022-03-24 10:12:32 It seems to be fine to do what I wanted this morning. I must have just made a "sleepy error" last night. 2022-03-24 10:13:26 So, when the addressing or floating point exception is actually generated by one of my primitives (which means I'm nowhere near a syscall), this works perfectly. If it's sitting there waiting for a keystroke, though, and I externally send it a sig 8 of sig 11, it hangs. 2022-03-24 10:13:43 So this whole apparatus doesn't play well with syscalls. 2022-03-24 10:13:59 But that's not really where I need it, either. 2022-03-24 10:16:42 An external signal sent while I'm in a loop (syscall free) works fine - it just interrupts the loop. 2022-03-24 10:36:59 Hmmm I'm sure there's some way of getting it to work while it's suspended 2022-03-24 10:38:30 KipIngram: Relevant? https://stackoverflow.com/a/32813165 2022-03-24 11:00:44 Yeah - I was thinking more about it. When I'm waiting for a keystroke, I'm suspended / asleep. Then the handler comes along and re-directs execution away from the code that's eventually going to wake me back up. So it's probably doing exactly what it's supposed to, but I'm asleep and have no way to wake up. 2022-03-24 11:01:28 The most brute-force thing to do would be to make the handler esaily switchable (I could just plug a return instruction into the first byte) and switch it off when I'm about to make a syscall and back on after. 2022-03-24 11:02:02 Then it should just ignore those signals if they're externally sent during a syscall. 2022-03-24 11:22:49 KipIngram: Have you looked at the stackoverflow answer I posted though? 2022-03-24 11:23:07 Not yet - troubleshooting something else at the moment. 2022-03-24 11:23:18 Okay because it looks like it could answer the problem 2022-03-24 11:41:24 Ah, so maybe I need the SA_RESTART flag. 2022-03-24 11:41:38 That does look on point. 2022-03-24 12:10:57 That seems to have done the trick. 2022-03-24 12:11:16 I still need to avoid taking the error recovery action if I'm in a syscall. 2022-03-24 12:11:36 But now if I plug a ret into the handler I no longer get the "shadow keystroke" 2022-03-24 12:11:42 Signal is just cleanly ignored. 2022-03-24 12:11:55 Thank you - that was spot on. 2022-03-24 12:12:44 So anyway, I'm not going to plug rets routinely - I'm going to have a small handful of these for different faults. I'll add a switch variable and have them all check it. 2022-03-24 12:13:24 Now that I know where my registers are in the stack context I can get at stuff like that. 2022-03-24 12:14:10 Of course, there are "gotchas" here. 2022-03-24 12:14:46 What if I send EXPECT a bad buffer address? It's not going to access that buffer itself - it's going to pass it into a read syscall. 2022-03-24 12:14:55 So the violation would occur IN the syscall. 2022-03-24 12:15:11 But anyway, forward progress here. 2022-03-24 12:21:12 Guess I could FILL the buffer before calling EXPECT. 2022-03-24 12:21:25 Then if it has any bad addresses, they'd fault on the fill. 2022-03-24 12:21:54 Or no - not that. Have EXPECT fill the buffer before making tye syscall. That's what I was thinking, even though it's not what I said. 2022-03-24 12:22:26 FILL is "rep fast." 2022-03-24 12:23:02 And that has the fringe benefit of clearing out old content. 2022-03-24 14:10:16 Ok, I added a switch and wrappered the few syscalls in my code with it. It now behaves extremely well - signals are ignored while I'm in a syscall and otherwise responded to. 2022-03-24 21:20:25 Finally got around to writing .wipe, so now "helper words" actually means something. 2022-03-24 21:20:40 Makes quite a difference - I have a whole bunch of helpers. 2022-03-24 21:20:54 hey KipIngram 2022-03-24 21:21:03 maw dave0 2022-03-24 21:21:12 sup? 2022-03-24 21:21:23 Not a lot. Just a routine work day. 2022-03-24 21:22:11 i should do some documentation! 2022-03-24 21:22:30 i've been putting off commenting my sectorFORTH 2022-03-24 21:23:49 KipIngram: i re-wrote sectorforth (https://github.com/cesarblum/sectorforth) from scratch and it works but i have to finish the code comments 2022-03-24 21:24:07 Is that the one that fits in one disk sector? 2022-03-24 21:24:12 yup 2022-03-24 21:24:16 Something tight would probably need comments. :-) 2022-03-24 21:24:34 There's bound to be some "cleverness" in there that bears explaining. 2022-03-24 21:25:07 the real interesting thing is the `hello.forth` which builds up a forth to print "hello world" 2022-03-24 21:25:25 I'm really more or less at the point where I could start working on my editor with comment support and so on. 2022-03-24 21:25:46 Yeah, that would be interesting. Bootstrapping is generally an interesting topic. 2022-03-24 21:25:47 cool 2022-03-24 21:27:05 rp@ pushes the address of the return stack pointer onto the data stack, which i use to make zero! : 0 rp@ rp@ - ; 2022-03-24 21:27:26 it's funny to me that you have to build the number `zero` 2022-03-24 21:29:47 Why not just : 0 dup - ; ? 2022-03-24 21:30:45 Of course, I even build 0 in assembly, technically - I push top of stack and then xor rcx, rcx. 2022-03-24 21:31:39 You know in "pure math" they do stunts like that - successive numbers are defined in terms of a "successor" iterator. 2022-03-24 21:32:06 They "build up" the natural numbers that way, when they're bootstrapping the whole shooting match. 2022-03-24 21:39:42 sectorFORTH has the primitives: : ; @ ! - nand 0= sp@ rp@ key emit and variables last here >in state 2022-03-24 21:40:06 sp@ pushes the current address of the data stack, rp@ does it for return stack 2022-03-24 21:40:13 : dup sp@ @ ; 2022-03-24 21:40:39 : 0 rp@ rp@ - ; and then : 1+ 0 0= - ; 2022-03-24 21:40:51 so it sort of uses the successor thing like you said :-) 2022-03-24 21:41:46 it was quite fun writing that 2022-03-24 21:57:38 Ah, I see. 2022-03-24 21:58:19 Interesting. 2022-03-24 21:58:50 So I guess it promises "true" is 1? 2022-03-24 21:59:00 Sorry - I mean -1. 2022-03-24 21:59:13 Dave0: that looks like fun. I have been playing with a 65816 forth that someone else developed but it is a bit too much to understand. This looks simpler with very few moving parts. 2022-03-24 22:03:01 So, no , ? 2022-03-24 22:03:14 Do : and ; behave as expected? 2022-03-24 22:03:31 KipIngram: yep, flags are 0 and -1 ... you coud also have used nand to make -1 but 0= is shorter :-) 2022-03-24 22:03:41 KipIngram: yup 2022-03-24 22:03:49 Yah - nand can do anything. :-) 2022-03-24 22:04:06 So it's got a whole interpreter compiler? And that fits in a sector? 2022-03-24 22:04:22 KipIngram: are you interested in having a look at it? i can zip up what i've got 2022-03-24 22:04:38 KipIngram: yup fully interactive, in a boot sector 2022-03-24 22:04:38 What's it written in? 2022-03-24 22:04:45 That's impressive. 2022-03-24 22:05:19 Nothing about the interpreter / compiler is "that hard," but by the time you get all the details tended to there's a fair bit there. 2022-03-24 22:08:15 KipIngram: https://paste.c-net.org/BobbieChopping 2022-03-24 22:11:15 Ok, that's pretty cool. I will want to look through that pretty carefully to see how it's put together. 2022-03-24 22:11:26 And you've got something you can run it on? 2022-03-24 22:11:47 oh i run it on dosbox 2022-03-24 22:11:57 Ah, ok. That counts. 2022-03-24 22:12:39 I've really been meaning to dig into some virtualization tools. I keep saying I want to write an OS - I don't actually have to wait until I design a piece of hardware. 2022-03-24 22:12:53 i did test the hello.forth file but it's tedious to type it all in (but it does work :-) 2022-03-24 22:13:32 KipIngram: i think writing an OS would be a lot of work! 2022-03-24 22:13:34 Mine's up to 18669 bytes now. 2022-03-24 22:13:45 That's the sum of the used body and header space. 2022-03-24 22:14:01 I've got that and the stacks living in a 64k buffer. 2022-03-24 22:14:25 oh is it for msdos? 2022-03-24 22:14:27 Well, where exactly the OS leaves off and one's tools begin - hard to say, I guess. 2022-03-24 22:14:54 No. It's intended to be portable. When I put it on a gadget someday it will just own all the RAM. 2022-03-24 22:15:06 oh nice 2022-03-24 22:15:11 And offer some sort of reasonable memory allocation tools. 2022-03-24 22:15:29 And some kind of file system, etc. 2022-03-24 22:16:06 i saw a homebrew cpu running minix and connected to the internet 2022-03-24 22:16:07 That bit about the blurry line between OS and tools is particularly true for Forth. It just sort of spans the whole gamut. 2022-03-24 22:16:21 Nice. I want to do an FPGA processor at some point. 2022-03-24 22:16:25 a forth os with tcp/ip stack and a web server would be awesome 2022-03-24 22:16:28 And would love to put those two projects together. 2022-03-24 22:16:47 I fancy having a "guaranteed back door free" computer that's actually marginally competent. 2022-03-24 22:17:00 i think chuck moore said an operating system is just a limitation in your programming langauge 2022-03-24 22:17:28 Sounds like something he might say. I do have some kind of notion that Forth "prefers" to run on bare metal. 2022-03-24 22:17:43 Running it under an OS keeps it from really shining quite as nicely. 2022-03-24 22:17:59 You wind up writing reams of stuff to interface to the existing OS, so you're really still having to use it. 2022-03-24 22:18:19 that said, I might try to turn this into my Linux shell at some point. 2022-03-24 22:18:28 That's another "project branch" I've thought about. 2022-03-24 22:19:01 It has NO notion of Linux right now, really. It uses a few syscalls, but there's no "systematic interface." 2022-03-24 22:19:42 I didn't really write it with the notion of mapping onto Linux nicely in mind - it's really written with a "stand alone" perspective. 2022-03-24 22:25:39 KipIngram: why do you think running forth under an OS keeps it from really shining? 2022-03-24 22:25:47 Looks like I currently have 336 words. 2022-03-24 22:25:53 I think yes, if it's a real forth 2022-03-24 22:26:00 That's after dropping all the helpers. 2022-03-24 22:26:43 but if you start making a language similar to forth then you can take the os to your advantage 2022-03-24 22:27:07 as long as you don't follow the forth 'specs' 2022-03-24 22:27:15 Well, like I said - because you have to operate "through the OS" to really "do" anything. 2022-03-24 22:27:47 I may just be being elitist. 2022-03-24 22:31:32 well forth dislikes an os, I agree 2022-03-24 22:31:50 he wants to be the os 2022-03-24 22:35:01 Yes. :-) 2022-03-24 22:35:35 I've rewritten my forth, now I've fixed a bug I had, couldn't use strings inside if, if-else, dotimes, etc 2022-03-24 22:36:04 and I think today I've written the most useful function in my life, a debug function xD 2022-03-24 22:36:33 it's just a function with an if to check if debug flag is on, I call it from all the functions I have 2022-03-24 22:36:35 How does that work? 2022-03-24 22:36:48 all functions call it passing some arguments 2022-03-24 22:36:53 I usually debug my Forth by staring at my code and inserting debug prints. 2022-03-24 22:37:18 I want a "real" debugger, but I'll have to write it and it will be a bit of a project. 2022-03-24 22:37:25 I want it integrated with the editor. 2022-03-24 22:37:58 I want it to use the "alternate console" - whenever I "go to debugger" (hit a breakpont, etc.), I want it to flip over to that console and draw the debug screen. 2022-03-24 22:38:08 Keep the primary console available to the application. 2022-03-24 22:38:54 Have a nice display that shows me my registers, my Forth stacks, whatever memory I've opted, etc. And a call tree. 2022-03-24 22:39:15 KipIngram: this is mostly what I do, but with a global flag 2022-03-24 22:39:24 which is pretty closely related to the return stack, so it's probably just a fancy labeling on the return stack. 2022-03-24 22:39:43 and I can put names of functions in a debug array so the debug function will print stuff only if called from those functions 2022-03-24 22:40:13 debug knows who is calling it, prints the name of the function which called it + the arguments given 2022-03-24 22:40:37 if there are no items in the debug array then prints for all functions 2022-03-24 22:41:31 That sounds kind of handy. 2022-03-24 22:41:32 https://termbin.com/gt1h if you want to try it you can just put some code and it will show all the functions 2022-03-24 22:41:44 it's a perl script so perl file.pl 2022-03-24 22:41:57 and has no readline, rlwrap or similar would be nice 2022-03-24 22:42:09 if you put just a 1 you'll see a lot of stuff 2022-03-24 22:42:20 has almost no builtins, but now if and dotimes work 2022-03-24 22:42:39 3 { "some text" . } dotimes 2022-03-24 22:42:51 you can disable the debug with 0 core-debug 2022-03-24 22:43:05 and turn on it again with 1 core-debug 2022-03-24 22:44:10 strings can have interpolation with other strings or numbers using ~a and ~% is a newline 2022-03-24 22:44:24 ~a takes an item from the stack and just puts it there 2022-03-24 22:44:58 it is handy btw, it helped me a lot to catch the bugs very fast as it's like a trace 2022-03-24 22:45:03 That sounds a little like the formatted output I put together on my last one. 2022-03-24 22:45:15 I mean every function says what it finds and what does/transforms to 2022-03-24 22:45:28 It "works" like TYPE, but if it seems format fields in the string it will take a stack argument for each one, and print it per the format field specifications. 2022-03-24 22:45:43 It was a pretty damn complete "printf like" setup. 2022-03-24 22:45:57 Used a bytecode interpreter to "execute" the format fields. 2022-03-24 22:46:15 That little vm had a "stack" of byte-wide items living in a 64-bit cell. 2022-03-24 22:46:18 I like what I have, I was worried last time I've tried because strings didn't work when used inside if or alike 2022-03-24 22:46:53 but sure I'll find some bug showing how bad the design is and I'll have to rewrite it XD 2022-03-24 22:47:04 instead of return stack I have an execution stack 2022-03-24 22:47:39 the interpreter is a loop that checks if there's data in that stack and just executes a word from there 2022-03-24 22:47:40 My "implementation before the previous one" was written in GNU C, and it was just so horrible looking I could hardly believe it. 2022-03-24 22:48:01 hahha mine is dirty surely 2022-03-24 22:48:48 and I'm not following the forth way, I shouldn't even say it's a forth like 2022-03-24 22:49:03 Hey, you're interested and that's cool. 2022-03-24 22:49:16 it just has a stack and rpn, but no return stack and no memory allocation 2022-03-24 22:49:41 but the stack can take any value including lists, and you can quote words with ' they'll get pushed on the stack 2022-03-24 22:50:15 and now that i've fixed that issue I can start adding builtins 2022-03-24 22:50:24 it can compile yet with : and ; 2022-03-24 22:50:37 and I've added [ and ] but idk what will happen 2022-03-24 22:50:42 didn't tried them 2022-03-24 22:51:59 I'm fond of [ and ] 2022-03-24 22:52:18 I don't really use them a particularly large amount, but I just like how easy you can switch back and forth. 2022-03-24 22:52:46 My most common thing is to use [ to end definitions that don't need a return at the end (because they loop back to the start). 2022-03-24 22:52:59 I think they are working 2022-03-24 22:53:06 Only the compile time part of what ; does is needed in that situation, and that's what [ is. 2022-03-24 22:53:12 Excellent. 2022-03-24 22:53:35 : oh 1 2 3 [ 4 5 6 ] ; pushes 4 5 6 on the stack 2022-03-24 22:53:36 As someone who was just desperately hoping something would work this time last night, I'm happy for you. :-) 2022-03-24 22:53:48 Looks good. 2022-03-24 22:53:56 Now does oh push 1 2 3? 2022-03-24 22:54:06 it does 2022-03-24 22:54:10 and only those 1 2 3 2022-03-24 22:54:24 Gold star. 2022-03-24 22:54:31 every time I execute, 4 5 6 never got into the definition 2022-03-24 22:54:46 Yup. 2022-03-24 22:55:53 but what should happen if I don't put a ] on the word definition? 2022-03-24 22:55:58 should be an error? 2022-03-24 23:01:21 seems to work anyways but not sure 2022-03-24 23:01:32 Well, it depends on how you handle end of line, I guess. 2022-03-24 23:02:00 In Forth if you don't use ; then you won't get a return, and unless there's some way you know you won't try to execute past there, Forth will just run off into the weeds. 2022-03-24 23:02:29 In my case there's an unconditional jump, so I know I don't need (;) (the runtime piece of ; ). 2022-03-24 23:03:07 : oh 9 8 7 [ 4 5 6 ; compiles oh and the stack then is { 4 5 6 } 2022-03-24 23:03:17 In old FIG Forth the header of your next word would be right there, but I deliberate put my headers remote so that I could put definitions literally right by each other and let execution pass along like that. 2022-03-24 23:03:21 if I execute oh then the stack is { 4 5 6 9 8 7 } 2022-03-24 23:03:23 That was an explicit plan. 2022-03-24 23:03:42 and stills putting 9 8 7 every time i call it 2022-03-24 23:03:53 I don't care about newlines 2022-03-24 23:04:01 well I'll try 2022-03-24 23:04:41 Reason I thought of it is that someone here in channel suggested to me a few days ago that since I always write short definitions I could let end of line end the definition. 2022-03-24 23:04:47 I'm not doing that, but it was a valid idea. 2022-03-24 23:05:25 it does not care about newlines, seems to work anyways 2022-03-24 23:06:07 I think that's as it should be. 2022-03-24 23:06:08 the fact is ; is immediate so does not care when is executed, it ends compiling mode, and uses a global array that holds the contents of the word definition 2022-03-24 23:06:25 In my past efforts I've not had newlines even supported. 2022-03-24 23:06:33 the word being defined is also global 2022-03-24 23:06:39 I just treated 4 kB disk blocks as 64 lines of 64 chars each. 2022-03-24 23:06:48 So it lookedlike one long line to Forth. 2022-03-24 23:07:03 and only in compile mode the interpreter adds stuff to that word compile array 2022-03-24 23:07:22 Right. ; is immediate, and runs the minute it's encountered. 2022-03-24 23:07:36 But it will usually 1) compile a (;) and 2) set STATE = 0. 2022-03-24 23:07:44 And possibly tail optimize. 2022-03-24 23:08:09 : gets the word to be defined and sets $word_to_compile to that name and enters compiling mode 2022-03-24 23:08:20 Ok. 2022-03-24 23:08:48 Same with mine. : is immediate (I can define words in the middle of words: 2022-03-24 23:09:01 : foo ...code... : bar ...code... ; 2022-03-24 23:09:18 ; compiles and resets the word contents, but does not the name 2022-03-24 23:09:22 It CREATEs a new dictionary entry, makes it a : def, and enters compile mode. 2022-03-24 23:09:25 :0 mine is not immediate, 2022-03-24 23:09:38 it typically isn't. 2022-03-24 23:09:49 If you want to do that you have to separate your headers and bodies. 2022-03-24 23:10:43 never thought about nested definitions 2022-03-24 23:10:55 I could change $word_to_compile to an array 2022-03-24 23:11:10 I don't even have nested lists 2022-03-24 23:11:13 Well, I've found it useful, but it's certainly optional. 2022-03-24 23:11:29 I would generally put them on different lines: 2022-03-24 23:11:35 : foo ...code... 2022-03-24 23:11:41 : bar ...code ... ; 2022-03-24 23:11:50 but then I should have a list of lists to hold the contents for every word being defined 2022-03-24 23:11:58 hmm 2022-03-24 23:11:59 And if bar recurses, it will jump back to bar, not foo. 2022-03-24 23:12:14 and ; ends both? 2022-03-24 23:12:19 yes. 2022-03-24 23:12:31 I could make a way to insert stuff in a word 2022-03-24 23:12:34 It compiles (;) and switches to STATE=0. 2022-03-24 23:12:56 KipIngram: ah! i understand your words now :-) 2022-03-24 23:13:07 how they can share code 2022-03-24 23:13:14 Best way to think about the body section is to regard it as an array of 32-bit cells. 2022-03-24 23:13:22 The headers "point into it." 2022-03-24 23:13:54 Well, before the 32-bit cells for definitions there is the machine code for the primitives and so on, but I 4-byte align after that's all assembled. 2022-03-24 23:14:40 So you need the headers only at compile time - in theory if you were compiling some gadget application you wouldn't need to include them in the image you flashed. 2022-03-24 23:14:45 initially I was thinking in make ; pop some array so the next ; would end the previous definition 2022-03-24 23:15:00 and have an array of arrays for the words contents 2022-03-24 23:15:29 Yeah - if your underlying system can just regard definitions as lists of items, then you can just stop at the end of the list. 2022-03-24 23:15:37 it's a nice idea, I'll save it 2022-03-24 23:16:03 I'm using perl, this is why my forth is so different 2022-03-24 23:16:18 doing it in the forth way would be counter productive 2022-03-24 23:16:19 Right - I still think you're learning stuff. 2022-03-24 23:16:33 hahah yes, I didnt learn forth yet 2022-03-24 23:16:49 wanted a forth in C but I'll try to add ffi to this one 2022-03-24 23:17:11 wanted not, but I want to use some C libraries 2022-03-24 23:17:50 and actually I'm designing while trying stuff, that's why I think I'll have to rewrite several times 2022-03-24 23:18:05 I guess later some feature will show a flaw in design 2022-03-24 23:18:12 I regard this one as a "start over" of the last one. 2022-03-24 23:18:23 Last one was my first assembly language effort since college. 2022-03-24 23:18:35 Assembly language Forth, I mean. 2022-03-24 23:19:07 I rewrote mine from scratch, using some previous code as reference, but not pasting any line 2022-03-24 23:19:14 Very first one was in assembly, for the 6809. 2022-03-24 23:19:30 It was hideious. 2022-03-24 23:19:35 I have to learn asm, now I have a use case :D 2022-03-24 23:19:36 hidious 2022-03-24 23:19:48 asm is very nice - there are just no restrictions. 2022-03-24 23:20:15 Certain aspects of the structure you have to get right, though, or you'll find yourself unable to write anything. 2022-03-24 23:20:27 Usually your code is made unwritable. 2022-03-24 23:21:02 in Linux you can call mprotect to change that, but I just allocated a buffer with full rwx permissions and copied the whole system to it. 2022-03-24 23:22:00 That load image is still present, though - COLD uses it to make a fresh copy. 2022-03-24 23:22:52 forth has something that I like, but I have no idea of what is it 2022-03-24 23:23:17 vms14: i like how forth isn't c :-) 2022-03-24 23:23:25 btw my forth will overwrite previous definitions 2022-03-24 23:23:32 :-) 2022-03-24 23:23:33 it's a hash instead of linked list 2022-03-24 23:23:35 dave0: xD 2022-03-24 23:23:38 cool 2022-03-24 23:23:50 KipIngram: not so cool I guess 2022-03-24 23:24:10 Right now mine won't do that. 2022-03-24 23:24:22 can't forget but delete them 2022-03-24 23:24:51 and for me it seemed right that a previous word would use a previous definition 2022-03-24 23:25:06 I see a flaw the fact mine overwrites them 2022-03-24 23:25:36 vms14: oohh it only overwrites them in the hash table? the definitions still exist but no name points to them? 2022-03-24 23:25:58 dave0: definitions would get overwritten 2022-03-24 23:26:08 vms14: ooh not allowed to do that 2022-03-24 23:26:12 and previous words using those, will now use the new one 2022-03-24 23:26:23 oh nevermind 2022-03-24 23:26:39 but that's not how it should be 2022-03-24 23:26:48 well, I have not even a return stack xD 2022-03-24 23:27:06 I have an execution stack :D 2022-03-24 23:27:26 using perl I don't see why I should stick to how forth does stuff 2022-03-24 23:27:53 and always liked to steal the concepts I like and do it in my way 2022-03-24 23:28:09 that's also why I like perl, I can do whatever I want however I want 2022-03-24 23:28:29 and I think it's also why I like forth, or at least one of the things I like from it 2022-03-24 23:28:46 Well, delete is actually a more flexible feature. In a typical system it leaves holes in the dictionary that aren't easy to re-use. 2022-03-24 23:28:56 I lied earlier - the header section is not completely indispensable. 2022-03-24 23:29:15 Headers point to the body implementations, but the cells within a word's definition point back to it's header. 2022-03-24 23:29:26 Specifically to a pair of pointers I call CFA/PFA. 2022-03-24 23:29:46 The names and the links aren't consulted at run-time, but the CFA always is and the PFA might be. 2022-03-24 23:29:50 Primitives have no PFA. 2022-03-24 23:30:08 actually my interpreter when finds a colon word to execute the only thing it does is to update the execution stack 2022-03-24 23:30:26 dotimes multiplies a list in the execution stack xD 2022-03-24 23:30:27 In FIG Forth the definition for a word immediately followed the CFA field, so to get from CFA to PFA was just "plus one cell." 2022-03-24 23:30:41 builtin ('dotimes', sub { my ($code, $times) = get(2); to_execution((@$code) x $times)}); 2022-03-24 23:30:47 But that precludes those "labels within a definition." 2022-03-24 23:31:05 but I can quote words to prevent their execution, they'll get pushed on the stack 2022-03-24 23:31:49 { 1 2 3 . . . } won't execute them, it will build a list like if it was compiling and then push that list to the stack 2022-03-24 23:32:15 Interesting. 2022-03-24 23:32:16 ( 1 2 3 . . . ) does execute them, actually ( pushes a delimiter on the stack and ) the end delimiter 2022-03-24 23:32:43 No slick features like that on mine - I'm either interpreting or compiling and that's really that. 2022-03-24 23:32:54 well ) does not push, but traverses the stack until it finds the ( delimiter 2022-03-24 23:33:05 then builds the list 2022-03-24 23:33:28 I like this because you can dup drop etc the delimiters 2022-03-24 23:33:49 there's a flaw as if someone pushes the delimiter for some other reason could get confused 2022-03-24 23:33:53 For me "definition space" is just one long thing - the only thing that stops execution from moving forward is a jump or a ; 2022-03-24 23:34:00 but the delimiters are a variable you can set 2022-03-24 23:34:34 Yeah, I've done some back and forth on how to input strings. 2022-03-24 23:34:44 Right now I'm thinking of having a word s and you'd say 2022-03-24 23:34:48 s "string" 2022-03-24 23:34:52 or s /string/ 2022-03-24 23:34:53 for me the way I've implemented strings does not seem right 2022-03-24 23:34:54 etc. 2022-03-24 23:35:10 but at least now the interpreter knows when something is a string 2022-03-24 23:35:26 That will put the string data in that "ropes" data structure we talked about a week ago or so, and leave a pointer to it on the stack. 2022-03-24 23:35:43 I mean I just split by spaces all the text, this gets in the way when the text has " some strings " 2022-03-24 23:36:07 so before doing that I convert all " stuff like this " into ^stuff-like-this 2022-03-24 23:36:09 xDDD 2022-03-24 23:36:58 Yes - I was thinking the other day about that general kind of thing - I decided Forth's "one character at a time" approach is nice - it can scan past spaces in string literals. 2022-03-24 23:37:04 strings being pushed on the stack also have this form, when the interpreter "executes" a string then does the interpolation if the string has ~a 2022-03-24 23:37:51 but for example ~% never get's converted to a newline except when you print it 2022-03-24 23:38:13 I'll have to take care when writing to files and alike 2022-03-24 23:38:45 a string on the execution stack can't have spaces or newlines 2022-03-24 23:39:38 once it's in the parameter stack does not care, but as the user will be able to add stuff to the execution stack it means he can also put strings there 2022-03-24 23:40:10 this is why I only do interpolation with ~a to get the values from the stack, but the string stills being in ^this-form~% 2022-03-24 23:40:37 only when printing ^ gets removed, - converted to a space and ~% to a newline 2022-03-24 23:41:47 this is a flaw I suppose 2022-03-24 23:43:13 "my cat is nice" 3 "~a~a" { "^3my-cat-is-nice" } 2022-03-24 23:43:37 but . prints as you would expect 2022-03-24 23:53:48 now the user can convert this string to a "normal" string, so words that use strings can use them 2022-03-24 23:54:04 but that converted string won't be able to get in the execution stack 2022-03-24 23:55:09 https://termbin.com/9bjq "ls" str shell 2022-03-24 23:55:39 and tolines converts that to a list of lines, but there's no way to operate on lists yet 2022-03-24 23:57:57 can't put "ls -t" because - is now a space 2022-03-24 23:58:00 ACTION cries