2022-02-20 01:10:09 I don't know how to implement the return stack 2022-02-20 01:10:25 I have a simple perl script trying to mimic a very simple forth 2022-02-20 01:11:28 but words are objects and there is no memory meaning 2022-02-20 01:11:32 https://termbin.com/lnfp 2022-02-20 01:11:32 2022-02-20 01:30:05 I usually end up having to make the return stack explicit 2022-02-20 01:31:09 ditto an "IP register" 2022-02-20 01:31:44 then the inner interpreter is an explicit loop like https://git.sr.ht/~remexre/rtf/tree/trunk/item/bs/machine.c#L60-66 2022-02-20 01:33:20 usually -> usually when impling forth in a language other than asm 2022-02-20 01:34:08 well, I guess most asm langs only have an explicit stack /shrug 2022-02-20 01:52:23 remexre: so the code is an ast and you traverse it? 2022-02-20 01:52:30 and every iteration is a word 2022-02-20 01:52:58 and moving that pointer would effectively return from the word 2022-02-20 01:53:03 huh, I don't really think of it that way, but I guess kinda sorta? 2022-02-20 01:53:12 I have to think about 2022-02-20 01:53:16 wrt use of the term "AST" 2022-02-20 01:53:53 well, I guess not really, because I have EXECUTE so it's definitely not a fixed tree 2022-02-20 01:54:24 I don't even know if the meaning of execute in my script is right 2022-02-20 01:55:00 I tried to make + a primary word so it didn't catch the numbers on the stack as it executed before 2022-02-20 01:55:10 immediate word* 2022-02-20 01:55:27 so it seems to "work" for only did in a simple case 2022-02-20 01:55:28 uhhhhhh + should definitely not be immediate 2022-02-20 01:55:38 yes, was to try 2022-02-20 01:56:00 but I'm not sure it will work later xD 2022-02-20 01:56:11 you probably want to have the state flag before you think about immediate words 2022-02-20 01:56:51 when compiling I look the words, if it's a number I make a literal word which is a closure that pushes the number on the stack 2022-02-20 01:57:10 if it's immediate it's executed and nothing is returned from that word 2022-02-20 01:57:34 if not it's looked in the dictionary and "copied" 2022-02-20 01:58:14 so when the "interpreter" (which does not exist yet) finds a word executes it, and execute is recursive if is a secondary word 2022-02-20 01:58:58 oh, you probably don't want the recursive execute; you want to model the return stack explicitly so you can write >R and R> 2022-02-20 01:59:16 I have to think about the return stack 2022-02-20 01:59:55 I think about forth-in-an-HLL a lot more like writing a bytecode VM than like writing a tree-walking interpreter 2022-02-20 02:00:10 I don't know how to implement and even if I could live without xd 2022-02-20 02:00:40 but I have to learn how to implement it as I'll need it sooner or later 2022-02-20 02:01:01 hmm 2022-02-20 02:01:43 I don't know how I'm supposed to save the memory of a word 2022-02-20 02:02:05 "the memory of"? 2022-02-20 02:02:05 I somehow have to make a checkpoint where I can return later 2022-02-20 02:02:10 oh 2022-02-20 02:03:07 so it's just a history of words? 2022-02-20 02:03:18 make your parameter field an array of objects, "abstract code addresses" are pairs of the word whose parameter field is being read from, and the index which is being referred to? 2022-02-20 02:05:36 I have to understand what the stack does first 2022-02-20 02:05:48 then I can think 2022-02-20 02:06:37 the problem is I'm not understanding what I have to solve 2022-02-20 02:06:54 so I'll look at what a return stack is 2022-02-20 02:07:55 the return stack isn't really too different from the normal stack; and due to R> and >R, they store the same kinds of data 2022-02-20 02:09:09 I just need to push the next word before jumping into a secondary? 2022-02-20 02:09:23 secondary? 2022-02-20 02:09:49 a secondary word, but nvm, it won't work 2022-02-20 02:10:21 executing a word doesn't necessarily touch the return stack 2022-02-20 02:10:23 remexre: when the program starts what's on the return stack? 2022-02-20 02:10:42 if in a HLL, I usually have some marker for "execution is done" 2022-02-20 02:10:45 if in asm, it's empty 2022-02-20 02:11:25 and when it finds a word if it's a primary word just executes, and when finds a secondary word, what does? 2022-02-20 02:11:40 what do you mean by primary and secondary? 2022-02-20 02:11:46 primary native word 2022-02-20 02:11:50 asm code 2022-02-20 02:11:58 secondary : definition ; 2022-02-20 02:12:15 those are normally called "code words" and "colon words" afaik 2022-02-20 02:12:20 xd sorry 2022-02-20 02:12:22 and they're handled in the same way 2022-02-20 02:12:32 like there's not a strong distinction between them 2022-02-20 02:12:47 colon words just have a particular piece of code in their code field 2022-02-20 02:12:56 usually called docol, docolon, (:), or some variation on those 2022-02-20 02:13:09 then what happens on the return stack once a word is found? 2022-02-20 02:13:38 found by the outer interpreter or inner interpreter 2022-02-20 02:13:48 :O idk 2022-02-20 02:14:11 it's the inner who manages the return stack 2022-02-20 02:14:22 and the outer just handles input not? 2022-02-20 02:14:23 the outer interpreter, aka the text interpreter, is the thing that handles the input text 2022-02-20 02:14:29 yeah for outer 2022-02-20 02:14:41 the inner interpreter itself does _not_ manage the return stack 2022-02-20 02:14:45 it manages the instruction pointer 2022-02-20 02:15:12 docol/docolon/(:)/enter (forgot that older stuff sometimes calls it enter) and (;)/exit manage the return stack for calling colon words 2022-02-20 02:15:12 atm I have no inner nor outer interpreter as I have to know how to implement the return stack first 2022-02-20 02:15:34 whatever the data structure you're using for the data stack is 2022-02-20 02:15:42 it's almost certainly suitable for the return stack too 2022-02-20 02:16:13 pff I wanted to learn forth before implementing it 2022-02-20 02:16:27 not this way xd 2022-02-20 02:17:08 remexre: yes, but how to manage, I mean the return stack will be an array 2022-02-20 02:17:26 have you looked at Moving Forth ? 2022-02-20 02:17:41 I have to read some stuff I didn't want to read this until I had a base of forth 2022-02-20 02:17:44 nope 2022-02-20 02:17:54 https://bradrodriguez.com/papers/moving1.htm 2022-02-20 02:18:27 ime it's the kind of thing where you have to read it, then once you've read it you start to make connections between all the parts 2022-02-20 02:18:54 oh I think I have read at least this part 2022-02-20 02:18:59 but it details pretty much all the important parts of a forth implementation 2022-02-20 02:19:07 thanks 2022-02-20 02:19:30 I didn't want to implement forth before learning it 2022-02-20 02:19:44 but I want to put sdl in forth 2022-02-20 02:19:58 and learn stuff by opening windows and drawing pixels 2022-02-20 02:20:16 tried gforth but can't find libraries in netbsd 2022-02-20 02:20:19 I'd probably say, check the FFI section of the manual of whatever implementation you're using? afaik stuff like that should be reasonably implementation- (and language-)independent 2022-02-20 02:22:03 remexre: no implementation available in netbsd has gui stuff, nor sockets or alike and gforth which let's you add bindings can't find the libraries it needs to even start "binding" 2022-02-20 02:22:45 although I see pforth has very little documented C ffi, maybe I should go there 2022-02-20 02:22:47 any chance that library is libffi and you just need to install it? haven't used gforth extensively, but that'd be pretty typically 2022-02-20 02:23:09 but anyways there is nothing better for learning about a language than to implement it 2022-02-20 02:25:07 remexre: in a colon word there is a pointer for every word and another that acts as the ip pointer? 2022-02-20 02:25:26 and that's what gets passed to the return stack 2022-02-20 02:25:48 the instruction pointer is global (or at least per "instance of the forth interpreter") 2022-02-20 02:26:10 if you can't take a pointer to an array element that you can ++, I would make it be a pair of an array and an index 2022-02-20 02:26:56 you're running a loop that's repeatedly doing get_word_at(ip++).cfa(); 2022-02-20 02:27:18 if you don't have ++, something like 2022-02-20 02:27:39 word = get_word_at(ip_array, ip_index); ip_index++; word.cfa(); 2022-02-20 02:28:10 er 2022-02-20 02:28:30 more like word.cfa(word) if you don't have a way to get a "this pointer" otherwise 2022-02-20 02:28:52 for a colon word, the cfa is docolon, which would look something like 2022-02-20 02:29:46 docolon_cfa(word) { return_stack.push(new IP(ip_array, ip_index)); ip_array = word; ip_index = 0; } 2022-02-20 02:30:07 ip_array = word.pfa; * 2022-02-20 02:31:18 all the words in the program are inside an array? 2022-02-20 02:31:30 I mean, the words the interpreter reads 2022-02-20 02:31:35 not the defined ones 2022-02-20 02:31:38 no, for something like : foo bar baz ; it'd have like 2022-02-20 02:32:05 foo = { name: "foo", cfa: docolon_cfa, pfa: [bar, baz, dosemi] } 2022-02-20 02:32:34 dosemi being aka (;) or exit 2022-02-20 02:32:49 and where 2022-02-20 02:33:39 dosemi.cfa = function(word) { ip = return_stack.pop() as IP; ip_array = ip.array; ip_index = ip.index; } 2022-02-20 02:34:02 thanks for the help remexre 2022-02-20 02:34:41 I'll try later to do something in a dirty way :D 2022-02-20 02:37:51 good luck! 2022-02-20 09:18:49 the jonesforth material is good. 2022-02-20 09:19:31 ACTION nods 2022-02-20 09:22:02 also uxn 2022-02-20 11:06:01 re Plan9 slash Inferno Styx protocol: anyone here have a list of the message type bytes handy? 2022-02-20 11:06:22 Zarutian_HTC: the manpage has them. on cat-v 2022-02-20 11:06:37 also, check nemo's book for the details on how it works, if you are interested. 2022-02-20 11:06:53 styx is the same as 9p of 9front. 2022-02-20 11:06:58 except for the name. 2022-02-20 11:07:08 oh was looking at https://www.vitanuova.com/inferno/man/5/INDEX.html 2022-02-20 11:07:24 I would suggest going with 9front.org 2022-02-20 11:07:42 taking a step back, what are you trying to do? 2022-02-20 11:07:58 a styx fs on inferno in forth? 2022-02-20 11:10:15 http://man.9front.org/5/ 2022-02-20 11:10:43 naah, just going to implement the protocol in forth but via stdin and stdout so I only would need EMIT and KEY? 2022-02-20 11:12:14 huh, I only get the constant name for the message type byte but not the numeral itself 2022-02-20 11:16:28 it refers to fcall.h file 2022-02-20 11:16:51 Zarutian_HTC: why are you doing this? key is a function call and it will be slow. 2022-02-20 11:16:59 sysread 2022-02-20 11:17:08 will be a syscall. 2022-02-20 11:17:46 you are assuming something about the forth I am using 2022-02-20 11:18:27 http://okturing.com/src/13142/body fcall.h 2022-02-20 11:19:30 aand that was what I was looking for 2022-02-20 11:21:18 re KEY? and EMIT : this forth impl might well be running on an ATmega328p with SPI sram for extra work ram. And one is having the stdin and stdout over serial ;รพ 2022-02-20 11:21:33 thanks, joe9 2022-02-20 11:22:13 so, you are implementing a 9p server on ATmega328p? 2022-02-20 11:22:18 cool idea. 2022-02-20 11:23:39 will probably implement it first ontop of an fcpu32 fantasy computer emulator 2022-02-20 11:28:05 then anyone curious could use nc and https://9fans.github.io/plan9port/man/man4/9pfuse.html to mount that fs 2022-02-20 16:29:11 siraben: does your ti84-forth work with KnightOS? I see you've referenced it in the docs as reading.. 2022-02-20 16:29:39 also does it work with TI-83 or 83+? 2022-02-20 17:12:23 lagash: does not work with KnightOS 2022-02-20 17:12:27 and yes it works on the 83+ 2022-02-20 19:29:37 it is correct that when compiling if I find an immediate word I just "enter" this word using the same enter function the inner interpreter uses? 2022-02-20 19:29:50 I think I have the return stack 2022-02-20 19:30:21 it's just a perl script again (I want to use the sdl bindings of perl) 2022-02-20 19:30:57 https://termbin.com/kcg9 2022-02-20 19:31:30 I have to make the outer interpreter and I'm missing stuff like postpone defer and alike