-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathcmd_execute.go
56 lines (46 loc) · 1001 Bytes
/
cmd_execute.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
package main
import (
"context"
"flag"
"fmt"
"github.com/google/subcommands"
"github.com/skx/go.vm/cpu"
)
type executeCmd struct {
}
//
// Glue
//
func (*executeCmd) Name() string { return "execute" }
func (*executeCmd) Synopsis() string { return "Executed a compiled program." }
func (*executeCmd) Usage() string {
return `execute :
Execute the bytecodes contained in the given input file.
`
}
//
// Flag setup: no flags
//
func (p *executeCmd) SetFlags(f *flag.FlagSet) {
}
//
// Entry-point.
//
func (p *executeCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
//
// For each file on the command-line we can now execute it.
//
for _, file := range f.Args() {
c := cpu.NewCPU()
err := c.LoadFile(file)
if err != nil {
fmt.Printf("Error loading file: %s\n", err)
}
err = c.Run()
if err != nil {
fmt.Printf("Error running file: %s\n", err)
return subcommands.ExitFailure
}
}
return subcommands.ExitSuccess
}