Commit Graph

38 Commits

Author SHA1 Message Date
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
7af3b8496c Add missing error handling branch
Fixes #255
2019-01-14 15:09:42 -05:00
Stanisław Barzowski
530cf7b07c Implement operators == and != as builtins (#221)
People use these operators in tight loops, without even
thinking about it, and it's previous implementation required
multiple object lookups (std.), string comparisons (for types)
and multiple jsonnet function calls.

This change introduces builtin, efficient implementation.
It results in ~3x speedup in strContains benchmark that
Angus provided on Slack.

Additional benefit is that equals/primitiveEquals distinction
is now obsolete, which made things simpler for everyone.
2018-05-23 22:26:30 -04:00
Dave Cunningham
405726fae2
Clone ASTs to avoid aliasing and double-unescaping (#210)
* Clone ASTs to avoid aliasing and double-unescaping
2018-03-07 11:23:32 -05:00
Marcelo Cantos
ed5f280c59 Apply golint recommendations (#196)
* Apply golint recommendations
2018-02-26 14:12:25 -05:00
Dave Cunningham
2ea01b24d8
Introduce a Parens AST (#189)
* Introduce a Parens AST
2018-02-16 13:01:14 -05:00
Dave Cunningham
fe6a54abaf Justify \/ escape 2017-12-07 21:05:26 -05:00
Stanisław Barzowski
03e2a7f474 Fix bad format string (#149) 2017-11-09 08:56:06 -05:00
Stanisław Barzowski
ed281bc563 Support for native callbacks 2017-10-13 15:49:06 -04:00
Stanisław Barzowski
ba0f236b14 Optional eval (#92)
* Optional arguments
2017-10-10 00:06:14 -04:00
Stanisław Barzowski
02a4eed22d Support $ in comprehesions, fixes #68 2017-10-03 19:51:01 -04:00
Stanisław Barzowski
80ce6ac112 Don't escape block strings (#98)
* Don't escape block strings
2017-10-03 14:29:12 -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
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
Stanisław Barzowski
0c86c9e109 Support of +:, in, in super
Also profiling
2017-09-28 22:21:46 -04:00
Stanisław Barzowski
78b4794523 Object comprehensions 2017-09-27 18:00:30 -04:00
Stanisław Barzowski
8638a21287 Object invariants (#62)
* Object invariants
2017-09-22 18:02:05 -04:00
Stanisław Barzowski
ad4be04fc1 Fix desugaring of assertions 2017-09-11 16:38:37 -04:00
Stanisław Barzowski
7ebcb06c98 Support for ifs in array comprehensions 2017-09-11 16:34:14 -04:00
Stanisław Barzowski
1e4797071f Even more builtins
Fix a bunch of bugs:
- Reverse meaning of boolean argument to objectFieldsEx and objectHasEx
- Slice desugaring using `std.slice` instead of `slice` as a field name.

Support + on string and something else.
Support + on arrays

assertEqual should now work properly
2017-09-08 14:19:19 -04:00
Stanisław Barzowski
860c3e6e70 Add more builtins 2017-09-07 15:41:41 -04:00
Stanisław Barzowski
c26c50c04b Array comprehensions (#35)
* Array comprehensions

Implemented using flatMap.

The representation in AST was changed - now it expresses
the semantic structure better.

Ifs in comprehensions are not supported yet, but easy.
2017-09-07 11:55:33 -04:00
Stanisław Barzowski
77b8b9e335 Optional args parser/lexer/ast support (#33)
* Optional args parser/lexer/ast support

Just "frontend" part. They are ignored during actual execution.
2017-09-06 11:53:10 -04:00
Stanisław Barzowski
b1427d563b Parser & desugarer support for "in" 2017-08-29 22:14:12 -04:00
Stanisław Barzowski
a4456d8ecf Add desugaring of standalone assertions 2017-08-29 22:09:40 -04:00
Alex Clemmer
0d716ae56f Move parser to its own package 2017-08-25 00:30:56 -04:00
Alex Clemmer
0cd1ad28cd Make parser members public 2017-08-25 00:30:56 -04:00
Alex Clemmer
ad56a074aa Move AST to its own package 2017-08-25 00:30:56 -04:00
Alex Clemmer
c610dec2ef Make AST data structures public 2017-08-25 00:30:56 -04:00
Stanisław Barzowski
5da57ac417 Interpreter & runtime - minimal usable version (#24)
* Interpreter & runtime - minimal usable version

Accomplishments in this commit:
* Majority of language features implemented:
	* Unary operators
	* Binary operators
	* Conditionals
	* Errors
	* Indexing arrays
	* Indexing objects
	* Object inheritance
	* Imports
	* Functions
	* Function calls
* There is a quite nice way for creating builtins
* Static analyzer is there with most of the functionality
* Standard library is included and parts unaffected by missing features
work
* Some bugs in existing parts fixed
* Most positive tests from C++ version pass, the rest is failing mostly
due to missing builtins and comprehensions.
* Some initial structure was created that should allow more incremental
  and focused changes in the future PRs.
* Some comments/explanations added
* Panics translated to a little bit more gentle internal errors (with a
  link to issues on github).

What still sucks:
* Stack traces & error messages (there's some stuff in place)
* Almost everything is in the same package
* Stuff is exported or unexporeted randomly (see above)
* Missing a few lexing/parsing features
* Missing builtins
* Missing support for extvars and top-level-args
* Checking function arguments is missing
* No clean Go API that commandline and compatibility layer to C can use
* No compatibility layer to C
* Assertions don't work (desugaring level, assertEquals works).
* Manifestation stack traces (and generally it could use some work).
* The way environments are constructed is sometimes suboptimal/clumsy.
2017-08-24 20:09:10 -04:00
Stanisław Barzowski
899b931c07 Fix unicode escape sequences & some desugaring 2017-08-16 12:08:28 -04:00
Stanisław Barzowski
91e1162cdd Make it possible to evaluate stdlib (#20)
* New features in parser and desugarer

Support for slices
Support for methods
Support for function sugar in locals
Prevent crashes with obj/arr comprehensions

After this change evaluating stdlib doesn't crash.
2017-08-15 14:08:15 -04:00
Stanisław Barzowski
a94bfef764 Add verbatim string support 2017-08-10 17:29:04 -04:00
Stanisław Barzowski
fd77883a3f Fix local bind body not being desugared
In Go `for i, val := range arr` creates a *copy*
so it was changing some temporary value.
2017-08-04 15:03:42 -04:00
Dave Cunningham
c5225a1b3a address jbeda's comments 2016-05-02 00:20:08 -04:00
Dave Cunningham
09c7c8c7c0 Pass through JSON 2016-04-04 02:16:03 -04:00
Dave Cunningham
563bbe12f4 First end-to-end test (addition of numbers) 2016-03-08 01:17:44 -05:00