2021-06-27 04:34:21 Why does this result in Stack overflow in gforth: 1000 allot here sp! 2021-06-27 04:34:54 Ah because it messes up with the text interpreter's stack state right? 2021-06-27 04:36:31 Indeed changing it inside compiled code and restoring before exit has no problem 2021-06-27 09:32:20 neuro_: No it's a stack overflow because you set the stack pointer to somewhere totally different, and the stack overflow check is just to make sure the pointer is in an appropriate range 2021-06-27 09:32:45 And the stack overflow check is usually only done at the interpreter loop, so in a compiled code it would not get checked before being restored again 2021-06-27 09:34:22 The interpreter loop is designed to handle the stack being changed, but not the return stack. But it can't handle the stack being moved apparently. 2021-06-27 12:20:04 That's right (what veltas said). It check stack bounds in between word interpretations. When you compile the change and the restore inside a word, no check is performed before you restore it. 2021-06-27 12:20:44 remexre: I wrote a new blog post https://siraben.github.io/2021/06/27/classical-math-coq.html 2021-06-27 12:20:54 You might try including a suitable update to sp0 as well. 2021-06-27 12:21:12 The stack check is to compare the stack pointer to the value in sp0. If you change them both, you may be fine. 2021-06-27 12:21:36 sp0 is just a variable that holds the address of the "bottom" of the stack. 2021-06-27 12:21:49 It's what the stack pointer should be when the stack is empty. 2021-06-27 12:23:05 Here: 2021-06-27 12:23:08 Gforth 0.7.3, Copyright (C) 1995-2008 Free Software Foundation, Inc. 2021-06-27 12:23:10 Gforth comes with ABSOLUTELY NO WARRANTY; for details type `license' 2021-06-27 12:23:12 Type `bye' to exit 2021-06-27 12:23:14 : newstack 1000 allot here sp0 ! here sp! ; ok 2021-06-27 12:23:16 newstack ok 2021-06-27 12:23:18 ok 2021-06-27 12:23:20 ok 2021-06-27 12:23:38 sp@ here - . 0 ok 2021-06-27 12:24:49 That seems to work. 2021-06-27 12:26:43 I would imagine you could do the return stack as well, but it would be more delicate. You'd need to copy over the return addresses on the stack required to get you back to the interpreter. That would 2021-06-27 12:26:47 Or something like that at least. 2021-06-27 12:27:01 Or you could do the update and then run QUIT. 2021-06-27 12:27:46 This also seems to work: 2021-06-27 12:27:59 : newreturnstack 1000 allot here rp0 ! here rp! quit ; 2021-06-27 12:28:33 QUIT abandons the extant return stack and clears it (rp0 @ rp!) and re-enters the outer interpreter. 2021-06-27 12:30:01 If I run newreturnstack and then do rp@ here - I get -128. So the interpreter loop has quite a few entries on the return stack already, apparently. 2021-06-27 12:31:57 So, long story short, the system knows where *both ends* of each stack is. To move the stack you have to change both of those things. 2021-06-27 12:32:10 both ends "are" 2021-06-27 14:15:29 oh hey, crc runs this channel! 2021-06-27 14:15:54 nice work on retroforth! 2021-06-27 14:16:06 siraben: huh, neat; I haven't seen sumor before, makes sense that something like it would exist 2021-06-27 14:16:27 its nice to see interesting stuff in the forth space 2021-06-27 14:19:38 eris[m]12: thanks, and welcome to the channel 2021-06-27 14:21:12 G'Day. May I ask what sumor is? 2021-06-27 14:21:22 ^^ 2021-06-27 14:22:20 Mat9: see https://siraben.github.io/2021/06/27/classical-math-coq.html 2021-06-27 14:22:35 thanks 2021-06-27 14:26:20 I find all that stuff siraben et al dwell on to be absolutely fascinting, and yet also completely outside my wheelhouse. Far enough outside that I thing quite a bit of effort would be involved in becom 2021-06-27 14:26:46 I sort of think of it as the "theoretical side" of math. 2021-06-27 14:27:01 I quite like theory in science, but I've never really delved deeply into that sort of thing on the math side. 2021-06-27 14:27:20 But I'm happy people are out there dealing with it. :-) 2021-06-27 14:31:34 I'm not sure what he inteded with his analysis but it would be probably helpful for checking program correctness 2021-06-27 14:34:58 ok, seems he is interrested in computer assisted theorem proving 2021-06-27 15:36:42 Yes, right - correctness proof is a core of his interests. 2021-06-27 15:37:09 And I respect the value of that sort of thing, in spite of not really having an interest in doing all the work I'd need to do to manage it myself. 2021-06-27 15:37:35 Lord knows there are enough bugs already - anything we can do to prevent / contain more of them is a good thing. 2021-06-27 16:52:42 Writing Forth code in assembler by hand compiling it without a REPL. It's already comfortable enough. 2021-06-27 17:31:45 I should write my own FORTH for P2 2021-06-27 17:31:59 i have a clever idea for making stack a bit faster 2021-06-27 17:32:03 P2? 2021-06-27 17:32:07 Propeller 2 2021-06-27 17:32:38 ah! 2021-06-27 17:32:42 the existing TAQOZ FORTH is great, but it's Propeller 1 optimized in places still 2021-06-27 17:32:52 do tell the ideas! 2021-06-27 17:33:27 Well, the system supports indirect access to it's (massive 496 longword) register file 2021-06-27 17:33:44 i kbow nothing of the propeller 2 other than the grotesque register count 2021-06-27 17:33:44 so it's optimal to put the stack entirely inside the system regfile 2021-06-27 17:33:51 how many bytes is a longword? 2021-06-27 17:33:54 4 2021-06-27 17:33:58 ah 2021-06-27 17:34:16 thats... 2021-06-27 17:34:20 more than i thought it had 2021-06-27 17:34:38 TAQOZ puts the stack in the local memory, but it's LUTRAM (512 x 32 bit as well, but not direct access like the regfile) 2021-06-27 17:34:47 so it still has to cache the TOS 2021-06-27 17:35:00 this gives better perf for words that don't push/drop, but worse for those that do 2021-06-27 17:35:24 as when they do it has to adjust it's 4 entry cache as you'd expect 2021-06-27 17:35:56 it also leaves most of LUTRAM unused which is :( 2021-06-27 17:36:50 putting it in the regfile and using indirection improves the perf of words that push/drop (No more cache juggling) and slightly worsens those that don't 2021-06-27 17:37:14 it's tradeoffs really 2021-06-27 17:38:19 i still need to bench it, but i think overall perf would improve a bit, in exchange for worsening in code that never changes the TOS pointer 2021-06-27 17:40:10 eris[m]12> i kbow nothing of the propeller 2 other than the grotesque register count | Also it's a really nice MCU, just.. needs better tooling ^^; 2021-06-27 17:40:32 full GCC/Clang support isn't there 2021-06-27 17:47:06 maw 2021-06-27 18:06:33 i kbow nothing of the prop"> thats good to hear 2021-06-27 18:36:29 ptoooooooo 2021-06-27 18:36:47 all next week 2021-06-27 18:37:03 have fun working, suckers! 2021-06-27 18:46:24 I have the weirdest problem 2021-06-27 18:46:55 I revised my DO/?DO/LOOP/+LOOP/I/J/LEAVE/UNLOOP to be written in assembly 2021-06-27 18:47:35 and now the return stack and occasionally the data stack are being corrupted randomly 2021-06-27 18:48:13 switching the code to use the default systick handler rather than the task systick handler makes the problem go away most of the time, but not all of the time 2021-06-27 18:49:57 Does it work flawless if you disable interrupts completely? 2021-06-27 18:50:03 nope 2021-06-27 18:50:48 Is count and limit on stack, or in dedicated registers? 2021-06-27 18:51:01 count and limit on the rstack 2021-06-27 18:51:09 leave address is also on the rstack 2021-06-27 18:51:30 are the implementations compatible enough to take half of the words from the asm impl and half from the previous forth impl? 2021-06-27 18:51:34 what does the corruption tend to look like? Can't help much more without code though 2021-06-27 18:51:43 Then it may be sensitive to the way you compile the primitives - maybe you can break it by mixing postpone in 2021-06-27 18:52:02 moon example is this: 2021-06-27 18:52:03 i.e. bisect the problem down to a single word 2021-06-27 18:52:19 yea if at all possible it'd be best to bisect 2021-06-27 18:52:59 : foo 0 over 16 + rot do false or loop ; 2021-06-27 18:53:18 this word originally took an address but I rendered the address irrelevant 2021-06-27 18:53:31 my brain always page faults when reading code with ROT 2021-06-27 18:53:40 usually it returns zero - very rarely it occasionally returns non-zero 2021-06-27 18:54:26 okay 2021-06-27 18:54:34 okay, got it now 2021-06-27 18:54:55 Could you please give a disassembler listing of FOO ? 2021-06-27 18:55:05 how can it be nondeterministic if interrupts are disabled? 2021-06-27 18:56:56 NMI? 2021-06-27 18:57:00 well wtff 2021-06-27 18:57:08 I just decompiled FOO 2021-06-27 18:57:19 and it's not compiling BLX instructions 2021-06-27 18:57:24 ow 2021-06-27 18:57:40 Sometimes explaining the problem solves it :-) 2021-06-27 18:57:47 Travis, have fun! 2021-06-27 18:58:09 And always disassembler definitions with strange behaviour as long as your compiler is unstable. 2021-06-27 18:58:53 actually, I'm wrong 2021-06-27 18:59:05 those are addresses being passed into DO and LOOP 2021-06-27 18:59:15 they're correct 2021-06-27 19:01:37 I'd forgotten that DO and LOOP both take an extra argument, the former being a LEAVE address to be put on the rstack and the latter being an address to jump to 2021-06-27 19:04:29 okay, I just tried something 2021-06-27 19:04:49 wait a sec that wouldn't work 2021-06-27 19:06:27 okay, I tried it again the right way this time 2021-06-27 19:06:37 I set the VTOI to $00200000 2021-06-27 19:07:17 what arch is your forth running on? 2021-06-27 19:07:27 to effectively turn off all interrupt handling, without turning off all interrupts (which is infeable in zeptoforth in practice, as there is a variety of code that turns int 2021-06-27 19:07:48 right now I'm running on Cortex-M7, specificially STM32F746 2021-06-27 19:08:00 anyways, it works when I do this 2021-06-27 19:09:08 does your implementation use any variables? perhaps it's non-reentrant 2021-06-27 19:09:22 do your interrupt handlers use do-loops? 2021-06-27 19:09:44 my LOOP implementation does not use variables 2021-06-27 19:10:17 I'd have to check to make sure my interrupt handlers don't use do-loops, but I don't think it'd be relevant 2021-06-27 19:11:54 also, my LOOP counter and end are stored on the rstack, not in registers 2021-06-27 19:12:05 okay, maybe add some assembly code at the beginning of your interrupt handler that saves the address of the code it interrupted in a global variable 2021-06-27 19:12:27 and then inside your test loop, as soon as your state gets corrupted, read that global and print it 2021-06-27 19:14:06 I know what code is being interrupted, that's the thing 2021-06-27 19:14:32 my big question is why is it corrupting it very infrequently 2021-06-27 19:16:08 well maybe it only happens during a 2-instruction window 2021-06-27 19:16:25 and also, it's corrupting both the data stack and the rstack 2021-06-27 19:16:45 which makes me think it's actually corrupting registers, not memory 2021-06-27 19:16:57 do interrupts run on their own stacks? 2021-06-27 19:17:03 nope 2021-06-27 19:17:52 perhaps there's a moment where a stack read or write is incomplete, so the interrupts overwrite the top slot? 2021-06-27 19:18:18 did you post your implementation of the relevant words here yet? 2021-06-27 19:18:27 IIRC aligned word accesses are atomic 2021-06-27 19:18:36 nope 2021-06-27 19:19:03 any reason not to? 2021-06-27 19:20:29 https://dpaste.org/dmFj#L 2021-06-27 19:22:16 https://dpaste.org/4kXr 2021-06-27 19:24:03 I didn't realize there's both a dpaste.org and dpaste.com... 2021-06-27 19:24:55 anyways 2021-06-27 19:28:05 to me nothing unkosher looks to be case with that code 2021-06-27 19:31:29 I just checked to make sure the non-FP exception frame format is the same on the M7 and the M4, and this is the case 2021-06-27 19:33:44 what's the purpose of the 6? 2021-06-27 19:36:06 R6 2021-06-27 19:36:34 it's compiling a group of instructions to set the value of R6 to a constant 2021-06-27 19:37:28 tos = r6? 2021-06-27 19:39:16 yep 2021-06-27 19:44:20 I'm trying to think of how an interrupt handler could be causing corruption of both the rstack and dstack - note that the only registers used internally by words which are n 2021-06-27 19:45:05 bbl 2021-06-27 20:07:24 back 2021-06-27 22:08:18 Mat9: the post was just about some surprising things that happen when one translate classical mathematics into a constructive setting 2021-06-27 22:08:44 for CS and program verification, there isn't much of an issue because CS is almost all constructive anyway 2021-06-27 22:10:00 Here's a more forth related thing, https://gist.github.com/siraben/4361eca01cb0395cfa3c993e0dd380f3 I wrote up a formal semantics for a subset of Forth, just to play around 2021-06-27 22:10:35 factorial defined as: 1 begin over O= not while factorial_body repeat swap drop 2021-06-27 22:10:56 s/translate/translates 2021-06-27 22:14:23 Coq is waaaay over my head 2021-06-27 22:14:30 but neat 2021-06-27 22:20:54 remexre: "Typed programs don't leak data" https://dodisturb.me/posts/2021-06-27-Typed-Programs-Dont-Leak-Data.html 2021-06-27 22:22:02 And using the right framework, you can prove real programs (e.g. written in C) correct https://gist.github.com/siraben/bdc2aa9b4a8f197722411b334febeaa0