Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"Lead us in a few words of silent prayer." -- Bill Peterson, former Houston Oiler football coach


devel / comp.lang.forth / Definition-body equivalence and interpretation semantics for SLITERAL

SubjectAuthor
* Definition-body equivalence and interpretation semantics for SLITERALRuvim
`* Re: Definition-body equivalence and interpretation semantics for SLITERALHugh Aguilar
 `- Re: Definition-body equivalence and interpretation semantics forBranimir Maksimovic

1
Definition-body equivalence and interpretation semantics for SLITERAL

<sja24e$a79$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=14815&group=comp.lang.forth#14815

  copy link   Newsgroups: comp.lang.forth
Path: rocksolid2!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ruvim.pi...@gmail.com (Ruvim)
Newsgroups: comp.lang.forth
Subject: Definition-body equivalence and interpretation semantics for SLITERAL
Date: Sat, 2 Oct 2021 19:41:47 +0300
Organization: A noiseless patient Spider
Lines: 124
Message-ID: <sja24e$a79$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 2 Oct 2021 16:41:50 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="07ff869245209e8690ca7cde708db0a2";
logging-data="10473"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19zrQaP6JVq99jkW5cjVySJ"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.1.2
Cancel-Lock: sha1:y87RbS2ijbAh/IoDLi+5ceP7LaQ=
Content-Language: en-US
 by: Ruvim - Sat, 2 Oct 2021 16:41 UTC

On 2021-10-01 17:00Z, in news:2021Oct1.190035@mips.complang.tuwien.ac.at
with subject "Compiling string literals", Anton Ertl wrote:
> Ruvim <ruvim.pinka@gmail.com> writes:
>> A native jump can be generated via AHEAD THEN as follows:
>>
>> : slit, ( c-addr u -- )
>> >r >r postpone ahead
>> r> align here r@ allot 0 c, align r@ over >r move
>> postpone then r> lit, r> lit,
>> ;
>>
>> : sliteral ( c-addr u -- | c-addr u )
>> state @ if slit, then
>> ; immediate
>
> Of course, this can be done in a simpler and less broken way by
> leaving the STATE-smartness away, e.g.:

Wow, our beloved topic!

>
> : sliteral ( c-addr u -- | c-addr u )
> >r >r postpone ahead
> r> align here r@ allot 0 c, align r@ over >r move
> postpone then r> lit, r> lit,
> ; immediate
(2)

I intentionally show the idea via the useful word "slit," (that is a
basic factor), and provide "sliteral" to only illustrate what "slit,"
does and how it can be used.

Concerning my implementation for "sliteral" — it demonstrates fairly
expected interpretation semantics (that I also prefer). Historically,
"sliteral" was implemented with these interpretation semantics in
SP-Forth at least since 1994 (and in many other Forth systems, I think).

Namely these semantics are as follows:

SLITERAL Interpretation: ( c-addr1 u -- c-addr2 u )
Store the string (c-addr1 u) in a transient buffer (c-addr2 u).
(1)

The most important thing in this regard is that these interpretation
semantics are the only possible variant that holds the copy and paste
ability between compilation state and interpretation state (or inside
and outside of a definition) for the word "sliteral".

For example, let a word "foo" is defined as follows:

: foo bar sliteral ;

If the phrase "bar sliteral" is copy-paste-able, then the following
phrases (in interpretation state) are equivalent:

foo type

bar sliteral type

This example also demonstrates the operational equivalence between a
word and its definition body ("definition-body equivalence"). It means
that the word can be replaced by its body (and vise versa) in any such
context when this word is encountered by the Forth text interpreter
(certainly, with reservation concerning names resolution).

Obviously, if and only if (iff) the definition-body equivalence is true
for a word with well defined interpretation semantics, then the
*definition body* of this word is copy-paste-able. Hence, the
definition-body equivalence can be used as a formal description for the
informal copy-paste-ability notion.

This conclusion provides us a way to establish the appropriate
interpretation semantics for a word for which the standard undefines
interpretation semantics.

In the example above, "bar" can be an immediate STATE-independent word
defined as:

: bar ( -- c-addr u ) s" test" ; immediate

: foo ( -- c-addr u ) bar sliteral ;

And the following test case falsifies the definition-body equivalence
for "foo":

t{ bar sliteral foo compare -> 0 }t

That is, if this test fails, then the definition-body equivalence for
the word "foo" is false, and then the given implementation for
"sliteral" doesn't support the copy-paste-ability, since the "foo"
definition body contains nothing except "sliteral" and its arguments.

