core/execution/Execution.protos

Repository
guillermomolina/protos
Commit
379c6fa63685c39a5954cfbd577bfda3b4df8e75
Tree
8cd4f4afe29ae4c3866381f38c1858108e9799f6
Blob
1ec8da9d28eb2c55c9dbe529faf92ad9cd5d0552
Source
View exact source on GitHub
// THE LICENSED WORK IS PROVIDED UNDER THE TERMS OF THE ADAPTIVE PUBLIC LICENSE
// ("LICENSE") AS FIRST COMPLETED BY: Guillermo Adrián Molina. ANY USE, PUBLIC
// DISPLAY, PUBLIC PERFORMANCE, REPRODUCTION OR DISTRIBUTION OF, OR PREPARATION OF
// DERIVATIVE WORKS BASED ON, THE LICENSED WORK CONSTITUTES RECIPIENT'S ACCEPTANCE
// OF THIS LICENSE AND ITS TERMS, WHETHER OR NOT SUCH RECIPIENT READS THE TERMS OF
// THE LICENSE. "LICENSED WORK" AND "RECIPIENT" ARE DEFINED IN THE LICENSE. A COPY
// OF THE LICENSE IS LOCATED IN THE TEXT FILE ENTITLED "LICENSE.TXT" ACCOMPANYING
// THE CONTENTS OF THIS FILE. IF A COPY OF THE LICENSE DOES NOT ACCOMPANY THIS
// FILE, A COPY OF THE LICENSE MAY ALSO BE OBTAINED AT THE FOLLOWING WEB SITE:
// https://github.com/guillermomolina/protos
//
// Software distributed under the License is distributed on an "AS IS" basis,
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
// the specific language governing rights and limitations under the License.

// EXTERNAL_PROCESS.md §§1-3: authority-free, source-backed external
// execution protocol. Possessing this prototype confers no authority: the
// private bridge authenticates the host grant and performs host effects.
// _coreExecutionBridge stays in the unpublished Core bootstrap context and
// is never a Prelude binding, module member or slot of Execution.
//
// start has exactly four arguments. Portable type validation and the argv
// snapshot happen here, before any host effect; native representability,
// the Map snapshot and environment-name uniqueness are checked by the
// bridge in the same turn.

Execution: {
    start: (...args) => {
        bridge: _coreExecutionBridge
        if(args.size() != 4) {
            Error().signal()
        }
        executable: args[0]
        arguments: args[1]
        environment: args[2]
        workingDirectory: args[3]

        argv: null
        valid: String.recognizes(executable) && Array.recognizes(arguments)
        if(valid) {
            argv = Array(...arguments)
            for(argument in argv) {
                if(!String.recognizes(argument)) {
                    valid = false
                }
            }
        }
        if(valid && (workingDirectory !== null)) {
            valid = String.recognizes(workingDirectory)
        }

        answer: null
        if(valid) {
            answer = bridge.start(this, executable, argv, environment, workingDirectory)
        } else {
            answer = bridge.failed(InvalidIOArgument {})
        }
        answer
    }
}