-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementation of the local
builtin with support for dynamic local scopes
#703
base: dev
Are you sure you want to change the base?
Commits on Apr 22, 2021
-
Incomplete: Add local and declare builtins with a dynamic scope
This implementation of local doesn't have proper scoping. The POSIX function scoping mechanism should be implemented in b_dot_cmd, although it should be done without breaking backward compatibility (i.e., typeset's behavior in POSIX functions shouldn't change as a result of implementing scoping). Discussion: ksh93#123 src/cmd/ksh93/sh/name.c: - Set a dynamic scope in ksh functions for the local and declare builtins. This currently doesn't work in POSIX functions since b_dot_cmd doesn't apply any scoping right now. src/cmd/ksh93/bltins/typeset.c, src/cmd/ksh93/sh/xec.c: - Only allow the local builtin to run inside of functions. This is accomplished by using a new 'SH_INFUNCTION' state set when ksh is inside of a function. - Set shp->st.var_local to shp->var_tree for declare and local to get a dynamic scope in ksh functions. For typeset use shp->var_base to get a static scope in ksh functions. This will need bug-testing for when local is used in namespaces. - Add local and declare to top comment alongside other builtins. - Add a dictionary generator entry for declare(1). src/cmd/ksh93/data/builtins.c, src/cmd/ksh93/include/builtins.h: - Add local and declare to the builtin table as declaration builtins. Depending on how local is specified in the next POSIX standard, it may need to be changed to a special builtin. That does break backward compatibility with existing ksh scripts though (such as one regression test script), so for now it's just a regular builtin. - Update the man pages with references to local(1). Add information to the man page about the intended scoping of declare and local, although it's not completely implemented in POSIX functions. src/cmd/ksh93/tests/builtins.sh: - Run one of the regression tests for builtins inside of a function to fix a test failure with the local builtin. src/cmd/ksh93/tests/local.sh: - Add a number of regression tests mostly targeted at the local builtin. Most of the bugs tested for here are present in the ksh93v- and ksh2020 implementations of local and declare.
Configuration menu - View commit details
-
Copy full SHA for ccfe8a6 - Browse repository at this point
Copy the full SHA ccfe8a6View commit details
Commits on Apr 26, 2021
-
Configuration menu - View commit details
-
Copy full SHA for 32672ad - Browse repository at this point
Copy the full SHA 32672adView commit details
Commits on May 3, 2021
-
Configuration menu - View commit details
-
Copy full SHA for 9ff934a - Browse repository at this point
Copy the full SHA 9ff934aView commit details
Commits on May 8, 2021
-
Configuration menu - View commit details
-
Copy full SHA for 3b55c89 - Browse repository at this point
Copy the full SHA 3b55c89View commit details
Commits on May 12, 2021
-
Configuration menu - View commit details
-
Copy full SHA for 03b849c - Browse repository at this point
Copy the full SHA 03b849cView commit details
Commits on May 23, 2021
-
Configuration menu - View commit details
-
Copy full SHA for 99a7bcb - Browse repository at this point
Copy the full SHA 99a7bcbView commit details
Commits on Dec 6, 2021
-
Configuration menu - View commit details
-
Copy full SHA for d369dfd - Browse repository at this point
Copy the full SHA d369dfdView commit details -
Configuration menu - View commit details
-
Copy full SHA for 94013f5 - Browse repository at this point
Copy the full SHA 94013f5View commit details
Commits on Dec 17, 2021
-
Configuration menu - View commit details
-
Copy full SHA for 03b5fb8 - Browse repository at this point
Copy the full SHA 03b5fb8View commit details
Commits on Jan 5, 2022
-
Configuration menu - View commit details
-
Copy full SHA for cf953aa - Browse repository at this point
Copy the full SHA cf953aaView commit details
Commits on Jan 27, 2022
-
Configuration menu - View commit details
-
Copy full SHA for ad96056 - Browse repository at this point
Copy the full SHA ad96056View commit details -
Configuration menu - View commit details
-
Copy full SHA for 91d3079 - Browse repository at this point
Copy the full SHA 91d3079View commit details
Commits on Jan 1, 2024
-
Configuration menu - View commit details
-
Copy full SHA for 7721eeb - Browse repository at this point
Copy the full SHA 7721eebView commit details -
Fix builtins.sh failure by setting NV_GLOBAL in POSIX functions
POSIX functions should default to placing variables on the global scope, so this should be perfectly fine.
Configuration menu - View commit details
-
Copy full SHA for 666cd88 - Browse repository at this point
Copy the full SHA 666cd88View commit details -
Configuration menu - View commit details
-
Copy full SHA for c9a2289 - Browse repository at this point
Copy the full SHA c9a2289View commit details -
Configuration menu - View commit details
-
Copy full SHA for eba8be8 - Browse repository at this point
Copy the full SHA eba8be8View commit details -
Configuration menu - View commit details
-
Copy full SHA for 3493f2d - Browse repository at this point
Copy the full SHA 3493f2dView commit details -
Configuration menu - View commit details
-
Copy full SHA for fa23bd4 - Browse repository at this point
Copy the full SHA fa23bd4View commit details -
Configuration menu - View commit details
-
Copy full SHA for 10f9ad1 - Browse repository at this point
Copy the full SHA 10f9ad1View commit details -
Configuration menu - View commit details
-
Copy full SHA for dc7841d - Browse repository at this point
Copy the full SHA dc7841dView commit details -
Configuration menu - View commit details
-
Copy full SHA for c91998b - Browse repository at this point
Copy the full SHA c91998bView commit details -
Configuration menu - View commit details
-
Copy full SHA for bffb6b8 - Browse repository at this point
Copy the full SHA bffb6b8View commit details -
I suspect that the only reason dynamic scoping even somewhat works is not because an actual scope was opened, but rather because the child functions use the parent function's scope outright. This is no good and will need a rewrite.
Configuration menu - View commit details
-
Copy full SHA for 33a6f17 - Browse repository at this point
Copy the full SHA 33a6f17View commit details
Commits on Jan 15, 2024
-
Abandon unsalvageable ksh93v- scoping code and rewrite scoping
See the lengthy comment in xec.c for a detailed explanation.
Configuration menu - View commit details
-
Copy full SHA for 88d77a5 - Browse repository at this point
Copy the full SHA 88d77a5View commit details
Commits on Jan 16, 2024
-
Configuration menu - View commit details
-
Copy full SHA for babebd0 - Browse repository at this point
Copy the full SHA babebd0View commit details -
Configuration menu - View commit details
-
Copy full SHA for 3f695ba - Browse repository at this point
Copy the full SHA 3f695baView commit details -
Configuration menu - View commit details
-
Copy full SHA for 50bb787 - Browse repository at this point
Copy the full SHA 50bb787View commit details -
Configuration menu - View commit details
-
Copy full SHA for a29d218 - Browse repository at this point
Copy the full SHA a29d218View commit details -
Fix modernish regression tests failing on init
Bear in mind that there are still three test failures in the modernish test suite, which are probably cause by switching to sh_funscope() for POSIX function handling: 001: push;set;check;send sig;unset;pop;check - FAIL: check traps, test var=$(trap) 007: trap stack in a subshell - FAIL: wrong output from 'trap' (3) 008: 'trap' can ignore sig if no stack traps - FAIL: not ignored while no stack traps These will need to be fixed at some point.
Configuration menu - View commit details
-
Copy full SHA for 81499fc - Browse repository at this point
Copy the full SHA 81499fcView commit details -
Configuration menu - View commit details
-
Copy full SHA for 6b5534e - Browse repository at this point
Copy the full SHA 6b5534eView commit details -
Configuration menu - View commit details
-
Copy full SHA for 9c751fe - Browse repository at this point
Copy the full SHA 9c751feView commit details -
Configuration menu - View commit details
-
Copy full SHA for 3732068 - Browse repository at this point
Copy the full SHA 3732068View commit details -
Configuration menu - View commit details
-
Copy full SHA for 45d8749 - Browse repository at this point
Copy the full SHA 45d8749View commit details -
Configuration menu - View commit details
-
Copy full SHA for 48a7d1d - Browse repository at this point
Copy the full SHA 48a7d1dView commit details -
Configuration menu - View commit details
-
Copy full SHA for c07491a - Browse repository at this point
Copy the full SHA c07491aView commit details -
Configuration menu - View commit details
-
Copy full SHA for c7ae6c8 - Browse repository at this point
Copy the full SHA c7ae6c8View commit details -
Configuration menu - View commit details
-
Copy full SHA for bfd0052 - Browse repository at this point
Copy the full SHA bfd0052View commit details -
Add static scoping flag and make other improvements
List of changes: - A -c flag has been added to typeset that allows you to use statically scoped variables in POSIX functions. - A noteable caveat regarding typeset -p's interactions with the new scoping functionality has been documented. - The regression tests have been overhauled to account for the special handling of 'command typeset' in sh_exec(). More were also added for the new 'typeset -c' feature. - The two nv_scan calls have been rolled into one faster call, which should have equivalent functionality (cf. the code for the scanfilter() function). - Increment copyright dates using the update_copyright script from the wiki.
Configuration menu - View commit details
-
Copy full SHA for 4434780 - Browse repository at this point
Copy the full SHA 4434780View commit details
Commits on Jan 17, 2024
-
Configuration menu - View commit details
-
Copy full SHA for 83d1324 - Browse repository at this point
Copy the full SHA 83d1324View commit details -
Configuration menu - View commit details
-
Copy full SHA for 189736a - Browse repository at this point
Copy the full SHA 189736aView commit details -
Configuration menu - View commit details
-
Copy full SHA for c08f2bf - Browse repository at this point
Copy the full SHA c08f2bfView commit details -
Configuration menu - View commit details
-
Copy full SHA for 31d2d24 - Browse repository at this point
Copy the full SHA 31d2d24View commit details -
Configuration menu - View commit details
-
Copy full SHA for 2a1ec61 - Browse repository at this point
Copy the full SHA 2a1ec61View commit details -
Configuration menu - View commit details
-
Copy full SHA for 6d5b2fa - Browse repository at this point
Copy the full SHA 6d5b2faView commit details -
Add preliminary support for -D to
typeset -p
TODO: Add regression tests for 'declare foo' and 'declare -l -i foo'.
Configuration menu - View commit details
-
Copy full SHA for 010b0e3 - Browse repository at this point
Copy the full SHA 010b0e3View commit details -
Configuration menu - View commit details
-
Copy full SHA for fe00155 - Browse repository at this point
Copy the full SHA fe00155View commit details
Commits on Jan 18, 2024
-
Configuration menu - View commit details
-
Copy full SHA for bae563d - Browse repository at this point
Copy the full SHA bae563dView commit details -
Add regression test for typeset -p output and update some documentation
- local.sh: Added tests for the presence of the -D flag in output. - sh.1: Removed this comment as this behavior is subject to change. - xec.c: Update comment (the ksh93v- code is something I'm trying to salvage, but it certainly does seem unsalvageable.)
Configuration menu - View commit details
-
Copy full SHA for b601a87 - Browse repository at this point
Copy the full SHA b601a87View commit details
Commits on Jan 23, 2024
-
Configuration menu - View commit details
-
Copy full SHA for 532a6c4 - Browse repository at this point
Copy the full SHA 532a6c4View commit details
Commits on Feb 6, 2024
-
Configuration menu - View commit details
-
Copy full SHA for c338eef - Browse repository at this point
Copy the full SHA c338eefView commit details -
On a side note, I haven't had the chance develop local(1) further because of a lack of time. In any case the current scoping bug is evading a fix. The current approach needs significant changes, as it has no backward compatibility when POSIX functions are nested in ksh functions (the normal ksh93 behavior is to have POSIX functions inherit the ksh function's full scope and use it directly, which necessarily includes the ksh function's statically scoped local variables. The current approach doesn't allow for this as POSIX functions have their own scope for the local builtin. Backward compatibility is currently achieved by having typeset modify the global scope directly, but that's not really the correct thing to do. I have tried altering typeset to modify the parent ksh function's scope directly, but such changes cannot be seen in the POSIX function itself after the variable in the parent function was changed, as the change only happens in the parent scope and not the current local scope (which defeats the whole purpose). To attempt to fix that, I then tried linking the parent scope to the local scope, but so far that just breaks the local scope (the cdt API lends itself very poorly to dynamic scoping).
Configuration menu - View commit details
-
Copy full SHA for 560d73d - Browse repository at this point
Copy the full SHA 560d73dView commit details
Commits on Feb 14, 2024
-
Configuration menu - View commit details
-
Copy full SHA for 0d91670 - Browse repository at this point
Copy the full SHA 0d91670View commit details -
Configuration menu - View commit details
-
Copy full SHA for 24757cd - Browse repository at this point
Copy the full SHA 24757cdView commit details -
Configuration menu - View commit details
-
Copy full SHA for a473068 - Browse repository at this point
Copy the full SHA a473068View commit details
Commits on Feb 15, 2024
-
Configuration menu - View commit details
-
Copy full SHA for c04159d - Browse repository at this point
Copy the full SHA c04159dView commit details