THLEK

From Esolang
Jump to navigation Jump to search

THLEK (an acronym for THree LEtter Keywords) is a stack-based language by User:Cocosbeans. As the full name implies, the instructions in THLEK are always three characters long. This allows code to be interpreted without any delimiters (i.e. whitespace), since the code length will always be divisible by three. Whitespace can be added for human legibility but it is ignored by the interpreter. For instance, the code mrk x01 end ifc tru jmp x01 end eof can be written as mrkx01endifctrujmpx01endeof and it will execute exactly the same.

Memory

THLEK has two sets of memory: the Memory tape, and the Stack.
The Memory tape is a fixed-size tape of Cells that can store data. As the tape has 256 cells at all times, Cells can be indexed by their Address, a number between x00 and xff. NOTE that the address x10 cannot be accessed as it always stores the 257th value from the Stack, acting as overflow storage.
The Stack is a stack of Cells that works on a FILO basis and can be pushed to and popped from. The Stack can hold up to 256 cells, and if an extra Cell is pushed to the Stack, the top Cell is popped to Address x10. When using the interpreter, this can be disabled by providing the argument --no-overflow which frees the Address of its reservation, but this will cause the program to immediately halt with a code of 3 if the Stack overflows. No value below the top Cell can be mutated or accessed until it becomes the top Cell.

Syntax

All instructions in THLEK are three characters long. They are not case-sensitive, but their order does matter. Numbers in THLEK are hexadecimal, and are always written as two nibbles prefixed with x. While only 8-bit numbers can be written into the code, mathematical operations can be used to produce a signed 32-bit number.
Below is an example of how to bypass the 8-bit restriction. In this example, the sum of xff + x10 (0x10f) is stored to address x01, then is later compared to xff. If x10f > xff, then it prints that value (271).

psh xff end
psh x10 end
dmp x01 end
ptr x01 end
ifc grt rpv xff
    doc
        plv rpv end
    edc
eif
eof

Control

In THLEK, you can test an expression's truth and then perform some code based on the result. THLEK supports the basic If Then (Else) control, and has standard logical and mathematical operators. You can define an If statement that only has a then body, but not an else body, with ifc. To add an else body, the keyword is ife. Unlike other expressions, If statements end with eif.

Glossary

Keyword Arguments expected Full name Description
edc None End Do Condition Marks the end of the then body of an If statement.
ede None End Do Else Marks the end of the else body of an If statement.
eif None End If Marks the end of an If statement.
eof None End Of File Marks the end of the code. Can also be used to halt the program at any point.
end None End Marks the end of an expression.
fls None False Represents the False boolean value.
jmp rpv Jump If a number is given, jumps to the marker that corresponds to that number. If no existing marker exists, the program halts with code 5. If rpv is given, jumps to the marker with the number at the address that the pointer currently points to.
mrk Marker (number) Marker Sets the index where the keyword is written as a marker that can be jumped to with the specified number.
pcc None Pop and Clear Cell Pops the top Cell of the Stack, effectively deleting it.
pop rpa Pop Pops the top Cell of the Stack to the specified address, or to the pointer's current address if rpa is given.
rpa None Refer to Pointer Address Returns the address that the pointer is currently pointing to.
rpv None Refer to Pointer Value Returns the value at the address that the pointer is currently pointing to.
spa Address (number) Set Pointer to Address Sets the pointer to a given Address.
tru None True Represents the True boolean value.

this page is wip, and so is its implementation :)