Skip to content

Commit

Permalink
rename skylark -> starlark
Browse files Browse the repository at this point in the history
Change-Id: Iebd0e040ff674b2f9da39bf5242c8afaa7f4ddc8
  • Loading branch information
adonovan committed Oct 23, 2018
1 parent ce5c2fa commit e3deafe
Show file tree
Hide file tree
Showing 51 changed files with 750 additions and 749 deletions.
61 changes: 31 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@

<!-- This file is the project homepage at github.com/google/skylark -->
<!-- This file is the project homepage at github.com/google/starlark -->

# Skylark in Go
# Starlark in Go

This is the home of the _Skylark in Go_ project.
Skylark in Go is an interpreter for Skylark, implemented in Go.
This is the home of the _Starlark in Go_ project.
Starlark in Go is an interpreter for Starlark, implemented in Go.
Starlark was formerly known as Skylark.

Skylark is a dialect of Python intended for use as a configuration language.
Starlark is a dialect of Python intended for use as a configuration language.
Like Python, it is an untyped dynamic language with high-level data
types, first-class functions with lexical scope, and garbage collection.
Unlike CPython, independent Skylark threads execute in parallel, so
Skylark workloads scale well on parallel machines.
Skylark is a small and simple language with a familiar and highly
Unlike CPython, independent Starlark threads execute in parallel, so
Starlark workloads scale well on parallel machines.
Starlark is a small and simple language with a familiar and highly
readable syntax. You can use it as an expressive notation for
structured data, defining functions to eliminate repetition, or you
can use it to add scripting capabilities to an existing application.

A Skylark interpreter is typically embedded within a larger
A Starlark interpreter is typically embedded within a larger
application, and the application may define additional domain-specific
functions and data types beyond those provided by the core language.
For example, Skylark was originally developed for the
For example, Starlark was originally developed for the
[Bazel build tool](https://bazel.build).
Bazel uses Skylark as the notation both for its BUILD files (like
Bazel uses Starlark as the notation both for its BUILD files (like
Makefiles, these declare the executables, libraries, and tests in a
directory) and for [its macro
language](https://docs.bazel.build/versions/master/skylark/language.html),
language](https://docs.bazel.build/versions/master/starlark/language.html),
through which Bazel is extended with custom logic to support new
languages and compilers.

Expand All @@ -35,27 +36,27 @@ languages and compilers.

* About the Go implementation: [doc/impl.md](doc/impl.md)

* API documentation: [godoc.org/github.com/google/skylark](https://godoc.org/github.com/google/skylark)
* API documentation: [godoc.org/github.com/google/starlark](https://godoc.org/github.com/google/starlark)

* Mailing list: [skylark-go](https://groups.google.com/forum/#!forum/skylark-go)
* Mailing list: [starlark-go](https://groups.google.com/forum/#!forum/starlark-go)

* Issue tracker: [https://github.com/google/skylark/issues](https://github.com/google/skylark/issues)
* Issue tracker: [https://github.com/google/starlark/issues](https://github.com/google/starlark/issues)

* Travis CI: ![Travis CI](https://travis-ci.org/google/skylark.svg) [https://travis-ci.org/google/skylark](https://travis-ci.org/google/skylark)
* Travis CI: ![Travis CI](https://travis-ci.org/google/starlark.svg) [https://travis-ci.org/google/starlark](https://travis-ci.org/google/starlark)

### Getting started

Build the code:

```shell
$ go get github.com/google/skylark/...
$ go build github.com/google/skylark/cmd/skylark
$ go get github.com/google/starlark/...
$ go build github.com/google/starlark/cmd/starlark
```

Run the interpreter:

```
$ cat coins.sky
$ cat coins.star
coins = {
'dime': 10,
'nickel': 5,
Expand All @@ -65,15 +66,15 @@ coins = {
print('By name:\t' + ', '.join(sorted(coins.keys())))
print('By value:\t' + ', '.join(sorted(coins.keys(), key=coins.get)))
$ ./skylark coins.sky
$ ./starlark coins.star
By name: dime, nickel, penny, quarter
By value: penny, nickel, dime, quarter
```

Interact with the read-eval-print loop (REPL):

```
$ ./skylark
$ ./starlark
>>> def fibonacci(n):
... res = list(range(n))
... for i in res[2:]:
Expand All @@ -90,16 +91,16 @@ When you have finished, type `Ctrl-D` to close the REPL's input stream.
### Contributing

We welcome submissions but please let us know what you're working on
if you want to change or add to the Skylark repository.
if you want to change or add to the Starlark repository.

Before undertaking to write something new for the Skylark project,
Before undertaking to write something new for the Starlark project,
please file an issue or claim an existing issue.
All significant changes to the language or to the interpreter's Go
API must be discussed before they can be accepted.
This gives all participants a chance to validate the design and to
avoid duplication of effort.

Despite some differences, the Go implementation of Skylark strives to
Despite some differences, the Go implementation of Starlark strives to
match the behavior of the Java implementation used by Bazel.
For that reason, proposals to change the language itself should
generally be directed to the Bazel team, not to the maintainers of
Expand Down Expand Up @@ -127,13 +128,13 @@ stage in the project, although we will endeavor to keep them to a minimum.
Now that the project's long-term name ("Starlark") has been decided,
we plan to copy this repository to github.com/google/starlark and
change the canonical import path for all packages to starlark.net/starlark.
The current github.com/google/skylark repository will be frozen.
The current github.com/google/starlark repository will be frozen.
Once the Bazel team has finalized the version 1 language specification,
we will be more rigorous with interface stability.

### Credits

Skylark was designed and implemented in Java by
Starlark was designed and implemented in Java by
Ulf Adams,
Lukács Berki,
Jon Brandvein,
Expand All @@ -149,14 +150,14 @@ its scanner was derived from one written by Russ Cox.

### Legal

Skylark in Go is Copyright (c) 2017 The Bazel Authors.
Starlark in Go is Copyright (c) 2017 The Bazel Authors.
All rights reserved.

It is provided under a 3-clause BSD license:
[LICENSE](https://github.com/google/skylark/blob/master/LICENSE).
[LICENSE](https://github.com/google/starlark/blob/master/LICENSE).

The name "Skylark" is a code name of the Bazel project.
The name "Starlark" is a code name of the Bazel project.
The Bazel team plans to rename the language to "Starlark" to reflect its
applicability to projects unrelated to Bazel.

Skylark in Go is not an official Google product.
Starlark in Go is not an official Google product.
20 changes: 10 additions & 10 deletions cmd/skylark/skylark.go → cmd/starlark/starlark.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// The skylark command interprets a Skylark file.
// The starlark command interprets a Starlark file.
// With no arguments, it starts a read-eval-print loop (REPL).
package main

Expand All @@ -15,9 +15,9 @@ import (
"sort"
"strings"

"github.com/google/skylark"
"github.com/google/skylark/repl"
"github.com/google/skylark/resolve"
"github.com/google/starlark"
"github.com/google/starlark/repl"
"github.com/google/starlark/resolve"
)

// flags
Expand All @@ -36,7 +36,7 @@ func init() {
}

func main() {
log.SetPrefix("skylark: ")
log.SetPrefix("starlark: ")
log.SetFlags(0)
flag.Parse()

Expand All @@ -51,24 +51,24 @@ func main() {
defer pprof.StopCPUProfile()
}

thread := &skylark.Thread{Load: repl.MakeLoad()}
globals := make(skylark.StringDict)
thread := &starlark.Thread{Load: repl.MakeLoad()}
globals := make(starlark.StringDict)

switch len(flag.Args()) {
case 0:
fmt.Println("Welcome to Skylark (github.com/google/skylark)")
fmt.Println("Welcome to Starlark (github.com/google/starlark)")
repl.REPL(thread, globals)
case 1:
// Execute specified file.
filename := flag.Args()[0]
var err error
globals, err = skylark.ExecFile(thread, filename, nil, nil)
globals, err = starlark.ExecFile(thread, filename, nil, nil)
if err != nil {
repl.PrintError(err)
os.Exit(1)
}
default:
log.Fatal("want at most one Skylark file name")
log.Fatal("want at most one Starlark file name")
}

// Print the global environment.
Expand Down
34 changes: 17 additions & 17 deletions doc/impl.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

# Skylark in Go: Implementation
# Starlark in Go: Implementation

This document (a work in progress) describes some of the design
choices of the Go implementation of Skylark.
choices of the Go implementation of Starlark.

* [Scanner](#scanner)
* [Parser](#parser)
Expand Down Expand Up @@ -40,7 +40,7 @@ cases would require additional lookahead.
The resolver reports structural errors in the program, such as the use
of `break` and `continue` outside of a loop.

Skylark has stricter syntactic limitations than Python. For example,
Starlark has stricter syntactic limitations than Python. For example,
it does not permit `for` loops or `if` statements at top level, nor
does it permit global variables to be bound more than once.
These limitations come from the Bazel project's desire to make it easy
Expand All @@ -66,15 +66,15 @@ any uses of dialect features that have not been enabled.

<b>Integers:</b> Integers are representing using `big.Int`, an
arbitrary precision integer. This representation was chosen because,
for many applications, Skylark must be able to handle without loss
for many applications, Starlark must be able to handle without loss
protocol buffer values containing signed and unsigned 64-bit integers,
which requires 65 bits of precision.

Small integers (<256) are preallocated, but all other values require
memory allocation. Integer performance is relatively poor, but it
matters little for Bazel-like workloads which depend much
more on lists of strings than on integers. (Recall that a typical loop
over a list in Skylark does not materialize the loop index as an `int`.)
over a list in Starlark does not materialize the loop index as an `int`.)

An optimization worth trying would be to represent integers using
either an `int32` or `big.Int`, with the `big.Int` used only when
Expand All @@ -95,11 +95,11 @@ greater than, or equal: it may also fail.
TODO: discuss UTF-8 and string.bytes method.

<b>Dictionaries and sets</b>:
Skylark dictionaries have predictable iteration order.
Furthermore, many Skylark values are hashable in Skylark even though
Starlark dictionaries have predictable iteration order.
Furthermore, many Starlark values are hashable in Starlark even though
the Go values that represent them are not hashable in Go: big
integers, for example.
Consequently, we cannot use Go maps to implement Skylark's dictionary.
Consequently, we cannot use Go maps to implement Starlark's dictionary.

We use a simple hash table whose buckets are linked lists, each
element of which holds up to 8 key/value pairs. In a well-distributed
Expand All @@ -108,13 +108,13 @@ key/value item is part of doubly-linked list that maintains the
insertion order of the elements for iteration.

<b>Struct:</b>
The `skylarkstruct` Go package provides a non-standard Skylark
The `starlarkstruct` Go package provides a non-standard Starlark
extension data type, `struct`, that maps field identifiers to
arbitrary values. Fields are accessed using dot notation: `y = s.f`.
This data type is extensively used in Bazel, but its specification is
currently evolving.

Skylark has no `class` mechanism, nor equivalent of Python's
Starlark has no `class` mechanism, nor equivalent of Python's
`namedtuple`, though it is likely that future versions will support
some way to define a record data type of several fields, with a
representation more efficient than a hash table.
Expand All @@ -123,8 +123,8 @@ representation more efficient than a hash table.
### Freezing

All mutable values created during module initialization are _frozen_
upon its completion. It is this property that permits a Skylark module
to be referenced by two Skylark threads running concurrently (such as
upon its completion. It is this property that permits a Starlark module
to be referenced by two Starlark threads running concurrently (such as
the initialization threads of two other modules) without the
possibility of a data race.

Expand Down Expand Up @@ -162,7 +162,7 @@ extra bookkeeping so that modification of the underlying collection
invalidates the iterator, and the next attempt to use it fails.
This often helps to detect subtle mistakes.

Skylark takes this a step further. Instead of mutation of the
Starlark takes this a step further. Instead of mutation of the
collection invalidating the iterator, the act of iterating makes the
collection temporarily immutable, so that an attempt to, say, delete a
dict element while looping over the dict, will fail. The error is
Expand All @@ -182,7 +182,7 @@ to call `Done` on each iterator once it is no longer needed.

```
TODO
skylark.Value interface and subinterfaces
starlark.Value interface and subinterfaces
argument passing to builtins: UnpackArgs, UnpackPositionalArgs.
```

Expand All @@ -207,7 +207,7 @@ array from a `make([]Value, n)` allocation always escapes
([Go issue 20533](https://github.com/golang/go/issues/20533)).
Because the bytecode interpreter's operand stack has a non-constant
length, it must be allocated with `make`. The resulting allocation
adds to the cost of each Skylark function call; this can be tolerated
adds to the cost of each Starlark function call; this can be tolerated
by amortizing one very large stack allocation across many calls.
More problematic appears to be the cost of the additional GC write
barriers incurred by every VM operation: every intermediate result is
Expand All @@ -227,9 +227,9 @@ Load

```
TODO
skylarktest package
starlarktest package
`assert` module
skylarkstruct
starlarkstruct
integration with Go testing.T
```

Expand Down
Loading

0 comments on commit e3deafe

Please sign in to comment.