func (a *ast) Execute(args []string) error { if len(args) != 1 { return fmt.Errorf("expected an input file") } f, err := os.Open(args[0]) if err != nil { return err } defer f.Close() b, err := ioutil.ReadAll(f) if err != nil { return err } p := parser.New() syms, _, err := p.Parse(args[0], b) if err != nil { if a.AllErrors { scanner.PrintError(stdout, err) } return err } out := stdout if a.Output != "" { outf, err := os.Open(a.Output) if err != nil { return err } defer outf.Close() out = outf } for _, sym := range syms { fmt.Fprintln(out, sym) } return nil }
// Compile takes a module identifier and a reader, and compiles its source date // to an in-memory representation of agora bytecode, ready to be executed. // If an error is encountered, it is returned as second value, otherwise it is // nil. func (c *Compiler) Compile(id string, r io.Reader) (*bytecode.File, error) { b, err := ioutil.ReadAll(r) if err != nil { return nil, err } p := parser.New() syms, scps, err := p.Parse(id, b) if err != nil { return nil, err } e := new(emitter.Emitter) return e.Emit(id, syms, scps) }