Tsb

From Esolang
Jump to navigation Jump to search

Tsb is a programming language that compiles to Seabass and was made to simplify coding in it, while retaining many of Seabass's design choices.

Basics

General

Unlike raw Seabass, Tsb is based mostly on usage of the Extended Stack and variables in it. Extended stack is an infinite tape with numbered cells, starting from zero, so variable names begin with a # and end with an integer marking the variable's place in the Extended Stack. Apart from regular variables, there are also "hypervariables", they begin with a double octothorpe (##1, for example) and point to an Extended Stack cell with their content. If #1 contains a 2, ##1 would act the same as #2.

Assignment

Variables can be assigned with a value of any of the four types:

#0 = True / Boolean logic
#1 = 5 / Integers
#2 = 5.5 / Floats
#3 = "Text" / Strings

Pure values can only be used during assignment, all commands operate exclusively with existing variables. By default all variables contain a zero.

Basic math commands

#0 = #1+#2
#0 = #1-#2
#0 = #1*#2
#0 = #1\#2 /division
#0 = #1\\#2
#0 = #1^#2
#0 = #1%#2

Backslash is used for division because slash is used to mark comments, similarly to Seabass.

Other math commands

Numbers can be incremented or decremented by one with ++/--, or more.

#3++ /+1
#3++35 /+35
#3++#4

Copying

Variables can be copied, unless they're strings, but it is possible to copy strings by one character at a time. If the same variable is assigned with two strings, the result will be these two strings joined. Copying:

#0 = #1

Code that outputs "abcdef":

#3 = "abc";#3 = "def"
out #3

As shown in the example above, using a ; to separate statements is also acceptable, unless there are spaces before the first statement.

Loops

In Tsb loops can be done via "goto points", just like in Seabass. Goto points must be set explicitly with the colon symbol, so that they could be used later. Infinite loop example:

:7
jump :7

Structure

Tsb configures accumulator and deccumulator like this for optimal number generation:

0    3125
0    625
0    125
c    25
0    5
a    b

a, b and c are frequently used as temporary variables, the zero above "a" must remain constant, otherwise the post-function cleanup process would not work. The three temporary variables always equal zero at the start of a command.

Functions

Functions usually start with a command and may change one variable or make a new one.

Function Description
round #1 rounds #1
int #3 saves #3 as an integer
root #7 saves the square root of #7 at #7
out #5 outputs #5
outn #4 outputs #4 with a newline at the end, does not work for numbers and #0
input #6 #8 stores input as a string at #8, input text is set to #6
inp #15 simple input, stores the input number at #15 (only numbers accepted as input)
charget #9 #10 #11 #9'th character is extracted from #10 and is saved at #11
numget #14 #13 #12 #14'th number is extracted from #13 and saved at #12
jump :15 goto point :15 is activated
literal idso "idso" will be inserted into the code
random #21 #22 #23 random number between #21 and #22 will be saved at #23
write #16 #17 write #16 to file named #17
append #18 #19 append filename #19 with text #18
read #21 #20 read text from text file #20 and store it at #21
pass does nothing, must be present after a logical statement if it has no other commands

True functions

Tsb supports functions, but there are differences between how they act in Seabass and Tsb.

fun 7:
    ...

The statement above declares a true function named 7. run fun7 #3 #4 - uses #3 as input to function 7 and moves output to cell 4. global - declares usage of global Extended Stack (all variables), must be closed with another "global". Note: the function input within the function is kept inside local #0, so the code below prints a four. The output of the function is also taken from local #0 at the end of execution of the function.

fun 3:
    square #0
#2 = 2
run fun3 #2 #3
out #3

Compiler specifics

Output

The original compiler written in Python will only output the finished code in the console. However, if any of the lines in Tsb code are /useoutput, the compiler will also save the result as output.txt in the script's directory.

Input

Input can only be taken from input.tsb in the compiler's directory.

Other

Most functions save variables only as floats to shorten the compiled code.

Examples

Hello, World!

#0 = "Hello, World!";out #0

FizzBuzz

#3 = 3
#5 = 5
#15 =15
#8 = 0

#0 = "Fizz\n"
#1 = "Buzz"
#2 = "FizzBuzz"
#14 = "\n"

#4 = 20/max
#6 = 0/counter

:7
if #6<=#4:
    #7 = #6%#15
    if #7=#8:
        outn #2
    else:
        #7 = #6%#5
        if #7=#8:
            outn #1
        else:
            #7 = #6%#3
            if #7=#8:
                outn #0
            else:
                out #6
                out #14
    #6++
    jump :7

External resources