Deutsch English Français Italiano |
<2024Aug1.143532@mips.complang.tuwien.ac.at> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: anton@mips.complang.tuwien.ac.at (Anton Ertl) Newsgroups: comp.lang.forth Subject: Re: Operator =?UTF-8?B?b3ZlcmxvYWRpbmc/?= Date: Thu, 01 Aug 2024 12:35:32 GMT Organization: Institut fuer Computersprachen, Technische Universitaet Wien Lines: 57 Message-ID: <2024Aug1.143532@mips.complang.tuwien.ac.at> References: <a1aab44ee3b1b56c2f54f2606e98d040@www.novabbs.com> <v8b04c$137lg$1@dont-email.me> <b181be5d4e6c9abd8ed22606ab2dfb91@www.novabbs.com> Injection-Date: Thu, 01 Aug 2024 15:35:09 +0200 (CEST) Injection-Info: dont-email.me; posting-host="9c6cb8df3cbe72c15b04922cd88fdb90"; logging-data="2312287"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+6qxf2gBj4iJPbaT1m0o1q" Cancel-Lock: sha1:kcD5h7JHqH+PcR2ugnd08A+HklQ= X-newsreader: xrn 10.11 Bytes: 3270 minforth@gmx.net (minforth) writes: >the runtime action of an xVALUE (even when >compiled) >involves to walk a type-specific operator chain (a large CASE construct >in VFX). Instead of a CASE, an alternative is to have a table that is indexted by the number of the operator. This is used in Gforth. And AFAICS, we managed to get rid of the OPERATOR variable. Instead, the operator passes the index on the stack to "(to)" or "(to),", which does the table lookup and then runs ("(to)") or compiles ("(to),") the appropriate method. Gforth uses a parsing approach, which allows passing the index on the stack instead of through a variable and provides better error checking. E.g., for TO the implementation is: : int-to ( "name" x -- ) \ gforth-internal \g Interpretation semantics of \code{to}. record-name 0 (') (to) ; : comp-to ( compilation "name" -- ; run-time x -- ) \ gforth-internal \g Compilation semantics of \code{to}. record-name 0 (') (to), ; immediate restrict ' int-to ' comp-to interpret/compile: TO ( value "name" -- ) \ core-ext \g changes the value of @var{name} to @var{value} Here 0 is the index into the table. RECORD-NAME just records meta-information for Gforth's development environment. For (TO) the help text is: '(to)' ( val operation xt -- ) gforth-1.0 "paren-to" xt is of a value like word name. Stores val 'to' name. operation selects between 'to' (0), '+to' (1), 'addr' (2), 'action-of' (3) and 'is' (4). (TO) is a method of the word specified by xt, so different words have different implementations, but they are basically to look up the appropriate table entry end execute it. E.g., for a word defined with VALUE, the table entry with index 0 (i.e., TO) of the word is the xt of "!", and (TO) performs ( val xt ) >body ! The thing about "(TO)," means that when compiling this stuff, the whole table lookup is performed at compile time, and what is compiled is equivalent to ( val ) [ xt >body ] literal ! - anton -- M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html New standard: https://forth-standard.org/ EuroForth 2024: https://euro.theforth.net