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

Issue #91 progress. #194

Merged
merged 36 commits into from
Jun 7, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
31c5110
resetting cpp baseline to be the c templates
thirtytwobits Jan 30, 2021
7571c2e
test_support_headers generates without error
thirtytwobits Jan 31, 2021
3e193c8
various progress
thirtytwobits Feb 7, 2021
1f1c645
refocusing on POD first
thirtytwobits Feb 7, 2021
6d3ab90
adding python 3.9 testing
thirtytwobits Feb 10, 2021
c424dcf
progress on c++ POD generation
thirtytwobits Feb 10, 2021
d57a395
bunch of whitespace fixes
thirtytwobits Feb 16, 2021
9b2e764
fixing c build
thirtytwobits Feb 22, 2021
16ff4c7
fixing builds and adding platoform info to generated headers
thirtytwobits Feb 22, 2021
5e9431c
starting a variable-length array type
thirtytwobits Feb 27, 2021
714b0cd
Adding 01heap and updating other submodules
thirtytwobits Feb 28, 2021
993986b
adding bracket operator
thirtytwobits Feb 28, 2021
34f20d6
good progress on the variable length array type
thirtytwobits Feb 28, 2021
3ccd5ca
A lot of stuff in this one:
thirtytwobits Mar 12, 2021
32a75f5
fixing up noexcept specifiers
thirtytwobits Mar 13, 2021
8e93b8b
adding array type override
thirtytwobits Mar 14, 2021
5a9b016
version bump
thirtytwobits Mar 14, 2021
70ac699
fixing git submodules (I think)
thirtytwobits Mar 15, 2021
36b248c
fixing python tests
thirtytwobits Mar 17, 2021
79ab99c
fixing a build problem with unity
thirtytwobits Mar 17, 2021
5189e4b
fixing accidental typo
thirtytwobits Mar 17, 2021
1ee1d84
fixing typing error
thirtytwobits Mar 17, 2021
c73d4d0
progress on fixing up build
thirtytwobits Mar 17, 2021
5cdce00
fixing script permissions
thirtytwobits Mar 17, 2021
b2f0039
disabling coverage for now
thirtytwobits Mar 18, 2021
31edfe4
Fixing GCC 9 and earlier syntax
thirtytwobits Mar 21, 2021
803445f
parallelizing python builds
thirtytwobits Mar 22, 2021
ff3c0b4
fixing script permissions
thirtytwobits Mar 22, 2021
9d24d43
increasing host parallelism
thirtytwobits Mar 23, 2021
808f36c
fixing concurrency issues with native build
thirtytwobits Mar 23, 2021
fd96a1b
fixing my verify overrides.
thirtytwobits Mar 24, 2021
bc478f5
more responses based on the PR
thirtytwobits May 11, 2021
f91de11
More fixups per Pavels comments
thirtytwobits May 31, 2021
f3ae63f
last bits o fixup
thirtytwobits Jun 6, 2021
3309f9b
removing unneeded macro
thirtytwobits Jun 7, 2021
da79d79
disallowing array for var array
thirtytwobits Jun 7, 2021
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
Prev Previous commit
Next Next commit
various progress
  • Loading branch information
thirtytwobits committed May 7, 2021
commit 3e193c847dad322e37b296659c331e229afd8dbf
1 change: 1 addition & 0 deletions .vscode/spellright.dict
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,4 @@ nunavut
setattr
linesep
unittest
configparser
13 changes: 12 additions & 1 deletion src/nunavut/lang/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,22 @@ class Language:

@classmethod
def _as_dict(cls, value: str) -> typing.Dict[str, typing.Any]:
def _narrow(value: str) -> typing.Any:
if value is None:
return None
try:
return int(value)
except ValueError:
pass
if value.lower() == 'true' or value.lower() == 'false':
return bool(value)
return str(value)

value_as_dict = dict()
value_pairs = value.strip().split('\n')
for pair in value_pairs:
kv = pair.strip().split('=')
value_as_dict[kv[0].strip()] = kv[1].strip()
value_as_dict[kv[0].strip()] = _narrow(kv[1].strip())
return value_as_dict

@classmethod
Expand Down
68 changes: 67 additions & 1 deletion src/nunavut/lang/cpp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,73 @@ def filter_to_static_assertion_value(obj: typing.Any) -> str:
if isinstance(obj, str):
return '"{}"'.format(obj)

raise ValueError('Cannot convert object of type {} into an integer in a stable manner.'.format(type(obj)))
raise ValueError('Cannot convert object of type {} into a C++ type in a stable manner.'.format(type(obj)))


