From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18914 invoked by alias); 26 Sep 2015 05:23:21 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 36635 Received: (qmail 3360 invoked from network); 26 Sep 2015 05:23:19 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.0 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version:content-type; bh=K1dO7raiFeDgDltdcYSIPRmIoePyxzaAX5jsLNuyyy4=; b=crmoC/1l8M22vCANdkbT5q0jBFiqkXt2RB9Ovn6i74PfSoJ8nhrZ/gIGuDdSk5rs2y fsrPBDmEOsO2ShuUkDRPfmKB/x4ZtxSqA1nBND+biZ1HRA8eFCAeoqd5S1Lsq1H9ORsw ZpWygGGVF2PgG8QdqprABGTjhzLCK53z5LR0aJTwXUCeZcQXkzwqMcJli9mh5oJmZ0m2 kBJiFceNsljY6AneAifAyZYCLut7c6IieQpb72hAi/7lR2X9i7+dO+0PZvo0g6xajkfV p4mPoktI3of3NhvvNGzirGJEfXisPanpVFjN6eDaHRzdMnYQoyB1XRN/PoWaKTv+z9eL ZV6A== X-Gm-Message-State: ALoCoQl656Vh7VxOLGteG7rxyqKY0/2rv8lm2NFZ92igGzpdQvQX+jCy+LoGtntqQyfvd5Ak/iI6 X-Received: by 10.182.216.203 with SMTP id os11mr4837314obc.14.1443244995153; Fri, 25 Sep 2015 22:23:15 -0700 (PDT) From: Bart Schaefer Message-Id: <150925222312.ZM12569@torch.brasslantern.com> Date: Fri, 25 Sep 2015 22:23:12 -0700 In-Reply-To: <20150925101540.5d2ded9c@pwslap01u.europe.root.pri> Comments: In reply to Peter Stephenson "Re: Proof of concept: "static" parameter scope" (Sep 25, 10:15am) References: <150924192305.ZM2680@torch.brasslantern.com> <20150925101540.5d2ded9c@pwslap01u.europe.root.pri> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-workers@zsh.org Subject: Re: Proof of concept: "static" parameter scope MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Sep 25, 10:15am, Peter Stephenson wrote: } Subject: Re: Proof of concept: "static" parameter scope } } On Thu, 24 Sep 2015 19:23:05 -0700 } Bart Schaefer wrote: } > Modules can't declare keywords, so this isn't able to support the new } > array assignment syntax used by "local" et al. However, the entry point } > is coded to match that call signature. } } I think the biggest issue with fixing this is it's going to change the } "features" interface to modules as we'll have to add a feature type that } defines a typeset-style interface (and a corresponding reserved word, } but I think we can tie the two together). Or ... diff --git a/Doc/Zsh/mod_static.yo b/Doc/Zsh/mod_static.yo index 4342a92..6b461e7 100644 --- a/Doc/Zsh/mod_static.yo +++ b/Doc/Zsh/mod_static.yo @@ -36,6 +36,11 @@ parameter. This may change in the future. ) enditem() +The module also adds the option `tt(-S)' to the `tt(local)' builtin. +Using `tt(local -S)' is equivalent to calling `tt(static)', but allows +use of array assignment (parenthesized word list) syntax in the +declaration. + Parameters declared with tt(static) have the following properties: ifnzman() startitemize() diff --git a/Src/Modules/param_static.c b/Src/Modules/param_static.c index b6c2403..c5354b2 100644 --- a/Src/Modules/param_static.c +++ b/Src/Modules/param_static.c @@ -172,6 +172,13 @@ bin_static(char *nam, char **args, LinkList assigns, Options ops, int func) int from_typeset = 1; makestatic_error = 0; + if (!OPT_ISSET(ops, 'S')) + return bin_typeset(nam, args, assigns, ops, func); + else if (OPT_ISSET(ops, 'T')) { + zwarn("bad option: -T"); + return 1; + } + if (locallevel == 0) { if (isset(WARNCREATEGLOBAL)) zwarnnam(nam, "invalid local scope, using globals"); @@ -495,7 +502,7 @@ printstaticnode(HashNode hn, int printflags) static struct builtin bintab[] = { /* Copied almost verbatim from BUILTIN("local") */ - BUILTIN("static", BINF_PLUSOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL | BINF_ASSIGN, (HandlerFunc)bin_static, 0, -1, 0, "AE:%F:%HL:%R:%UZ:%ahi:%lprtux", NULL) + BUILTIN("static", BINF_PLUSOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL | BINF_ASSIGN, (HandlerFunc)bin_static, 0, -1, 0, "AE:%F:%HL:%R:%SUZ:%ahi:%lprtux", "S") }; static struct features module_features = { @@ -506,16 +513,27 @@ static struct features module_features = { 0 }; +/* Same optstr as BUILTIN("local") but with 'S' added */ +static char *optstr_local = "AE:%F:%HL:%R:%STUZ:%ahi:%lprtux"; +static struct builtin save_local; + /**/ int setup_(UNUSED(Module m)) { + HashNode hn = builtintab->getnode(builtintab, "local"); + /* Horrible, horrible hack */ getparamnode = realparamtab->getnode; realparamtab->getnode = getstaticnode; realparamtab->getnode2 = getstaticnode2; realparamtab->printnode = printstaticnode; + /* Even more horrible hack */ + save_local = *(Builtin)hn; + ((Builtin)hn)->handlerfunc = bintab[0].handlerfunc; + ((Builtin)hn)->optstr = optstr_local; + return 0; } @@ -546,6 +564,9 @@ boot_(Module m) int cleanup_(Module m) { + HashNode hn = builtintab->getnode(builtintab, "local"); + *(Builtin)hn = save_local; + realparamtab->getnode = getparamnode; realparamtab->getnode2 = gethashnode2; realparamtab->printnode = printparamnode; diff --git a/Test/V10static.ztst b/Test/V10static.ztst index 11f54e0..cc69db7 100644 --- a/Test/V10static.ztst +++ b/Test/V10static.ztst @@ -50,8 +50,7 @@ # Depends on zsh-5.0.9 typeset keyword typeset -a array_test=(top level) () { - static -a array_test - array_test=(in function) + local -Sa array_test=(in function) () { static array_test print $+array_test @@ -107,7 +106,7 @@ print ${(t)hash_test} ${(kv)hash_test} } outer () { - static -A hash_test; hash_test=(in function) + local -SA hash_test=(in function) typeset -p hash_test inner } @@ -159,7 +158,7 @@ F:note "typeset" rather than "static" in output from outer $ZTST_testdir/../Src/zsh -fc 'print X $array_test' } () { - static -ax array_test; array_test=(whaat) + local -Sax array_test=(whaat) print Y $array_test $ZTST_testdir/../Src/zsh -fc 'print X $array_test' inner @@ -195,7 +194,7 @@ F:note "typeset" rather than "static" in output from outer typeset -A hash_test=(top level) () { - static -A hash_test; hash_test=(in function) + local -SA hash_test=(in function) () { print X ${(kv)hash_test} } @@ -209,7 +208,7 @@ F:note "typeset" rather than "static" in output from outer typeset -A hash_test=(top level) () { - static -A hash_test; hash_test=(in function) + local -SA hash_test=(in function) () { print X ${(kv)hash_test} hash_test[in]=deeper @@ -224,8 +223,8 @@ F:note "typeset" rather than "static" in output from outer typeset -A hash_test=(top level) () { - static -a array_test; array_test=(in function) - static -A hash_test; hash_test=($array_test) + local -Sa array_test=(in function) + local -SA hash_test=($array_test) () { print X ${(kv)hash_test} hash_test=(even deeper) @@ -241,7 +240,7 @@ F:note "typeset" rather than "static" in output from outer typeset -A hash_test=(top level) () { - static -A hash_test; hash_test=(in function) + local -SA hash_test=(in function) () { print X ${(kv)hash_test} unset hash_test