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

Allow expressions with type constructors #1313

Merged
merged 23 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
480bbe4
Fix bug in cast from `real` to `interval`.
rsmmr Dec 3, 2022
57a5682
Support arbitrary expression as argument to `interval(...)` and `inte…
rsmmr Dec 3, 2022
54b22f8
Port more type constructors to new call operators.
rsmmr Dec 8, 2022
0636d23
Port `port` ctor expression to new model.
rsmmr Dec 9, 2022
7aa2c14
Address review feedback.
rsmmr Dec 9, 2022
e35fa30
Move negation out of parser.
rsmmr Dec 12, 2022
7737659
Rework integer out-of-range checking.
rsmmr Dec 12, 2022
1829081
Add general constant folding.
rsmmr Dec 12, 2022
afc45a5
Add test exercising various integer out-of-range situations.
rsmmr Dec 12, 2022
2ddb1d7
Move ctor replacement from normalizer into constant folder.
rsmmr Dec 12, 2022
38d6621
Update printer to output type constructors.
rsmmr Dec 12, 2022
0e8ed00
Add test to check substitution of ctor nodes.
rsmmr Dec 12, 2022
86c720d
Remove debugging output from integer range checks.
rsmmr Dec 12, 2022
97484b0
Suppress clang-tidy warnings.
rsmmr Dec 12, 2022
fa20890
Outsource an integer range check to SafeInt.
rsmmr Dec 15, 2022
4a79137
Add boolean folding.
rsmmr Dec 16, 2022
5d1c311
Fix printing of enum constants.
rsmmr Dec 16, 2022
3240fa8
Fix printing of ID scopes.
rsmmr Dec 16, 2022
0df4162
Fix clang-tidy warnings.
rsmmr Jan 11, 2023
a44ecdc
Fix a couple of unit tests for Alpine.
rsmmr Jan 11, 2023
d66cc1a
Suppress GCC warnings.
rsmmr Jan 18, 2023
10ee02c
Fix issue in Bison grammar.
rsmmr Jan 18, 2023
78ae64b
Change SafeInt repository over to a fork including a fix.
rsmmr Jan 18, 2023
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
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Checks: '
-misc-unused-parameters,
-misc-const-correctness,
-misc-confusable-identifiers,
-misc-const-correctness,
modernize-*,
-modernize-avoid-c-arrays,
Expand Down
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
url = https://github.com/onqtam/doctest.git
[submodule "3rdparty/SafeInt"]
path = 3rdparty/SafeInt
url = https://github.com/dcleblanc/SafeInt
rsmmr marked this conversation as resolved.
Show resolved Hide resolved
url = https://github.com/rsmmr/SafeInt.git
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rsmmr, do you plan to upstream your patch? Also, using a private fork is not ideal as it makes pulling in upstream fixes impossible for anyone but you.

[submodule "3rdparty/ArticleEnumClass-v2"]
path = 3rdparty/ArticleEnumClass-v2
url = https://github.com/Dalzhim/ArticleEnumClass-v2
Expand Down
2 changes: 1 addition & 1 deletion 3rdparty/SafeInt
Submodule SafeInt updated 47 files
+0 −65 .appveyor.yml
+11 −0 .gitignore
+0 −131 .travis.yml
+23 −27 CMakeLists.txt
+2 −0 README.md
+494 −710 SafeInt.hpp
+6,385 −0 Test/AddTestCase.cpp
+107 −6,633 Test/AddVerify.cpp
+1 −0 Test/CastVerify.cpp
+1 −0 Test/ClangTest/.gitignore
+205 −0 Test/ClangTest/CMakeLists.txt
+17 −1 Test/ClangTest/makefile
+2 −0 Test/ClangTest/readme.txt
+3 −2 Test/CompileTest.cpp
+2,178 −0 Test/DivTestCase.cpp
+276 −1,788 Test/DivVerify.cpp
+1 −0 Test/GccTest/.gitignore
+177 −0 Test/GccTest/CMakeLists.txt
+14 −1 Test/GccTest/makefile
+1 −0 Test/IncDecVerify.cpp
+1 −0 Test/ModVerify.cpp
+152 −0 Test/MsvcTest/CMakeLists.txt
+4 −0 Test/MsvcTest/build_test.cmd
+1,348 −0 Test/MultTestCase.cpp
+275 −1,186 Test/MultVerify.cpp
+5 −0 Test/MultVerify.h
+12 −2 Test/SafeIntTestVS17/SafeIntTestVS17.sln
+5 −0 Test/SafeIntTestVS17/SafeIntTestVS17/SafeIntTestVS17.vcxproj
+15 −0 Test/SafeIntTestVS17/SafeIntTestVS17/SafeIntTestVS17.vcxproj.filters
+6 −11 Test/SafeIntTestVS17/Scratch/Scratch.cpp
+6,343 −0 Test/SubTestCase.cpp
+65 −6,602 Test/SubVerify.cpp
+151 −0 Test/TestCase.h
+25 −0 Test/TestMain.cpp
+0 −49 Test/TestMain.h
+160 −0 Test/c_safe_math/c_safe_math.vcxproj
+494 −0 Test/c_safe_math/compile_test.c
+11 −0 Test/c_safe_math/safe_math_compile.c
+28 −0 Test/c_safe_math/safe_math_test.c
+107 −0 Test/c_safe_math/safe_math_test.h
+171 −0 Test/c_safe_math/safe_math_test_add.cpp
+171 −0 Test/c_safe_math/safe_math_test_div.cpp
+171 −0 Test/c_safe_math/safe_math_test_mult.cpp
+173 −0 Test/c_safe_math/safe_math_test_sub.cpp
+678 −0 helpfile.md
+1,034 −0 safe_math.h
+2,587 −0 safe_math_impl.h
6 changes: 6 additions & 0 deletions doc/autogen/types/error.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@
Retrieves the textual description associated with the error.

.. rubric:: Operators

.. spicy:operator:: error::Call error error(string)
Creates an error with the given message.

68 changes: 68 additions & 0 deletions doc/autogen/types/integer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,70 @@
Computes the bit-wise 'xor' of the two integers.

.. spicy:operator:: integer::Call int<16> int16(int)
Creates a 16-bit signed integer value.

.. spicy:operator:: integer::Call int<16> int16(uint)
Creates a 16-bit signed integer value.

.. spicy:operator:: integer::Call int<32> int32(int)
Creates a 32-bit signed integer value.

.. spicy:operator:: integer::Call int<32> int32(uint)
Creates a 32-bit signed integer value.

.. spicy:operator:: integer::Call int<64> int64(int)
Creates a 64-bit signed integer value.

.. spicy:operator:: integer::Call int<64> int64(uint)
Creates a 64-bit signed integer value.

.. spicy:operator:: integer::Call int<8> int8(int)
Creates a 8-bit signed integer value.

.. spicy:operator:: integer::Call int<8> int8(uint)
Creates a 8-bit signed integer value.

.. spicy:operator:: integer::Call uint<16> uint16(int)
Creates a 16-bit unsigned integer value.

.. spicy:operator:: integer::Call uint<16> uint16(uint)
Creates a 16-bit unsigned integer value.

.. spicy:operator:: integer::Call uint<32> uint32(int)
Creates a 32-bit unsigned integer value.

.. spicy:operator:: integer::Call uint<32> uint32(uint)
Creates a 32-bit unsigned integer value.

.. spicy:operator:: integer::Call uint<64> uint64(int)
Creates a 64-bit unsigned integer value.

.. spicy:operator:: integer::Call uint<64> uint64(uint)
Creates a 64-bit unsigned integer value.

.. spicy:operator:: integer::Call uint<8> uint8(int)
Creates a 8-bit unsigned integer value.

.. spicy:operator:: integer::Call uint<8> uint8(uint)
Creates a 8-bit unsigned integer value.

.. spicy:operator:: integer::Cast bool cast<bool-type>(int)
Converts the value to a boolean by comparing against zero
Expand Down Expand Up @@ -220,6 +284,10 @@
Inverts the sign of the integer.

.. spicy:operator:: integer::SignNeg int op:- t:uint op:
Inverts the sign of the integer.

.. spicy:operator:: integer::Sum int t:int <sp> op:+ <sp> t:int
Computes the sum of the integers.
Expand Down
22 changes: 22 additions & 0 deletions doc/autogen/types/interval.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,28 @@

.. rubric:: Operators

.. spicy:operator:: interval::Call interval interval(int)
Creates an interval interpreting the argument as number of seconds.

.. spicy:operator:: interval::Call interval interval(real)
Creates an interval interpreting the argument as number of seconds.

.. spicy:operator:: interval::Call interval interval(uint)
Creates an interval interpreting the argument as number of seconds.

.. spicy:operator:: interval::Call interval interval_ns(int)
Creates an interval interpreting the argument as number of
nanoseconds.

.. spicy:operator:: interval::Call interval interval_ns(uint)
Creates an interval interpreting the argument as number of
nanoseconds.

.. spicy:operator:: interval::Difference interval t:interval <sp> op:- <sp> t:interval
Returns the difference of the intervals.
Expand Down
4 changes: 4 additions & 0 deletions doc/autogen/types/port.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

.. rubric:: Operators

.. spicy:operator:: port::Call port port(uint<16>, enum)
Creates a port instance.

.. spicy:operator:: port::Equal bool t:port <sp> op:== <sp> t:port
Compares two port values.
Expand Down
4 changes: 4 additions & 0 deletions doc/autogen/types/stream.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
Returns an iterator to the beginning of the container's content.

.. spicy:operator:: stream::Call stream stream(bytes)
Creates a stream instance preinitialized with the given data.

.. spicy:operator:: stream::End <iterator> end(<container>)
Returns an iterator to the end of the container's content.
Expand Down
20 changes: 20 additions & 0 deletions doc/autogen/types/time.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,26 @@

.. rubric:: Operators

.. spicy:operator:: time::Call time time(int)
Creates an time interpreting the argument as number of seconds.

.. spicy:operator:: time::Call time time(real)
Creates an time interpreting the argument as number of seconds.

.. spicy:operator:: time::Call time time(uint)
Creates an time interpreting the argument as number of seconds.

.. spicy:operator:: time::Call time time_ns(int)
Creates an time interpreting the argument as number of nanoseconds.

.. spicy:operator:: time::Call time time_ns(uint)
Creates an time interpreting the argument as number of nanoseconds.

.. spicy:operator:: time::Difference interval t:time <sp> op:- <sp> t:time
Returns the difference of the times.
Expand Down
1 change: 1 addition & 0 deletions hilti/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ set(SOURCES
src/library.cc
src/logging.cc
src/main.cc
src/safe-math.cc
src/type-info.cc
src/types/address.cc
src/types/bytes.cc
Expand Down
19 changes: 19 additions & 0 deletions hilti/runtime/include/safe-math.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2020-2022 by the Zeek Project. See LICENSE for details.
//
// Wrapper around functionality from 3rdparty's safe-math that we need. This
// needs to be in a separate implementation file because one cannot include
// both SafeInt.h and safe-math.h at the same time.

#pragma once

#include <cstdint>

namespace hilti::rt::integer {

/**
* Negates an unsigned value, returning a signed value. Will through a
* `OutOfRange` if not possible.
*/
extern int64_t safe_negate(uint64_t x);

} // namespace hilti::rt::integer
8 changes: 5 additions & 3 deletions hilti/runtime/include/types/interval.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Interval {
*
* @param nsecs interval in nanoseconds.
*/
explicit Interval(hilti::rt::integer::safe<int64_t> nsecs, NanosecondTag /*unused*/) : _nsecs(nsecs) {}
explicit Interval(const hilti::rt::integer::safe<int64_t>& nsecs, NanosecondTag /*unused*/) : _nsecs(nsecs) {}
rsmmr marked this conversation as resolved.
Show resolved Hide resolved

/**
* Constructs an interval from a double value.
Expand Down Expand Up @@ -73,9 +73,11 @@ class Interval {
Interval operator+(const Interval& other) const { return Interval(_nsecs + other._nsecs, NanosecondTag()); }
Interval operator-(const Interval& other) const { return Interval(_nsecs - other._nsecs, NanosecondTag()); }

Interval operator*(hilti::rt::integer::safe<std::int64_t> i) const { return Interval(_nsecs * i, NanosecondTag()); }
Interval operator*(const hilti::rt::integer::safe<std::int64_t>& i) const {
return Interval(_nsecs * i, NanosecondTag());
}

Interval operator*(hilti::rt::integer::safe<std::uint64_t> i) const {
Interval operator*(const hilti::rt::integer::safe<std::uint64_t>& i) const {
return Interval(_nsecs * i.Ref(), NanosecondTag());
}

Expand Down
Loading