Skip to content

Commit

Permalink
vendor starlight
Browse files Browse the repository at this point in the history
  • Loading branch information
glycerine committed Dec 25, 2018
1 parent 5e831c9 commit 5f3b9ad
Show file tree
Hide file tree
Showing 71 changed files with 4,995 additions and 10 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Monty is a fork derived from the starlark-go project by Google engineers
Alan Donovan and Jay Conrod. Their code is available at https://go.starlark.net ,
also known as https://github.com/google/starlark-go.

Monty uses code from Nate Finch's https://github.com/starlight-go/starlight
starlight-go is licensed under the MIT license.

An adaptation of the README for Starlark-Go follows.

## Starlark in Go
Expand Down
44 changes: 34 additions & 10 deletions cmd/monty/main.go → cmd/monty/monty.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,29 @@ import (
"github.com/glycerine/monty/repl"
"github.com/glycerine/monty/resolve"
"github.com/glycerine/monty/starlark"

"github.com/glycerine/monty/starlarktest"
"github.com/glycerine/monty/verb"
)

var vv = verb.VV

// flags
var (
cpuprofile = flag.String("cpuprofile", "", "gather CPU profile in this file")
showenv = flag.Bool("showenv", false, "on success, print final global environment")
execprog = flag.String("c", "", "execute program `prog`")
)

// non-standard dialect flags
func init() {
flag.BoolVar(&resolve.AllowFloat, "float", resolve.AllowFloat, "allow floating-point numbers")
flag.BoolVar(&resolve.AllowSet, "set", resolve.AllowSet, "allow set data type")
flag.BoolVar(&resolve.AllowLambda, "lambda", resolve.AllowLambda, "allow lambda expressions")
flag.BoolVar(&resolve.AllowNestedDef, "nesteddef", resolve.AllowNestedDef, "allow nested def statements")
flag.BoolVar(&resolve.AllowBitwise, "bitwise", resolve.AllowBitwise, "allow bitwise operations (&, |, ^, ~, <<, and >>)")
flag.BoolVar(&resolve.AllowRecursion, "recursion", resolve.AllowRecursion, "allow while statements and recursive functions")
flag.BoolVar(&resolve.AllowGlobalReassign, "globalreassign", resolve.AllowGlobalReassign, "allow reassignment of globals, and if/for/while statements at top level")
resolve.AllowNestedDef = true // allow def statements within function bodies
resolve.AllowLambda = true // allow lambda expressions
resolve.AllowFloat = true // allow floating point literals, the 'float' built-in, and x / y
resolve.AllowSet = true // allow the 'set' built-in
resolve.AllowBitwise = true // allow bitwise operations
resolve.AllowRecursion = true // allow while statements and recursive functions
resolve.AllowGlobalReassign = true // allow reassignment of globals, and if/for/while statements at top level
//resolve.AllowAddressable = true
}

func main() {
Expand All @@ -56,7 +61,12 @@ func main() {
}

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

globals, err := starlarktest.LoadAssertModule()
if err != nil {
panic(err)
}

switch {
case flag.NArg() == 1 || *execprog != "":
Expand All @@ -74,14 +84,28 @@ func main() {
filename = flag.Arg(0)
}
thread.Name = "exec " + filename
globals, err = starlark.ExecFile(thread, filename, src, nil)
back, err := starlark.ExecFile(thread, filename, src, globals)
if err != nil {
repl.PrintError(err)
os.Exit(1)
}

vv("before merge, globals = '%s'", globals)
vv("back = '%s'", back)

// merge back into globals
for k, v := range back {
globals[k] = v
}

vv("after merge globals = '%s'", globals)

case flag.NArg() == 0:
fmt.Println("Welcome to Monty (github.com/glycerine/monty)")
thread.Name = "REPL"

vv("before REPL, globals = '%s'", globals)

repl.REPL(thread, globals)
default:
log.Fatal("want at most one Monty file name")
Expand Down
3 changes: 3 additions & 0 deletions starlark/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ import (
"github.com/glycerine/monty/starlark"
"github.com/glycerine/monty/starlarktest"
"github.com/glycerine/monty/syntax"
"github.com/glycerine/monty/verb"
)

var vv = verb.VV

// A test may enable non-standard options by containing (e.g.) "option:recursion".
func setOptions(src string) {
resolve.AllowBitwise = option(src, "bitwise")
Expand Down
23 changes: 23 additions & 0 deletions vendor/github.com/starlight-go/starlight/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions vendor/github.com/starlight-go/starlight/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions vendor/github.com/starlight-go/starlight/Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions vendor/github.com/starlight-go/starlight/Gopkg.toml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions vendor/github.com/starlight-go/starlight/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

117 changes: 117 additions & 0 deletions vendor/github.com/starlight-go/starlight/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5f3b9ad

Please sign in to comment.