Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: endianness of wordcode



On Mar 27,  1:43pm, Sven Wischnowsky wrote:
} Subject: Re: endianness of wordcode
}
} Bart Schaefer wrote:
} 
} > In particular
} > I'm not sure how to explain what happens if you do
} > 
} > 	zcompile -c foo foo bar frob ding
} > 	fpath=($PWD)
} > 	autoload foo
} > 	foo
} 
} I don't understand what you mean here. If foo is already defined, the
} autoload won't change that and you just get that executed.  If foo is
} unfunction'ed before the autoload, it loads foo.zwc and executes foo
} just as expected. At least for me. What am I missing?

Sorry, I got in too much of a hurry there ... in each of these examples,
the zcompile line explains how the file foo.zwc was created; the other
three lines were then executed in a fresh "zsh -f" so that _none_ of the
functions (foo bar frob ding) are defined.

The question in this first case is:  `bar', `frob' and `ding' do not
become available when foo is autoloaded, but why not?  If I had a text
(not .zwc) file named `foo' inside a directory in $fpath, and that
file contained four functions, and I said to autoload foo and then I
executed foo, all four functions would become defined.

If I'd said `fpath=($PWD/foo)' so that foo.zwc was treated like a
directory, I'd expect only `foo' to be searched out of it; but since
`foo' is *inside* a directory in $fpath, I expected it to be treated
like a script.  (Well, *I* didn't, but I'm trying to think like a
newbie.)

} > And I'm even more confused by
} > 
} > 	zcompile -c foo -k foo bar frob ding
} > 	fpath=($PWD)
} > 	autoload foo
} > 	foo
} > 
} > which first executes "foo" successfully and then prints
} > 
} > 	foo:3: foo: function not defined by file
} > 
} > leaving "foo" as an undefined (but marked autoloaded) function.
} 
} Here at least `foo' was already defined, right.

No, again I messed up ... the zcompile was in a separate shell.

} This is a problem I
} hadn't thought about. If we save it to be loaded ksh-style, the init
} code originally surrounding the function definition (if there was any) 
} is, of course, already deleted. So, the best attempt we could do is to 
} put the body of the function in a `foo() { body }' and save that [...]
} Note also, that for ksh-style autoloaded function that aren't
} loaded yet, the whole contents of the definition file is put into the
} wordcode file (i.e. one gets different results depending on whether
} the function is already loaded or not).

Given this, I think we should just make -k not work at all with -c, and
ignore kshautoload on -c as well, i.e. -c always behaves as if -z.  If
-k is given, stop with an error, and if kshautoload is set, print an
informative warning message but write the file anyway.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



Messages sorted by: Reverse Date, Date, Thread, Author