[SLOF] [PATCH] Add a global "dir" method

Benjamin Herrenschmidt benh at kernel.crashing.org
Thu Jun 9 18:07:12 AEST 2016


On Thu, 2016-06-09 at 02:18 -0500, Segher Boessenkool wrote:
> On Thu, Jun 09, 2016 at 01:46:46PM +1000, Benjamin Herrenschmidt
> wrote:
> > 
> > +: do-dir ( devstr len -- )
> > +  cr ." Directory of: " 2dup type ."  ... "
> That is debug code, right?  The user knows what he typed, and if not,
> he can always look one line up ;-)

Well, it's de-aliased which is handy, that's why I left it there.

> > 
> > +  open-dev dup IF
> > +    s" dir" 2 pick ['] $call-method CATCH IF
> > +       ." no dir method on target !" cr
> > +       3drop
> > +    THEN
> > +    close-dev cr
> > +  ELSE drop THEN
> > +;
> dup IF ... ELSE drop THEN
> 
> is the same as
> 
> ?dup IF ... THEN

ok.

> > 
> > +: dir ( "{devstring}" -- )
> > +    parse-word de-alias do-dir
> > +;
> A more usual name for do-dir would be (dir) or $dir .

ok.

> > 
> > +: find-path ( dir-cluster name len -- cluster file-len is-dir?
> > true | false )
> Things will be simpler if you store to dir? directly here, instead of
> passing it around.

Not necessarily and I don't like functions like that having side
effects, it makes the code even more convoluted. This find-path
has no side effect, only inputs and outputs.

> As an aside, a word that ends in a question mark usually leaves a
> boolean on the stack, not an address.

ok.

> > 
> > +  \ Store right side on return stack
> > +  2>r
> Useless comments are useless ;-)

It's not useless, it wasn't clear to me which side was left and which
one was right :-)

Cheers,
Ben.

> Segher


More information about the SLOF mailing list