From this test we can infer the only possible interpretation semantics
(1) for "sliteral" that guarantee the copy-paste-ability.

The copy-paste-ability property is so tempting because the code
fragments for which this property is true can be tested interpretively.
And such behavior is expected for words in Forth by default. And even
many non ordinary words are specified to hold this property.

So when it's possible, it's reasonable to provide such interpretation
semantics for words that guarantee the copy-paste-ability for these words.

From this point of view, the implementation (2) for "sliteral" is more
broken (informally), since it doesn't support the copy-paste-ability.

But my implementation supports the copy-paste-ability, and also it's
totally correct from the formal point of view (i.e. standard compliance).

If somebody still thinks it's incorrect, I will be glad to discuss the
problem of "postpone" and immediate STATE-dependent words again, with
new arguments.

--
Ruvim

Re: Definition-body equivalence and interpretation semantics for SLITERAL

<b8802433-c3fe-44e3-bb9c-9c028339cea0n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=14818&group=comp.lang.forth#14818

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:ac8:6889:: with SMTP id m9mr5313006qtq.138.1633205994860;
Sat, 02 Oct 2021 13:19:54 -0700 (PDT)
X-Received: by 2002:a37:9eca:: with SMTP id h193mr3672245qke.127.1633205994692;
Sat, 02 Oct 2021 13:19:54 -0700 (PDT)
Path: rocksolid2!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Sat, 2 Oct 2021 13:19:54 -0700 (PDT)
In-Reply-To: <sja24e$a79$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=148.167.132.245; posting-account=OxDKOgoAAADW0cxAqHqpN1zqeCoSsDap
NNTP-Posting-Host: 148.167.132.245
References: <sja24e$a79$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <b8802433-c3fe-44e3-bb9c-9c028339cea0n@googlegroups.com>
Subject: Re: Definition-body equivalence and interpretation semantics for SLITERAL
From: hughagui...@gmail.com (Hugh Aguilar)
Injection-Date: Sat, 02 Oct 2021 20:19:54 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 113
 by: Hugh Aguilar - Sat, 2 Oct 2021 20:19 UTC

On Saturday, October 2, 2021 at 9:41:52 AM UTC-7, Ruvim wrote:
> SLITERAL Interpretation: ( c-addr1 u -- c-addr2 u )
> Store the string (c-addr1 u) in a transient buffer (c-addr2 u).
> (1)
>
> The most important thing in this regard is that these interpretation
> semantics are the only possible variant that holds the copy and paste
> ability between compilation state and interpretation state (or inside
> and outside of a definition) for the word "sliteral".

A transient buffer??? What could we use for that?
My <CSTR buffer would work. This code was in the novice package in 2010.
Note that SPECIAL-MACRO: was added later to support the use of these
words inside of MACRO: and POST: that are my early-binding macro words.
I have to special-case any words that extract data from the input stream.
Note that Anton Ertl's ]] fails completely in supporting words that extract data
from the input stream (such as S| S" C" [CHAR] POSTPONE etc.). Anton Ertl's
]] also fails to support literal numbers --- his code is an unfunny joke --- the fact
that this crap code comes from a Forth-200x committee member makes
the entire Forth community look ridiculous.
----------------------------------------------------------------------------------------------------
\ ******
\ ****** These are some string words.
\ ******

: [string] ( delimiter -- ) \ runtime: -- adr cnt
parse postpone sliteral ;
immediate

char & comment \ this is the old version of <STRING> that I used before <CSTR had a circular buffer

: <string> ( delimiter -- adr cnt )
parse here swap 2dup 2>r \ -- adr here cnt \r: -- here cnt
chars dup allot move
2r> ;

&

: <<string>> ( delimiter -- str )
<cstr parse <+cstr> cstr> ;

: <string> ( delimiter -- adr cnt )
<<string>> count ;

: string ( delimiter -- ) \ runtime: -- adr cnt
state @ if postpone [string]
else <string> then ;
immediate

