eval: Add builtin "print"

This commit is contained in:
Cheer Xiao 2013-10-02 22:10:07 +08:00
parent 39abd54013
commit 29061872c7

View File

@ -1,5 +1,9 @@
package eval
import (
"fmt"
)
type ioType byte
const (
@ -17,6 +21,7 @@ type builtin struct {
var builtins = map[string]builtin {
"put": builtin{implPut, [3]ioType{unusedIO, chanIO}},
"print": builtin{implPrint, [3]ioType{unusedIO}},
}
func implPut(args []string, ios [3]*io) {
@ -25,3 +30,14 @@ func implPut(args []string, ios [3]*io) {
out <- args[i]
}
}
func implPrint(args []string, ios [3]*io) {
out := ios[1].f
args = args[1:]
args_if := make([]interface{}, len(args))
for i, a := range args {
args_if[i] = a
}
fmt.Fprint(out, args_if...)
}