1. 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

    Комментарии (27)
  2. 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)
  3. Куча / Говнокод #27780

    +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
    (** Set of all possible interleaving of two traces is a trace
      ensemble. As we later prove in [interleaving_to_permutation], this
      definition is dual to [Permutation]. *)
      Inductive Interleaving : list TE -> list TE -> TraceEnsemble :=
      | ilv_cons_l : forall te t1 t2 t,
          Interleaving t1 t2 t ->
          Interleaving (te :: t1) t2 (te :: t)
      | ilv_cons_r : forall te t1 t2 t,
          Interleaving t1 t2 t ->
          Interleaving t1 (te :: t2) (te :: t)
      | ilv_nil : Interleaving [] [] [].
    
    Попытка оптимизации:
    
      (* Left-biased version of [Interleaving] that doesn't make
      distinction between schedulings of commuting elements: *)
      Inductive UniqueInterleaving : list TE -> list TE -> TraceEnsemble :=
      | uilv_cons_l : forall l t1 t2 t,
          UniqueInterleaving t1 t2 t ->
          UniqueInterleaving (l :: t1) t2 (l :: t)
      | uilv_cons_r1 : forall l r t1 t2 t,
          ~trace_elems_commute l r ->
          UniqueInterleaving (l :: t1) t2 (l :: t) ->
          UniqueInterleaving (l :: t1) (r :: t2) (r :: l :: t)
      | uilv_cons_r2 : forall r1 r2 t1 t2 t,
          UniqueInterleaving t1 (r1 :: t2) (r1 :: t) ->
          UniqueInterleaving t1 (r2 :: r1 :: t2) (r2 :: r1 :: t)
      | uilv_nil : forall t, UniqueInterleaving [] t t.

    Сложный говнокод. Почему вторая "оптимизированная" версия работает хуже первой?

    CHayT, 01 Ноября 2021

    Комментарии (26)
  4. Куча / Говнокод #27779

    0

    1. 1
    2. 2
    Be gone, malicious spirit from the anus!
    We don't say "amen", because we may step on the mines; we say "True"!

    Херня рулит.

    nPOnOBeDHuK, 01 Ноября 2021

    Комментарии (5)
  5. Куча / Говнокод #27778

    0

    1. 1
    https://twitter.com/RCS/status/1452367702727831565

    Ай, Молодца !!!

    gne4do, 31 Октября 2021

    Комментарии (1)
  6. 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)
  7. 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)
  8. 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)
  9. 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)
  10. C# / Говнокод #27773

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    private List<OutputData> AddSomeSpecialStateToFoo(
                List<OutputData> foos,
                IDictionary<Guid, SomeSpecialState> fooStates)
            {
                foreach(var foo in foos)
                {
                    foo .State = fooStates.FirstOrDefault(x => x.Key == cam.FooId).Value;
                }
    
                return foos;
            }

    Митируем листы и юзаем словарь правильно.

    LozorcevDiyosha, 29 Октября 2021

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