Mandelbrot brainf *** programını çalıştırırken neden programım takılıyor?


9

C becerilerimi geliştirmek istedim, bu yüzden bazı programların fikirlerini araştırıyorum.

Birisi basit bir Brainf *** yorumlayıcısı ve sonra bir derleyici oluşturmayı önerir. İşte buradayım.

Yorumlayıcıyı oluşturdum ve Mandelbrot programı dışında beklendiği gibi çalışıyor:

A mandelbrot set fractal viewer in brainfuck written by Erik Bosman
+++++++++++++[->++>>>+++++>++>+<<<<<<]>>>>>++++++>--->>>>>>>>>>+++++++++++++++[[
>>>>>>>>>]+[<<<<<<<<<]>>>>>>>>>-]+[>>>>>>>>[-]>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>[-]+
<<<<<<<+++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>>+>>>>>>>>>>>>>>>>>>>>>>>>>>
>+<<<<<<<<<<<<<<<<<[<<<<<<<<<]>>>[-]+[>>>>>>[>>>>>>>[-]>>]<<<<<<<<<[<<<<<<<<<]>>
>>>>>[-]+<<<<<<++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>+<<<<<<+++++++[-[->>>
>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>+<<<<<<<<<<<<<<<<[<<<<<<<<<]>>>[[-]>>>>>>[>>>>>
>>[-<<<<<<+>>>>>>]<<<<<<[->>>>>>+<<+<<<+<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>
[>>>>>>>>[-<<<<<<<+>>>>>>>]<<<<<<<[->>>>>>>+<<+<<<+<<]>>>>>>>>]<<<<<<<<<[<<<<<<<
<<]>>>>>>>[-<<<<<<<+>>>>>>>]<<<<<<<[->>>>>>>+<<+<<<<<]>>>>>>>>>+++++++++++++++[[
>>>>>>>>>]+>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>-]+[
>+>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>->>>>[-<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]]+>[-<[>>>>>>>>>]<<<<<<<<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>[-]<<<++++
+[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>->>>>>>>>>>>>>>>>>>>>>>>>>>>-<<<<<<[<<<<
<<<<<]]>>>]

Nedenini anlamıyorum, ama programım sonsuz bir döngü içinde sıkışıp kalıyor. Gdb kullanarak hata ayıklamaya çalışıyorum, ancak neden sıkıştığını görmek için doğru kesme noktasını bulmak zor.

Program aşağıdaki gibidir:

#include <stdio.h>
#include <stdlib.h>

// Brainfuck instructions
//  > Math stuff
#define INCR '+' // +1 on current MS
#define DECR '-' // -1 on current MS
//  > Memory slot stuff
#define FORW '>' // Go to next MS
#define BACK '<' // Go to previous MS
//  > Logic stuff
#define SJMP '[' // Loop till current MS value is equal to zero
#define EJMP ']' // Jump to the beginning of the loop
//  > I/O stuff
#define PRTC '.' // Print character with MS value as ASCII code
#define GETC ',' // Get an user input ASCII character code

typedef unsigned char byte;

// The brainfuck program struct
typedef struct {
      byte *values;
      int size;
      int index;

      byte *loops_starts;
      int loop_size;
      int loop_index;

} BrainfuckProgram;

void initialize(BrainfuckProgram *bfp) {
      bfp->values = malloc(bfp->size * sizeof(*bfp->values));
      bfp->loops_starts = malloc(bfp->size * sizeof(*bfp->loops_starts));
}

int allocate_values(BrainfuckProgram *bfp) {
      byte *newMem = realloc(bfp->values, bfp->size * sizeof(byte));

      if (!newMem) {
            return 1;
      }
      bfp->values = newMem;

      return 0;
}

int allocate_new_loop(BrainfuckProgram *bfp) {
      byte *newMem = realloc(bfp->loops_starts, bfp->loop_size * sizeof(byte));

      if (!newMem) {
            return 1;
      }
      bfp->loops_starts = newMem;

      return 0;
}

void set_value(BrainfuckProgram *bfp, byte value) {
      int tempValue = value < 0 ? 255: value % 256;
      *(bfp->values + bfp->index) = tempValue;
}

int get_value(BrainfuckProgram *bfp) {
      return *(bfp->values + bfp->index);
}

// FILE functions
int get_file_name(int argc, char *argv[], char** fname) {
     if (argc == 1) {
           printf("File name is missing\n");
           return 1;
     }

     *fname = argv[1];
     return 0;
}

int get_file_size(FILE *file) {
    fseek(file, 0L, SEEK_END);
    int size = ftell(file);
    rewind(file);
    return size;
}

// Main function
int main(int argc, char *argv[]) {
      // Vector part
      BrainfuckProgram bfp = {
            .values = NULL,
            .size = 1,
            .index = 0,

            .loops_starts = NULL,
            .loop_index = 0,
            .loop_size = 0

      };


      initialize(&bfp);

      // FILE Part
    char* fname = NULL;
      int error = get_file_name(argc, argv, &fname);
      if (error) {
            goto exit;
      }

    // Create file variable
    FILE *fin = NULL;
    fin = fopen(fname, "r");

    int size = get_file_size(fin);

    // Create a char array of the right size
    byte *prog = NULL;
    prog = malloc(size * sizeof(*prog));
      // Read 1 byte size times
    fread(prog, 1, size, fin);

    for (int i = 0; i < size; i++) {
            byte current =  *(prog+i);
        switch (current) {
            case INCR:
                        set_value(&bfp, get_value(&bfp) + 1);
                break;

            case DECR:
                        set_value(&bfp, get_value(&bfp) - 1);
                break;

            case FORW:
                        // if index+1 == size then we are at the
                        // last element of the vector cause
                        // size = index - 1
                        if (bfp.index+1 == bfp.size) {
                              bfp.size++;

                              int error = allocate_values(&bfp);
                              if (error) {
                                    printf("an error occured while forwarding pointer");
                                    goto close;
                              }
                        }
                        bfp.index++;

                break;

            case BACK:
                        // bfp.index == 0 then !bfp.index == true
                        if (!bfp.index) {
                             printf("can go back from index 0\n");
                             goto close;
                        }
                        bfp.index--;

                break;

            case SJMP:
                        if (bfp.loop_index == bfp.size) {
                              bfp.loop_size++;

                              int error = allocate_new_loop(&bfp);
                              if (error) {
                                    printf("an error occured while forwarding pointer");
                                    goto close;
                              }

                        }
                        bfp.loop_index++;
                        *(bfp.loops_starts + bfp.loop_index) = i;

                break;

            case EJMP:
                        if (bfp.loop_index == -1) {
                              printf("cannot go back");
                              goto close;
                        }

                        if (get_value(&bfp) != 0) {
                              i = *(bfp.loops_starts + bfp.loop_index);

                        } else {
                              bfp.loop_index--;

                        }

                break;

            case PRTC:
                        printf("%c", get_value(&bfp));

                break;

            case GETC:
                        ; // Semicolon here because of the label error
                        byte buf;
                        scanf("%c", &buf);
                        set_value(&bfp, buf);

                break;

        }
    }

      close:
            fclose(fin);

      exit:
            ;

    return 0;
}

Yanlış yaptığım şeyler hakkında C ile ilgili bazı tavsiyelerde bulunmak istiyorum.


1
Programın soruna gönderecek kadar küçük olduğunu, bunun yerine bir bağlantı olduğunu düşünüyorum.
KamilCuk

1
Bir hata ayıklayıcıda kodunuzu gözden geçirin; ve / veya çalışırken ve görünüşte sonsuz döngüde kesme noktaları olan balıklar
MM

2
Çoğu insanın yaptığı gibi tür adını 3 kez tekrarlamak yerine uygun malloc deyimini kullanmak için oy kullanıyorum
MM

3
İmzasız bir karakter value < 0 ? 255: value % 256 ne zaman yazdığınızı açıklayabilir misiniz value?
MM

2
Mandelbrot hesaplama açısından pahalıdır, bir tercüman ideal değildir. Programın ne kadar sürmesi gerektiği konusunda gerçek bir fikriniz yoksa "takılmak", "henüz yapılmadı" dan ayırt edilemez. Gece boyunca çalışmasına izin verin, bir BF derleyicisi yazmak için fikirler üzerinde uyuyun.
Hans Passant

Yanıtlar:


4

Mandelbrot programı iyi bir tercümanla çalışmak için yeterli zaman alır. Sevgiler, o kadar iyi değil. Bu yüzden başlangıçta "askıda kalıyor".

Sahip olduğunuz bazı iyi fikirler, performans açısından:

  • ön hesaplayıcı döngüler

Performans açısından bazı kötü fikirler:

  • Arama yerine soyutlanmış ayırma işlevlerini kullanma realloc
  • kullanarak scanfve printfyerine getcharveputchar

Yaptığın bazı garip şeyler:

  • Bir unsigned charsarmalama örtük olduğunda manuel olarak kesme
  • a'nın unsigned char0'dan küçük olup olmadığını kontrol etme
  • kullanılarak *(x + y)dizi dizin yerine sözdizimix[y]
  • Bu önceden hesaplanmış döngüler kullandığınızı sanmıyorum, eğer muhtemelen doğru değilse
  • Ayrıca, her döngüden her geçtiğinizde muhtemelen yeni bir önceden hesaplanmış döngü oluşturursunuz
  • İşaretçiler yerine get_valueve set_valueişlevlerini kullanma (optimizasyonlarla derlemezseniz bu bir performans sorunu olacaktır)

Birkaç öneri:

  • Mümkün olduğunca fazla ihtiyacınız olmadığında arama işlevlerinden kaçınmaya çalışın.
  • Bu referansı kullanarak bir BrainFuck-> C derleyicisi yazın .

İkinci düşüncede, bunun yerine bu programda hata ayıklamaya çalışmalısınız .

Ayrıca , GPLv3 ile sorun yaşıyorsanız tercümanımı referans olarak da kullanabilirsiniz . Döngülerin önceden hesaplanmadığını unutmayın.


Bana verdiğiniz tüm tavsiyeleri uygulamaya çalışacağım, teşekkürler! Bir sorum olsa da, önceden hesaplanmış döngü ile ne demek istiyorsun?
Thomas Teixeira

1
@ThomasTeixeira allocate_new_loopve loop_index?
SS Anne
Sitemizi kullandığınızda şunları okuyup anladığınızı kabul etmiş olursunuz: Çerez Politikası ve Gizlilik Politikası.
Licensed under cc by-sa 3.0 with attribution required.