Add io_reader.peek_u64le_at

This commit is contained in:
Nigel Tao committed 2020-03-19 11:33:22 +11:00
1 parent 31cfaaeb4e
commit b86373aff5
6 files changed
+39 -45

No files matched your search

+5
View File
@@ -248,6 +248,11 @@ var Funcs = []string{
"io_reader.peek_u64be() u64",
"io_reader.peek_u64le() u64",
// As an implementation restriction, we require that offset has a constant
// value. The (0x1_0000 - sizeof(u64)) limit is arbitrary, but high enough
// in practice.
"io_reader.peek_u64le_at(offset: u32[..= 0xFFF8]) u64",
"io_reader.available() u64",
"io_reader.count_since(mark: u64) u64",
"io_reader.is_closed() bool",
+14 -2
View File
@@ -1068,10 +1068,22 @@ func (q *checker) bcheckExprCallSpecialCases(n *a.Expr, depth uint32) (bounds, e
} else if err != nil {
return bounds{}, err
}
advance, update = worstCase.ConstValue(), true
if advance == nil {
if worstCase.ConstValue() == nil {
return bounds{}, fmt.Errorf("check: skip_fast worst_case is not a constant value")
}
advance, update = worstCase.ConstValue(), true
} else if method == t.IDPeekU64LEAt {
args := n.Args()
if len(args) != 1 {
return bounds{}, fmt.Errorf("check: internal error: bad peek_u64le_at arguments")
}
offset := args[0].AsArg().Value()
if offset.ConstValue() == nil {
return bounds{}, fmt.Errorf("check: peek_u64le_at offset is not a constant value")
}
advance, update = big.NewInt(8), false
advance.Add(advance, offset.ConstValue())
} else if method >= t.IDPeekU8 {
if m := method - t.IDPeekU8; m < t.ID(len(ioMethodAdvances)) {
+4
View File
@@ -544,6 +544,8 @@ const (
// --------
IDPeekU64LEAt = ID(0x1A0)
IDPeekU8 = ID(0x1A1)
IDPeekU16BE = ID(0x1A2)
@@ -899,6 +901,8 @@ var builtInsByID = [nBuiltInIDs]string{
// --------
IDPeekU64LEAt: "peek_u64le_at",
IDPeekU8: "peek_u8",
IDPeekU16BE: "peek_u16be",