From 98ea7c5a6446dc9e23af08443d84bde98ff75c38 Mon Sep 17 00:00:00 2001 From: Riabtsev Yaroslav Date: Sun, 14 Aug 2022 18:21:21 +0300 Subject: [PATCH 1/3] char v1 --- citation.cff | 1 + project/src/transpiler/aliases.h | 14 +++++ project/src/transpiler/record_manager.cpp | 9 --- project/src/transpiler/record_manager.h | 2 - project/src/transpiler/recorddecl.cpp | 2 +- project/src/transpiler/transpile_helper.cpp | 31 +++++++--- project/src/transpiler/vardecl.cpp | 12 ++-- .../tests/in_progress/for_main/bugs/for01.c | 10 ++++ project/tests/main/char/char01.c | 59 +++++++++++++++++++ project/tests/main/char/char02.c | 16 +++++ result/eo/c2eo/coperators/as-int8.eo | 10 ++++ result/eo/c2eo/coperators/as-uint8.eo | 6 ++ result/eo/c2eo/coperators/post-dec-int8.eo | 9 +++ result/eo/c2eo/coperators/post-dec-uint8.eo | 9 +++ result/eo/c2eo/coperators/post-inc-int8.eo | 9 +++ result/eo/c2eo/coperators/post-inc-uint8.eo | 9 +++ result/eo/c2eo/coperators/pre-dec-int8.eo | 7 +++ result/eo/c2eo/coperators/pre-dec-uint8.eo | 7 +++ result/eo/c2eo/coperators/pre-inc-int8.eo | 7 +++ result/eo/c2eo/coperators/pre-inc-uint8.eo | 7 +++ result/eo/c2eo/coperators/read-as-int8.eo | 7 +++ result/eo/c2eo/coperators/read-as-uint8.eo | 4 ++ result/eo/c2eo/coperators/write-as-int8.eo | 8 +++ result/eo/c2eo/coperators/write-as-uint8.eo | 8 +++ result/run.sh | 2 +- 25 files changed, 237 insertions(+), 28 deletions(-) create mode 100644 project/tests/in_progress/for_main/bugs/for01.c create mode 100644 project/tests/main/char/char01.c create mode 100644 project/tests/main/char/char02.c create mode 100644 result/eo/c2eo/coperators/as-int8.eo create mode 100644 result/eo/c2eo/coperators/as-uint8.eo create mode 100644 result/eo/c2eo/coperators/post-dec-int8.eo create mode 100644 result/eo/c2eo/coperators/post-dec-uint8.eo create mode 100644 result/eo/c2eo/coperators/post-inc-int8.eo create mode 100644 result/eo/c2eo/coperators/post-inc-uint8.eo create mode 100644 result/eo/c2eo/coperators/pre-dec-int8.eo create mode 100644 result/eo/c2eo/coperators/pre-dec-uint8.eo create mode 100644 result/eo/c2eo/coperators/pre-inc-int8.eo create mode 100644 result/eo/c2eo/coperators/pre-inc-uint8.eo create mode 100644 result/eo/c2eo/coperators/read-as-int8.eo create mode 100644 result/eo/c2eo/coperators/read-as-uint8.eo create mode 100644 result/eo/c2eo/coperators/write-as-int8.eo create mode 100644 result/eo/c2eo/coperators/write-as-uint8.eo diff --git a/citation.cff b/citation.cff index 6edacb1c..a437d773 100644 --- a/citation.cff +++ b/citation.cff @@ -11,6 +11,7 @@ authors: orcid: "https://orcid.org/0000-0002-4957-5695" - family-names: "Ryabtsev" given-names: "Yaroslav" + orcid: "https://orcid.org/0000-0001-5530-3752" - family-names: "Kamensky" given-names: "Andrey" title: "c2eo: C to EO transpiler" diff --git a/project/src/transpiler/aliases.h b/project/src/transpiler/aliases.h index faf098ca..37fd54a7 100644 --- a/project/src/transpiler/aliases.h +++ b/project/src/transpiler/aliases.h @@ -54,9 +54,11 @@ std::map known_aliases = { {"as-bool", "+alias c2eo.coperators.as-bool"}, {"as-float32", "+alias c2eo.coperators.as-float32"}, {"as-float64", "+alias c2eo.coperators.as-float64"}, + {"as-int8", "+alias c2eo.coperators.as-int8"}, {"as-int16", "+alias c2eo.coperators.as-int16"}, {"as-int32", "+alias c2eo.coperators.as-int32"}, {"as-int64", "+alias c2eo.coperators.as-int64"}, + {"as-uint8", "+alias c2eo.coperators.as-uint8"}, {"as-uint16", "+alias c2eo.coperators.as-uint16"}, {"as-uint32", "+alias c2eo.coperators.as-uint32"}, {"bit-and", "+alias c2eo.coperators.bit-and"}, @@ -85,34 +87,42 @@ std::map known_aliases = { {"pos", "+alias c2eo.coperators.pos"}, {"post-dec-float32", "+alias c2eo.coperators.post-dec-float32"}, {"post-dec-float64", "+alias c2eo.coperators.post-dec-float64"}, + {"post-dec-int8", "+alias c2eo.coperators.post-dec-int8"}, {"post-dec-int16", "+alias c2eo.coperators.post-dec-int16"}, {"post-dec-int32", "+alias c2eo.coperators.post-dec-int32"}, {"post-dec-int64", "+alias c2eo.coperators.post-dec-int64"}, {"post-dec-ptr", "+alias c2eo.coperators.post-dec-ptr"}, + {"post-dec-uint8", "+alias c2eo.coperators.post-dec-uint8"}, {"post-dec-uint16", "+alias c2eo.coperators.post-dec-uint16"}, {"post-dec-uint32", "+alias c2eo.coperators.post-dec-uint32"}, {"post-inc-float32", "+alias c2eo.coperators.post-inc-float32"}, {"post-inc-float64", "+alias c2eo.coperators.post-inc-float64"}, + {"post-inc-int8", "+alias c2eo.coperators.post-inc-int8"}, {"post-inc-int16", "+alias c2eo.coperators.post-inc-int16"}, {"post-inc-int32", "+alias c2eo.coperators.post-inc-int32"}, {"post-inc-int64", "+alias c2eo.coperators.post-inc-int64"}, {"post-inc-ptr", "+alias c2eo.coperators.post-inc-ptr"}, + {"post-inc-uint8", "+alias c2eo.coperators.post-inc-uint8"}, {"post-inc-uint16", "+alias c2eo.coperators.post-inc-uint16"}, {"post-inc-uint32", "+alias c2eo.coperators.post-inc-uint32"}, {"pre-dec-float32", "+alias c2eo.coperators.pre-dec-float32"}, {"pre-dec-float64", "+alias c2eo.coperators.pre-dec-float64"}, + {"pre-dec-int8", "+alias c2eo.coperators.pre-dec-int8"}, {"pre-dec-int16", "+alias c2eo.coperators.pre-dec-int16"}, {"pre-dec-int32", "+alias c2eo.coperators.pre-dec-int32"}, {"pre-dec-int64", "+alias c2eo.coperators.pre-dec-int64"}, {"pre-dec-ptr", "+alias c2eo.coperators.pre-dec-ptr"}, + {"pre-dec-uint8", "+alias c2eo.coperators.pre-dec-uint8"}, {"pre-dec-uint16", "+alias c2eo.coperators.pre-dec-uint16"}, {"pre-dec-uint32", "+alias c2eo.coperators.pre-dec-uint32"}, {"pre-inc-float32", "+alias c2eo.coperators.pre-inc-float32"}, {"pre-inc-float64", "+alias c2eo.coperators.pre-inc-float64"}, + {"pre-inc-int8", "+alias c2eo.coperators.pre-inc-int8"}, {"pre-inc-int16", "+alias c2eo.coperators.pre-inc-int16"}, {"pre-inc-int32", "+alias c2eo.coperators.pre-inc-int32"}, {"pre-inc-int64", "+alias c2eo.coperators.pre-inc-int64"}, {"pre-inc-ptr", "+alias c2eo.coperators.pre-inc-ptr"}, + {"pre-inc-uint8", "+alias c2eo.coperators.pre-inc-uint8"}, {"pre-inc-uint16", "+alias c2eo.coperators.pre-inc-uint16"}, {"pre-inc-uint32", "+alias c2eo.coperators.pre-inc-uint32"}, {"printf", "+alias c2eo.coperators.printf"}, @@ -122,11 +132,13 @@ std::map known_aliases = { {"read-as-bool", "+alias c2eo.coperators.read-as-bool"}, {"read-as-float32", "+alias c2eo.coperators.read-as-float32"}, {"read-as-float64", "+alias c2eo.coperators.read-as-float64"}, + {"read-as-int8", "+alias c2eo.coperators.read-as-int8"}, {"read-as-int16", "+alias c2eo.coperators.read-as-int16"}, {"read-as-int32", "+alias c2eo.coperators.read-as-int32"}, {"read-as-int64", "+alias c2eo.coperators.read-as-int64"}, {"read-as-ptr", "+alias c2eo.coperators.read-as-ptr"}, {"read-as-string", "+alias c2eo.coperators.read-as-string"}, + {"read-as-uint8", "+alias c2eo.coperators.read-as-uint8"}, {"read-as-uint16", "+alias c2eo.coperators.read-as-uint16"}, {"read-as-uint32", "+alias c2eo.coperators.read-as-uint32"}, {"shift-left", "+alias c2eo.coperators.shift-left"}, @@ -136,11 +148,13 @@ std::map known_aliases = { {"write-as-bool", "+alias c2eo.coperators.write-as-bool"}, {"write-as-float32", "+alias c2eo.coperators.write-as-float32"}, {"write-as-float64", "+alias c2eo.coperators.write-as-float64"}, + {"write-as-int8", "+alias c2eo.coperators.write-as-int8"}, {"write-as-int16", "+alias c2eo.coperators.write-as-int16"}, {"write-as-int32", "+alias c2eo.coperators.write-as-int32"}, {"write-as-int64", "+alias c2eo.coperators.write-as-int64"}, {"write-as-ptr", "+alias c2eo.coperators.write-as-ptr"}, {"write-as-string", "+alias c2eo.coperators.write-as-string"}, + {"write-as-uint8", "+alias c2eo.coperators.write-as-uint8"}, {"write-as-uint16", "+alias c2eo.coperators.write-as-uint16"}, {"write-as-uint32", "+alias c2eo.coperators.write-as-uint32"}, }; diff --git a/project/src/transpiler/record_manager.cpp b/project/src/transpiler/record_manager.cpp index 21a1e8af..431a184c 100644 --- a/project/src/transpiler/record_manager.cpp +++ b/project/src/transpiler/record_manager.cpp @@ -46,15 +46,6 @@ RecordType *RecordManager::GetById(int64_t id) { return nullptr; } -__attribute__((unused)) size_t RecordManager::GetShift( - int64_t id, const std::string &member) { - RecordType *rt = GetById(id); - if (rt != nullptr) { - return rt->fields[member].second; - } - return -1; -} - EOObject RecordManager::GetShiftAlias(int64_t id, const std::string &member) { RecordType *rt = GetById(id); if (rt != nullptr) { diff --git a/project/src/transpiler/record_manager.h b/project/src/transpiler/record_manager.h index a84386cb..7b4b45dc 100644 --- a/project/src/transpiler/record_manager.h +++ b/project/src/transpiler/record_manager.h @@ -51,8 +51,6 @@ struct RecordManager { std::map> fields, bool is_local); RecordType *GetById(int64_t id); - __attribute__((unused)) size_t GetShift(int64_t id, - const std::string &member); [[nodiscard]] std::vector::const_iterator begin() const; [[nodiscard]] std::vector::const_iterator end() const; diff --git a/project/src/transpiler/recorddecl.cpp b/project/src/transpiler/recorddecl.cpp index c44c4929..4292f57d 100644 --- a/project/src/transpiler/recorddecl.cpp +++ b/project/src/transpiler/recorddecl.cpp @@ -73,7 +73,7 @@ std::vector ProcessRecordType(const clang::RecordDecl *RD, auto *field = llvm::dyn_cast(*it); if (field == nullptr) { - return {}; + continue; } std::string field_name; if (!field->isUnnamedBitfield() && !field->getNameAsString().empty()) { diff --git a/project/src/transpiler/transpile_helper.cpp b/project/src/transpiler/transpile_helper.cpp index edd4cfed..fa6d99a2 100644 --- a/project/src/transpiler/transpile_helper.cpp +++ b/project/src/transpiler/transpile_helper.cpp @@ -139,6 +139,8 @@ EOObject GetSwitchEOObject(const SwitchStmt *p_stmt); EOObject GetCaseCondEOObject(const vector &all_cases, const EOObject &switch_exp, size_t i); +EOObject GetCharacterLiteralEOObject(const clang::CharacterLiteral *p_literal); +// EOObject GetStringToListEOObject(const clang::StringLiteral *str); extern UnitTranspiler transpiler; extern ASTContext *context; @@ -361,6 +363,10 @@ EOObject GetStmtEOObject(const Stmt *stmt) { const auto *op = dyn_cast(stmt); return GetIntegerLiteralEOObject(op); } + if (stmt_class == Stmt::CharacterLiteralClass) { + const auto *op = dyn_cast(stmt); + return GetCharacterLiteralEOObject(op); + } if (stmt_class == Stmt::FloatingLiteralClass) { const auto *op = dyn_cast(stmt); return GetFloatingLiteralEOObject(op); @@ -433,7 +439,14 @@ EOObject GetStmtEOObject(const Stmt *stmt) { return EOObject(EOObjectType::EO_PLUG); } - +EOObject GetCharacterLiteralEOObject(const clang::CharacterLiteral *p_literal) { + if (p_literal != nullptr) { + unsigned int an_int = p_literal->getValue(); + std::string str_val{std::to_string(an_int)}; + return EOObject{str_val, EOObjectType::EO_LITERAL}; + } + return EOObject{EOObjectType::EO_PLUG}; +} EOObject GetInitListEOObject(const clang::InitListExpr *list) { EOObject eoList{"*", EOObjectType::EO_EMPTY}; clang::QualType qualType = list->getType().getDesugaredType(*context); @@ -1379,10 +1392,10 @@ std::string GetPostfix(QualType qual_type) { if (!type_ptr->isSignedIntegerType()) { str += "u"; } - if (type_ptr->isCharType()) { - str += "char"; - return str; - } + // if (type_ptr->isCharType()) { + // str += "int8"; + // return str; + // } if (type_ptr->isIntegerType()) { str += "int" + std::to_string(type_size); return str; @@ -1414,10 +1427,10 @@ std::string GetTypeName(QualType qual_type) { if (!type_ptr->isSignedIntegerType()) { str += "u"; } - if (type_ptr->isCharType()) { - str += "char"; - return str; - } + // if (type_ptr->isCharType()) { + // str += "char"; + // return str; + // } if (type_ptr->isIntegerType()) { str += "int" + std::to_string(type_size); return str; diff --git a/project/src/transpiler/vardecl.cpp b/project/src/transpiler/vardecl.cpp index 336211c2..14e79b2e 100755 --- a/project/src/transpiler/vardecl.cpp +++ b/project/src/transpiler/vardecl.cpp @@ -106,13 +106,13 @@ EOObject InitValueAnalysis(const VarDecl *VD) { std::string str; if (init_val->isInt()) { auto int_value = init_val->getInt().getExtValue(); - if (type_ptr->isCharType()) { - str = "'"; - str += static_cast(int_value); - str += "'"; - } else { +// if (type_ptr->isCharType()) { +// str = "'"; +// str += static_cast(int_value); +// str += "'"; +// } else { str = std::to_string(int_value); - } +// } } else if (init_val->isFloat() && (size == double_size)) { auto float_value = init_val->getFloat().convertToDouble(); str = std::to_string(float_value); diff --git a/project/tests/in_progress/for_main/bugs/for01.c b/project/tests/in_progress/for_main/bugs/for01.c new file mode 100644 index 00000000..aaaa076f --- /dev/null +++ b/project/tests/in_progress/for_main/bugs/for01.c @@ -0,0 +1,10 @@ +#include "stdio.h" +int main() { + for (int i = 0; i < 1; i++) + printf("%d\n", i); + for (int i = 0; i < 1; i++) + printf("%d\n", i); + for (int i = 0; i < 1; i++) + printf("%d\n", i); + return 0; +} diff --git a/project/tests/main/char/char01.c b/project/tests/main/char/char01.c new file mode 100644 index 00000000..de168f56 --- /dev/null +++ b/project/tests/main/char/char01.c @@ -0,0 +1,59 @@ +#include "stdio.h" +char c = 5; +unsigned char uc = 5; +int main() { + char lc = 5; + unsigned char ulc = 5; + + printf("%d\n", c); + printf("%d\n", uc); + printf("%d\n", lc); + printf("%d\n", ulc); + + c++; + uc++; + lc++; + ulc++; + + printf("%d\n", c); + printf("%d\n", uc); + printf("%d\n", lc); + printf("%d\n", ulc); + + c--; + uc--; + lc--; + ulc--; + + printf("%d\n", c); + printf("%d\n", uc); + printf("%d\n", lc); + printf("%d\n", ulc); + + c += 1000; + uc += 1000; + lc += 1000; + ulc += 1000; + + printf("%d\n", c); + printf("%d\n", uc); + printf("%d\n", lc); + printf("%d\n", ulc); + + c -= 2000; + uc -= 2000; + lc -= 2000; + ulc -= 2000; + + printf("%d\n", c); + printf("%d\n", uc); + printf("%d\n", lc); + printf("%d\n", ulc); + +// printf("%c\n", c); +// printf("%c\n", uc); +// printf("%c\n", lc); +// printf("%c\n", ulc); + + return 0; +} diff --git a/project/tests/main/char/char02.c b/project/tests/main/char/char02.c new file mode 100644 index 00000000..4b33c65d --- /dev/null +++ b/project/tests/main/char/char02.c @@ -0,0 +1,16 @@ +#include "stdio.h" +char c[] = {3, 4, 5, 6, 7, 8, 9}; +char str[] = "hell"; +char str2[] = {'h', 1, 2, 3, 'k'}; +unsigned char str3[] = {'h', -1, -2, 3, 'k'}; +int main() { + for (int i = 0; i < 8; i++) + printf("%d\n", c[i]); + for (int i = 0; i < 5; i++) + printf("%d\n", str[i]); + for (int j = 0; j < 5; j++) + printf("%d\n", str2[j]); + for (int j = 0; j < 5; j++) + printf("%d\n", str3[j]); + return 0; +} diff --git a/result/eo/c2eo/coperators/as-int8.eo b/result/eo/c2eo/coperators/as-int8.eo new file mode 100644 index 00000000..463b5a94 --- /dev/null +++ b/result/eo/c2eo/coperators/as-int8.eo @@ -0,0 +1,10 @@ ++alias org.eolang.math.number + ++package c2eo.coperators + +[a] > as-int8 + (number a).as-int > value! + if. > @ + (value.as-bytes.slice 7 1).as-int.gte 0 + (00-00-00-00-00-00-00.concat (value.as-bytes.slice 7 1)).as-int + (FF-FF-FF-FF-FF-FF-FF.concat (value.as-bytes.slice 7 1)).as-int diff --git a/result/eo/c2eo/coperators/as-uint8.eo b/result/eo/c2eo/coperators/as-uint8.eo new file mode 100644 index 00000000..7740e65d --- /dev/null +++ b/result/eo/c2eo/coperators/as-uint8.eo @@ -0,0 +1,6 @@ ++alias org.eolang.math.number + ++package c2eo.coperators + +[a] > as-uint8 + (00-00-00-00-00-00-00.concat ((number a).as-int.as-bytes.slice 7 1)).as-int > @ diff --git a/result/eo/c2eo/coperators/post-dec-int8.eo b/result/eo/c2eo/coperators/post-dec-int8.eo new file mode 100644 index 00000000..278ff8c4 --- /dev/null +++ b/result/eo/c2eo/coperators/post-dec-int8.eo @@ -0,0 +1,9 @@ ++alias c2eo.coperators.read-as-int8 ++alias c2eo.coperators.write-as-int8 + ++package c2eo.coperators + +[a] > post-dec-int8 + seq > @ + write-as-int8 a ((read-as-int8 a).minus 1) + (read-as-int8 a).plus 1 diff --git a/result/eo/c2eo/coperators/post-dec-uint8.eo b/result/eo/c2eo/coperators/post-dec-uint8.eo new file mode 100644 index 00000000..973000e8 --- /dev/null +++ b/result/eo/c2eo/coperators/post-dec-uint8.eo @@ -0,0 +1,9 @@ ++alias c2eo.coperators.read-as-uint8 ++alias c2eo.coperators.write-as-uint8 + ++package c2eo.coperators + +[a] > post-dec-uint8 + seq > @ + write-as-uint8 a ((read-as-uint8 a).minus 1) + (read-as-uint8 a).plus 1 diff --git a/result/eo/c2eo/coperators/post-inc-int8.eo b/result/eo/c2eo/coperators/post-inc-int8.eo new file mode 100644 index 00000000..4c61fb8b --- /dev/null +++ b/result/eo/c2eo/coperators/post-inc-int8.eo @@ -0,0 +1,9 @@ ++alias c2eo.coperators.read-as-int8 ++alias c2eo.coperators.write-as-int8 + ++package c2eo.coperators + +[a] > post-inc-int8 + seq > @ + write-as-int8 a ((read-as-int8 a).plus 1) + (read-as-int8 a).minus 1 diff --git a/result/eo/c2eo/coperators/post-inc-uint8.eo b/result/eo/c2eo/coperators/post-inc-uint8.eo new file mode 100644 index 00000000..9b75c36f --- /dev/null +++ b/result/eo/c2eo/coperators/post-inc-uint8.eo @@ -0,0 +1,9 @@ ++alias c2eo.coperators.read-as-uint8 ++alias c2eo.coperators.write-as-uint8 + ++package c2eo.coperators + +[a] > post-inc-uint8 + seq > @ + write-as-uint8 a ((read-as-uint8 a).plus 1) + (read-as-uint8 a).minus 1 diff --git a/result/eo/c2eo/coperators/pre-dec-int8.eo b/result/eo/c2eo/coperators/pre-dec-int8.eo new file mode 100644 index 00000000..aa6111d3 --- /dev/null +++ b/result/eo/c2eo/coperators/pre-dec-int8.eo @@ -0,0 +1,7 @@ ++alias c2eo.coperators.read-as-int8 ++alias c2eo.coperators.write-as-int8 + ++package c2eo.coperators + +[a] > pre-dec-int8 + write-as-int8 a ((read-as-int8 a).minus 1) > @ diff --git a/result/eo/c2eo/coperators/pre-dec-uint8.eo b/result/eo/c2eo/coperators/pre-dec-uint8.eo new file mode 100644 index 00000000..3642a4b0 --- /dev/null +++ b/result/eo/c2eo/coperators/pre-dec-uint8.eo @@ -0,0 +1,7 @@ ++alias c2eo.coperators.read-as-uint8 ++alias c2eo.coperators.write-as-uint8 + ++package c2eo.coperators + +[a] > pre-dec-uint8 + write-as-uint8 a ((read-as-uint8 a).minus 1) > @ diff --git a/result/eo/c2eo/coperators/pre-inc-int8.eo b/result/eo/c2eo/coperators/pre-inc-int8.eo new file mode 100644 index 00000000..a9fedfc3 --- /dev/null +++ b/result/eo/c2eo/coperators/pre-inc-int8.eo @@ -0,0 +1,7 @@ ++alias c2eo.coperators.read-as-int8 ++alias c2eo.coperators.write-as-int8 + ++package c2eo.coperators + +[a] > pre-inc-int8 + write-as-int8 a ((read-as-int8 a).plus 1) > @ diff --git a/result/eo/c2eo/coperators/pre-inc-uint8.eo b/result/eo/c2eo/coperators/pre-inc-uint8.eo new file mode 100644 index 00000000..b2891316 --- /dev/null +++ b/result/eo/c2eo/coperators/pre-inc-uint8.eo @@ -0,0 +1,7 @@ ++alias c2eo.coperators.read-as-uint8 ++alias c2eo.coperators.write-as-uint8 + ++package c2eo.coperators + +[a] > pre-inc-uint8 + write-as-uint8 a ((read-as-uint8 a).plus 1) > @ diff --git a/result/eo/c2eo/coperators/read-as-int8.eo b/result/eo/c2eo/coperators/read-as-int8.eo new file mode 100644 index 00000000..f36baec7 --- /dev/null +++ b/result/eo/c2eo/coperators/read-as-int8.eo @@ -0,0 +1,7 @@ ++package c2eo.coperators + +[a] > read-as-int8 + if. > @ + (a.read 1).as-int.gte 0 + (00-00-00-00-00-00-00.concat (a.read 1)).as-int + (FF-FF-FF-FF-FF-FF-FF.concat (a.read 1)).as-int \ No newline at end of file diff --git a/result/eo/c2eo/coperators/read-as-uint8.eo b/result/eo/c2eo/coperators/read-as-uint8.eo new file mode 100644 index 00000000..fcd9797d --- /dev/null +++ b/result/eo/c2eo/coperators/read-as-uint8.eo @@ -0,0 +1,4 @@ ++package c2eo.coperators + +[a] > read-as-uint8 + (00-00-00-00-00-00-00.concat (a.read 1)).as-int > @ diff --git a/result/eo/c2eo/coperators/write-as-int8.eo b/result/eo/c2eo/coperators/write-as-int8.eo new file mode 100644 index 00000000..3787e6d8 --- /dev/null +++ b/result/eo/c2eo/coperators/write-as-int8.eo @@ -0,0 +1,8 @@ ++alias c2eo.coperators.read-as-int8 + ++package c2eo.coperators + +[a b] > write-as-int8 + seq > @ + a.write (b.as-bytes.slice 7 1) + read-as-int8 a diff --git a/result/eo/c2eo/coperators/write-as-uint8.eo b/result/eo/c2eo/coperators/write-as-uint8.eo new file mode 100644 index 00000000..d3626d89 --- /dev/null +++ b/result/eo/c2eo/coperators/write-as-uint8.eo @@ -0,0 +1,8 @@ ++alias c2eo.coperators.read-as-uint8 + ++package c2eo.coperators + +[a b] > write-as-uint8 + seq > @ + a.write (b.as-bytes.slice 7 1) + read-as-uint8 a diff --git a/result/run.sh b/result/run.sh index 0d1604aa..0760a4c2 100644 --- a/result/run.sh +++ b/result/run.sh @@ -1,3 +1,3 @@ #!/bin/bash -java -Xmx256m -cp target/classes:target/eo-runtime.jar org.eolang.Main c2eo.src.union.some_104.global "$@" +java -Xmx256m -cp target/classes:target/eo-runtime.jar org.eolang.Main c2eo.src.bug02.init01.global "$@" From c1a7ff64d60895b4022f22d51fcbd4a4f76b8031 Mon Sep 17 00:00:00 2001 From: Riabtsev Yaroslav Date: Sun, 14 Aug 2022 18:28:18 +0300 Subject: [PATCH 2/3] clang-format --- project/src/transpiler/vardecl.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/project/src/transpiler/vardecl.cpp b/project/src/transpiler/vardecl.cpp index 14e79b2e..822c6b9f 100755 --- a/project/src/transpiler/vardecl.cpp +++ b/project/src/transpiler/vardecl.cpp @@ -106,13 +106,13 @@ EOObject InitValueAnalysis(const VarDecl *VD) { std::string str; if (init_val->isInt()) { auto int_value = init_val->getInt().getExtValue(); -// if (type_ptr->isCharType()) { -// str = "'"; -// str += static_cast(int_value); -// str += "'"; -// } else { - str = std::to_string(int_value); -// } + // if (type_ptr->isCharType()) { + // str = "'"; + // str += static_cast(int_value); + // str += "'"; + // } else { + str = std::to_string(int_value); + // } } else if (init_val->isFloat() && (size == double_size)) { auto float_value = init_val->getFloat().convertToDouble(); str = std::to_string(float_value); From 50a82cab4542ef9843e3b01ca93ef5ba24be0613 Mon Sep 17 00:00:00 2001 From: Riabtsev Yaroslav Date: Sun, 14 Aug 2022 18:59:29 +0300 Subject: [PATCH 3/3] clang-tidy --- project/src/transpiler/vardecl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/src/transpiler/vardecl.cpp b/project/src/transpiler/vardecl.cpp index 822c6b9f..d296d388 100755 --- a/project/src/transpiler/vardecl.cpp +++ b/project/src/transpiler/vardecl.cpp @@ -94,7 +94,7 @@ EOObject InitValueEOObj(const VarDecl *VD, bool is_init) { EOObject InitValueAnalysis(const VarDecl *VD) { auto qual_type = VD->getType(); - const auto *type_ptr = qual_type.getTypePtr(); + // const auto *type_ptr = qual_type.getTypePtr(); auto type_info = VD->getASTContext().getTypeInfo(qual_type); auto size = type_info.Width;