This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Cruor's profile picture

Shurtle Preview

Started by Cruor, 08 October 2014 - 07:28 PM
Cruor #1
Posted 08 October 2014 - 09:28 PM
Shurtle is a stack based language for making turtle movement from the shell more convenient.

The project was started because I found the built in `go` program too inconvenient, and wanted something which was easier to use, and more powerful.
So far Shurtle supports more than just basic Turtle movment. It has for loops, while loops and ternary, making it able to do most of your turtle shenanigans.

Documentation and example programs are work in progress.

Documentation as of 2015-07-26

Stack
    The stack is FILO (First In Last Out)

    Strings and number literals are pushed to the stack
    Any uppercase character is a "Variable" and the variables value will be pushed to the stack

Variables
    D: "down"
    U: "up"
    F: "forward"
    I: "inventory"

    R: "right"
    L: "left"

    S: 64 - Stack
    H: 32 - Half Stack
    Q: 16 - 1/4 Stack

    M: "minecraft:"

    V: nil - Values during loop is stored here
    K: nil - Loop iteration number is stored here

    N: "\n"
    T: true

    A: {} - This is always a empty table
    B: {__type = "block"} - A custom type table to "wall" away parts of the stack

    X: 0 - X position relative to starting point, forward = x + 1, back = x - 1
    Y: 0 - Y position relative to starting point, up = y + 1, down = y - 1
    Z: 0 - Z position relative to starting point, right = z + 1, left = z - 1

    W: 0 - Direction relative to starting point

    G: nil - The amount of fuel in ComputerCraft, the amount of energy in OpenComputers

Operators
    Applicable operator methods are checked in order, which is specified in order underneat
    For example: `w`(sleep) will allways try to sleep for "n" seconds before it uses the "none" method

    Methods in the documentation are by default verbose (pushes values to stack), any not verbose methods will be explicity marked
    None of the operators for loops or ternary are verbose, or has return values

    Arguments are writtens as their types (string, number, boolean, etc)
    If the type is "any" it means it can be any type (besides "block")
    If the type is "none" it means that operator method does not take any argument

    Operators with no applicable methods will not error, and will be ignored

