Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…hal#289)

- OpenCyphal#288 : Updating dev container documentation to point to ghcr.
- OpenCyphal#283 : Detecting fixed boolean arrays and modifying c++ to emit
std::bitset
- OpenCyphal#271 : Changing the type used when comparing array lengths to avoid
compiler warnings.
  • Loading branch information
thirtytwobits authored Mar 7, 2023
1 parent 609f7ee commit a2b24f0
Show file tree
Hide file tree
Showing 15 changed files with 125 additions and 209 deletions.
22 changes: 11 additions & 11 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{
"name": "Python dev environment",
"dockerFile": "python.Dockerfile",
"context": "..",
"settings": {
"terminal.integrated.shell.linux": "/bin/bash"
},
"image": "ghcr.io/opencyphal/toxic:tx20.4.1",
"workspaceFolder": "/workspace",
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind,consistency=delegated",
"mounts": [
"source=root-vscode-server,target=/root/.vscode-server/extensions,type=volume",
"source=nunavut-tox,target=/workspace/.tox,type=volume"
],
"extensions": [
"uavcan.dsdl",
"wholroyd.jinja",
"ban.spellright",
"ms-python.python"
],
"customizations": {
"vscode": {
"extensions": [
"uavcan.dsdl",
"wholroyd.jinja",
"ban.spellright",
"ms-python.python"
]
}
},
"postCreateCommand": "git submodule update --init --recursive && tox -e local"
}
3 changes: 0 additions & 3 deletions .devcontainer/python.Dockerfile

This file was deleted.

1 change: 0 additions & 1 deletion .vscode/.spellignore

This file was deleted.

8 changes: 5 additions & 3 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
"/System/Library/Frameworks",
"/Library/Frameworks"
],
"defines": ["NUNAVUT_SUPPORT_LANGUAGE_OPTION_ENABLE_OVERRIDE_VARIABLE_ARRAY_CAPACITY=1"],
"defines": [
"NUNAVUT_SUPPORT_LANGUAGE_OPTION_ENABLE_OVERRIDE_VARIABLE_ARRAY_CAPACITY=1"
],
"compileCommands": "${workspaceFolder}/.vscode/compile_commands.json",
"configurationProvider": "ms-vscode.cmake-tools",
"cStandard": "c11",
Expand Down Expand Up @@ -87,7 +89,7 @@
},
{
"name": "Linux-cpp",
"intelliSenseMode": "gcc-x64",
"intelliSenseMode": "linux-gcc-x64",
"includePath": [
"${workspaceFolder}/submodules/googletest/googlemock/include",
"${workspaceFolder}/submodules/unity/src",
Expand All @@ -106,4 +108,4 @@
}
],
"version": 4
}
}
27 changes: 26 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -186,5 +186,30 @@
"env": "",
"environment": "",
"sourceFileMap": "${sourceFileMapObj}"
}
},
"spellright.ignoreRegExps": [
"/DLCs/g",
"/rhs/ig",
"/_?rx_?/",
"/_?tx_?/",
"/Kirienko/g",
"/Pavel/g",
"/gtests/g",
"/(lib)?cyphal/g",
"/ovfl/g",
"/Cyphal/ig",
"/tparam/g",
"/\\.hpp/g",
"/endcode/g",
"/defgroup/",
"/dst/",
"/lvs/",
"/g(oogle)?mock/",
"/g(oogle)?test/",
"/(?:de?|con)struct(?:able?|or)/",
"/(lib)?uavcan/",
"/nunavut/i",
"/dsdl/i",
"/bitspan/"
],
}
154 changes: 0 additions & 154 deletions .vscode/spellright.dict

This file was deleted.

14 changes: 9 additions & 5 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,28 @@ To run the full suite of `tox`_ tests locally you'll need docker. Once you have
and running do::

git submodule update --init --recursive
docker pull uavcan/toxic:py35-py39-sq
docker run --rm -v $PWD:/repo uavcan/toxic:py35-py39-sq tox
docker pull ghcr.io/opencyphal/toxic:tx20.4.1
docker run --rm -v $PWD:/repo ghcr.io/opencyphal/toxic:tx20.4.1 tox

