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

[Core\export] add documentation example #1621

Open
github-actions bot opened this issue Apr 29, 2024 · 0 comments
Open

[Core\export] add documentation example #1621

github-actions bot opened this issue Apr 29, 2024 · 0 comments
Labels
documentation Improvements or additions to documentation easy Easy issues that can be solved in little time library Issues related to the standard library todo Automatically generated issues from TODOs in the code

Comments

@github-actions
Copy link

[Core\export] add documentation example

# TODO(Core\export) add documentation example

                    Error_AssertionFailed(x.codify())

    builtin "export",
        alias       = unaliased, 
        op          = opNop,
        rule        = PrefixPrecedence,
        description = "export given container children to current scope",
        args        = {
            "module"     : {Module, Dictionary, Object}
        },
        attrs       = {
            "all"   : ({Logical},"export everything, regardless of whether it's been marked as public (makes sense only for modules)")
        },
        returns     = {Nothing},
        # TODO(Core\export) add documentation example
        #  labels: library, documentation, easy
        example     = """
        """:
            #=======================================================
            let exportAll = hadAttr("all")

            if xKind in {Module, Object}:

                var internalObjName = 
                    if xKind == Module:
                        "__" & x.singleton.proto.name
                    else:
                        when not defined(WEB):
                            "__omodule" & "_" & $(genOid())
                        else:
                            "__omodule" & "_" & $(rand(1_000_000_000..2_000_000_000))

                SetSym(internalObjName, x.singleton)

                var valuePairs = 
                    if xKind == Module:
                        x.singleton.o
                    else:
                        x.o

                for k,v in valuePairs.pairs:
                    if v.kind == Method and (exportAll or v.mpublic):
                        let newParams = v.mparams.filter((prm) => prm != "this").map((prm) => newString(prm))
                        var newBody = copyValue(v.mmain)
                        newBody = newBlock(@[
                            newLabel("this"),
                            newWord(internalObjName),
                            newWord("do"),
                            newBody
                        ])

                        var inPath: ref string = nil
                        if (let methodPath = v.info.path; not methodPath.isNil):
                            new(inPath)
                            inPath[] = methodPath[]

                        let fnc = newFunctionFromDefinition(newParams,newBody, inPath=inPath)

                        SetSym(k, fnc)
            else:
                for k,v in x.d.pairs:
                    SetSym(k, v)

    builtin "function",
        alias       = dollar,
        op          = opFunc,

30aca7dcd96c7faeacf2e52fba387b2dd237b602

@github-actions github-actions bot added documentation Improvements or additions to documentation easy Easy issues that can be solved in little time library Issues related to the standard library todo Automatically generated issues from TODOs in the code labels Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation easy Easy issues that can be solved in little time library Issues related to the standard library todo Automatically generated issues from TODOs in the code
Projects
None yet
Development

No branches or pull requests

0 participants