Math, strings and what not
    +
        number number
            Addition

        number string
            Concatenation

        string number
            Concatenation

        any table
            Append to table

    -
        number number
            Subtraction

        s::string strip::string
            Remove "strip" from the end of "s", "strip" is a Lua pattern

        n::number
            -n

        table
            If captured, pops last element and pushes table and the value onto the stack
            Else, removes the last element in the table and puts it back on the stack

    ^
        number number
            Power

        number table
            If the value is nil, a false will be used instead

            If captured, pushes the table and the value at the index back onto the stack
            Else, puts the value at the index onto the stack

        string table
            If the value is nil, a false will be used instead

            If captured, pushes the table and the value at the index back onto the stack
            Else, puts the value at the index onto the stack

    !
        boolean
            Logical not

    &
        boolean boolean
            Logical and

    |
        boolean boolean
            Logical or

    %
        number number
            Modulo

    *
        number number
            Multiplication

        string table
            Join table into a single string, inserting the delimiter between each value

        number string
            Repeats the string s for n times

    /
        number number
            Division

        s::string sep::string
            Split string "s" on "sep", "sep" is a Lua pattern

    ,
        string
            If captured, push the string and the string length onto the stack
            Else, put string length onto the stack

        table
            If captured, push the table and the table length onto the stack
            Else, put table length onto the stack

        n::number
            Table with values from 1 to n

    .
        any
            Discard

    _
        table
            Pushes the table, and a shallow copy of it onto the stack

        any
            Duplicated top value on stack

    \\
        any any
            Swap the two top values on the stack

    @
        any any any
            Rotate the top three values on the stack
            (No, I don't even what that means, complain to CJam)

    =
        any any
            Equality check

    >
        number number
            Greater than

        table number
            Slices the table from n + 1 to end of table

            If captured, push the table and the slice back onto the stack
            Else, put the slice onto the stack

    <
        number number
            Less than

        table number
            Slices the table from start to n

            If captured, push the table and the slice back onto the stack
            Else, put the slice onto the stack            

    o
        any
            Not verbose, no return value

            Print

    w
        number
            Not verbose

            Sleeps for n seconds

        none
            Not verbose

            ComputerCraft: Sleep for 1 tick
            OpenComputers: yields once

    $
        Not verbose (does not affect itself)

        The return values of the next operator call will be pushed to the stack

Loops
    [
        For loop start
        Can iterate over tables, strings and numbers

        Strings are character wise
        Tables are element wise
        Numbers are from 1 to n

        Variable V will be set to the current iteration value
        Variable K will be set to the current iteration index

        If the object isn't iterateable it will jump to matching ]

    ]
        for loop end
        Will jump back to [ if there is more to iterate

    #
        Conditional part of while loops

    {
        While loop start
        If the top element on the stack is true (actuall true, not in boolean context) the loop will run until it hits }
        Otherwise the loop will end

    }
        If the loop has a condition mark it will jump back to it, otherwise to the start

    (
        Continue

    )
        Break

Ternary
    ?
        If the top value on the stack is true (actuall true, not boolean context) it will run code until :, ; or end of file
        If it is false it will jump to :

    :
        If the top value of the stack was true, jump to ; or end of file, otherwise do nothing

    ;
        Clean up dirty black magic

Turtle
    All movement is "non blockable", meaning it can fail

    f
        number
            Not verbose, returns true if all movement succeded

            Forward for n blocks

        none
            Not verbose, returns true if movement succeded

            Forward

    b
        number
            Not verbose, returns true if all movement succeded

            Back for n blocks

        none
            Not verbose, returns true if movement succeded

            Back

    u
        number
            Not verbose, returns true if all movement succeded

            Up for n blocks

        none
            Not verbose, returns true if movement succeded

            Up

    d
        number
            Not verbose, returns true if all movement succeded

            Down for n blocks

        none
            Not verbose, returns true if movement succeded

            Down

    l
        number
            Not verbose, returns true if all movement succeded

            Turn left n times

        none
            Not verbose, returns true if movement succeded
            Turn left

    r
        number
            Not verbose, returns true if all movement succeded

            Turn right n times

        none
            Not verbose, returns true if movement succeded

            Turn right

    m
        string
            Not verbose, returns true if anything was mined

            Digs in the direction specified, "forward", "up", "down" are valid

        none
            Not verbose, returns true if anything was mined

            Digs forward

    p
        string
            Not verbose, returns true if anything was placed

            Places in the direction specified, "forward", "up", "down" are valid

        none
            Not verbose, returns true if anything was placed

            Places forward

    a
        string
            Not verbose, returns true if anything was attacked

            Attacks in the direction specified, "forward", "up", "down" are valid

        none
            Not verbose, returns true if anything was placed

            Attacks forward

    q
        string number number
            Not verbose, returns true if successful

            Only valid direction is "inventory"
            Transfers n items from current slot to slot m

        string number
            Not verbose, returns true if successful

            if the direction specified is "forward", "up" or "down", drops n items from the current slot in the direction

            If the direction specified is "inventory", it transfers the stack in the current slot to slot n

        string
            Not verbose, returns true if successful

            Drops the stack in the current slot in the direction specified, "forward", "up", "down" are valid

        number
            Not verbose, returns true if successful

            Drops n items from the current slot forwards

        none
            Not verbose, returns true if successful

            Drops the stack in the current slot forwards

    t
        string number
            Not verbose, returns true if successful

            Takes n items from the direction specified, "forward", "up" and "down" are valid

        string
            Not verbose, returns true if successful

            Takes a stack of items from the direction specified, "forward", "up" and "down" are valid

        number
            Not verbose, returns true if successful

            Takes n items from the front

        none
            Not verbose, returns true if successful

            Takes a stack of items from the front

    c
        number
            Item count in slot n

        none
            Item count in current slot

    s
        string
            Not verbose, returns selected slot or false if not successful

            Selects a slot the item specified
            Prioritizes non full slots over full ones

            For example "minecraft:wheat_seeds", "minecraft:iron_ore"

        number
            Not verbose, returns selected slot or false if not successful

            Selects slot n

        none
            Gets the current selected slot

    e
        string
            Not verbose, returns true if item was equip

            Equips item in current slot to the side specified, "left" and "right" are valid sides

        none
            Not verbose, returns true if item was equip

            Equips the item in the current slot to the right hand
            "Yea, I'm just going to decide... And turtles are right handed" -Cruor

    g
        number
            Not verbose, returns true if item is a fuel

            Refuels using n items from the current slot

        none
            Not verbose, returns true if item is a fuel

            Refuels with all the items in the current slot

    i
        When no item/block is present, the block is "minecraft:air", and the damage value is 0

        number
            Inspects the item in slot n

            Pushes the damage value and block name

        string
            Inspects in specified direction

            If direction is "forward", "up" or "down" it will check the block in that direction
            If direction is "inventory" it will inspect the current slot

            Pushes the damage value and block name

        none
            Inspects forward

            Pushes the damage value and block name

Example farm program

#T{
    'Starting farming'o

    #T{
        DiM'wheat'+=\7=&amp;?
            1s
            Dm
        ;

        M'wheat_seeds'+ $s?
            Dp
        ;

        $f!?
            GS<?
                'Feed me :<'o

                Qs

                #GS<{
                    5w
                    g
                }
            ;

            W0=?
                r
                $f!?
                    )
                ;
                r
            :
                l
                $f!?
                    )
                ;
                l
            ;
        ;
    }

    Zb
    l
    Xb

    #M'wheat'+ $s{
        Uq
    }

    'Waiting for plants'o
    600w
}

Old preview video[media]http://youtu.be/rzTXxKYfoRM[/media]

At the moment the project is still in alpha, and is not publicly available.
Edited on 26 July 2015 - 01:09 PM
Cruor #2
Posted 26 July 2015 - 03:11 PM
Cleaned up topic. Documentation and example code added.
flaghacker #3
Posted 26 July 2015 - 06:26 PM
Hmmm… It looks to me that this language is more complex and less readable than plain Lua… Doesn't it make stuff harder in the end?
cyanisaac #4
Posted 26 July 2015 - 08:34 PM
Wouldn't this belong in the Programs section? Or the APIs/Utilities section?
biggest yikes #5
Posted 26 July 2015 - 10:36 PM
Wouldn't this belong in the Programs section? Or the APIs/Utilities section?
There's no code.
Oddstr13 #6
Posted 27 July 2015 - 07:36 AM
Hmmm… It looks to me that this language is more complex and less readable than plain Lua… Doesn't it make stuff harder in the end?

The primary usage of this language is as a replacement for the CraftOS buildt in program, go.

go forward 3 right forward 2
vs.
g 3fr2f

A slightly more advanced example; while turtle can mine upwards, mine forward and move forward:
g #U$m{mf}