Skip to content

Jump Errors ? #15

Closed
Closed

Description

@HoratioGamer

So I found that StarScript can apparently execute scripts, and it had some interesting commands in it, so, I was digging deeper when I found this inside the very cute machine code virtual machine someone has created...

starscript/src/main/java/org/meteordev/starscript

/Starscript.java

Lines 70-72

                case Jump:              { int jump = ((script.code[ip++] << 8) & 0xFF) | (script.code[ip++] & 0xFF); ip += jump; break; }
                case JumpIfTrue:        { int jump = ((script.code[ip++] << 8) & 0xFF) | (script.code[ip++] & 0xFF); if (peek().isTruthy()) ip += jump; break; }
                case JumpIfFalse:       { int jump = ((script.code[ip++] << 8) & 0xFF) | (script.code[ip++] & 0xFF); if (!peek().isTruthy()) ip += jump; break; }

I do not speak Java specifically, but from my knowledge of other computer languages, machine code and creating virtual machines, it looks like the repeated expression to compute "jump" is an error. I think it should have been written instead as:

int jump = ((script.code[ip++] & 0XFF) << 8) | (script.code[ip++] & 0xFF);

Which still makes the compiled script machine code syntax not usual in the sense that the instruction is coded Jump HighByte LowByte, but whatever. But at least with the correction it has both a functional high and a low byte. As written:

((script.code[ip++] << 8) & 0xFF) = 0, always, so there can never be a high byte of the jump address.

...unless JAVA is different from every other language I know.

I suspect no one has ever created a program substantially over 256 bytes compiled, otherwise it would have failed on a Jump statement. This might be an opportunity to change it to Jump LowByte HighByte in both the compiler and decompiler as well as the machine code virtual machine.

I find this under-use situation very sad because it seems to me this is a really useful script language, far easier to use than JSMACROS. With the addition of a few more instructions, which I believe is something I can do, even in JAVA, it could be really really cool and useful. I have not seen the compiler yet, so, I do not know what the higher level language looks like, if there is one, but I would program this in Assembly: OpCodes and arguments instead of bytes. I have written machine code, assembly, and coded virtual machine simulators. I have decades of experience in this.

Can someone please tell me how these scripts are compiled and what the source code looks like ?

And can any of this be executed from Meteor ?

(That is what I was looking for in the code, found the execution section first... and what looks like an error repeated 3 times.)