@template_language_filter(__name__)
def filter_type(language: Language,
obj: typing.Any) -> str:
"""
Tries to convert a Python object into a c++ typename.

Will raise a ValueError if the object provided does not (yet) have an available conversion in this function.

Currently supported types are string:

.. invisible-code-block: python

from nunavut.lang.cpp import filter_to_static_assertion_type

.. code-block:: python

# given
template = '{{ "Any" | to_static_assertion_type }}'

# then
rendered = "const char* const"

.. invisible-code-block: python

jinja_filter_tester(filter_to_static_assertion_type, template, rendered, 'cpp')

int:

.. code-block:: python

# given
template = '{{ 123 | to_static_assertion_type }}'

# then
rendered = 'long long'

.. invisible-code-block: python

jinja_filter_tester(filter_to_static_assertion_type, template, rendered, 'cpp')

and bool:

.. code-block:: python

# given
template = '{{ True | to_static_assertion_type }}'

# then
rendered = 'bool'

.. invisible-code-block: python

jinja_filter_tester(filter_to_static_assertion_type, template, rendered, 'cpp')

"""

if isinstance(obj, bool):
return "bool"
if isinstance(obj, int):
return "long long"
if isinstance(obj, str):
return "const char* const"

return filter_type_from_primitive(language, obj)


@template_language_filter(__name__)
Expand Down
32 changes: 19 additions & 13 deletions src/nunavut/lang/cpp/support/serialization.j2
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
#ifndef NUNAVUT_SUPPORT_SERIALIZATION_HPP_INCLUDED
#define NUNAVUT_SUPPORT_SERIALIZATION_HPP_INCLUDED

namespace nunavut
{

static_assert(__cplusplus < 201100L,
"Unsupported language: ISO C11, C++11, or a newer version of either is required.");

Expand All @@ -51,7 +54,7 @@ static_assert(sizeof({{ typename_unsigned_bit_length }}) >= sizeof({{ typename_u
"unsigned_bit_length type specified.");

{% for key, value in options.items() -%}
constexpr define {{ "NUNAVUT_SUPPORT_LANGUAGE_OPTION_{}".format(key) | ln.c.macrofy }} {{ value | to_static_assertion_value }}
constexpr {{ value | type }} {{ key | id }} = {{ value | value }};
{% endfor %}

/// Nunavut returns 0 for success and < 0 for any failure. It is always adequate to check that error_value < 0
Expand All @@ -61,14 +64,16 @@ constexpr define {{ "NUNAVUT_SUPPORT_LANGUAGE_OPTION_{}".format(key) | ln.c.macr
/// (-128 is not used). Error code 1 is currently also not used to avoid conflicts with 3rd-party software.
///
/// Return values > 0 for Nunavut serialization are undefined.
#define NUNAVUT_SUCCESS 0
// API usage errors:
#define NUNAVUT_ERROR_INVALID_ARGUMENT 2
#define NUNAVUT_ERROR_SERIALIZATION_BUFFER_TOO_SMALL 3
// Invalid representation (caused by bad input data, not API misuse):
#define NUNAVUT_ERROR_REPRESENTATION_BAD_ARRAY_LENGTH 10
#define NUNAVUT_ERROR_REPRESENTATION_BAD_UNION_TAG 11
#define NUNAVUT_ERROR_REPRESENTATION_BAD_DELIMITER_HEADER 12

enum class Result : int
{
Success = 0,
ErrorInvalidArgument = 2,
ErrorSerializationBufferTooSmall = 3,
ErrorRepresentationBadArrayLength = 10,
ErrorRepresentationBadUnionTag = 11,
ErrorRepresentationBadDelimiterHeader = 12
};

{% if not options.omit_float_serialization_support -%}
/// Detect whether the target platform is compatible with IEEE 754.
Expand All @@ -82,9 +87,8 @@ constexpr define {{ "NUNAVUT_SUPPORT_LANGUAGE_OPTION_{}".format(key) | ln.c.macr
#ifndef NUNAVUT_ASSERT
// By default Nunavut does not generate assert statements since the logic to halt a program is platform
// dependent and because this header requires an absolute minimum from a platform and from the C standard library.
// Most platforms can simply define "NUNAVUT_ASSERT(x)=assert(x)" (<assert.h> is always included by Nunavut).
# error "You must either define NUNAVUT_ASSERT or you need to disable assertions" \
" when generating serialization support code using Nunavut language options"
// Most platforms can simply define "NUNAVUT_ASSERT(x)=assert(x)".
# error "You must either define NUNAVUT_ASSERT or disable assertions."
#endif
{% endif -%}

Expand Down Expand Up @@ -117,7 +121,7 @@ static inline {{ typename_unsigned_bit_length }} nunavutChooseMin(const {{ typen
/// [--------------- fragment_offset_bits ---------------][--- fragment_length_bits ---]
/// [-- out bits --]
///
static inline {{ typename_unsigned_bit_length }} nunavutSaturateBufferFragmentBitLength(
constexpr {{ typename_unsigned_bit_length }} nunavutSaturateBufferFragmentBitLength(
const {{ typename_unsigned_length }} buffer_size_bytes, {# -#}
const {{ typename_unsigned_bit_length }} fragment_offset_bits, {# -#}
const {{ typename_unsigned_bit_length }} fragment_length_bits)
Expand Down Expand Up @@ -640,4 +644,6 @@ static inline {{typename_float_64}} nunavutGetF64(

{% endif -%}

} // end namespace nunavut

#endif // NUNAVUT_SUPPORT_SERIALIZATION_HPP_INCLUDED