mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-21 00:47:28 +01:00
Add a "deref" unary operator.
This commit is contained in:
1 parent
51bd52239b
commit
2cd6ebed8e
8 files changed
+55
-53
No files matched your search
@@ -362,14 +362,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
}
|
||||
|
||||
func (g *gen) writeExprUnaryOp(b *buffer, n *a.Expr, rp replacementPolicy, pp parenthesesPolicy, depth uint32) error {
|
||||
switch n.ID0().Key() {
|
||||
case t.KeyXUnaryPlus:
|
||||
b.writeb('+')
|
||||
case t.KeyXUnaryMinus:
|
||||
b.writeb('-')
|
||||
case t.KeyXUnaryNot:
|
||||
b.writeb('!')
|
||||
}
|
||||
b.writes(cOpNames[0xFF&n.ID0().Key()])
|
||||
return g.writeExpr(b, n.RHS().Expr(), rp, parenthesesMandatory, depth)
|
||||
}
|
||||
|
||||
@@ -528,9 +521,11 @@ var cOpNames = [256]string{
|
||||
t.KeyPercentEq: " %= ",
|
||||
t.KeyTildePlusEq: " += ",
|
||||
|
||||
t.KeyXUnaryPlus: "+",
|
||||
t.KeyXUnaryMinus: "-",
|
||||
t.KeyXUnaryNot: "!",
|
||||
t.KeyXUnaryPlus: " + ",
|
||||
t.KeyXUnaryMinus: " - ",
|
||||
t.KeyXUnaryNot: " ! ",
|
||||
t.KeyXUnaryRef: " & ",
|
||||
t.KeyXUnaryDeref: " * ",
|
||||
|
||||
t.KeyXBinaryPlus: " + ",
|
||||
t.KeyXBinaryMinus: " - ",
|
||||
|
||||
@@ -247,22 +247,24 @@ func (g *gen) writeStatement(b *buffer, n *a.Node, depth uint32) error {
|
||||
name := v.Name().String(g.tm)
|
||||
b.writes("{\n")
|
||||
|
||||
// TODO: don't assume that the slice is a slice of u8.
|
||||
// TODO: don't assume that the slice is a slice of u8. In particular,
|
||||
// the code gen can be subtle if the slice element type has zero size,
|
||||
// such as the empty struct.
|
||||
b.printf("puffs_base_slice_u8 %sslice_%s =", iPrefix, name)
|
||||
if err := g.writeExpr(b, v.Value(), replaceCallSuspendibles, parenthesesOptional, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
b.writes(";\n")
|
||||
b.printf("uint8_t* %sptr_%s = %sslice_%s.ptr;\n", iPrefix, name, iPrefix, name)
|
||||
b.printf("uint8_t* %s%s = %sslice_%s.ptr;\n", vPrefix, name, iPrefix, name)
|
||||
b.printf("uint8_t* %send_%s = %sslice_%s.ptr + %sslice_%s.len;\n",
|
||||
iPrefix, name, iPrefix, name, iPrefix, name)
|
||||
b.printf("while (%sptr_%s < %send_%s) {\n", iPrefix, name, iPrefix, name)
|
||||
b.printf("while (%s%s < %send_%s) {\n", vPrefix, name, iPrefix, name)
|
||||
for _, o := range n.Body() {
|
||||
if err := g.writeStatement(b, o, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
b.printf("%sptr_%s++;\n}\n", iPrefix, name)
|
||||
b.printf("%s%s++;\n}\n", vPrefix, name)
|
||||
|
||||
b.writes("}\n")
|
||||
return nil
|
||||
|
||||
Reference in new issue
Block a user