- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
interface Surface {
n: number;
}
let shiny: Surface = {
n: 10.0
}
function main() {
print(shiny.n);
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
0
interface Surface {
n: number;
}
let shiny: Surface = {
n: 10.0
}
function main() {
print(shiny.n);
}
шах и мат С/C++ девелоперам :) (постов не будет - сайт все блокирует)
0
.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
+2
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;
}
спасибо папочка за паттерн матчинг
+1
(** 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.
Сложный говнокод. Почему вторая "оптимизированная" версия работает хуже первой?
0
Be gone, malicious spirit from the anus!
We don't say "amen", because we may step on the mines; we say "True"!
Херня рулит.
0
https://twitter.com/RCS/status/1452367702727831565
Ай, Молодца !!!
+1
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
+2
// 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;
};
у некоторых линукс-юзеров может упасть на этапе линковки
0
#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
покруче гомоиконности
0
const boost::escaped_list_separator<char> els("\\"s, " \n\t"s, "\"");
boost::replace_all(src, "\"", "\"\\\"");
const boost::tokenizer tok(src, els);
els не умеет в keeping quotes хнык хнык