To run a limited suite using only locally available interpreters directly on your host machine,
skip the docker invocations and use ``tox -s``.

To run the language verification build you'll need to use a different docker container::

docker pull uavcan/c_cpp:ubuntu-20.04
docker run --rm -it -v $PWD:/repo uavcan/c_cpp:ubuntu-20.04
cd /repo
docker pull ghcr.io/opencyphal/toolshed:ts20.4.1
docker run --rm -it -v $PWD:/workspace ghcr.io/opencyphal/toolshed:ts20.4.1
cd /workspace
./.github/verify.py -l c
./.github/verify.py -l cpp

The verify.py script is a simple commandline generator for our cmake scripts. Use help for details::

./.github/verify.py --help

If you get a "denied" response from ghcr your ip might be getting rate-limited. While these are public containers
you'll have to login to get around any rate-limiting for your local site. See [the github docs](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry)
for how to setup a docker client login.

Files Generated by the Tests
================================================

Expand Down
7 changes: 5 additions & 2 deletions src/nunavut/_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def __init__(self) -> None:
self.uses_float = False
self.uses_variable_length_array = False
self.uses_array = False
self.uses_boolean_static_array = False
self.uses_bool = False
self.uses_primitive_static_array = False
self.uses_union = False
Expand Down Expand Up @@ -118,10 +119,12 @@ def _extract_dependent_types_handle_array_type(
) -> None:
if isinstance(dependant_type, pydsdl.VariableLengthArrayType):
inout_dependencies.uses_variable_length_array = True
elif isinstance(dependant_type.element_type, pydsdl.BooleanType):
inout_dependencies.uses_boolean_static_array = True
elif isinstance(dependant_type.element_type, pydsdl.PrimitiveType):
inout_dependencies.uses_primitive_static_array = True
else:
inout_dependencies.uses_array = True
if isinstance(dependant_type.element_type, pydsdl.PrimitiveType):
inout_dependencies.uses_primitive_static_array = True

