mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-21 00:47:28 +01:00
Generate C code for an_array[:].
This commit is contained in:
1 parent
f107ec155d
commit
a9f12c23a4
6 files changed
+70
-16
No files matched your search
@@ -188,8 +188,28 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
return nil
|
||||
|
||||
case t.KeyColon:
|
||||
// n is a slice.
|
||||
// TODO.
|
||||
// n is a slice.
|
||||
lhs := n.LHS().Expr()
|
||||
mhs := n.MHS().Expr()
|
||||
rhs := n.RHS().Expr()
|
||||
if mhs == nil && rhs == nil {
|
||||
if lhs.MType().Decorator().Key() == t.KeyOpenBracket {
|
||||
// Slice of an array.
|
||||
// TODO: don't assume that the slice is a slice of u8.
|
||||
b.writes("((puffs_base_slice_u8){.ptr = ")
|
||||
if err := g.writeExpr(b, lhs, rp, parenthesesMandatory, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
b.printf(", .len=%s})", lhs.MType().ArrayLength().ConstValue())
|
||||
} else {
|
||||
// Slice of a slice.
|
||||
if err := g.writeExpr(b, lhs, rp, parenthesesMandatory, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("TODO: writeExprOther for a non-trivial slice")
|
||||
|
||||
case t.KeyDot:
|
||||
lhs := n.LHS().Expr()
|
||||
|
||||
@@ -61,12 +61,10 @@ func (g *gen) writeStatement(b *buffer, n *a.Node, depth uint32) error {
|
||||
// TODO: delete this hack that only matches "foo.copy_from(etc)".
|
||||
if isThatMethod(g.tm, n, t.KeyCopyFrom, 1) {
|
||||
b.writes("puffs_base_slice_u8_copy_from(")
|
||||
// TODO: don't hard-code this.history (a [32768]u8) as the
|
||||
// receiver. In any case, the receiver should probably be a slice
|
||||
// instead of an array.
|
||||
b.writes("((puffs_base_slice_u8){")
|
||||
b.writes(".ptr=self->private_impl.f_history,")
|
||||
b.writes(".len=sizeof(self->private_impl.f_history)})")
|
||||
receiver := n.LHS().Expr().LHS().Expr()
|
||||
if err := g.writeExpr(b, receiver, replaceCallSuspendibles, parenthesesMandatory, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
b.writeb(',')
|
||||
a := n.Args()[0].Arg().Value()
|
||||
if err := g.writeExpr(b, a, replaceCallSuspendibles, parenthesesMandatory, depth); err != nil {
|
||||
|
||||
Reference in new issue
Block a user