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

ExtVar support #77

Merged
merged 1 commit into from
Sep 29, 2017
Merged

ExtVar support #77

merged 1 commit into from
Sep 29, 2017

Conversation

sbarzowski
Copy link
Collaborator

Only through internal API. Also no TLA support at the moment.

@sbarzowski
Copy link
Collaborator Author

@sparkprime @lwander

@coveralls
Copy link

coveralls commented Sep 25, 2017

Coverage Status

Coverage increased (+0.7%) to 83.754% when pulling aa3635e on sbarzowski:external-vars into 650825c on google:master.

interpreter.go Outdated
idArrayElement ast.Identifier // TODO what is it?
idInvariant ast.Identifier // TODO what is it?
externalVars vmExtMap // TODO what is it?
// Current stack. It
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing word(s) after It

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed

@coveralls
Copy link

coveralls commented Sep 25, 2017

Coverage Status

Coverage increased (+0.7%) to 83.754% when pulling e184785 on sbarzowski:external-vars into 650825c on google:master.

imports.go Outdated
func codeToPV(e *evaluator, filename string, code string) potentialValue {
node, err := snippetToAST(filename, code)
if err != nil {
// TODO(sbarzowski) perhaps we should wrap (static) error here
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be a runtime error. Current behavior of C++ is broken. We need to document and test
each case (import, importstr, ext-code, tla-code).

It should be allowed to import from a non-existent file in a branch that never gets executed. That is the semantics of the language.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So yeah I think if you want to eagerly pre-parse the AST, you have to defer any syntax error until actual use. The C++ implementation re-parses it every time it's referred to I think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The C++ implementation re-parses it every time it's referred to I think?

No. I think Go and C++ implementation handle caching in pretty much the same way:

/** Import another Jsonnet file.
     *
     * If the file has already been imported, then use that version.  This maintains
     * referential transparency in the case of writes to disk during execution.  The
     * cache holds a thunk in order to cache the resulting value of execution.
     *
     * \param loc Location of the import statement.
     * \param file Path to the filename.
     */
    HeapThunk *import(const LocationRange &loc, const LiteralString *file)
    {
        ImportCacheValue *input = importString(loc, file);
        if (input->thunk == nullptr) {
            // EVALUATION CODE
        }
        return input->thunk;
    }

/** Import a file as a string.
     *
     * If the file has already been imported, then use that version.  This maintains
     * referential transparency in the case of writes to disk during execution.
     *
     * \param loc Location of the import statement.
     * \param file Path to the filename.
     * \param found_here If non-null, used to store the actual path of the file
     */
    ImportCacheValue *importString(const LocationRange &loc, const LiteralString *file)
    {
        std::string dir = dir_name(loc.file);

        const UString &path = file->value;

        std::pair<std::string, UString> key(dir, path);
        ImportCacheValue *cached_value = cachedImports[key];
        if (cached_value != nullptr)
            return cached_value;
        // [code that actually fetches it]
        cachedImports[key] = input_ptr;
        return input_ptr;
    }

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated TODO to reflect the decision.

@coveralls
Copy link

coveralls commented Sep 28, 2017

Coverage Status

Coverage increased (+0.7%) to 83.913% when pulling 750b2d1 on sbarzowski:external-vars into 93bcf64 on google:master.

@sparkprime sparkprime merged commit b1a9c0b into google:master Sep 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants