From be6cd2217b6bb1bb411d46ebd9d003dfd928af96 Mon Sep 17 00:00:00 2001 From: Mel Date: Wed, 17 Aug 2022 00:07:35 +0000 Subject: Add different "say" outputs to VM --- pkg/lang/vm/output.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 pkg/lang/vm/output.go (limited to 'pkg/lang/vm/output.go') diff --git a/pkg/lang/vm/output.go b/pkg/lang/vm/output.go new file mode 100644 index 0000000..1ef2357 --- /dev/null +++ b/pkg/lang/vm/output.go @@ -0,0 +1,45 @@ +package vm + +type Output interface { + Write(message string) error +} + +type EmptyOutput struct{} + +func NewEmptyOutput() *EmptyOutput { + return &EmptyOutput{} +} + +func (o *EmptyOutput) Write(message string) error { + return nil +} + +type GatheringOutput struct { + messages []string +} + +func NewGatheringOutput() *GatheringOutput { + return &GatheringOutput{ + messages: make([]string, 0, 8), + } +} + +func (o *GatheringOutput) Messages() []string { + return o.messages +} + +func (o *GatheringOutput) Write(message string) error { + o.messages = append(o.messages, message) + return nil +} + +type ConsoleOutput struct{} + +func NewConsoleOutput() *ConsoleOutput { + return &ConsoleOutput{} +} + +func (o *ConsoleOutput) Write(message string) error { + println(message) + return nil +} -- cgit 1.4.1