brainstack

From Esolang
Jump to navigation Jump to search

A language derived from brainfuck, brainstack provides commands to alter the stack, enter a stack, and leave it.

Brainstack Syntax Spec.

There are a few extra commands in brainstack.

^ PUSH

Pushes the value at the current cell onto the stack.

Converter Implementation (0.2):

MOV EAX,[pos]
PUSH [tape+EAX]

V POP

Pops a value off of the stack and into the current cell.

Converter Implementation (0.2):

MOV EAX,[pos]
POP [tape+EAX]

/ ENTER

Enters a new stack.

Converter Implementation (0.2):

ENTER 0x50000

\ LEAVE

Exits the current stack.

Converter Implementation (0.2):

LEAVE

! DECLARE

Declares a function by name.

Example:

!clearcell{[+]}

Converter Implementation (?):

BSFunc<Name>:

# STATIC DECLARE

Declares a macro by name.

Example:

#clearcell{[+]}

Converter Implementation (?):

<Nothing>

* CALL

Calls a function by name.

Example:

*clearcell*

Converter Implementation (?):

CALL BSFunc<Name>

% STATIC CALL

'Calls' a macro by name.

Example:

%clearcell%

Converter Implementation (?):

<Preprocessed>

0 NOP

Does nothing.

Converter Implementation (?):

NOP

@ ASM

Inline assembly.

Example:

@MOV ECX,0@ ; Don't use EAX!!!

$ MACRO ARG

Used for macro definitions.

$n for arguments. $u for an id unique to this call.

Example:

#repeat{@rpt$u:@@MOV ECX,$0@$1@LOOP rpt$u@}

| ARG SEPERATOR

Used to separate arguments in calls

Example:

%repeat|65|+%

Untested Examples

Print the alphabet to the screen (in allcaps).

#repeat{@rpt$u:@@MOV ECX,$0@$1@LOOP rpt$u@}
(%repeat|65|+%.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.)

Take all input and increment it by 128.

#i10{++++++++++}
!i32{%i10%%i10%%i10%++}
(,[*i32**i32**i32**i32*.0,])

Take all input and increment it by 128 more efficiently.

(,[@MOV ECX,[pos]@@ADD [tape+ECX],128]@.0,])

Tested Examples

Nothing yet.

Extended Possibilities

Networking

: CONNECT

Attempt to connect to an ip, first byte at the pointer, and then the three to the left. Does not shift the pointer. New connection is pushed onto the connection stack.

_ SEND

Send the byte under the pointer with the current connection.

~ RECEIVE

Receive a byte from the current connection, and store it under the pointer.

; DISCONNECT

Disconnect the current connection and pop it off the connection stack.

File IO

" OPEN

Open a file with a filename starting after the pointer, terminated by the value under the pointer. If the value under the pointer is !, open the file for writing. Upon success, push the file stream onto the file stack, and set the value under the pointer to 1. Upon failure, reset the value under the pointer to 0.

? ALTER

If the current file is open for writing, write the byte under the pointer to the file. If the current file is open for reading, read from the file into the byte under the pointer. If no file is open, set the byte under the pointer to 255.

' CLOSE

Close the current file, free the memory used, and pop it off of the file stack.