• Assembler woes

    From Harald Markus Wirth@21:1/5 to All on Wed Jan 20 17:04:05 2021
    My current assembler isn't good, and I need to come up with a better
    solution. I am missing a high level understanding of pMARS does its
    assembling.

    I find pMARS' code is hard to read. Without understanding a few key
    things, I cannot blindly translate pMARS' assembler to JavaScript.

    /* Here is the automaton */

    _the_ automaton. What automaton?
    That comment caused more harm than it helped :)

    Since the code isn't very clear to me, my last resort would be to
    painstakingly retrace its workings (possibly step debugging it) and
    replacing the cryptic identifiers with speaking ones.

    If anyone has an idea, how I could avoid that work, I'd appreciate it
    very much.

    Greetings,
    H.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stephen Gunnell@21:1/5 to All on Wed Jan 20 14:39:01 2021
    Hi Harald,

    What are you trying to achieve here? By pMARS assembler do you mean redcode? Are you trying to build a redcode interpreter in javascript? Tell us a bit about your goals.

    Steveg

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Harald Markus Wirth@21:1/5 to Stephen Gunnell on Thu Jan 21 12:55:18 2021
    On 1/20/21 11:39 PM, Stephen Gunnell wrote:
    Hi Harald,

    What are you trying to achieve here? By pMARS assembler do you mean redcode? Are you trying to build a redcode interpreter in javascript? Tell us a bit about your goals.

    Steveg


    By "assembler" I mean the translation program ("compiler") from
    macro-Redcode to loadfile format.

    I keep finding errors in my assembler, mostly because I seem to be
    working on wrong assumptions, and I suspect my general approach is bad
    too. In a real world scenario one would perhaps not use recursions and
    string replacements, like I do atm.

    I keep reading this asm.c, but it isn't much fun, because the code isn't
    very self-explanatory. If no better solution comes up, I will have to
    somehow analyze pMARS' source. *shudders*

    Maybe there is another assmebler out there, which has nicer code, or
    some kind of high level description of the translation steps?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stephen Gunnell@21:1/5 to Harald Markus Wirth on Thu Jan 21 19:25:09 2021
    On Thursday, 21 January 2021 at 7:55:20 pm UTC+8, Harald Markus Wirth wrote:
    On 1/20/21 11:39 PM, Stephen Gunnell wrote:
    Hi Harald,

    What are you trying to achieve here? By pMARS assembler do you mean redcode? Are you trying to build a redcode interpreter in javascript? Tell us a bit about your goals.

    Steveg

    By "assembler" I mean the translation program ("compiler") from macro-Redcode to loadfile format.

    I keep finding errors in my assembler, mostly because I seem to be
    working on wrong assumptions, and I suspect my general approach is bad
    too. In a real world scenario one would perhaps not use recursions and string replacements, like I do atm.

    I keep reading this asm.c, but it isn't much fun, because the code isn't very self-explanatory. If no better solution comes up, I will have to somehow analyze pMARS' source. *shudders*

    Maybe there is another assmebler out there, which has nicer code, or
    some kind of high level description of the translation steps?

    Okay, I think I see your problem. Be warned it is two decades since I last grunged around in the guts of pMARS. pMARS is a runtime, it has a macro system that has become a part of the language but is not part of the specification. After the macro
    expansion is done "Assembly" is a trivial translation process to load up the core image and then pMARS proceeds directly to execution. "Automaton" probably refers to the execution component.
    The hard bits are the macro system and the exact sequencing of the execution process. Here is a page of pMARS alternatives, one of them may well have more readable code: https://corewar.co.uk/simulators.htm

    Good luck!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From skybuck2000@21:1/5 to All on Fri Jan 22 01:32:37 2021
    Oh one more thing... I did try and write a pmars/redcode assembler once, long ago probably 2009 :)

    The thing I ran into was the math/script engine needed to actually do the script/math sections of redcode.

    pmars/redcode allows some formulas to be written in macros and such... this requires some kind of math engine/calculator that can do math.

    So eventually you may also run into this problem as well.

    That does require a bit of "compiler technology" to interpret math/formulas and perhaps make some syntax tree and process it.

    So writing "just an assembler" will not be enough...

    Bye,
    Skybuck.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From skybuck2000@21:1/5 to All on Fri Jan 22 01:37:31 2021
    Also one remark/question combo:

    I have no idea how to test an assembler/language ? Which is kinda strange coming from me... having written thousands of Delphi test programs.

    Ofcourse if I understood BFN or whatever it was called to describe languages perhaps I could write more thorough programs, but then you are only testing the official theory of how a language is supposed to work.

    Such test programs would be insufficient because one also has to test the implementation of the language itself if one wants to find errors in the implementation which is what you might also be indicating, then again you do seem to indicate to desire
    some compatibility with pmars even if pmars may have flaws.

    Does anybody have any thoughts on how to properly test a language and try out all kinds of combinations ?

    Perhaps that is a starting point, trying out combinations.

    However my initial idea was "monkeys typing on a keyboard". However the time required to go through all possible letters/number/symbol combinations is huge :)

    Perhaps based on this simple observation one could argue that testing the validity of a programming language is infeasible, however some practical methods could be used to garantuee at least some level of quality ;) :)

    For now I believe testing programming languages will be a job-stable thing and will not be automated any time soon :)

    Bitcoin has some automation though to check it's code/patches against errors or such... so there is some automation out there, though for now hackers still out smart these tools and find bugs in bitcoin, one was recently found in 2018 ! ;) :)

    Bye,
    Skybuck.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From skybuck2000@21:1/5 to All on Fri Jan 22 01:30:13 2021
    Hello,

    I too would be interested in a better written mars assembler that is "compliant" with the standard pmars.

    I just googled pmars and asm.c and this came up:

    https://github.com/martinus/exhaust-ma/blob/master/asm.c

    Maybe this is any help ?

    Bye for now,
    Skybuck.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)