Generate C code for an_array[:].

This commit is contained in:
Nigel Tao committed 2017-09-23 10:51:04 +10:00
1 parent f107ec155d
commit a9f12c23a4
6 files changed
+70 -16

No files matched your search

+22 -2
View File
@@ -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()
+4 -6
View File
@@ -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 {
+2 -3
View File
@@ -650,9 +650,8 @@ puffs_flate_status puffs_flate_decoder_decode(puffs_flate_decoder* self,
if (((uint64_t)(v_written.len)) >= 32768) {
v_written = puffs_base_slice_u8_suffix(v_written, 32768);
puffs_base_slice_u8_copy_from(
((puffs_base_slice_u8){
.ptr = self->private_impl.f_history,
.len = sizeof(self->private_impl.f_history)}),
((puffs_base_slice_u8){.ptr = self->private_impl.f_history,
.len = 32768}),
v_written);
self->private_impl.f_history_index = 32768;
}
+6 -2
View File
@@ -761,8 +761,12 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int,
}
case t.KeyColon:
// TODO.
return nil, nil, fmt.Errorf("check: unrecognized token.Key (0x%X) for bcheckExprOther", n.ID0().Key())
mhs := n.MHS().Expr()
rhs := n.RHS().Expr()
if mhs == nil && rhs == nil {
return nil, nil, nil
}
return nil, nil, fmt.Errorf("TODO: bcheckExprOther for a non-trivial slice")
case t.KeyDot:
// TODO: delete this hack that only matches "in".
+35 -1
View File
@@ -487,7 +487,41 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
case t.KeyColon:
// n is a slice.
// TODO.
if mhs := n.MHS().Expr(); mhs != nil {
if err := q.tcheckExpr(mhs, depth); err != nil {
return err
}
mTyp := mhs.MType()
if !mTyp.IsNumTypeOrIdeal() {
return fmt.Errorf("check: %s is a slice expression but %s has type %s, not a numeric type",
n.String(q.tm), mhs.String(q.tm), mTyp.String(q.tm))
}
}
if rhs := n.RHS().Expr(); rhs != nil {
if err := q.tcheckExpr(rhs, depth); err != nil {
return err
}
rTyp := rhs.MType()
if !rTyp.IsNumTypeOrIdeal() {
return fmt.Errorf("check: %s is a slice expression but %s has type %s, not a numeric type",
n.String(q.tm), rhs.String(q.tm), rTyp.String(q.tm))
}
}
lhs := n.LHS().Expr()
if err := q.tcheckExpr(lhs, depth); err != nil {
return err
}
lTyp := lhs.MType()
switch lTyp.Decorator().Key() {
default:
return fmt.Errorf("check: %s is a slice expression but %s has type %s, not an array or slice type",
n.String(q.tm), lhs.String(q.tm), lTyp.String(q.tm))
case t.KeyOpenBracket:
n.SetMType(a.NewTypeExpr(t.IDColon, 0, nil, nil, lTyp.Inner()))
case t.KeyColon:
n.SetMType(lTyp)
}
return nil
case t.KeyDot:
return q.tcheckDot(n, depth)
+1 -2
View File
@@ -114,8 +114,7 @@ pub func decoder.decode?(dst writer1, src reader1)() {
var written[] u8 = in.dst.slice()
if written.length() >= (32 * 1024) {
written = written.suffix(up_to:32 * 1024)
// TODO: change this.history to this.history[:].
this.history.copy_from(s:written)
this.history[:].copy_from(s:written)
this.history_index = 32 * 1024
} else {
// TODO: fill part of the history.