\ STRING is similar to S" except that it takes the delimiter as a parameter rather than use the " mark.
\ STRING is state-smart (unlike S" that has undefined behavior for interpreting), so be careful.

: s| ( -- ) \ runtime: -- adr cnt
[char] | postpone string ;
immediate

\ S| is like S" except with a | delimiter.
\ This is primarily used for strings that have a " inside of them.
\ Notice that Gforth allows a POSTPONE of STRING, but does not allow a POSTPONE of S" (when interpreting).

: s" ( -- ) \ runtime: -- adr cnt
[char] " postpone string ;
immediate

\ This S" works in interpretive mode, which isn't necessarily true of the ANS-Forth version.

: c" ( -- ) \ runtime: -- str
state @ if postpone c"
else [char] " <<string>> then ;
immediate

\ In Gforth, C" doesn't work in interpretive mode, so here is one that does.
\ This is a huge help when testing functions that take counted strings as arguments.

\ I didn't write a function that would use an arbitrary delimiter, because ANS-Forth only provides SLITERAL,
\ but nothing similar for counted strings.

: special-macro: ( xt -- xt | 0 ) \ returns 0 if xt was special-cased
[ 'special-macro: @ ] literal execute dup 0= if exit then
case
['] string of postpone string postpone dlit, 0 exit endof
['] s| of postpone s| postpone dlit, 0 exit endof
['] s" of postpone s" postpone dlit, 0 exit endof
['] c" of postpone c" postpone lit, 0 exit endof
exit endcase ; \ -- xt \ EXIT with xt if it was never special-cased

' special-macro: 'special-macro: !

\ STRING S| S" and C" all needed to be special-cased in MACRO: so SPECIAL-MACRO: had to be upgraded with these.
\ It is okay that S" and C" are in the original SPECIAL-MACRO: too, because they won't match.
\ The xt given here will be of the new version (because FIND finds the latest version) and won't match the old xt in the original SPECIAL-MACRO:

char & comment \ this is some code to test MACRO:

macro: <mmm> ( flag -- ) \ a demonstration of MACRO:
0= abort" *** MMM needs a non-zero flag to execute ***"
456 . s" Hello " type s| from: "the Great Hugh" (Stephen Pelc's term for me)| type cr
-1 if ." Note that raw ANS-Forth can't FIND words like IF without the disambiguifiers." cr then
[char] A . ['] + .
c" I have ['] working." count type cr ;

: mmm ( -- )
123 . -1 <mmm> 789 . ;

&

: rtype ( adr cnt size -- ) \ right-justified --- like .R except for strings
over -
spaces type ;

: ltype ( adr cnt size -- ) \ left-justified
over - -rot
type spaces ;
----------------------------------------------------------------------------------------------------

Re: Definition-body equivalence and interpretation semantics for SLITERAL

<ne76J.23137$4X4.14361@fx27.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=14822&group=comp.lang.forth#14822

  copy link   Newsgroups: comp.lang.forth
Path: rocksolid2!news.neodome.net!news.uzoreto.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!feeder1.feed.usenet.farm!feed.usenet.farm!peer02.ams4!peer.am4.highwinds-media.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx27.iad.POSTED!not-for-mail
Newsgroups: comp.lang.forth
From: branimir...@icloud.com (Branimir Maksimovic)
Subject: Re: Definition-body equivalence and interpretation semantics for
SLITERAL
References: <sja24e$a79$1@dont-email.me>
<b8802433-c3fe-44e3-bb9c-9c028339cea0n@googlegroups.com>
User-Agent: slrn/1.0.3 (Darwin)
Lines: 127
Message-ID: <ne76J.23137$4X4.14361@fx27.iad>
X-Complaints-To: abuse@usenet-news.net
NNTP-Posting-Date: Sun, 03 Oct 2021 00:57:55 UTC
Organization: usenet-news.net
Date: Sun, 03 Oct 2021 00:57:55 GMT
X-Received-Bytes: 6188
 by: Branimir Maksimovic - Sun, 3 Oct 2021 00:57 UTC

Thanks Hugh!
Top posting as i don't answer anything actually ...

On 2021-10-02, Hugh Aguilar <hughaguilar96@gmail.com> wrote:
> On Saturday, October 2, 2021 at 9:41:52 AM UTC-7, Ruvim wrote:
>> SLITERAL Interpretation: ( c-addr1 u -- c-addr2 u )
>> Store the string (c-addr1 u) in a transient buffer (c-addr2 u).
>> (1)
>>
>> The most important thing in this regard is that these interpretation
>> semantics are the only possible variant that holds the copy and paste
>> ability between compilation state and interpretation state (or inside
>> and outside of a definition) for the word "sliteral".
>
> A transient buffer??? What could we use for that?
> My <CSTR buffer would work. This code was in the novice package in 2010.
> Note that SPECIAL-MACRO: was added later to support the use of these
> words inside of MACRO: and POST: that are my early-binding macro words.
> I have to special-case any words that extract data from the input stream.
> Note that Anton Ertl's ]] fails completely in supporting words that extract data
> from the input stream (such as S| S" C" [CHAR] POSTPONE etc.). Anton Ertl's
> ]] also fails to support literal numbers --- his code is an unfunny joke --- the fact
> that this crap code comes from a Forth-200x committee member makes
> the entire Forth community look ridiculous.
> ----------------------------------------------------------------------------------------------------
> \ ******
> \ ****** These are some string words.
> \ ******
>
>: [string] ( delimiter -- ) \ runtime: -- adr cnt
> parse postpone sliteral ;
> immediate
>
> char & comment \ this is the old version of <STRING> that I used before <CSTR had a circular buffer
>
>: <string> ( delimiter -- adr cnt )
> parse here swap 2dup 2>r \ -- adr here cnt \r: -- here cnt
> chars dup allot move
> 2r> ;
>
> &
>
>: <<string>> ( delimiter -- str )
> <cstr parse <+cstr> cstr> ;
>
>: <string> ( delimiter -- adr cnt )
> <<string>> count ;
>
>: string ( delimiter -- ) \ runtime: -- adr cnt
> state @ if postpone [string]
> else <string> then ;
> immediate
>
> \ STRING is similar to S" except that it takes the delimiter as a parameter rather than use the " mark.
> \ STRING is state-smart (unlike S" that has undefined behavior for interpreting), so be careful.
>
>: s| ( -- ) \ runtime: -- adr cnt
> [char] | postpone string ;
> immediate
>
> \ S| is like S" except with a | delimiter.
> \ This is primarily used for strings that have a " inside of them.
> \ Notice that Gforth allows a POSTPONE of STRING, but does not allow a POSTPONE of S" (when interpreting).
>
>: s" ( -- ) \ runtime: -- adr cnt
> [char] " postpone string ;
> immediate
>
> \ This S" works in interpretive mode, which isn't necessarily true of the ANS-Forth version.
>
>: c" ( -- ) \ runtime: -- str
> state @ if postpone c"
> else [char] " <<string>> then ;
> immediate
>
> \ In Gforth, C" doesn't work in interpretive mode, so here is one that does.
> \ This is a huge help when testing functions that take counted strings as arguments.
>
> \ I didn't write a function that would use an arbitrary delimiter, because ANS-Forth only provides SLITERAL,
> \ but nothing similar for counted strings.
>
>: special-macro: ( xt -- xt | 0 ) \ returns 0 if xt was special-cased
> [ 'special-macro: @ ] literal execute dup 0= if exit then
> case
> ['] string of postpone string postpone dlit, 0 exit endof
> ['] s| of postpone s| postpone dlit, 0 exit endof
> ['] s" of postpone s" postpone dlit, 0 exit endof
> ['] c" of postpone c" postpone lit, 0 exit endof
> exit endcase ; \ -- xt \ EXIT with xt if it was never special-cased
>
> ' special-macro: 'special-macro: !
>
> \ STRING S| S" and C" all needed to be special-cased in MACRO: so SPECIAL-MACRO: had to be upgraded with these.
> \ It is okay that S" and C" are in the original SPECIAL-MACRO: too, because they won't match.
> \ The xt given here will be of the new version (because FIND finds the latest version) and won't match the old xt in the original SPECIAL-MACRO:
>
> char & comment \ this is some code to test MACRO:
>
> macro: <mmm> ( flag -- ) \ a demonstration of MACRO:
> 0= abort" *** MMM needs a non-zero flag to execute ***"
> 456 . s" Hello " type s| from: "the Great Hugh" (Stephen Pelc's term for me)| type cr
> -1 if ." Note that raw ANS-Forth can't FIND words like IF without the disambiguifiers." cr then
> [char] A . ['] + .
> c" I have ['] working." count type cr ;
>
>: mmm ( -- )
> 123 . -1 <mmm> 789 . ;
>
> &
>
>: rtype ( adr cnt size -- ) \ right-justified --- like .R except for strings
> over -
> spaces type ;
>
>: ltype ( adr cnt size -- ) \ left-justified
> over - -rot
> type spaces ;
> ----------------------------------------------------------------------------------------------------

--

7-77-777
Evil Sinner!
to weak you should be meek, and you should brainfuck stronger
https://github.com/rofl0r/chaos-pp

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor