Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warnings and documentation for "at-most" constructs #128

Merged
merged 3 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions doc/3d-lang.rst
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,10 @@ A variation is:

* ``T f[:byte-size-single-element-array-at-most n]``

similar to the previous form, but where ``n`` is an upper bound on the
size in bytes.
which describes a field ``f`` that contains a single element of type
``T`` occupying at most ``n`` bytes, followed by padding bytes to make
up to ``n`` bytes. This construct thus always consumes exactly ``n``
bytes.

We expect to add several other kinds of variable-length array-like
types in the uture.
Expand Down
6 changes: 3 additions & 3 deletions src/3d/Ast.fst
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ let field_bitwidth_t = either (with_meta_t int) bitfield_attr
type array_qualifier =
| ByteArrayByteSize //[
| ArrayByteSize //[:byte-size
| ArrayByteSizeAtMost //[:byte-size-at-most
| ArrayByteSizeAtMost //[:byte-size-single-element-array-at-most
| ArrayByteSizeSingleElementArray //[:byte-size-single-element-array

[@@ PpxDerivingYoJson ]
Expand Down Expand Up @@ -1114,11 +1114,11 @@ and print_atomic_field (f:atomic_field) : ML string =
begin match q with
| ByteArrayByteSize -> Printf.sprintf "[%s]" (print_expr e)
| ArrayByteSize -> Printf.sprintf "[:byte-size %s]" (print_expr e)
| ArrayByteSizeAtMost -> Printf.sprintf "[:byte-size-at-most %s]" (print_expr e)
| ArrayByteSizeAtMost -> Printf.sprintf "[:byte-size-single-element-array-at-most %s]" (print_expr e)
| ArrayByteSizeSingleElementArray -> Printf.sprintf "[:byte-size-single-element-array %s]" (print_expr e)
end
| FieldString None -> Printf.sprintf "[::zeroterm]"
| FieldString (Some sz) -> Printf.sprintf "[:zeroterm-b-te-size-at-most %s]" (print_expr sz)
| FieldString (Some sz) -> Printf.sprintf "[:zeroterm-byte-size-at-most %s]" (print_expr sz)
| FieldConsumeAll -> Printf.sprintf "[:consume-all]"
in
let sf = f.v in
Expand Down
2 changes: 1 addition & 1 deletion src/3d/TypeSizes.fst
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ let size_and_alignment_of_atomic_field (env:env_t) (f:atomic_field)

| FieldArrayQualified (n, ByteArrayByteSize) ->
if base_size <> Fixed 1
then warning "Expected a byte array; if the underlying array elements are larger than a byte, use the '[:byte-size' notation"
then error "Expected a byte array; if the underlying array elements are larger than a byte, use the '[:byte-size' notation"
f.range;
let n = value_of_const_expr env n in
begin
Expand Down
2 changes: 1 addition & 1 deletion src/3d/ocaml/lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ rule token =
| "]" { locate lexbuf RBRACK }
| "[=" { deprecation_warning lexbuf "[:byte-size-single-element-array";
locate lexbuf LBRACK_EQ }
| "[<=" { deprecation_warning lexbuf "[:byte-size-at-most";
| "[<=" { deprecation_warning lexbuf "[:byte-size-single-element-array-at-most";
locate lexbuf LBRACK_LEQ }
| "*" { locate lexbuf STAR }
| "/" { locate lexbuf DIV }
Expand Down
Loading