mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-22 08:47:28 +01:00
Generate C code for "x as T".
This commit is contained in:
1 parent
e87cdaa9f5
commit
db41d789a5
4 files changed
+30
-4
No files matched your search
+23
-2
@@ -706,8 +706,7 @@ func (g *gen) writeExprUnaryOp(n *a.Expr, depth uint32) error {
|
|||||||
func (g *gen) writeExprBinaryOp(n *a.Expr, depth uint32) error {
|
func (g *gen) writeExprBinaryOp(n *a.Expr, depth uint32) error {
|
||||||
op := n.ID0()
|
op := n.ID0()
|
||||||
if op.Key() == t.KeyXBinaryAs {
|
if op.Key() == t.KeyXBinaryAs {
|
||||||
// TODO.
|
return g.writeExprAs(n.LHS().Expr(), n.RHS().TypeExpr(), depth)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
g.writeb('(')
|
g.writeb('(')
|
||||||
if err := g.writeExpr(n.LHS().Expr(), depth); err != nil {
|
if err := g.writeExpr(n.LHS().Expr(), depth); err != nil {
|
||||||
@@ -722,6 +721,28 @@ func (g *gen) writeExprBinaryOp(n *a.Expr, depth uint32) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *gen) writeExprAs(lhs *a.Expr, rhs *a.TypeExpr, depth uint32) error {
|
||||||
|
g.writes("((")
|
||||||
|
for {
|
||||||
|
if rhs.PackageOrDecorator() == 0 {
|
||||||
|
if k := rhs.Name().Key(); k < t.Key(len(cTypeNames)) {
|
||||||
|
if s := cTypeNames[k]; s != "" {
|
||||||
|
g.writes(s)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// TODO: fix this.
|
||||||
|
return fmt.Errorf("cannot convert Puffs type %q to C", rhs.String(g.idMap))
|
||||||
|
}
|
||||||
|
g.writes(")(")
|
||||||
|
if err := g.writeExpr(lhs, depth); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
g.writes("))")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (g *gen) writeExprAssociativeOp(n *a.Expr, depth uint32) error {
|
func (g *gen) writeExprAssociativeOp(n *a.Expr, depth uint32) error {
|
||||||
// TODO.
|
// TODO.
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
+1
-1
@@ -214,7 +214,7 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self,
|
|||||||
v_width = (self->f_literal_width + 1);
|
v_width = (self->f_literal_width + 1);
|
||||||
while (1) {
|
while (1) {
|
||||||
while ((v_n_bits < v_width)) {
|
while ((v_n_bits < v_width)) {
|
||||||
v_bits |= 0;
|
v_bits |= ((uint32_t)(0));
|
||||||
v_n_bits += 8;
|
v_n_bits += 8;
|
||||||
}
|
}
|
||||||
v_bits >>= v_width;
|
v_bits >>= v_width;
|
||||||
|
|||||||
@@ -438,6 +438,10 @@ var builtInsByKey = [nBuiltInKeys]struct {
|
|||||||
KeyAmpHat: {"&^", IDAmpHat},
|
KeyAmpHat: {"&^", IDAmpHat},
|
||||||
KeyPipe: {"|", IDPipe},
|
KeyPipe: {"|", IDPipe},
|
||||||
KeyHat: {"^", IDHat},
|
KeyHat: {"^", IDHat},
|
||||||
|
// TODO: tilde-ops such as ~+ for ignoring overflow. Swift defines overflow
|
||||||
|
// ops for +, - and *. Swift syntax uses a leading &. Puffs uses a leading
|
||||||
|
// ~ as it is less ambiguous with the &^ operator (and any potential use of
|
||||||
|
// & as address-of) and ~ is otherwise unused.
|
||||||
|
|
||||||
KeyNotEq: {"!=", IDNotEq},
|
KeyNotEq: {"!=", IDNotEq},
|
||||||
KeyLessThan: {"<", IDLessThan},
|
KeyLessThan: {"<", IDLessThan},
|
||||||
@@ -450,6 +454,7 @@ var builtInsByKey = [nBuiltInKeys]struct {
|
|||||||
KeyOr: {"or", IDOr},
|
KeyOr: {"or", IDOr},
|
||||||
KeyNot: {"not", IDNot},
|
KeyNot: {"not", IDNot},
|
||||||
KeyAs: {"as", IDAs},
|
KeyAs: {"as", IDAs},
|
||||||
|
// TODO: do we need a "~as" form of the as operator, similar to "~+".
|
||||||
|
|
||||||
KeyFunc: {"func", IDFunc},
|
KeyFunc: {"func", IDFunc},
|
||||||
KeyPtr: {"ptr", IDPtr},
|
KeyPtr: {"ptr", IDPtr},
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ pub func lzw_decoder.decode?(dst ptr buf1, src ptr buf1, src_final bool)() {
|
|||||||
post n_bits >= width,
|
post n_bits >= width,
|
||||||
{
|
{
|
||||||
assert n_bits < 12 via "a < b: a < c; c <= b"(c:width)
|
assert n_bits < 12 via "a < b: a < c; c <= b"(c:width)
|
||||||
bits |= 0 // TODO.
|
bits |= 0 as u32 // TODO
|
||||||
n_bits += 8
|
n_bits += 8
|
||||||
}
|
}
|
||||||
// TODO: var code u32[..4095] = bits.low_bits(width)
|
// TODO: var code u32[..4095] = bits.low_bits(width)
|
||||||
|
|||||||
Reference in new issue
Block a user