When adding long strings, don't copy them immediately. Instead
build long strings only when their contents are requested.
This allows to build a long string from parts, using a regular
operator+ in linear time. This lets users to worry much less
about using std.join etc.
If indexing the string is mixed with building it using operator+
the behavior can still be quadratic. We may want to address it in
a later change.
* feat(parser): export parser.Children
As parser was moved to internal/parser, it is not possible to import it into
external projects anymore.
However, parser.Children() is handy to use in static analysis tools, so it is
worth exporting. This does that by adding a stub package
`github.com/google/go-jsonnet/parser` that wraps the internal function.
Signed-off-by: sh0rez <me@shorez.de>
* Renamed jsonValue obj field to val
* Renamed jsonValue children field to owned + added an explicit comment about this field
* Got rid of unnecessary vm handle checks
* Renamed arg to param, identifiers to paramNames
* Raised maxID value to 100 000
* Removed freedIDs entry check
* Fixed jsonnet_json_array_append, jsonnet_json_object_append bugs
* jsonValue now stores the list of related struct_JsonnetJsonValue
instead of handles ids
* It adds new API which allows using VM for importing
files in external tools "just as Jsonnet would". This is
primarily intended for use in static analysis tools.
* Imports are now cached between evaluate calls. This may improve
performance significantly for some users. I would like to add
some way of achieving this with commandline in the future.
* Additional layer of caching was internally added - AST level.
This was necessary so that Jsonnet could always return the same
exact AST when asked multiple times (meaning the same pointers).
Sort is something that is highly optimized in most languages
and users can expect it to be fast. We can piggyback on
the Go implementation.
This change results in 100x speedup on bench.06.jsonnet.
There is no reason for external users to directly depend
on parser. It had a few random things exported as well,
namely errors and "children" functions (helpers for AST
traversal).
It was easy to extract the errors package, but I needed to leave
children in parser for now. The errors package was also
made internal, but it's a candidate for making it public
again potentially (if someone wants to display error messages
just like us). For now it's probably too incomplete anyway.
This change has a potential of breaking the existing users
since we technically remove public APIs. These were not needed
or even helpful for actually running Jsonnet code, but perhaps
someone used them anyway.
The initially empty ast.StdAst was created to break the circular
dependency. The generation of stdlib AST used to depend on
the primary "jsonnet" package, which meant that "jsonnet"
could not depend on it directly. Hence stdlib needed to be put
in the ast package. Now dumpstdlibast no longer depends on Jsonnet,
so we can get rid of this complication.
All code using ast.StdAst should now use astgen.StdAst.
Before this change updating BUILD.bazel file with Gazelle
would add `c-bindings/libgojsonnet.h` to `srcs/`.
It was prevented manually, but someone is going to let it slip
in at some point, so it's better to just not include it there
in the first place.
This change adds caching to objects fields, i.e. now subsequent
references to an object field are going to be served from cache.
Cache is kept within an object. Objects created with operator +
start with a clean cache (they have to, because in general all
the fields may have changed their values due to late binding).
This change comes naturally with a change of structure of objects,
now valueObject is a concrete struct which keeps "uncachedObject"
which is roughly equivalent to old objects.
Treating the "cpp-jsonnet" Git submodule as a separate local Bazel
repository precludes use of the "go-jsonnet" repository from other
workspaces, as Bazel misinterprets the relative path to the local
"cpp-jsonnet" repository. Instead, use the Git submodule content
directly along the package path from the workspace root.