printing: commit some refactors (probably broken)

This commit is contained in:
Michael McLoughlin
2018-12-11 00:18:22 -08:00
parent 4dc909a81e
commit c882e52510
21 changed files with 398 additions and 222 deletions

View File

@@ -1,6 +1,11 @@
package pass
import "github.com/mmcloughlin/avo"
import (
"io"
"github.com/mmcloughlin/avo"
"github.com/mmcloughlin/avo/printer"
)
var Compile = Concat(
FunctionPass(LabelTarget),
@@ -42,3 +47,19 @@ func Concat(passes ...Interface) Interface {
return nil
})
}
type Output struct {
Writer io.WriteCloser
Printer printer.Printer
}
func (o *Output) Execute(f *avo.File) error {
b, err := o.Printer.Print(f)
if err != nil {
return err
}
if _, err = o.Writer.Write(b); err != nil {
return err
}
return o.Writer.Close()
}