Skip to content

Precalculation is not cell size sensitive. #3

Open
@rdebath

Description

@rdebath

This is a much larger piece of BF, however, it is expressly designed so that it's as easy as possible for a BF translator to convert.

As such a translator as good as Esotope-bfc can convert it completely to a simple text string ("hello world"), but it picks the wrong one!

Expected results:

BrainFuck$ bfi -b8 testing/Cellsize3.b
8 bit cells
BrainFuck$ bfi -b16 testing/Cellsize3.b
16 bit cells
BrainFuck$ bfi -b32 testing/Cellsize3.b
32 bit cells
BrainFuck$ bfi -b64 testing/Cellsize3.b
Non-binary or huge cells.
BrainFuck$

Actual Result:

BrainFuck$ esotope-bfc -s8 testing/Cellsize3.b
/* generated by esotope-bfc */
#include <stdio.h>
#include <stdint.h>
#define PUTS(s) fwrite(s, 1, sizeof(s)-1, stdout)
static uint8_t m[100000], *p = m;
int main(void) {
        PUTS("Non-binary or huge cells.\n");
        return 0;
}
BrainFuck$

BF code

[ This contains a VERY simple check for the three common bit sizes.
  It's the original version for the Bitwidth.b test program.

  In addition a check has been added on the start to check
  for really large, or non-binary, cells.
]

[-]>[-]
++++  [<++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>-]
     <[>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<-]
     >[<++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>-]
     <[>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<-]
     >[<++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>+<-]
+< [>>[-<<
        ----------------------------------------------------------------
    >>]<<

    [-]>[-]+++++++++++++[<++++++>-]<.>++++++++[<++++>-]<+.-.>++++++++[<-----
    --->-]<-.>+++++++++[<++++++>-]<-.+++++++.+++++.-------------.>++++[<++++
    >-]<+.+++++++.[-]++++++++[>++++<-]>.<++++++++++[>++++++++<-]>-.+++.[-]++
    ++++++[<++++>-]<.>+++++++++[<++++++++>-]<.+++++++++++++.--------------.-
    -.[-]++++++++[>++++<-]>.<+++++++++++[>++++++<-]>+.++.+++++++..+++++++.<+
    +++++++++[>-------<-]>+.[-]++++++++++.[-]<

]>[[-]>[-]<

// Calculate the value 256 and test if it's zero
++++++++[>++++++++<-]>[<++++>-]
+<[>-<
    // Not zero so multiply by 256 again to get 65536
    [>++++<-]>[<++++++++>-]<[>++++++++<-]
    +>[>
        // Print "32"
        ++++++++++[>+++++<-]>+.-.[-]<
    <[-]<->] <[>>
        // Print "16"
        +++++++[>+++++++<-]>.+++++.[-]<
<<[-]]] >[>
    // Print "8"
    ++++++++[>+++++++<-]>.[-]<
<[-]]<
// Print " bit cells\n"
+++++++++++[>+++>+++++++++>+++++++++>+<<<<-]>-.>-.+++++++.+++++++++++.<.
>>.++.+++++++..<-.>>-
Clean up used cells.
[-]<[-]<[-]<[-]<
]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions