aboutsummaryrefslogtreecommitdiff
path: root/syntax/syntax.go
AgeCommit message (Collapse)Author
2018-12-07Add while statement and allow recursion (#39)Alessandro Arzilli
Adds a flag, AllowRecursion, that enables while statements and recursive functions.
2018-11-01add docs/PKG/index.html redirects and import commentsAlan Donovan
2018-10-23rename skylark -> starlarkAlan Donovan
Change-Id: Iebd0e040ff674b2f9da39bf5242c8afaa7f4ddc8
2018-03-30skylark: byte code compiler and interpreter (#95)alandonovan
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.
2018-03-13Remove predeclared names from the module globals dict (#86)alandonovan
* 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)
2018-03-02syntax: add (*LoadStmt).ModuleName accessor method, for convenience (#76)alandonovan
2018-02-26Add new node ParenExpr (#65)Laurent Le Brun
This is a no-op for the interpreter, but it adds more information to the AST.
2018-02-22Attach comments to AST nodes. (#64)Laurent Le Brun
* 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)
2018-01-22Syntax: support multiprecision integer literals (#58)Mohamed Elqdusy
* 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
2017-10-02skylark: create GitHub repository from google3@170697745Alan Donovan