Age | Commit message (Collapse) | Author |
|
Adds a flag, AllowRecursion, that enables while statements and
recursive functions.
|
|
|
|
Change-Id: Iebd0e040ff674b2f9da39bf5242c8afaa7f4ddc8
|
|
A byte code is a more efficient representation of the program for
execution, as it is more compact than an AST, and it is readily
serializable, permitting the work of parsing, resolving, and
compilation to be amortized across runs when the byte code is cached
in the file system.
This change defines a simple byte code, compiler, and interpreter for
Skylark, using ideas from Python and Emacs Lisp.
It also deletes the tree-based evaluator. I evaluated (ha!) keeping
both and switching between them dynamically, compiling the program
just before the 2nd or nth invocation of a function. (In a build
system, a great many "functions" are executed exactly once, such as
the toplevel of a BUILD file.) However, the performance gain over
always compiling was barely measurable and did not justify the cost of
maintaining two different interpreters. Also, just-in-time compilation
makes program dynamics very complex.
Details:
- the toplevel code of a module is now represented as a function
of no parameters, enabling various simplifications.
- Every Frame now has a Function. Backtracing is simpler.
Only the leaf frame (the error) has a position;
all the parent frames record only the program counter of
the call instruction, and compute the position from this
as needed.
- To keep the line number table encoding simple and compact,
EvalError no longer reports column information.
It would be nice to add it back with a carefully tuned encoding.
Breaking API changes:
- Thread.{Push,Pop} are gone.
The reason they were initially exposed is exemplified by the
TestRepeatedExec test case, which is better served by the new API:
var predeclared skylark.StringDict
// parse and compile
_, prog, err = SourceProgram("foo.sky", src, predeclared.Has)
// "in between" stuff goes here
// execute toplevel
globals, err = prog.Init(thread, predeclared)
- ExecOptions.BeforeExec is gone, and thus so is ExecOptions.
This function existed so that clients could "get in between"
producing a program and executing it, but the new low-level API
(see above) above separates these operations explicitly.
Now that Exec and ExecOptions are no more expressive than ExecFile,
they have been deleted.
Thanks to Jay Conrod for earlier rounds of review,
including substantial simplifications.
|
|
* Remove predeclared names from the module globals dict
Previously, the Skylark spec and Go implementation had a notion
of "predeclared globals", which are module globals that have a value
before execution begins, such as the 'glob' function in
the Bazel build language. This is undesirable because it causes
every module to appear to define 'glob', and it makes this name
accessible to other modules through the load statement.
This CL changes the spec and implementation to match the Bazel behavior:
predeclared names like glob are no longer part of the module's globals dictionary,
but are treated similar to universal names such as None and len.
From the Skylark program's perspective, there is no difference
between per-module predeclared names and universal
predeclared names, and the spec now uses only the term "predeclared".
However, the resolver distinguishes them as an optimization as this allows
the evaluator to use separate dictionaries to represent the
universal and the per-module portions.
API CHANGE: The ExecFile function has changed, and so must all its callers.
Previously, it accepted the globals dictionary as a parameter,
populated with predeclared names, and execution would add more
names to this dictionary. Now, it accepts the predeclared
dictionary (which it does not modify), and returns the globals
dictionary.
Also: the resolver now assigns an index to each global,
allowing the evaluator to use a flat representation for
globals similar to that for locals.
Fixes #75
(See also Google internal issue b/74460309)
|
|
|
|
This is a no-op for the interpreter, but it adds more information to the
AST.
|
|
* Attach comments to AST nodes.
This feature is off by default. More testing will be needed before
exposing it to the ParseFile function.
Logic is copied from Buildifier (https://github.com/bazelbuild/buildtools/tree/master/build).
bug #63
* Fix tests by saving the state of 'blank' in the scanner.
* - Rename flattenAST
- Add new argument to the Parser and the Scanner
- Update tests
* Remove global constant keepComments
* Update more tests (new argument to the parser)
* Add CommentsRef to allow allocating comments
Address a few other issues
* Remove the COMMENT tokens
Parser won't see COMMENT tokens anymore. The list is kept by the
scanner. This simplifies the code and reverts some of my previous
changes.
* Address review comments
* - Removed the .Suffix boolean
- Renamed CommentsRef to commentsRef
- Simplified assignComments function (reversing was not useful)
* assignComments leaves early if there is no comments
+ address other review comments
* Address review comments (for -> if, removed useless code about suffix comments)
|
|
* Syntax: support multiprecision integer literals
* Using INT token type for both cases
the parser is handling int64 and *big.Int values as a token of the type INT
* Tests for bigInt
* Testing large integer literals
* Deleting some comments
* Fixing a space
|
|
|