mandelbrot brainf *** 프로그램을 실행하는 동안 프로그램이 계속 멈추는 이유는 무엇입니까?


9

C 기술을 향상시키고 싶었으므로 프로그램 아이디어를 검색했습니다.

누군가 간단한 Brainf *** 인터프리터와 컴파일러를 만들 것을 제안합니다. 그래서 여기 있습니다.

나는 인터프리터를 만들었고 Mandelbrot 프로그램을 제외하고는 예상대로 작동합니다.

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

나는 왜 그런지 이해하지 못하지만 내 프로그램은 어떤 종류의 끝없는 루프에 계속 붙어 있습니다. gdb를 사용하여 디버깅하려고하지만 왜 멈추는 지 알기 위해 올바른 중단 점을 찾기가 어렵습니다.

프로그램은 다음과 같습니다.

#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;
}

내가 잘못한 것에 대해 C 관련 조언을하고 싶습니다.


1
나는 프로그램이 귀하의 질문에 게시하기에 충분히 작고 그에 대한 링크라고 생각합니다.
KamilCuk

1
디버거에서 코드를 단계별로 실행하십시오. 및 / 또는 무한 루프에서 달리는 동안 중단 점이있는 물고기
MM

2
대부분의 사람들이하는 것처럼 유형 이름을 3 번 반복하는 대신 적절한 malloc 관용구를 사용하여
MM

3
서명되지 않은 문자가 value < 0 ? 255: value % 256 언제 작성되는지 설명 할 수 value있습니까?
MM

2
Mandelbrot는 계산 비용이 많이 들며 통역사는 이상적이지 않습니다. 프로그램이 얼마나 오래 걸리는지 알지 못하는 경우 "정착"은 "아직 수행되지 않음"과 구별 할 수 없습니다. 밤새 실행하고 BF 컴파일러를 작성하는 아이디어를 자십시오.
Hans Passant

답변:


4

Mandelbrot 프로그램은 훌륭한 통역사를 운영하는 데 상당한 시간이 걸립니다. 당신의 글쎄, 그것은 좋지 않습니다. 그것이 처음에 "매달려"있는 이유입니다.

성능 측면에서 좋은 아이디어 :

  • 사전 계산 루프

성능 측면에서 나쁜 아이디어 :

  • 호출하는 대신 추상화 된 할당 함수 사용 realloc
  • 사용 scanf하고 printf대신 getchar하고putchar

당신이 한 이상한 일들 :

  • unsigned char랩 어라운드가 암시적일 때 수동으로 잘라 내기
  • unsigned char가 0보다 작은 지 확인
  • 하여 *(x + y)배열 인덱스 대신 구문x[y]
  • 사전 계산 된 루프를 실제로 사용하지 않는다고 생각합니다.
  • 루프를 다시 갈 때마다 미리 계산 된 새 루프를 만들 수도 있습니다.
  • 은 Using get_valueset_value대신 포인터의 기능은 (당신이 최적화 컴파일하지 않는 경우이 성능 문제가 될 것입니다)

몇 가지 제안 :

  • 가능한 한 많이 필요하지 않을 때는 함수 호출을 피하십시오.
  • 이 reference를 사용하여 BrainFuck-> C 컴파일러를 작성 하십시오 .

다시 생각하면 이 프로그램 을 디버깅해야 할 수도 있습니다. 대신 합니다.

GPLv3에 괜찮다면 통역사 를 참조로 사용할 수도 있습니다 . 루프를 미리 계산하지는 않습니다.


나는 당신이 내게 준 모든 조언을 이행하려고 노력할 것입니다, 감사합니다! 질문이 있지만 사전 계산 루프가 무엇을 의미합니까?
Thomas Teixeira

1
@ThomasTeixeira allocate_new_looploop_index?
SS Anne
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.