Кресты / Говнокод #27568 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  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
// https://github.com/seanbaxter/circle/blob/master/examples/README.md#tldr
// ...
// Circle's primary syntactic element is the @meta keyword, which runs the prefixed statement
// during source translation (or during template instantiation in dependent contexts).

// https://github.com/seanbaxter/circle/blob/master/examples/README.md#same-language-reflection
// duff1.cxx

void duff_copy1(char* dest, const char* source, size_t count) {
  const char* end = source + count;
  while(size_t count = end - source) {
    switch(count % 8) {
      case 0: *dest++ = *source++; // Fall-through to case 7
      case 7: *dest++ = *source++; // Fall-through to case 6...
      case 6: *dest++ = *source++;
      case 5: *dest++ = *source++;
      case 4: *dest++ = *source++;
      case 3: *dest++ = *source++;
      case 2: *dest++ = *source++;
      case 1: *dest++ = *source++;
      break;
    }
  }
}

// Reproduced above is a simplified version of Duff's device, an infamous memcpy function designed
// to reduce the amount of branching in the operation. (The loop is optimally interleaved with the switch,
// but I'm trying to illustrate some other points and don't want to add to the confusion.) Once we enter the
// switch, perform an assignment and unconditionally progress to the next case statement. This algorithm
// cries out for automation. The case statements have indices that run from 8 down to 1, modulo 8. Can we give it the Circle treatment?

// duff2.cxx

void duff_copy2(char* dest, const char* source, size_t count) {
  const char* end = source + count;
  while(size_t count = end - source) {
    switch(count % 8) {
      @meta for(int i = 8; i > 0; --i)
        case i % 8: *dest++ = *source++;
      break;
    }
  }

Но гомоиконности таким подкостыливанием вы естественно не добавите!

Запостил: j123123 j123123, (Updated )

Комментарии (21) RSS

    • А что еще ожидать от крестушков, изнасилованных в мозг крестопарашными шаблонами?
      Ответить
    • Circle is a compiler that extends C++17 for new introspection, reflection and compile-time execution.
      @meta
      Ответить
      • Да.
        > Circle is a new programming language that extends C++ 20 to support data-driven imperative metaprogramming.
        >* An integrated interpreter supports the execution of normal C++ statements at compile time.

        Но почему-то в примерах пишет он как на Сишке: fopen, printf, указатели, структы (никаких классов).
        Из С++ там только template
        Ответить
    • Опять доебался.
      Проставлю пиво, если с первого раза угадаешь на каком языке данный кусок кода:
      a = 5;
      Ответить
      • Похоже на assembler, но не уверен — я в языках не очень разбираюсь.
        Ответить
        • К слову, знак равенства действительно использовался всякими «масмами»/«тасмами», но в макросах. Аналог псевдоинструкции «EQU». А точка с запятой — начало комментария.
          Ответить
          • И в fasm.
            Assembly-Time Variables

            When you write something like foo = 3 in FASM, it introduces a new assembly-time variable. Despite the fact that the official FASM manual refers to them as "constants" sometimes (apparently, for historical reasons), they're actually variables: you can change them. Check this out:
            Ответить
        • Причём «расширенный синтаксис», в котором вычисленное значение можно терять.
          Ответить
            • Надо найти «нормальный». Помню, «Irie Pascal» ближе всех приблизился к «Standard Pascal», потом «gpc» (который перестали поддерживать и под новые версии «gcc» его нужно патчить самому), ну и можно попробовать «BP» или «FPC» с выключенным «расширенным синтаксисом».

              Итак, «FPC» с директивой {$X-} не берёт:
              https://ideone.com/Mx55zk

              С {$X+} тоже не берёт:
              https://ideone.com/AQhevR

              Оказывается, в «расширенном синтаксисе» он может терять результат вызова функции (вызывать её как процедуру, т. е. как аналог сишной функции с типом результата «void»), но терять результат сложного выражения не может.

              Ещё оказалось, что «gpc» зачем-то включили в «Ideone», но я не помню, какой директивой в «gpc» переключается диалект. Пробуем с дефолтными настройками:
              https://ideone.com/SUIsth

              Не берёт.
              Ответить
  • – Вот то-то и оно… – проговорила, Марго вытирая салфеткой губы, – любишь. А эта блядища этого не ценит!
    Ответить

Добавить комментарий

Помни, guest, за тобой могут следить!

    А не использовать ли нам bbcode?


    8