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

    Всего: 43

  2. C++ / Говнокод #27794

    −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
    #include <cstdio>
    
    int main(void)
    {
        static char data[] = "sosu hui\n";
        __asm
        {
            mov eax, 0
            ploop:
                mov bl, [data + eax]
                push eax
                push bx
                call putchar
                pop bx
                pop eax
                inc eax
                cmp bl, 0
                jnz ploop
    
        }
    
        return 0;
    }

    digitalEugene, 05 Ноября 2021

    Комментарии (13)
  3. Assembler / Говнокод #27782

    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
    .org 80h
    data:
    	db "Hello, world!\n"
    	db 0
    start:
    	mov %c 1h
    	mov %bp @data
    	mov %si 0
    	.loop:
    		mov %al [%si + %bp]
    		inc %si
    		cmp %al 0h
    		jz @.exit
    		int 5h
    		jmp @.loop
    	.exit:
    	int 0h
    
      0080  48 65 6C 6C 6F 20 77 6F 72 6C 64 21 0A 00 02 02
      0090  01 00 02 06 80 00 02 05 00 00 03 0A 38 09 05 0C
      00A0 0A 00 00 0E AB 00 0B 05 0D 9A 00 0B 00 00 00 00

    накодил виртуальную машину, заспидранил Hello World за четыре дня. рекорд.
    https://github.com/kcalbSphere/PVC-16

    digitalEugene, 01 Ноября 2021

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

    +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
    uint16_t Mnemonic::describeMnemonics(void) const
    {
    	uint16_t result = 0;
    	size_t i = 0;
    	for (auto&& m : mnemonics)
    		result += m.index() << i++ * 4;
    
    	return result;
    }
    ...
    switch(mnemonic.describeMnemonics())
    {
    	case constructDescription(REGISTER, REGISTER):
    	{
    ...
    	}
    	break;
    
    	case constructDescription(REGISTER, CONSTANT):
    	{
    ...
    	}
    	break;
    
    	case constructDescription(REGISTER, LABEL):
    	{
    ...
    	}
    	break;
    
    	case constructDescription(REGISTER, INDIRECT_ADDRESS):
    	{
    ...
    	}
    	break;
    
    	case constructDescription(INDIRECT_ADDRESS, REGISTER):
    	{
    ...
    	}
    	break;
    
    	default:
    		break;
    
    }

    спасибо папочка за паттерн матчинг

    digitalEugene, 01 Ноября 2021

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

    +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
    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
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    if (op.size() == 1)
    				{
    					if (op[0].id == LexemID::REGISTER)
    					{
    						if (isSIBbase(registerName2registerId.at( std::get<std::string>(op[0].lexemas))))
    							mnemonic.mnemonics.emplace_back(IndirectAddress{
    								.base = Register(std::get<std::string>(op[0].lexemas))
    								});
    						else
    							mnemonic.mnemonics.emplace_back(IndirectAddress{
    								.index = Register(std::get<std::string>(op[0].lexemas))
    								});
    					}
    					else if (op[0].id == LexemID::LABEL_USE)
    						mnemonic.mnemonics.emplace_back(IndirectAddress{
    							.disp = LabelUse(std::get<std::string>(op[0].lexemas))
    							});
    					else if (op[0].id == LexemID::NUMBER)
    						mnemonic.mnemonics.emplace_back(IndirectAddress{
    							.disp = Constant(std::get<int>(op[0].lexemas))
    							});
    				}
    				else if (op.size() == 3)
    				{
    					if (const auto operation = std::get<std::string>(op[1].lexemas)[0]; operation == '+')
    					{
    						if (op[0].id == LexemID::REGISTER && op[2].id == LexemID::REGISTER)
    						{
    							if (isSIBbase(registerName2registerId.at(std::get<std::string>(op[0].lexemas))))
    								mnemonic.mnemonics.emplace_back(IndirectAddress{
    									.base = Register(std::get<std::string>(op[0].lexemas)),
    									.index = Register(std::get<std::string>(op[2].lexemas))
    									});
    							else
    								mnemonic.mnemonics.emplace_back(IndirectAddress{
    									.base = Register(std::get<std::string>(op[2].lexemas)),
    									.index = Register(std::get<std::string>(op[0].lexemas))
    									});
    						}
    						else if (op[0].id == LexemID::REGISTER && op[2].id == LexemID::NUMBER)
    						{
    							if (isSIBbase(registerName2registerId.at(std::get<std::string>(op[0].lexemas))))
    								mnemonic.mnemonics.emplace_back(IndirectAddress{
    									.base = Register(std::get<std::string>(op[0].lexemas)),
    									.disp = Constant(std::get<int>(op[2].lexemas))
    									});
    							else
    								mnemonic.mnemonics.emplace_back(IndirectAddress{
    									.index = Register(std::get<std::string>(op[0].lexemas)),
    									.disp = Constant(std::get<int>(op[2].lexemas))
    									});
    						}
    						else if (op[0].id == LexemID::REGISTER && op[2].id == LexemID::LABEL_USE)
    						{
    							if (isSIBbase(registerName2registerId.at(std::get<std::string>(op[0].lexemas))))
    								mnemonic.mnemonics.emplace_back(IndirectAddress{
    									.base = Register(std::get<std::string>(op[0].lexemas)),
    									.disp = LabelUse(std::get<std::string>(op[2].lexemas))
    									});
    							else
    								mnemonic.mnemonics.emplace_back(IndirectAddress{
    								.index = Register(std::get<std::string>(op[0].lexemas)),
    								.disp = LabelUse(std::get<std::string>(op[2].lexemas))
    									});
    						}
    					}
    					else if (operation == '*')
    					{
    						if (op[0].id == LexemID::NUMBER && op[2].id == LexemID::REGISTER)
    							mnemonic.mnemonics.emplace_back(IndirectAddress{
    								.base = Register(std::get<std::string>(op[2].lexemas)),
    								.scale = static_cast<uint8_t>(std::get<int>(op[0].lexemas))
    								});
    					}
    				}
    				else if(op.size() == 5)
    				{
    
    					if (op[4].id == LexemID::REGISTER)
    						mnemonic.mnemonics.emplace_back(IndirectAddress{
    							.base  = Register(std::get<std::string>(op[4].lexemas)),
    							.index = Register(std::get<std::string>(op[2].lexemas)),
    							.scale = static_cast<uint8_t>(std::get<int>(op[0].lexemas))
    							});
    					else if (op[4].id == LexemID::NUMBER)
    						mnemonic.mnemonics.emplace_back(IndirectAddress{
    							.index = Register(std::get<std::string>(op[2].lexemas)),
    							.scale = static_cast<uint8_t>(std::get<int>(op[0].lexemas)),
    							.disp = Constant(std::get<int>(op[4].lexemas))
    							});
    					else if (op[4].id == LexemID::LABEL_USE)
    						mnemonic.mnemonics.emplace_back(IndirectAddress{
    							.index = Register(std::get<std::string>(op[2].lexemas)),
    							.scale = static_cast<uint8_t>(std::get<int>(op[0].lexemas)),
    							.disp = LabelUse(std::get<std::string>(op[4].lexemas))
    							});
    ...

    чё к щам близко?

    https://github.com/kcalbSphere/PVC-16/blob/master/pvc-asm/syntaxer.cpp

    digitalEugene, 31 Октября 2021

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

    +2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    // a.h
    inline struct $q1 {unsigned a;} $q1i;
    
    // main.cpp
    #include "a.h"
    int main(int argc, char** args) 
    {
        $q1i.a = argc; 
        return $q1i.a;
    };

    у некоторых линукс-юзеров может упасть на этапе линковки

    digitalEugene, 31 Октября 2021

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

    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
    #define REGISTERS_LIST A, B, C, D, E, SI, BP, SP, IP
    #define LREGISTERS_LIST AH, AL, BH, BL, CH, CL, DH, DL, EH, EL, SIH, SIL, BPH, BPL, SPH, SPL, IPH, IPL
    
    enum RegisterID
    {
    	REGISTERS_LIST,
    	LREGISTERS_LIST
    };
    
    const static std::string registerId2registerName[] = {
    #define _MAP(x) #x
    	MAP_LIST(_MAP, REGISTERS_LIST),
    	MAP_LIST(_MAP, LREGISTERS_LIST)
    };
    #undef _MAP
    
    const static std::map<std::string, RegisterID> registerName2registerId = {
    #define _MAP(x) {#x, x}
    	MAP_LIST(_MAP, REGISTERS_LIST),
    	MAP_LIST(_MAP, LREGISTERS_LIST)
    };
    #undef _MAP

    покруче гомоиконности

    digitalEugene, 30 Октября 2021

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    const boost::escaped_list_separator<char> els("\\"s, " \n\t"s, "\"");
    
    boost::replace_all(src, "\"", "\"\\\"");
    const boost::tokenizer tok(src, els);

    els не умеет в keeping quotes хнык хнык

    digitalEugene, 30 Октября 2021

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    auto DivisibleBy = [](int d)
        {
            return [d](int m) { return m % d == 0; };
        };
     
        if (ranges::any_of(v, DivisibleBy(7))) {
            std::cout << "At least one number is divisible by 7\n";
        }

    https://en.cppreference.com/w/cpp/algorithm/ranges/all_any_none_of

    digitalEugene, 26 Октября 2021

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

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    int main(void)
    {
        std::string data = "HELLO WORLD!\n";
        std::transform(
            data.begin(), data.end(), 
            std::ostream_iterator<char>(std::cout, ""),
        std::bind(std::plus<char>(), std::placeholders::_1, 1));
        
        return 0;
    }

    А как сделать это ещё короче?

    digitalEugene, 02 Июня 2021

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

    +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
    template<typename ReturnType, typename... Arguments>
    std::enable_if_t<!std::is_same_v<ReturnType, void>, std::deque<ReturnType>>
    emit(Event<ReturnType, Arguments...>& event, const std::tuple<Arguments...>& args)
    {
    	std::deque<ReturnType> toReturn;
    
    	for (auto&& c : event.subscribers | std::views::values)
    		toReturn.push_back(std::apply(c, args));
    
    	return toReturn;
    }
    
    template<typename ReturnType, typename... Arguments>
    void emit(Event<ReturnType, Arguments...>& event, const std::tuple<Arguments...>& args)
    {
    	for (auto&& c : event.subscribers | std::views::values)
    		std::apply(c, args);
    }

    кодить всё же надо трезвым.

    digitalEugene, 30 Мая 2021

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