()
| 26 | } |
| 27 | |
| 28 | func main() { |
| 29 | env := fuzz.NewEnv() |
| 30 | for name := range env { |
| 31 | keywords = append(keywords, name) |
| 32 | } |
| 33 | fn := fuzz.Func() |
| 34 | keywords = append(keywords, "fn") |
| 35 | home, err := os.UserHomeDir() |
| 36 | if err != nil { |
| 37 | panic(err) |
| 38 | } |
| 39 | rl, err := readline.NewEx(&readline.Config{ |
| 40 | Prompt: "❯ ", |
| 41 | AutoComplete: completer{append(builtin.Names, keywords...)}, |
| 42 | HistoryFile: home + "/.expr_history", |
| 43 | }) |
| 44 | if err != nil { |
| 45 | panic(err) |
| 46 | } |
| 47 | defer rl.Close() |
| 48 | |
| 49 | var memUsage uint64 |
| 50 | var program *vm.Program |
| 51 | |
| 52 | for { |
| 53 | line, err := rl.Readline() |
| 54 | if err != nil { // io.EOF when Ctrl-D is pressed |
| 55 | break |
| 56 | } |
| 57 | line = strings.TrimSpace(line) |
| 58 | |
| 59 | switch line { |
| 60 | case "": |
| 61 | continue |
| 62 | |
| 63 | case "exit": |
| 64 | return |
| 65 | |
| 66 | case "mem": |
| 67 | fmt.Printf("memory usage: %s\n", humanizeBytes(memUsage)) |
| 68 | continue |
| 69 | |
| 70 | case "opcodes": |
| 71 | if program == nil { |
| 72 | fmt.Println("no program") |
| 73 | continue |
| 74 | } |
| 75 | fmt.Println(program.Disassemble()) |
| 76 | continue |
| 77 | |
| 78 | case "debug": |
| 79 | if program == nil { |
| 80 | fmt.Println("no program") |
| 81 | continue |
| 82 | } |
| 83 | debug.StartDebugger(program, env) |
| 84 | continue |
| 85 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…