Activity

  1. MineGame159 commented on Sep 7, 2023

    @MineGame159
    Member

    Yeah looks like thats wrong, good catch. Strange how nobody ran into it before since I saw / made quite long starscript expressions, guess they werent 256 bytes long.

  2. HoratioGamer commented on Sep 7, 2023

    @HoratioGamer
    Author

    OK, I have not figured this out clearly, but, if this is just translating StarScript formatting expressions into this bytecode, then, my first wild guess would be, where would Jump be used in such a linear processing problem ?

    Maybe Jump is just not used.

    Jump and JumpIfTrue were the two most interesting commands here, because it means I can program Algorithms in this language. Algorithm = program a box in meteor, meaning, people with a wealth of programming experience can program a Minecraft Entity to do a great number of things without ever learning JAVA and all the sticky non-sequential, implied aspects of it.

  3. MineGame159 commented on Sep 7, 2023

    @MineGame159
    Member

    The syntax wiki states that you can call predefined functions but you cant create new ones. And the jump instructions are for the conditional (aka ternary) operator. You can see some basic examples in the README of Starscript or the presets of text HUD in Meteor.

  4. HoratioGamer commented on Sep 7, 2023

    @HoratioGamer
    Author

    Which HUD text exactly ? I have looked though them find them very elementary, giving me know clue how to do more interesting stuff.

  5. MineGame159 commented on Sep 7, 2023

    @MineGame159
    Member

    I dont know from the top of my head but if you look through the different presets you will see some that use the conditional operator and call functions.

  6. HoratioGamer commented on Sep 7, 2023

    @HoratioGamer
    Author

    (aka ternary) operator you mean this? <condition> ? <expression when condition is true> : <expression when condition is false>

    Does not exist in any of the 20-languages I know. Makes for very hard to read code, no room for proper comments.

  7. MineGame159 commented on Sep 7, 2023

    @MineGame159
    Member

    Well I dont know which languages you know but it is present in MANY languages I know. Also Starscript doesnt even have comments. I am sure you have noticed it is just a text formatting language. You dont have multiple lines to work with, cant create variables, loops, functions or objects. So having a proper if statement is just not necessary and wouldnt even work in the context of Starscript.

  8. HoratioGamer commented on Sep 7, 2023

    @HoratioGamer
    Author

    Oh, but StarScript could be so much more than a formatting language, easily. Yes, I am volunteering.

    All it needs is a command escape character, and a command that reads source code script from a filename, like Baritone reads schematics. The source code becomes script bytecode right after it is read, and existing StarScript code executes it. What would be new is the potential to create a script that does not end, that is an algorithm like a poor-man's mod. Attempting to execute the same script again, while it is still running should be a signal to kill the previous instance. So if it is bound to a key in a macro, it automatically toggles on and off when the key is pressed.

    I just have to be clear that minecraft variables are read on the fly, not once before execution from which point they are static -- static for the execution of the script is not as versatile.

    How would it do anything? By formatting strings that are Baritone commands.

    A watcher (polling between instructions) in an executing instance of StarScript would have to monitor for messages to the log from Baritone that say "ok cancel" or whatever, so, the Baritone Cancel command can kill the executing StarScript scripts also.

  9. HoratioGamer commented on Sep 7, 2023

    @HoratioGamer
    Author

    OK, I see where the ternary operator is used in 4 HUD elements.

    Here is an example of the code in the Assembly/Structured Language that would go with this bytecode:

    
    // Comment
    // Script that does x.
    // 
    Label Top     //  A new command that is a compiler directive, it does not translate into bytecode
                         //  creates a marker at this instruction pointer location that a JUMP can use later
                         //  This label is not used in this program
                         //   Lots of extra labels are created automatically and resolved to instruction pointer addresses when the
                         //   first pass of compilation is done.   
                         //   Second pass completes the authoring of bytecode.
    //
    // Infinite loop that keeps trying to get the player to go to either x =0 or x= 50000, whichever is closer
    //
    // This is just one small element of a program for a bot that might be programmed to return home 
    //  when it completes a mission.  
    //  This code is extremely simplified.
    //
    //  To help explain how structured language blocks like If-Else-EndIf blocks or While-EndWhile are coded into 
    //  existing instructions during compilation, comments have been added.
    //
    While {True}                // codes to 
                                       //     Label SS-While-Top-0001   (because it is the first structure block the compiler found)
                                       //     True
                                       //     JumpIfFalse SS-While-Exit-0001
    
    
       //
       // If Baritone is not running, begin composing a new Baritone command
       If { baritone.process_name ==  ""}                  // codes to 
                                       //     LoadLive baritone.process_name
                                       //     Constant ""
                                       //     Equals
                                       //     JumpIfFalse SS-If-ElseIf-0002
            Constant "goto " 
    
            If { player.pos.x ==   0 }          // Codes to
                                                           //     LoadLive  player.pos.x     A new command to load a live string into the stack, not a static one
                                                           //     Constant 0
                                                           //     Equals
                                                           //     JumpIfFalse  SS-If-ElseIf-0003
                Jump Arrived
            ElseIf {player.pos.x ==   50000  }     // Codes to
                                                           //     Jump SS-If-EndIf-0003
                                                           //     Label SS-If-ElseIf-0003
                                                           //     LoadLive  player.pos.x     A new command to load a live string into the stack, not a static one
                                                           //     Constant 50000
                                                           //     Equals
                                                           //     JumpIfFalse  SS-If-ElseIf-0004
                Jump Arrived
            ElseIf  {player.pos.x  <  25000  }                        // codes to 
                                                    //      Jump SS-If-EndIf-0003 
                                                    //      Label SS-If-ElseIf-0004
                                                    //     Constant 25000
                                                    //     Equals
                                                    //     JumpIfFalse  SS-If-ElseIf-0005
               Constant 0
            Else                                // codes to 
                                                    //      Jump SS-If-EndIf-0003 
                                                    //      Label SS-If-ElseIf-0005
               Constant 50000
            EndIf                                       // codes to 
                                                           //      Label SS-If-EndIf-0003 
            Append 
            Constant " ~ ~ "
            Append
            Baritone                     // codes as:
                                              // Constant "#"             This assures nothing can go to game chat by accident.   
                                              //                                           A totally different Chat command might be used for that.   
                                              // Exch                         Exchange top two stack elements
                                              // Append
                                              // pop top string and send it to Baritone
            
        EndIf                              // codes as 
                                              //       Label SS-If-ElseIf-0002    because this if had no else
                                              //       Label SS-If-EndIf-0002   so that if there had been an else if would give the true block 
    EndWhile                    // codes to 
                                       //     Jump SS-While-Top-0001
                                       //     Label SS-While-Exit-0001  
    Label Arrived
    
    End
    

    New commands might be added to the list of Reverse Polish Notation / stack using commands (like high end HP calculators from the 1980's or PostScript from 1980s-present) commands.

    Dupe or Push -- duplicate the top item on the stack so the top two items are the same as the top item before.
    Exch -- exchange the top two items.

    I have years of experience writing code that wrote PostScript code, those commands were essential.

    More new structured language blocks can be made (/ means the other part of the block is on a new line that encloses a block of code:

     `Repeat / Until {}`    or     `Do / While {}`      or both
     `Loop / EndLoop`                        -- Equivalent to While {true}
     `For / Next` or `For / EndFor`               -- counted loops with a loop variable stored in a separate storage.
    
     `ForEach / EndForEach`                -- awfully useful in TCL to parse lists of arguments.   
    
     `Break n`                                    -- break out of n layers of loop/while/repeat/for structures
     `Continue n`                               -- the single Break/Continue can lead to the need for Jump or carrying temp variables.  
     `Switch {} / Case / EndCase / EndSwitch`
    

    These are just more automatically-generated condition tests and jumps to automatically generated labels. Trivial stuff.

    True User functions Function / Return / EndFunction can be created. There are two conditions: The function must be defined before it is used to keep the compilation to 2 passes. The user is responsible for maintaining the stack integrity, as in, getting the right number of arguments into the stack before the call, pulling the right number of arguments from the stack in the call, pushing the right data onto the stack after, but not the push and pop of return addresses. If the Function Returns one value, it is coded as an Exch / Jump , pulling the return address from the stack.

    This is another PostScript thing, substitution macros:

    /Name  
       substitution code 
    Def
    

    So in future, one just has to say

    Name

    and the compiler knows to insert the expansion. Again, substitution macros must be defined before they are used so that compilation is 2 passes.

    The compiler needs a stack that counts how many nested structure blocks we are inside, to check that any block-ending keyword matches the current top of the structure stack -- detect syntax errors, generate the automatic labels, and also to implement Break n and Continue n.

    When running, it would probably be most convenient if StarScript had an array of structures with Data, NameContext, StructureLevel. So that local variables, like for For loops or inside Functions could be unique to their context and structure nesting level. Once out of the function or block it was valid in, it becomes invalid.

  10. HoratioGamer commented on Sep 7, 2023

    @HoratioGamer
    Author

    StarScript has the ability to run programs that compile to up to 65k of bytecode -- that is a HUGE program. Controllers for entire buildings ran on less program space for a long time. The Space Shuttles each had 5 main computers with 12k of program space each... only in aggregate are they comparable to StarScript.

    Trust me, a really competent bot could be programmed. Meteor modules could be activated and deactivated.

    "StarScript Copilot" is a possibility.

    Cooperating bots is a possibility -- communications by IG whispers... if new log lines could be monitored.

  11. MineGame159 commented on Sep 8, 2023

    @MineGame159
    Member

    I am not entirely against a scripting solution for Meteor but Starscript is not it. This is a formatting language, nothing more.

  12. HoratioGamer commented on Sep 8, 2023

    @HoratioGamer
    Author

    The problem is, the JAVAheads in the Meteor discord cant imagine anything that is not JAVA being useful.

    The most useful language ever was the first Procomm scripting language, which Aspect might be a superset of, never used Aspect, I had a better internet by then. That language was designed to negotiate (talk and listen) telephone modem connections to different services, however, they accidentally put enough commands in it to make it more widely useful. It could conduct entire sessions, automatically transferring data, files, updating off-line email servers, navigate remote access interfaces that required selections or commands before an IP/PPP connection could be made. There was no length limit I was aware of on those scripts. I had some very long and useful ones.

    What I suggest is adding a few things no one is obligated to use, an optional plus. Any expansion of StarScript by the plus would be completely transparent to its current uses. One of those would be an unused script compiler function/procedure that takes the code above and turns it into bytecode -- a simple two-pass linear process I have coded at least 3 times before, including the down-authoring of structured language blocks into available commands like Label and Jump.

    Yes, it may ultimately require another interface in Meteor, they can call it Meteor Script for all I care, or a command in Meteor .commands to access what I have suggested. We can cross that bridge when we get to it after there is a powerful ability available.

    The Meteor developers may not have realized that they have accepted a non-JAVA bytecode into the project, may have no idea how powerful it could be with an Assembly Language compiler in addition to the string formatting compiler that must exist somewhere, though I still have not found it.

    The advantage of the bytecode you have developed is, it has no implied execution, it is all on the surface, step by step, and all execution is explicitly sequential. I have experienced teaching a JAVAhead assembly language. I understand it is unfamiliar, but, "it is linear, in small steps, just take it step by step" works. Understanding it one statement at a time, it forms the words in the story that is the process, what it does. Yes low level languages have a forest for the trees problem, but it is better than Java's Forest.forest.smallforest problem where you have to read 30-100 lines of code in 100 files to find the flippin trees of what is it is actually doing right now. There is no other library of inherited functions in your language, no parent class to go read about, which might have another parent class. There is no abstraction. There is nothing happening in the background automatically once one understands a stack. It reads like reverse Polish notation HTML, like Turtle Logo Graphics, like PostScript, like dozens of simple but powerful scripting languages that have existed in the past.

    For those who have bent their mind around JAVA's inherent twist and concealment, they cannot understand how a simple linear language is far more understandable by more people, programmable by anyone with any programming background.

    Meteor devs will never allow a non-Java scripting language written from scratch. They will just dismissively say, go read JSMACROS, which they have, and I have, and I quickly determined it was not accessible to me, and not the most accessible solution.

    They will never accept anything from me. I lack the general ability to write it from scratch in JAVA. Starscript is an existing platform where many parts of it are far more linearly written (I like the writing style), that is why I can read them and am confident I can add to them.

    Think of this from the point of view of a player. They are an ant blissfully unaware of the layered Gordian Knot of JAVA that is the game and all the mods. They play the game and accomplish goals. They flip switches (modules) on and off. This scripting language could be far closer to the world view of the surface ant.

  13. HoratioGamer commented on Sep 8, 2023

    @HoratioGamer
    Author

    Step one is to add limits checking to current commands of the current StarScript execution "run" command, so it can raise a StarScript execution error. Yes, the string formatting compiler probably has these, but, two layers of error trapping never hurt anything.

    Error trapping is needed if people are to write things that become bytecode. Bottom up, no errors. No program written in Forth ever accidentally duplicated (duped) a nuclear power plant, real or imagined.

  14. MineGame159 commented on Sep 8, 2023

    @MineGame159
    Member

    Fixed in 77fa442.

  15. hellidox commented on Sep 9, 2023

    @hellidox

    Yeah looks like thats wrong, good catch. Strange how nobody ran into it before since I saw / made quite long starscript expressions, guess they werent 256 bytes long.

    i know for a fact ive made 600-700 byte hud expressions before

  16. HoratioGamer commented on Sep 9, 2023

    @HoratioGamer
    Author
  17. GreemDev commented on Sep 9, 2023

    @GreemDev
    Contributor

    The problem is, the JAVAheads in the Meteor discord cant imagine anything that is not JAVA being useful.

    No actually minegame said he wouldn't be opposed to scripting in Meteor, it's just that Starscript isn't it.

    The Meteor developers may not have realized that they have accepted a non-JAVA bytecode into the project, may have no idea how powerful it could be with an Assembly Language compiler in addition to the string formatting compiler that must exist somewhere, though I still have not found it.

    who the hell cares

    For those who have bent their mind around JAVA's inherent twist and concealment, they cannot understand how a simple linear language is far more understandable by more people, programmable by anyone with any programming background.

    We get it, you don't like Java, how is this relevant

    Meteor devs will never allow a non-Java scripting language written from scratch. They will just dismissively say, go read JSMACROS, which they have, and I have, and I quickly determined it was not accessible to me, and not the most accessible solution.

    Can you read? Like, at all?
    and before you say "But it'd probably be written in Java", who cares? this is a project primarily used for a block game (written in java) client mod. there's absolutely no need to write it at a low level to then reference from java code.

    They will never accept anything from me. I lack the general ability to write it from scratch in JAVA. Starscript is an existing platform where many parts of it are far more linearly written (I like the writing style), that is why I can read them and am confident I can add to them.

    Ok, then don't contribute

    By the way, it's Java, or even java. It's not an acronym.

    This entire conversation reads like someone who is really desperate to let people who use Java know that they hate Java.
    Shut up and go back to writing Assembly in vim.

  18. HoratioGamer commented on Sep 9, 2023

    @HoratioGamer
    Author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions