ucglib/build/opcode/
debug.rs

1// Copyright 2019 Jeremy Wall
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14use std::fmt;
15
16use super::Composite;
17use super::Primitive;
18use super::Value;
19
20use Composite::{List, Tuple};
21use Primitive::{Bool, Empty, Float, Int, Str};
22use Value::{C, F, M, P, S, T};
23
24impl fmt::Debug for Value {
25    fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result {
26        match self {
27            P(Bool(v)) => write!(w, "Bool({})", v),
28            P(Int(v)) => write!(w, "Int({})", v),
29            P(Float(v)) => write!(w, "Float({})", v),
30            P(Str(v)) => write!(w, "String({})", v),
31            P(Empty) => write!(w, "NULL"),
32            C(List(ref els, _)) => {
33                write!(w, "List[")?;
34                for e in els {
35                    write!(w, "{:?},", e)?;
36                }
37                write!(w, "]")
38            }
39            C(Tuple(ref flds, _)) => {
40                write!(w, "Tuple(")?;
41                for (k, v) in flds {
42                    write!(w, "\"{}\"={:?},", k, v)?;
43                }
44                write!(w, ")")
45            }
46            F(_) => write!(w, "<Func>"),
47            M(_) => write!(w, "<Module>"),
48            T(_) => write!(w, "<Expression>"),
49            S(v) => write!(w, "Symbol({})", v),
50        }
51    }
52}