zb3 / malbolge-tools

Web based Malbolge interactive interpreter and a collection of code generators.
18 stars 2 forks source link

Runtime Error: Illegal jump #1

Open t-m-z opened 3 years ago

t-m-z commented 3 years ago

Hello, some weeks ago I read about Malbolge. I found this an interesting project and started to write an Interpreter. Secondly I looked for some hints how to write a Generator. I found two versions. Yours JavaScripts and a Python-Script at https://github.com/wallstop/MalbolgeGenerator., which seems to be easier to implement. I did it and startet to test. Of course, the generated Malbolge-program could be executed with my interpreter. I also was able to run it with http://www.malbolge.doleczek.pl/#. However, when I ran it with your Interpreter I receive an error message "Runtime Error: Illegal jump".

The text to print is "Welcome". The Malbolge-program is

'C%;:9876;:zy1wvut,rqpo-,+*j"F~%|{"b~w|uz\xqvunsrqSonPOeMLKg`HGFE[CYX]Vz=<;:9O7SL4JONMFEDC+AFE'CB;:">~6;49216/S32r*/(',lkj"'~}C#"!~`vut\xwpoWVrTSRQmfkdcbJIH^FEDCBX@\U=Y;QV8T6RKo2HML.J,+*FE'C<;:?!~6;49y76/u-,+*/o-m+k#(!g%|dzyxwvuzyxwvotVlqjRhmfkMc)JIH^]baZ_^@\Uyf

The normalized-Version is

*o*ppppppoo**p****p****oooo*p<poppo*opopo*opoopooo*oo**p***op****p*ppop<*****p*op*pooopppp*poo*oopp*o*popoppop<oo*poppo***popp<oooo*ppp*oopp**o****opoppp***p*****p*op*o*po*o*op<*poo*o***oo*opppo**popo*oop*ppppo*o*o*pop*op*ppppppooooopo*pop*popo*p<***ppoopoo*op<v

Because there is no jump I believe, your Interpreter is somehow faulty.

zb3 commented 3 years ago

Unfortunately I have to say that this is working as intended. Your program crashes the reference interpreter (I checked that), so it should also crash mine.

You've actually rediscovered a bug in the spec, see this: https://stackoverflow.com/questions/57484219/tritwise-rotate-right-and-tritwise-crazy-operation-throws-a-segmentation-fault

As you can see, the spec is broken when it comes to the * and p opcodes, but existing programs and the reference interpreter already rely on that flaw. I could change the way it works so that out-of-bounds reads cause the cell not to be updated, but then it wouldn't be Malbolge, but something else.

Your program works with some interpreters precisely because they ignore out-of-bounds access and write values like undefined (in case of JavaScript) into memory, or treat the negative memory index -X as 59049-X (in case of Python). Since in your case that memory cell isn't read again, the program prints the correct output, giving you the impression that those interpreters are correct and mine is broken. But technically, this isn't Malbolge...

esoteric-programmer commented 3 years ago

zb3 is right. You should never write a non-ascii character to the meomry cell that is modified by the xlat2-encryption. Don't operate on cells where the C register points to. To separate the C and D register, you can do a MovD command (or a Jmp command) at the start of your program. All existing Malbolge generators shall do so.

However, the error message of the interpreter is incorrect or misleading. If you are interested in Malbolge, you can also contact me. I have done a lot of Malbolge related work in 2012-2015, but I'm still interested in Malbolge.

zb3 commented 3 years ago

I'd be happy to change the error message, but what should it be? Would "illegal write" be more helpful?

esoteric-programmer commented 3 years ago

I would suggest something like "cannot encipher non-ASCII value". Not perfect, but something like this.

It can be caused by either an illegal jump or modification of the current cell. So, "illegal write" and "illegal jump" are two possible reasons for the error. I'm not sure if there are other possible causes, but at the moment I cannot think of any.

So, you may also write something like "illegal jump or illegal write" instead of the cryptic message "cannot encipher non-ASCII value" I suggested above.

zb3 commented 3 years ago

I guess that both these messages are by themselves not enough to understand the whole picture, so I think I'll just use "Illegal jump" after the i instruction, and "Illegal write" otherwise. I'll also keep this issue open so others hopefully end up here, rediscovering this (perhaps intentional?) flaw in the spec :)

t-m-z commented 3 years ago

Thanks for your quick and detailed explanation. So firstly I have to correct my interpreter and secondly I have to think about the generating part.