Skip to content

filesystem: SCRIPTPATH and SCRIPTDIR  #1524

Open

Description

@abitrolly

Interpreters are pure. In their raw form they don't know anything about system calls. Then it comes "standard library" that adds these system call. Now interpreter can "open files" and do some other immediately useful stuff. The interpreter becomes practical, like Python.

The drawback of batteries included and buried under the surface, is that it is not easy to decouple these things to fix them for specific cases. My case are scripts that work from script dir. Like installation, testing, data analysis. Most interpreters have some hacks to get the directory of the script.

import os 
dir_path = os.path.dirname(os.path.realpath(__file__))

https://stackoverflow.com/questions/5137497/find-the-current-directory-and-files-directory?noredirect=1&lq=1

#!/usr/bin/env bash

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

https://stackoverflow.com/questions/59895/how-do-i-get-the-directory-where-a-bash-script-is-located-from-within-the-script

This stuff is unreadable. It requires so much system knowledge to understand, that I doubt anybody from new generation will be able to learn it. That's why WASI can decouple and simplify this inheritance of hacks.

interpreter + filesystem = context

When you just add filesystem calls to interpreter, it is not enough. Interpreter can run file from filesystem. Can run string from command line parameter. Can run code piped to it from other process. In each of these three cases, the context for the code will be different. the context should be full path for file, parameter for cmdline, pipe for running from stdin, console for running stuff from interactive prompt. For file, the context should also include full dirname, because it is important.

Maybe call it running context, or maybe there is a better name, but it really helps to have some specification for that. Because it will help so many tool authors to get around this unspecified behavior in interpreters.

Activity

  1. sbc100 commented on Aug 4, 2024

    @sbc100
    Member

    This seems like maybe an issue for the WASI repository?

  2. abitrolly commented on Aug 4, 2024

    @abitrolly
    Author

    @sbc100 maybe. I don't remember by which link I got here. Can you move it?

  3. sbc100 commented on Aug 4, 2024

    @sbc100
    Member

    I don't have permission to do that. Perhaps @dschuff can do it?

  4. dschuff commented on Aug 8, 2024

    @dschuff
    Member

    Are you suggesting some change to the spec, or some change to a particular interpreter, e.g. the reference interpreter? The core spec itself tries to separate out everything about the "context" by using an abstract embedding interface Interfaces to the filesystem would be on the "outside" of this interface. Practically speaking though, most interpreters (or the JS embedding) may or may not have an internal API that looks exactly like that, though; it's more a way to separate concerns.

  5. abitrolly commented on Aug 13, 2024

    @abitrolly
    Author

    @dschuff needed for all interpreters that run scripts from filesystem. It probably makes sense to try implement SCRIPTPATH and SCRIPTDIR in reference interpreter to see how to update the spec for all other interpreters to include this feature.

  6. sbc100 commented on Aug 13, 2024

    @sbc100
    Member

    The core spec doesn't specify anything to do with filesystems. Any discussion of filesystem APIs likely belongs in the WASI repo. I suggest we move this issue there.

  7. abitrolly commented on Aug 13, 2024

    @abitrolly
    Author

    @sbc100 I don't have privileges to move it. @dschuff can you move it?

  8. dschuff commented on Aug 14, 2024

    @dschuff
    Member

    IIUC this isn't about the filesystem API though, it's about how interpreters work (but unrelated to how they actually implement the wasm language). But the spec doesn't actually say anything about how interpreters should work, aside from the language semantics. The reference interpreter has some functionality for convenience (in terms of text format extensions and whatever command line flags it has), but it's not normative, and I don't know if it's actually specified. So if I'm understanding correctly what you're asking for, I don't think there's a place to put it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions