Add use_save_code to std/gif/decode_lzw.puffs.

This commit is contained in:
Nigel Tao committed 2017-06-09 14:51:39 +10:00
1 parent 0b034d7f6e
commit ddbbdecce6
5 files changed
+65 -6

No files matched your search

+15 -2
View File
@@ -14,6 +14,7 @@ package main
import (
"bytes"
"fmt"
"math/big"
"os"
"os/exec"
"strings"
@@ -24,6 +25,11 @@ import (
t "github.com/google/puffs/lang/token"
)
var (
zero = big.NewInt(0)
one = big.NewInt(1)
)
// Prefixes are prepended to names to form a namespace and to avoid e.g.
// "double" being a valid Puffs variable name but not a valid C one.
const (
@@ -890,8 +896,15 @@ func (g *gen) writeExpr(n *a.Expr, rp replacementPolicy, pp parenthesesPolicy, d
}
if cv := n.ConstValue(); cv != nil {
// TODO: write false/true instead of 0/1 if n.MType() is bool?
g.writes(cv.String())
if nTyp := n.MType(); nTyp.PackageOrDecorator() != 0 || nTyp.Name().Key() != t.KeyBool {
g.writes(cv.String())
} else if cv.Cmp(zero) == 0 {
g.writes("false")
} else if cv.Cmp(one) == 0 {
g.writes("true")
} else {
return fmt.Errorf("%v has type bool but constant value %v is neither 0 or 1", n.String(g.tm), cv)
}
return nil
}