EgonOlsen71 / basicv2

A Commodore (CBM) BASIC V2 interpreter/compiler written in Java
https://egonolsen71.github.io/basicv2/
The Unlicense
84 stars 15 forks source link

Fixes ON ... as being treated as a list of GOTOs #13

Closed ciplogic closed 5 years ago

ciplogic commented 5 years ago

Also, I extracted compiling individual tests, so if needed is much easier to run an individual file test

ciplogic commented 5 years ago

There is still another bug. But it is a bit too late for me to investigate. At least now there is no DATA error in "Poetry" "game".

I hope to look into it tomorrow and hopefully find the other causes.

ciplogic commented 5 years ago

I was trying to make "next phase" being:

"1 GOTO inliner"

The construct is this:

1 INITIAL_COMMANDS: GOTO 5
2 (something)
...
5 SOME_COMMANDS : GOTO 2

And after this I should have:

1 INITIAL_COMMANDS: SOME_COMMANDS 
2 (something)
...
5 SOME_COMMANDS : GOTO 2

And I am hitting a wall with "clone" method. As I need to clone "SOME_COMMANDS" into line 1, is it a proper way to do it? I noticed that the clone method is not doing too much (it instantiate via reflection the final class and sets "NAME" to be of that specific code). Should I copy the "SOME COMMANDS" into a string, parse them and get the line out of it? (it looks a nice enough solution, but I am not sure if this is what is the way or is other nicer way).

EgonOlsen71 commented 5 years ago

That clone method is used at parse time to make an instance clone of the specimen of the command that the parser has used to determine which command it actually is. It wasn't meant to be used to create a clone of a fully populated instance. Your solution with just parsing the remaining commands as a string sounds feasible to me.