// PrintVal prints the given value corresponding to the given data type.
// The value is already checked for the compatibility with the data type.
195924
func PrintVal(t design.DataType, val interface{}) string {
	switch {
	case t.IsPrimitive():
		// For primitive types, simply print the value
		s := fmt.Sprintf("%#v", val)
		switch t {
		case design.Number:
			v := val
			if i, ok := val.(int); ok {
				v = float64(i)
			}
			s = fmt.Sprintf("%f", v)
		case design.DateTime:
			s = fmt.Sprintf("time.Parse(time.RFC3339, %s)", s)
		}
		return s
	case t.IsHash():
		// The input is a hash
		h := t.ToHash()
		hval := val.(map[interface{}]interface{})
		if len(hval) == 0 {
			return fmt.Sprintf("%s{}", GoTypeName(t, nil, 0, false))
		}
		var buffer bytes.Buffer
		buffer.WriteString(fmt.Sprintf("%s{", GoTypeName(t, nil, 0, false)))
		for k, v := range hval {
			buffer.WriteString(fmt.Sprintf("%s: %s, ", PrintVal(h.KeyType.Type, k), PrintVal(h.ElemType.Type, v)))
		}
		buffer.Truncate(buffer.Len() - 2) // remove ", "
		buffer.WriteString("}")
		return buffer.String()
	case t.IsArray():
		// Input is an array
		a := t.ToArray()
		aval := val.([]interface{})
		if len(aval) == 0 {
			return fmt.Sprintf("%s{}", GoTypeName(t, nil, 0, false))
		}
		var buffer bytes.Buffer
		buffer.WriteString(fmt.Sprintf("%s{", GoTypeName(t, nil, 0, false)))
		for _, e := range aval {
			buffer.WriteString(fmt.Sprintf("%s, ", PrintVal(a.ElemType.Type, e)))
		}
		buffer.Truncate(buffer.Len() - 2) // remove ", "
		buffer.WriteString("}")
		return buffer.String()
	default:
		// shouldn't happen as the value's compatibility is already checked.
		panic("unknown type")
	}
}
818032
func (w *Wrapper) Println(values ...interface{}) {
	for i, v := range values {
		if i != len(values)-1 {
			fmt.Fprintf(w, "%v\t", v)
		} else {
			fmt.Fprintf(w, "%v", v)
		}
	}
	fmt.Fprintln(w)
}
385053
func (l *Logger) Printf(format string, v ...interface{}) {
	l.Fprint(l.flags, LEVEL_PRINT, 2, fmt.Sprintf(format, v...), nil)
}
620952
func (a *Writer) Printf(format string, args ...interface{}) (int, error) {
	return fmt.Fprintf(a.w, format, args...)
}
608986
func (c *Code) PrintIf(condition bool, args ...interface{}) {
	if !condition {
		return
	}
	if len(args) > 0 {
		for i := 0; i < c.indent; i++ {
			c.text += indentation
		}
		c.text += fmt.Sprintf(args[0].(string), args[1:]...)
	}
	c.text += "\n"
}
445860
func (w *Wrapper) Printf(format string, values ...interface{}) {
	fmt.Fprintf(w, format+"\t", values...)
}
1069786
func (t *Tag) StringVal() (string, error) {
	if t.format != StringVal {
		return "", t.typeErr(StringVal)
	}
	return t.strVal, nil
}
1092840
func PrintOp(fn *Funcode, pc uint32, op Opcode, arg uint32) {
	if op < OpcodeArgMin {
		fmt.Fprintf(os.Stderr, "\t%d\t%s\n", pc, op)
		return
	}

	var comment string
	switch op {
	case CONSTANT:
		switch x := fn.Prog.Constants[arg].(type) {
		case string:
			comment = strconv.Quote(x)
		default:
			comment = fmt.Sprint(x)
		}
	case MAKEFUNC:
		comment = fn.Prog.Functions[arg].Name
	case SETLOCAL, LOCAL:
		comment = fn.Locals[arg].Name
	case SETGLOBAL, GLOBAL:
		comment = fn.Prog.Globals[arg].Name
	case ATTR, SETFIELD, PREDECLARED, UNIVERSAL:
		comment = fn.Prog.Names[arg]
	case FREE:
		comment = fn.Freevars[arg].Name
	case CALL, CALL_VAR, CALL_KW, CALL_VAR_KW:
		comment = fmt.Sprintf("%d pos, %d named", arg>>8, arg&0xff)
	default:
		// JMP, CJMP, ITERJMP, MAKETUPLE, MAKELIST, LOAD, UNPACK:
		// arg is just a number
	}
	var buf bytes.Buffer
	fmt.Fprintf(&buf, "\t%d\t%-10s\t%d", pc, op, arg)
	if comment != "" {
		fmt.Fprint(&buf, "\t; ", comment)
	}
	fmt.Fprintln(&buf)
	os.Stderr.Write(buf.Bytes())
}
1282921
func (l *Logger) Printf(format string, v ...interface{}) {
	l.Emit(0, fmt.Sprintf(format, v...), nil)
}
158141
func (db *GoLevelDB) Print() {
	str, _ := db.db.GetProperty("leveldb.stats")
	fmt.Printf("%v\n", str)

	itr := db.db.NewIterator(nil, nil)
	for itr.Next() {
		key := itr.Key()
		value := itr.Value()
		fmt.Printf("[%X]:\t[%X]\n", key, value)
	}
}
256070
func (s *Server) printf(format string, a ...interface{}) {
	if s.events != nil {
		s.events.Printf(format, a...)
	}
}
844984
func (a *Writer) Print(args ...interface{}) (int, error) {
	return fmt.Fprint(a.w, args...)
}
881911
func Println(a ...interface{}) (int, error) {
	a = append(a, ResetCode)
	compileValues(&a)
	return fmt.Println(a...)
}
79057
func Printf(format string, v ...interface{}) {
	if Severity >= LevelInfo {
		std.Output(5, fmt.Sprintf(format, v...), LevelInfo)
	}
}
624334
func Print(err error) string {
	return fmt.Sprintf("%v: %v\n", Code(err), err.Error())
}
1184270
func (c *Color) Printf(format string, a ...interface{}) (n int, err error) {
	c.Set()
	defer c.unset()

	return fmt.Fprintf(Output, format, a...)
}
1110791
func (p *Pretty) PrintValue(val r.Value, level int) {
	if !val.IsValid() {
		io.WriteString(p.Out, p.NilString)
		return
	}

	cur := strings.Repeat(p.Indent, level)
	next := strings.Repeat(p.Indent, level+1)

	nl := "\n"
	if len(p.Indent) == 0 {
		nl = " "
	}

	if p.MaxLevel > 0 && level >= p.MaxLevel {
		io.WriteString(p.Out, val.String())
		return
	}

	switch val.Kind() {
	case r.Int, r.Int8, r.Int16, r.Int32, r.Int64:
		io.WriteString(p.Out, strconv.FormatInt(val.Int(), 10))

	case r.Uint, r.Uint8, r.Uint16, r.Uint32, r.Uint64:
		io.WriteString(p.Out, strconv.FormatUint(val.Uint(), 10))

	case r.Float32, r.Float64:
		io.WriteString(p.Out, strconv.FormatFloat(val.Float(), 'f', -1, 64))

	case r.String:
		io.WriteString(p.Out, strconv.Quote(val.String()))

	case r.Bool:
		io.WriteString(p.Out, strconv.FormatBool(val.Bool()))

	case r.Map:
		l := val.Len()

		io.WriteString(p.Out, "{"+nl)
		for i, k := range val.MapKeys() {
			io.WriteString(p.Out, next)
			io.WriteString(p.Out, strconv.Quote(k.String()))
			io.WriteString(p.Out, ": ")
			p.PrintValue(val.MapIndex(k), level+1)
			if i < l-1 {
				io.WriteString(p.Out, ","+nl)
			} else {
				io.WriteString(p.Out, nl)
			}
		}
		io.WriteString(p.Out, cur)
		io.WriteString(p.Out, "}")

	case r.Array, r.Slice:
		l := val.Len()

		if p.Compact && l == 0 {
			io.WriteString(p.Out, "[]")
		} else {
			io.WriteString(p.Out, "["+nl)
			for i := 0; i < l; i++ {
				io.WriteString(p.Out, next)
				p.PrintValue(val.Index(i), level+1)
				if i < l-1 {
					io.WriteString(p.Out, ","+nl)
				} else {
					io.WriteString(p.Out, nl)
				}
			}
			io.WriteString(p.Out, cur)
			io.WriteString(p.Out, "]")
		}

	case r.Interface, r.Ptr:
		p.PrintValue(val.Elem(), level)

	case r.Struct:
		if val.CanInterface() {
			i := val.Interface()
			if i, ok := i.(fmt.Stringer); ok {
				io.WriteString(p.Out, i.String())
			} else {
				l := val.NumField()

				sOpen := "struct {"

				if p.Compact {
					sOpen = "{"
				}

				if p.Compact && l == 0 {
					io.WriteString(p.Out, "{}")
				} else {
					io.WriteString(p.Out, sOpen+nl)
					for i := 0; i < l; i++ {
						io.WriteString(p.Out, next)
						io.WriteString(p.Out, val.Type().Field(i).Name)
						io.WriteString(p.Out, ": ")
						p.PrintValue(val.Field(i), level+1)
						if i < l-1 {
							io.WriteString(p.Out, ","+nl)
						} else {
							io.WriteString(p.Out, nl)
						}
					}
					io.WriteString(p.Out, cur)
					io.WriteString(p.Out, "}")
				}
			}
		} else {
			io.WriteString(p.Out, "protected")
		}

	default:
		io.WriteString(p.Out, "unsupported:")
		io.WriteString(p.Out, val.String())
	}
}