Skip to content
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

Nested .STATIC Sections #117

Open
cspiel opened this issue Mar 5, 2019 · 0 comments
Open

Nested .STATIC Sections #117

cspiel opened this issue Mar 5, 2019 · 0 comments

Comments

@cspiel
Copy link
Collaborator

cspiel commented Mar 5, 2019

.STATIC sections nested inside sections are interesting.

  • Problem 1: The documentation says (in section 4.15.1) that plain
    .STATIC targets export all of their variables. However, the
    export appears incomplete: we can access such a variable, but a
    function defined inside the same .STATIC block does not retrieve
    the variable's contents. No error is emitted, though.

  • Problem 2: If we export a function from a section and this
    function binds a variable from a nested .STATIC section, the
    binding dissappears outside of the defining section.

Example program (see comments for locations of Problem 1 and
Problem 2):

##  Uncomment the next line to see dynamic binding in action.
#public.b = $'top-level def'


section
        .STATIC:  # `.MEMO' works, too ;-)
                a = $'sectioned, static def'
                fa() =
                        return $(a)

                ##  Use `a' and `fa' inside of static block.
                println($"[section] [static]  a = <$(a)>")
                println($"[section] [static]  fa: <$(fa)>")


        ##  Use `a' and `fa' outside of static block.
        println($"[section]           a = <$(a)>")

        ##  Problem 1: No error here, but "empty" result.  We have
        ##  just proven that `a' is visible, so `fa' ought to return
        ##  `a's contents.
        println($"[section]           fa: <$(fa)>")


        ##  Copy static `a' to non-static `b'.
        b = $(a)
        println($"[section]           b = <$(b)>")

        ga() =
                return $(a)
        gb() =
                return $(b)


        ##  Use `ga' and `gb' in the same scope as their definitions.
        println($"[section]           ga: <$(ga)>")
        println($"[section]           gb: <$(gb)>")

        ##  `unbound variable' error triggered outside of `section'
        ##  disappears if we add `a' to the export list.  No need to
        ##  export `b', though because of dynamic binding.
        export ga gb


##  Sectioned `b' has been "captured" by `gb'.
println($"gb: <$(gb)>")

##  Problem 2: The next line fails with `unbound variable: public.a'.
println($"ga: <$(ga)>")

Output of osh example.om:

[section] [static]  a = <sectioned, static def>
[section] [static]  fa: <sectioned, static def>
[section]           a = <sectioned, static def>
[section]           fa: <>
[section]           b = <sectioned, static def>
[section]           ga: <sectioned, static def>
[section]           gb: <sectioned, static def>
gb: <sectioned, static def>
*** omake error:
   File example.om: line 30, characters 23-27
   unbound variable: public.a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant