-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
62 lines (46 loc) · 1.5 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// +build ignore
// Copyright 2013-2014 Rocky Bernstein
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
// This is a simple REPL (read-eval-print loop) for Go.
// (rocky) My intent here is to have something that I can debug in
// the ssa-debugger tortoise/gub.sh. Right now that can't handle the
// unsafe package, pointers, and calls to C code. So that let's out
// go-gnureadline and lineedit.
// See also main_gr.go for GNU readline code.
import (
"bufio"
"fmt"
"os"
"reflect"
"github.com/rocky/go-fish"
"github.com/rocky/go-fish/cmd"
)
func intro_text() {
repl.Section("== A simple Go eval REPL ==")
fmt.Printf(`
Results of expression are stored in variable slice "results".
The environment is stored in global variable "env".
Short form assignment, e.g. a, b := 1, 2, is supported.
Enter expressions to be evaluated at the "gofish>" prompt.
To see all results, type: "results".
To quit, enter: "quit" or Ctrl-D (EOF).
To get help, enter: "help".
`)
}
// Set up the Go package, function, constant, variable environment; then REPL
// (Read, Eval, Print, and Loop).
func main() {
// A place to store result values of expressions entered
// interactively
env := repl.MakeEvalEnv()
// Make this truly self-referential
env.Vars["env"] = reflect.ValueOf(env)
intro_text()
repl.Input = bufio.NewReader(os.Stdin)
// Initialize REPL commands
fishcmd.Init()
repl.REPL(env, repl.SimpleReadLine, repl.SimpleInspect)
os.Exit(repl.ExitCode)
}