1. Список говнокодов пользователя ASD_77

    Всего: 129

  2. JavaScript / Говнокод #27265

    +2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    function main()
    {
    	f1();
    }
    
    function f1(a = 10)
    {    
        return a;
    }
    
    // code for 1
    
    module @"1.ts"  {
      func @main() {
        %c0_i32 = constant 0 : i32
        %0 = typescript.undef : i32
        %1 = call @f1(%c0_i32, %0) : (i32, i32) -> i32
        return
      }
      func private @f1(%arg0: i32, %arg1: i32) -> i32 attributes {OptionalFrom = 1 : i8} {
        %c10_i32 = constant 10 : i32
        %c1_i32 = constant 1 : i32
        %0 = alloca() : memref<i32>
        %1 = cmpi ult, %arg0, %c1_i32 : i32
        %2 = scf.if %1 -> (i32) {
          scf.yield %c10_i32 : i32
        } else {
          scf.yield %arg1 : i32
        }
        store %2, %0[] : memref<i32>
        %3 = load %0[] : memref<i32>
        return %3 : i32
      }
    }
    
    // code for 2
    
    ; ModuleID = 'LLVMDialectModule'
    source_filename = "LLVMDialectModule"
    target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
    target triple = "x86_64-pc-windows-msvc"
    
    declare i8* @malloc(i64)
    
    declare void @free(i8*)
    
    define void @main() !dbg !3 {
      %1 = call i32 @f1(i32 0, i32 undef), !dbg !7
      ret void, !dbg !9
    }
    
    define i32 @f1(i32 %0, i32 %1) !dbg !10 {
      %3 = alloca i32, i64 ptrtoint (i32* getelementptr (i32, i32* null, i64 1) to i64), align 4, !dbg !11
      %4 = insertvalue { i32*, i32*, i64 } undef, i32* %3, 0, !dbg !11
      %5 = insertvalue { i32*, i32*, i64 } %4, i32* %3, 1, !dbg !11
      %6 = insertvalue { i32*, i32*, i64 } %5, i64 0, 2, !dbg !11
      %7 = icmp ult i32 %0, 1, !dbg !11
      br i1 %7, label %8, label %9, !dbg !11
    
    8:                                                ; preds = %2
      br label %10, !dbg !11
    
    9:                                                ; preds = %2
      br label %10, !dbg !11
    
    10:                                               ; preds = %8, %9
      %11 = phi i32 [ %1, %9 ], [ 10, %8 ]
      br label %12, !dbg !11
    
    12:                                               ; preds = %10
      %13 = extractvalue { i32*, i32*, i64 } %6, 1, !dbg !11
      store i32 %11, i32* %13, align 4, !dbg !11
      %14 = extractvalue { i32*, i32*, i64 } %6, 1, !dbg !11
      %15 = load i32, i32* %14, align 4, !dbg !11
      ret i32 %15, !dbg !13
    }

    История о том как я компайлер писал. (предисторию знают думаю все). Посмотрите на код и сравните с ужасным кодом на С. Это простенький javascript который тоже може быть скомпиленным в исполняемый год. а что для этого надо. просто несколько шагов.

    1) компилим код через чудо компилятор tsc.exe --emit=mlir-affine c:\1.ts



    а дальше может получить LLVM IL который можно компилировать

    2) компилим код через чудо компилятор tsc.exe --emit=mlir-llvm c:\1.ts



    а далее компилим код

    llc.exe --filetype=obj -o=out.o 1.ll


    запускаем a.exe

    и оно работает :)

    ASD_77, 19 Февраля 2021

    Комментарии (30)
  3. Си / Говнокод #27230

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    function main()
    {
    	assert(false, "defl0");
    }
    
    // получаетм MLIR tsc.exe --emit=mlir C:\temp\2.ts
    
    module  {
      func @main() {
        %false = constant false
        typescript.assert %false, "defl0"
        return
      }
    }
    
    // или MLIR-LLVM
    
    module  {
      llvm.mlir.global internal constant @f_7029868395233414505("C:\\temp\\2.ts\00")
      llvm.mlir.global internal constant @m_964876063036005986("defl0\00")
      llvm.func @_assert(!llvm.ptr<i8>, !llvm.ptr<i8>, i32)
      llvm.func @main() {
        %0 = llvm.mlir.constant(false) : i1
        llvm.cond_br %0, ^bb1, ^bb2
      ^bb1:  // pred: ^bb0
        llvm.return
      ^bb2:  // pred: ^bb0
        %1 = llvm.mlir.addressof @m_964876063036005986 : !llvm.ptr<array<6 x i8>>
        %2 = llvm.mlir.constant(0 : index) : i64
        %3 = llvm.getelementptr %1[%2, %2] : (!llvm.ptr<array<6 x i8>>, i64, i64) -> !llvm.ptr<i8>
        %4 = llvm.mlir.addressof @f_7029868395233414505 : !llvm.ptr<array<13 x i8>>
        %5 = llvm.mlir.constant(0 : index) : i64
        %6 = llvm.getelementptr %4[%5, %5] : (!llvm.ptr<array<13 x i8>>, i64, i64) -> !llvm.ptr<i8>
        %7 = llvm.mlir.constant(5 : i32) : i32
        llvm.call @_assert(%3, %6, %7) : (!llvm.ptr<i8>, !llvm.ptr<i8>, i32) -> ()
        llvm.unreachable
      }
    }
    
    // переводим в LLVM mlir-translate.exe --mlir-to-llvmir -o=out.il 1.mlir и получаем полный абзец
    
    ; ModuleID = 'LLVMDialectModule'
    source_filename = "LLVMDialectModule"
    
    @m_15759024501200700639 = internal constant [6 x i8] c"defl2\00"
    @f_7029868395233414505 = internal constant [13 x i8] c"C:\\temp\\2.ts\00"
    @m_9918845950589312633 = internal constant [6 x i8] c"defl0\00"
    
    declare i8* @malloc(i64)
    
    declare void @free(i8*)
    
    declare void @_assert(i8*, i8*, i32)
    
    define void @main() !dbg !3 {
      br i1 false, label %1, label %3, !dbg !7
    
    1:                                                ; preds = %0
      br i1 false, label %2, label %4, !dbg !9
    
    2:                                                ; preds = %1
      ret void, !dbg !10
    
    3:                                                ; preds = %0
      call void @_assert(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @m_9918845950589312633, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @f_7029868395233414505, i64 0, i64 0), i32 5), !dbg !11
      unreachable, !dbg !12
    
    4:                                                ; preds = %1
      call void @_assert(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @m_15759024501200700639, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @f_7029868395233414505, i64 0, i64 0), i32 12), !dbg !13
      unreachable, !dbg !14
    }
    
    // компилим это говно и получаем EXE
    // llc.exe --filetype=obj -o=out.o out.il
    // lld.exe -flavor link out.o "libcmt.lib" "libvcruntime.lib" "kernel32.lib" "libucrt.lib" "uuid.lib" 
    // запускаем и вуаля
    
    // Output:
    // Assertion failed: defl0, file C:\temp\2.ts, line 5

    продолжаем говнокодить. что получается из одной строчки после компиляции когда в TypeScript (компайлером)

    ну все сказанно в говнокоде

    ASD_77, 02 Февраля 2021

    Комментарии (57)
  4. C++ / Говнокод #27220

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    void testToken(const char *value, size_t tokenExpected)
    {
        antlr4::ANTLRInputStream input(value);
        typescript::TypeScriptLexerANTLR lexer(&input);
    
        auto tokens = lexer.getAllTokens();
    
        printTokens(lexer, tokens);
    
        auto token = tokens.front().get();
    
        std::ostringstream stringStream;
        stringStream << "Expecting: [" << lexer.getTokenNames()[tokenExpected] << "] \"" << value << "\" but get: [" << lexer.getTokenNames()[token->getType()] << "] \"" << token->getText() << "\".";
        auto msg = stringStream.str();    
    
        ASSERT_EQUAL_MSG(token->getType(), tokenExpected, msg);
        ASSERT_THROW_MSG(token->getText().compare(value) == 0, msg);
    }
    
    void testOctalIntegerLiteral()
    {
        testToken("01", l::OctalIntegerLiteral);
    }

    Мой расказ о том как жизни было нехрен делать и я начал писать копилятор для TypeScript. как это "пинание х..я" кончиться я не знаю. но вот начал с простого. собрал минимум для разработки это LLVM и ANTLR4. И уже написал свой первый (ну не совсем) lexer.

    вот тут можно посмотреть на убогость говнокода.
    https://github.com/ASDAlexander77/TypeScriptCompiler

    ASD_77, 20 Января 2021

    Комментарии (64)
  5. C# / Говнокод #26888

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    public bool IsTransfarable
            {
                get
                {
                    switch (unitType)
                    {
                        case UnitTypes.SIEGE_TANK:
                        case UnitTypes.WIDOW_MINE:
                        case UnitTypes.SIEGE_TANK_SIEGED:
                        case UnitTypes.WIDOW_MINE_BURROWED:
                            return true;
                    }
    
                    return false;
                }
            }

    если что догадается что это выложу весь код :)

    ASD_77, 24 Августа 2020

    Комментарии (20)
  6. C++ / Говнокод #26696

    +2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    template <typename F, class = decltype(F()(E()))>
        auto map(F p) -> std::vector< decltype(p(E())) >
        {        
            std::vector< decltype(p(E())) > result;
            std::transform(get().begin(), get().end(), std::back_inserter(result), [=](auto &v) {
                return mutable_(p)(v);
            });
    
            return result;
        }
    
        template <typename F, class = decltype(F()(E(), 0))>
        auto map(F p) -> std::vector< decltype(p(E(), 0)) >
        {        
            std::vector< decltype(p(E(), 0)) > result;
            auto first = &(get())[0];
            std::transform(get().begin(), get().end(), std::back_inserter(result), [=](auto &v) {
                auto index = &v - first;
                return mutable_(p)(v, index);
            });
    
            return result;
        }
    
    // и применение (e) => f()
        auto strs = (array<int>{ 1, 2, 3 }).map([](auto x)
        {
            return "X" + x;
        });
    
    // или (e, index) => f()
    
        auto strs = (array<int>{ 1, 2, 3 }).map([](auto x)
        {
            return x + i;
        });

    как я выкрутился бля... с разными маперами... как генерики в c#

    ASD_77, 27 Мая 2020

    Комментарии (24)
  7. C++ / Говнокод #26695

    +5

    1. 1
    https://github.com/ASDAlexander77/TypeScript2Cxx/blob/master/cpplib/core.h

    Нужна помощь смелых и умных людей, надо сделать review кода и посоветовать что там по стандартам улучшить... короче любая помощь welcome

    https://github.com/ASDAlexander77/TypeScript2Cxx/blob/master/cpplib/core.h

    ASD_77, 27 Мая 2020

    Комментарии (76)
  8. C++ / Говнокод #26682

    +1

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    struct any
        {
            std::any _val;
    
            inline constexpr any() : _val{}
            {
            }
    
            inline constexpr any(undefined_t) noexcept : _val{}
            {
            }
    
            inline constexpr any(std::nullopt_t) noexcept : _val{}
            {
            }
    
            template <typename T>
            inline constexpr any(const T &val) : _val{val}
            {
            }
    
            inline any(const any &val) noexcept : _val{val._val}
            {
            }
    
            inline any(any &&val) noexcept : _val{std::move(val._val)}
            {
            }
    
            inline any &operator=(const any &val)
            {
                _val = val._val;
                return *this;
            }
    
            inline operator bool()
            {
                if (!_val.has_value())
                {
                    return false;
                }
    
                auto type_index = std::type_index(_val.type());
                if (type_index == std::type_index(typeid(int)))
                {
                    return std::any_cast<int>(_val) > 0;
                }
                else if (type_index == std::type_index(typeid(double)))
                {
                    return std::any_cast<double>(_val) > 0;
                }
                else if (type_index == std::type_index(typeid(tstring)))
                {
                    return std::any_cast<tstring>(_val).size() > 0;
                }
                else if (type_index == std::type_index(typeid(tstring_view)))
                {
                    return std::any_cast<tstring_view>(_val).size() > 0;
                }
                else if (type_index == std::type_index(typeid(const char_t *)))
                {
                    auto v = std::any_cast<const char_t *>(_val);
                    return !v;
                }
                else if (type_index == std::type_index(typeid(std::nullptr_t)))
                {
                    return false;
                }
                else if (type_index == std::type_index(typeid(bool)))
                {
                    return std::any_cast<bool>(_val);
                }
    
                return true;
            }
    
            template <typename N = void>
            requires Arithmetic<N> any operator+(N n)
            {
                return any{std::any_cast<N>(this->_val) + n};
            }
    
            friend std::ostream &operator<<(std::ostream &os, const any &val_)
            {
                auto val = val_._val;
                if (val.has_value())
                {
                    auto type_index = std::type_index(val.type());
                    if (type_index == std::type_index(typeid(int)))
                    {
                        os << std::any_cast<int>(val);
                    }
                    else if (type_index == std::type_index(typeid(double)))
                    {
                        os << std::any_cast<double>(val);
                    }
                    else if (type_index == std::type_index(typeid(tstring)))
                    {
                        os << std::any_cast<tstring>(val);
                    }

    нужна помощь упростить этот ад.

    ASD_77, 21 Мая 2020

    Комментарии (6)
  9. C++ / Говнокод #26650

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    template <class... Args>
        void log(Args&&... args)
        {
            auto dummy = { (std::clog << args, 0)... };
            std::clog << std::endl;
        }

    новый printf на с++

    ASD_77, 12 Мая 2020

    Комментарии (12)
  10. C++ / Говнокод #26637

    +3

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    template<typename T>
    concept Addable = requires (T x) { x + x; }; // requires-expression
     
    template<typename T> requires Addable<T> // requires-clause, not requires-expression
    T add(T a, T b) { return a + b; }

    все решено.. перехожу писать код на "конецепты"

    ASD_77, 05 Мая 2020

    Комментарии (91)
  11. C++ / Говнокод #26634

    +3

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    class Person {
        protected name: string;
        constructor(name: string) { this.name = name; }
    }
    
    class Employee extends Person {
        private department: string;
    
        constructor(name: string, department: string) {
            super(name);
            this.department = department;
        }
    
        public get ElevatorPitch() {
            return `Hello, my name is ${this.name} and I work in ${this.department}.`;
        }
    }
    
    const howard = new Employee("Howard", "Sales");
    console.log(howard.ElevatorPitch);
    
    //===============================================>>>>>>>>>>>>>>>>>>
    
    #ifndef TEST_H
    #define TEST_H
    #include "core.h"
    
    using namespace js;
    
    class Person;
    class Employee;
    
    class Person : public object, public std::enable_shared_from_this<Person> {
    public:
        string name;
    
        Person(string name);
    };
    
    class Employee : public Person, public std::enable_shared_from_this<Employee> {
    public:
        string department;
    
        Employee(string name, string department);
        virtual any get_ElevatorPitch();
        Employee(string name);
    };
    
    extern std::shared_ptr<Employee> howard;
    #endif
    
    #include "test.h"
    
    using namespace js;
    
    Person::Person(string name) {
        this->name = name;
    }
    
    Employee::Employee(string name, string department) : Person(name) {
        this->department = department;
    }
    
    any Employee::get_ElevatorPitch()
    {
        return "Hello, my name is "_S + this->name + " and I work in "_S + this->department + "."_S;
    }
    
    Employee::Employee(string name) : Person(name) {
    }
    
    std::shared_ptr<Employee> howard = std::make_shared<Employee>("Howard"_S, "Sales"_S);
    
    void Main(void)
    {
        console->log(howard->get_ElevatorPitch());
    }
    
    int main(int argc, char** argv)
    {
        Main();
        return 0;
    }

    Было делать нехрен в жизни и решил наговнокодить транспайлер с TypeScript в С++

    https://github.com/ASDAlexander77/TypeScript2Cxx

    ASD_77, 05 Мая 2020

    Комментарии (4)