Commit Graph

68 Commits

Author SHA1 Message Date
Dominik Süß
6838b0a0b8
feat: add debugger support (#739) 2024-06-09 15:09:24 +01:00
Rohit Jangid
772ebba669 Add support to return int based value from native functions golang implementations 2023-04-13 14:51:53 +01:00
Jesse
2655afd2bd
memory align structs (#635)
feat: align most structs and add lint rule to enforce struct alignment
2022-10-19 06:19:15 +01:00
Jesse-Cameron
c450a168d4 perf: add size hint to map creation
in order to avoid unnecessary hashmap resizing, add size parameters when
creating maps
2022-09-16 18:26:18 +01:00
Angus Lees
856bd58872 Add 'importbin' statement
Add `importbin` statement.  Similar to `importstr` but the result is
an array of numbers (all integers 0-255).
2022-03-03 22:49:02 +00:00
Stanisław Barzowski
b00b56c335 Avoid depending on stdlib variable for desugaring.
The fix is easy – we just use "$std" which the user cannot access,
because it's not a valid identifier.
2021-08-09 19:25:33 +01:00
Hanyu Cui
f742f2463e
Allow setting a different output stream than os.Stderr for std.trace (#514)
Allow std.trace output to other streams
2021-02-09 14:44:23 +01:00
gotwarlost
6d6c293079 allow initialization of external and TLA code variables from an AST node.
This allows configuration of a VM with an external code variable that has been pre-parsed into an AST node.
This allows a caller to pre-parse a large object into a node and re-use that for multiple VMs. The cost
of converting the object to an ast.Node is incurred only once by the caller as opposed to having this
eagerly incurred (whether or not the object is used) before the eval.
2021-02-04 12:05:09 +01:00
Stanisław Barzowski
6140a2f75a Better stacktrace for manifestation, +: and object assertions.
Fixes #282
2021-01-01 19:17:27 +01:00
Stanisław Barzowski
797bfd89ed Better handling of stack traces.
Fixes multiple issues with stack traces leading to missing
stack trace lines. Also, we no longer put builtin context
on the line which *calls* the builtin as if it was a part
of the builtin itself.

Code for stack trace handling was centralized. We no longer
need traceElement argument in ~every function. Now the stack
trace state is kept solely in the interpreter.
2020-11-21 15:36:05 +01:00
Stanisław Barzowski
9ada769ce4 Make golangci-lint happy
Some of the suggestions are minor bug fixes (missing error handling).
2020-03-05 14:54:27 +01:00
Dave Cunningham
8b2b1ba839 Avoid float overflow errors at parse time. 2020-02-27 23:06:53 +00:00
Stanisław Barzowski
fe82a78401 Adaptive string representation
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.
2020-01-04 23:28:21 +01:00
Dave Cunningham
dc5c94ac78
Add fodder to AST nodes (#319)
* Preserve fodder during parsing.
2019-09-24 12:11:22 +01:00
Stanisław Barzowski
21c00f1b9e Better importing (caching & public API)
* 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).
2019-09-23 15:37:10 +02:00
alldroll
f00242da42 Add runtime check for binary +-* operations for numbers 2019-09-19 14:34:14 +01:00
Stanisław Barzowski
85fd887750 Unexport a bunch of symbols
Many things were exported for no particular reason.
2019-09-09 16:11:00 +02:00
Stanisław Barzowski
c77f22c99f Eliminate the unnecessary ast.StdAst
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.
2019-09-01 21:17:29 +02:00
Stanisław Barzowski
11e63b6703 Make golint happy (#296) 2019-07-24 13:02:12 -04:00
Stanisław Barzowski
e5e27c0f01 Object field caching
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.
2019-07-23 21:57:36 +02:00
Stanisław Barzowski
33b6dcfa53
Keep object locals only once in AST (#263)
Keep object locals only once in AST

For example this reduces the size of stdlib ast file
roughly 3x. Note that this change doesn't regenerate the stdlib,
so that the diff here is sane.

It is likely to slightly improve performance of code using
a lot of locals (~10% on bench.05.gen.jsonnet).

The desugaring is more strightforward now, and we're back
to desugaring each node exactly once.
2019-05-07 22:43:55 +02:00
Stanisław Barzowski
530e7960bd Fix improper stack trimming with operators and tailstrict
My understanding of origin of this bug was that once we
were creating thunks for binary operator arguments. So the environment
was no longer needed once they were created, so they could be tailcalls.

Now we're calling i.evaluate directly (for performance) and now
the environment cannot be destroyed during the evaluation of the first
argument.
2019-03-07 09:10:23 -05:00
Dave Cunningham
2973e24152
Internal refactor to improve performance (#225)
* Internal refactor to improve performance
2018-06-01 10:52:20 -04:00
Luke Granger-Brown
643210d274 Add string output support for multifile output (#220)
* Add test support for multi-file output.

* Add -update support for multi-file output tests.

* Add support for string output in multi-file output mode.

* Rename 'stringOutput' to 'stringOutputMode' to better express what it does

* Refactor main_test to make it less nested.

This also causes the -update flag to output a list of files which
have been updated. This does not include the paths which are deleted
for multi-file tests.
2018-05-09 11:49:07 -04:00
Stanisław Barzowski
f4428e6d47 Better Importer interface
As discussed in https://github.com/google/go-jsonnet/issues/190
2018-04-28 01:34:42 -04:00
Dave Cunningham
5cc426ed04 Bring submodule and stdlib to cpp master 2018-03-06 23:49:02 -05:00
Marcelo Cantos
ed5f280c59 Apply golint recommendations (#196)
* Apply golint recommendations
2018-02-26 14:12:25 -05:00
Petr Krebs
bed2cd89bc Do not assume that import path is always a filesystem path (do not clean it up) 2018-02-17 16:34:54 -05:00
Stanisław Barzowski
eedf6760ad Convert non-string errors to string 2018-01-18 12:48:38 -05:00
Stanisław Barzowski
d135effbe4 Add missing check for array out of bounds 2018-01-17 15:26:31 -05:00
Dave Cunningham
7c8f4d0b12
Call top level function even if there are no TLAs (match cpp semantics) (#169)
* Call top level function even if there are no TLAs (match cpp semantics)
2018-01-10 20:43:55 -05:00
Liang Mingqiang
aeda6138e5 experiment dump ast to source code (#101)
* Add facility to dump part of Go heap as Go code.

* Generate stdlib AST as Go code

* Use hardcoded stdlib AST instead of parsing it
2017-11-07 23:31:11 -05:00
Dave Cunningham
c60056c75f
Feature-complete commandline interface (#138)
* Feature-complete commandline interface
* Make errors match cpp implementation
2017-11-03 22:00:30 -04:00
Dave Cunningham
f965f9ee04
For compatability, emit the \n within the library, not the cmd (#137)
* For compatability, emit the \n within the library, not the commandline tool
* Also add manifestString to library
2017-10-29 21:41:01 -04:00
Alex Clemmer
52d2fdcfde Rename jsonnet.nativeFunction -> jsonnet.NativeFunction
Currently, `jsonnet.VM#NativeFunction` takes a single argument of type
`jsonnet.nativeFunction`. This is ok for internal use, but because this
type is private to the `jsonnet` package, it is not possible for a
third party to call this function (since it can't instantiate the type).

This commit makes this type public to remedy this problem.
2017-10-24 21:53:52 -04:00
Dave Cunningham
f3cb9eb8cf Rename 'ast' variable that shadowed package name. 2017-10-13 17:03:01 -04:00
Stanisław Barzowski
ed281bc563 Support for native callbacks 2017-10-13 15:49:06 -04:00
Stanisław Barzowski
0f049eaa38 Basic tailstrict support 2017-10-13 15:33:23 -04:00
Stanisław Barzowski
2db3d1c3cc TLA support 2017-10-12 20:00:45 -04:00
Stanisław Barzowski
4b0735826d Rename valueSimpleObjectField -> simpleObjectField
A field on it's own is not a value
2017-10-10 00:31:49 -04:00
Stanisław Barzowski
5b1798233c Represent types as Go objects, not strings (give them pointer identity) (#119)
Faster comparisons and IMO cleaner feeling overall.
It doesn't affect behaviour in any way.
2017-10-10 00:11:36 -04:00
Stanisław Barzowski
4a4a7fe459 Check index types (#116)
Before it would just crash
2017-10-10 00:09:32 -04:00
Stanisław Barzowski
ba0f236b14 Optional eval (#92)
* Optional arguments
2017-10-10 00:06:14 -04:00
Stanisław Barzowski
94797696a9 Remove commented out code 2017-10-03 15:17:43 -04:00
Stanisław Barzowski
774715b3cf Support for std.thisFile, fixes #91.
Sadly it means that std in no longer the same object in each file.
2017-10-03 15:17:43 -04:00
Stanisław Barzowski
c3459153df Location, error formatting and stack trace improvements (#59)
* Location, error formatting and stack trace improvements

* Static context for AST nodes
* Thunks no longer need `name`
* Prototype for showing snippets in error messages (old format still
available)
* Use ast.Function to represent methods and local function sugar.
* Change tests so that the error output is pretty
2017-10-03 14:27:44 -04:00
Stanisław Barzowski
ec94dec214 Remove stale TODOs 2017-09-29 12:36:29 -04:00
Stanisław Barzowski
e7249a1131 Separate manifestation from serialization to string
This is necessary for example for native functions
(which take json as arguments).

Standard "encoding/json" representation is used, but I have
mixed feeling about it. Not sure if treating json values as interface{}
is the right trade-off in our case.
2017-09-29 12:36:29 -04:00
Stanisław Barzowski
0b52ea4d40 Support for various kinds of strings in imports 2017-09-29 12:34:21 -04:00
Stanisław Barzowski
121a77c66f Remove a few stale TODOs 2017-09-29 12:32:44 -04:00