@classmethod
def _extract_dependent_types(
Expand Down
4 changes: 2 additions & 2 deletions src/nunavut/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
.. autodata:: __version__
"""

__version__ = "2.0.6"
__version__ = "2.0.7"
__license__ = "MIT"
__author__ = "OpenCyphal"
__copyright__ = "Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Copyright (c) 2022 OpenCyphal."
__copyright__ = "Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. Copyright (c) 2023 OpenCyphal."
__email__ = "maintainers@opencyphal.org"
12 changes: 10 additions & 2 deletions src/nunavut/lang/cpp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,10 @@ def do_includes_test(use_foobar, extension):
if self.get_config_value_as_bool("use_standard_types"):
if dep_types.uses_integer:
std_includes.append("cstdint")
if dep_types.uses_array:
if dep_types.uses_array or dep_types.uses_primitive_static_array:
std_includes.append("array")
if dep_types.uses_boolean_static_array:
std_includes.append("bitset")
if dep_types.uses_union and self._has_variant():
std_includes.append("variant")
includes_formatted = ["<{}>".format(include) for include in sorted(std_includes)]
Expand All @@ -281,6 +283,9 @@ def filter_id(self, instance: typing.Any, id_type: str = "any") -> str:

return self._get_token_encoder().strop(raw_name, id_type)

def create_bitset_decl(self, type: str, max_size: int) -> str:
return "std::bitset<{MAX_SIZE}>".format(MAX_SIZE=max_size)

def create_array_decl(self, type: str, max_size: int) -> str:
return "std::array<{TYPE},{MAX_SIZE}>".format(TYPE=type, MAX_SIZE=max_size)

Expand Down Expand Up @@ -989,7 +994,10 @@ def filter_declaration(language: Language, instance: pydsdl.Any) -> str:
TYPE=filter_declaration(language, instance.element_type), MAX_SIZE=instance.capacity
)
elif isinstance(instance, pydsdl.ArrayType):
return language.create_array_decl(filter_declaration(language, instance.element_type), instance.capacity)
if isinstance(instance.element_type, pydsdl.BooleanType):
return language.create_bitset_decl(filter_declaration(language, instance.element_type), instance.capacity)
else:
return language.create_array_decl(filter_declaration(language, instance.element_type), instance.capacity)
else:
return filter_full_reference_name(language, instance)

Expand Down
6 changes: 3 additions & 3 deletions src/nunavut/lang/cpp/templates/deserialization.j2
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
# spurious alignment of elements but the benefit of such optimization is believed to be negligible. #}
{% set element_offset = offset + t.element_type.bit_length_set.repeat_range(t.capacity - 1) %}
{% set ref_index = 'index'|to_template_unique_name %}
for (size_t {{ ref_index }} = 0U; {{ ref_index }} < {{ t.capacity }}UL; ++{{ ref_index }})
for ({{ typename_unsigned_length }} {{ ref_index }} = 0U; {{ ref_index }} < {{ t.capacity }}UL; ++{{ ref_index }})
{
{{ _deserialize_any(t.element_type, reference + ('[%s]'|format(ref_index)), element_offset)|trim|indent }}
}
Expand All @@ -184,7 +184,7 @@
{# DESERIALIZE THE IMPLICIT ARRAY LENGTH FIELD #}
{% set ref_size = 'size'|to_template_unique_name %}
// Array length prefix: {{ t.length_field_type }}
{{ _deserialize_integer(t.length_field_type, ('const %s %s'|format((t.length_field_type | declaration), ref_size)) , offset) }}
{{ _deserialize_integer(t.length_field_type, ('const %s %s'|format( typename_unsigned_length, ref_size)) , offset) }}
if ( {{ ref_size }} > {{ t.capacity }}U)
{
return -nunavut::support::Error::SerializationBadArrayLength;
Expand All @@ -201,7 +201,7 @@
{% endif %}
{# GENERAL CASE #}
{% set ref_index = 'index'|to_template_unique_name %}
for (size_t {{ ref_index }} = 0U; {{ ref_index }} < {{ ref_size }}; ++{{ ref_index }})
for ({{ typename_unsigned_length }} {{ ref_index }} = 0U; {{ ref_index }} < {{ ref_size }}; ++{{ ref_index }})
{
// TODO This is terribly inefficient. We need to completely refactor this template to use C++ emplace and
// move semantics instead of assuming C-style containers
Expand Down
4 changes: 2 additions & 2 deletions src/nunavut/lang/cpp/templates/serialization.j2
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@
# spurious alignment of elements but the benefit of such optimization is believed to be negligible. #}
{% set element_offset = offset + t.element_type.bit_length_set.repeat_range(t.capacity - 1) %}
{% set ref_index = 'index'|to_template_unique_name %}
for (size_t {{ ref_index }} = 0U; {{ ref_index }} < {{ t.capacity }}UL; ++{{ ref_index }})
for ({{ typename_unsigned_length }} {{ ref_index }} = 0U; {{ ref_index }} < {{ t.capacity }}UL; ++{{ ref_index }})
{
{{ _serialize_any(t.element_type, reference + ('[%s]'|format(ref_index)), element_offset)|trim|indent }}
}
Expand Down Expand Up @@ -308,7 +308,7 @@

{# GENERAL CASE #}
{% set ref_index = 'index'|to_template_unique_name %}
for (size_t {{ ref_index }} = 0U; {{ ref_index }} < {{ reference }}.size(); ++{{ ref_index }})
for ({{ typename_unsigned_length }} {{ ref_index }} = 0U; {{ ref_index }} < {{ reference }}.size(); ++{{ ref_index }})
{
{{
_serialize_any(t.element_type, reference + ('[%s]'|format(ref_index)), element_offset)
Expand Down
Loading

0 comments on commit a2b24f0

Please sign in to comment.