Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpecialCommand.toString returns empty string if appending code #27

Open
Zomis opened this issue Oct 18, 2015 · 6 comments
Open

SpecialCommand.toString returns empty string if appending code #27

Zomis opened this issue Oct 18, 2015 · 6 comments
Labels
Milestone

Comments

@Zomis
Copy link
Owner

Zomis commented Oct 18, 2015

Current code:

    @Override
    public String toString() {
        'GroovyCommand'
    }

Desired code:

    @Override
    public String toString() {
        'GroovyCommand: ' + this.code
    }

However, when changing this it somehow returns an empty string.

But doing this prints the code correctly:

    @Override
    public String toString() {
        println this.code
        'GroovyCommand'
    }
@Zomis Zomis added the bug label Oct 18, 2015
@Zomis Zomis added this to the 0.5 milestone Oct 18, 2015
@skiwi2
Copy link

skiwi2 commented Dec 6, 2015

However, when changing this it somehow returns an empty string.

Do you mean that this.code is returned as empty, or that the full text of 'GroovyCommand: ' + this.code is returned as empty?

@Zomis
Copy link
Owner Author

Zomis commented Dec 7, 2015

@skiwi2 If I remember correctly, the full text of 'GroovyCommand: ' + this.code is returned as empty.

@skiwi2
Copy link

skiwi2 commented Dec 7, 2015

To me this looks like your configuration has a caching issue, I get the following output when running Analyze on the by default provided BF code (only a part of the output is provided here):

Code instructions per command
NONE: 3732
ADD: 270
WHILE: 39
NEXT: 100
PREVIOUS: 54
SUBTRACT: 76
END_WHILE: 39
GroovyCommand: lastLoop 'initialize100': 1
GroovyCommand: assert value == 100: 1
GroovyCommand: loop 'setupFizz': 1
GroovyCommand: loop 'setupBuzz': 1
GroovyCommand: nextLoop 'gotoStart': 1
GroovyCommand: loop 'main': 1
GroovyCommand: nextLoop 'find254': 1
GroovyCommand: loop 'notEnd': 1
GroovyCommand: nextLoop 'notZero': 1
GroovyCommand: nextLoop 'skipText': 1
GroovyCommand: nextLoop 'next254': 1
GroovyCommand: nextLoop 'matchFound': 1
GroovyCommand: nextLoop 'find255': 1
GroovyCommand: nextLoop 'setBoolean': 1
GroovyCommand: nextLoop 'find252': 1
GroovyCommand: nextLoop 'resetCountdown': 1
GroovyCommand: nextLoop 'printText': 1
WRITE: 5
GroovyCommand: nextLoop 'next254': 1
GroovyCommand: nextLoop 'search255_afterFizzBuzzes': 1
GroovyCommand: nextLoops 'printNumber': 1
net.zomis.brainf.model.groovy.GroovySupportConverter$1@562a4221: 1
Total: 4336

Rightmost memory accessed is 31

@skiwi2
Copy link

skiwi2 commented Dec 7, 2015

I am not entirely sure how your Map<BrainfuckCommand, Integer> approach (in CommandCountAnalysis) is working though...

To me it looks like no hashcode and equals methods are provided in the BrainfuckCommand class, which makes them unsuitable to be used as keys in a Map.

@Zomis
Copy link
Owner Author

Zomis commented Dec 7, 2015

Okay, now it seems to work. No idea what caused it.

The CommandCountAnalysis is meant to count how many times each command is performed, totally unrelated to this issue. BrainfuckCommand is an interface BTW, not a class. And this SpecialCommand should not have hashCode and equals as two commands that have the same code should not be considered the same command for the CommandCountAnalysis. Using Object.hashCode and Object.equals does not make them unsuitable for use in a map. It's more when you have mutable objects, and put one into the map and retrieve another that it's unsuitable, or when you want a different equals check.

@Zomis Zomis closed this as completed Dec 7, 2015
@Zomis Zomis reopened this Dec 19, 2015
@Zomis
Copy link
Owner Author

Zomis commented Dec 19, 2015

This problem just re-appeared again when I did an analysis from command line. Apparently it is not fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants