Database of LIT to single xt?

This is a discussion on Database of LIT to single xt? within the Forth forums in Programming Languages category; hi : 0 DUP DUP XOR ; : -1 0 NOT ; any more? just as a code compaction exercise....

Go Back   Application Development Forum > Programming Languages > Forth

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-04-2008, 11:10 AM
jacko
Guest
 
Default Database of LIT to single xt?

hi

: 0 DUP DUP XOR ;
: -1 0 NOT ;

any more? just as a code compaction exercise.
Reply With Quote
  #2  
Old 08-04-2008, 11:43 AM
Jerry Avins
Guest
 
Default Re: Database of LIT to single xt?

jacko wrote:
> hi
>
> : 0 DUP DUP XOR ;


Fails when the stack is empty and the implementation has no guard cell.

> : -1 0 NOT ;
>
> any more? just as a code compaction exercise.


Jerry
--
Engineering is the art of making what you want from things you can get.
ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
Reply With Quote
  #3  
Old 08-04-2008, 11:54 AM
rickman
Guest
 
Default Re: Database of LIT to single xt?

On Aug 4, 11:43 am, Jerry Avins <j...@ieee.org> wrote:
> jacko wrote:
> > hi

>
> > : 0 DUP DUP XOR ;

>
> Fails when the stack is empty and the implementation has no guard cell.


This will only fail if the stack is designed to make it fail. The way
some implement stacks, there is no top or bottom and duping an "empty"
stack will produce a valid result for this case.

However, I don't see the purpose of defining 0 this way. A means has
to be provided for arbitrary literals and there is no reason that 0
can't be one of these. My understanding is this exercise is a way to
minimize the instruction set. How does defining 0 and -1 this way
save op codes?

Rick
Reply With Quote
  #4  
Old 08-04-2008, 07:10 PM
jacko
Guest
 
Default Re: Database of LIT to single xt?

On 4 Aug, 16:54, rickman <gnu...@gmail.com> wrote:
> On Aug 4, 11:43 am, Jerry Avins <j...@ieee.org> wrote:
>
> > jacko wrote:
> > > hi

>
> > > : 0 DUP DUP XOR ;

>
> > Fails when the stack is empty and the implementation has no guard cell.

>
> This will only fail if the stack is designed to make it fail. *The way
> some implement stacks, there is no top or bottom and duping an "empty"
> stack will produce a valid result for this case.
>
> However, I don't see the purpose of defining 0 this way. *A means has
> to be provided for arbitrary literals and there is no reason that 0
> can't be one of these. *My understanding is this exercise is a way to
> minimize the instruction set. *How does defining 0 and -1 this way
> save op codes?
>
> Rick


It doesn't really. as LIT val EXIT is three cells for any literal to
compact into 1 word to call by xt. Does make me wonder about how an
auto LIT compactor may work though.

cheers
jacko
Reply With Quote
  #5  
Old 08-05-2008, 02:22 AM
rickman
Guest
 
Default Re: Database of LIT to single xt?

On Aug 4, 7:10 pm, jacko <jackokr...@gmail.com> wrote:
> On 4 Aug, 16:54, rickman <gnu...@gmail.com> wrote:
>
>
>
> > On Aug 4, 11:43 am, Jerry Avins <j...@ieee.org> wrote:

>
> > > jacko wrote:
> > > > hi

>
> > > > : 0 DUP DUP XOR ;

>
> > > Fails when the stack is empty and the implementation has no guard cell.

>
> > This will only fail if the stack is designed to make it fail. The way
> > some implement stacks, there is no top or bottom and duping an "empty"
> > stack will produce a valid result for this case.

>
> > However, I don't see the purpose of defining 0 this way. A means has
> > to be provided for arbitrary literals and there is no reason that 0
> > can't be one of these. My understanding is this exercise is a way to
> > minimize the instruction set. How does defining 0 and -1 this way
> > save op codes?

>
> > Rick

>
> It doesn't really. as LIT val EXIT is three cells for any literal to
> compact into 1 word to call by xt. Does make me wonder about how an
> auto LIT compactor may work though.


An auto LIT compactor...??? I think my brother has one of those in
his kitchen. He uses it to smash the garbage into a small cube to go
to the curb. ;^)

Rick
Reply With Quote
  #6  
Old 08-05-2008, 04:56 AM
George Hubert
Guest
 
Default Re: Database of LIT to single xt?

On Aug 4, 4:10*pm, jacko <jackokr...@gmail.com> wrote:
> hi
>
> : 0 DUP DUP XOR ;
> : -1 0 NOT ;
>
> any more? just as a code compaction exercise.


The easiest way (as done in Fig Forth and other older Forths) is;

0 CONSTANT 0
1 CONSTANT 1
2 CONSTANT 2

why reinvent the wheel?

George Hubert
Reply With Quote
  #7  
Old 08-05-2008, 11:22 AM
jacko
Guest
 
Default Re: Database of LIT to single xt?

On 5 Aug, 09:56, George Hubert <georgeahub...@yahoo.co.uk> wrote:
> On Aug 4, 4:10*pm, jacko <jackokr...@gmail.com> wrote:
>
> > hi

>
> > : 0 DUP DUP XOR ;
> > : -1 0 NOT ;

>
> > any more? just as a code compaction exercise.

>
> The easiest way (as done in Fig Forth and other older Forths) is;
>
> 0 CONSTANT 0
> 1 CONSTANT 1
> 2 CONSTANT 2
>
> why reinvent the wheel?
>
> George Hubert


This is the most compact at:

saving = usages-2

cheers
jacko
Reply With Quote
  #8  
Old 08-05-2008, 02:49 PM
Aleksej Saushev
Guest
 
Default Re: Database of LIT to single xt?

George Hubert <georgeahubert@yahoo.co.uk> writes:

> On Aug 4, 4:10*pm, jacko <jackokr...@gmail.com> wrote:
>> hi
>>
>> : 0 DUP DUP XOR ;
>> : -1 0 NOT ;
>>
>> any more? just as a code compaction exercise.

>
> The easiest way (as done in Fig Forth and other older Forths) is;
>
> 0 CONSTANT 0
> 1 CONSTANT 1
> 2 CONSTANT 2


Maybe in some others, but definitly not in FIG Forth, where 0, 1, and 2
are primitive.


--
CE3OH...
Reply With Quote
  #9  
Old 08-06-2008, 01:03 PM
George Hubert
Guest
 
Default Re: Database of LIT to single xt?

On Aug 6, 6:16*pm, Albert van der Horst <alb...@spenarnc.xs4all.nl>
wrote:
> In article <b62033ec-0e09-4584-a1ef-6fcf3dc54...@e39g2000hsf.googlegroups..com>,
> George Hubert *<georgeahub...@yahoo.co.uk> wrote:
>
> >On Aug 4, 4:10=A0pm, jacko <jackokr...@gmail.com> wrote:
> >> hi

>
> >> : 0 DUP DUP XOR ;
> >> : -1 0 NOT ;

>
> >> any more? just as a code compaction exercise.

>
> >The easiest way (as done in Fig Forth and other older Forths) is;

>
> >0 CONSTANT 0
> >1 CONSTANT 1
> >2 CONSTANT 2

>
> >why reinvent the wheel?

>
> Why generate special case that may confuse an optimiser?
>


Since constants already exist in standard Forth then wouldn't
an optimiser handle them anyway (most seem to treat them the
same as literals).

The original question was producing an xt for specific literals,
which IMO is exactly what CONSTANT does.

George Hubert
Reply With Quote
  #10  
Old 08-06-2008, 01:16 PM
Albert van der Horst
Guest
 
Default Re: Database of LIT to single xt?

In article <b62033ec-0e09-4584-a1ef-6fcf3dc54712@e39g2000hsf.googlegroups.com>,
George Hubert <georgeahubert@yahoo.co.uk> wrote:
>On Aug 4, 4:10=A0pm, jacko <jackokr...@gmail.com> wrote:
>> hi
>>
>> : 0 DUP DUP XOR ;
>> : -1 0 NOT ;
>>
>> any more? just as a code compaction exercise.

>
>The easiest way (as done in Fig Forth and other older Forths) is;
>
>0 CONSTANT 0
>1 CONSTANT 1
>2 CONSTANT 2
>
>why reinvent the wheel?


Why generate special case that may confuse an optimiser?

>
>George Hubert



--
--
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- like all pyramid schemes -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 05:17 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.