User:MDude/Sipper

From Esolang
Jump to navigation Jump to search

Sipper is a reversible programming language designed with the idea of reversible logic as a requisite of physically reversible computers that can used to increase energy efficiency by acting as a co-proccessor. It is named after the fact that it's designed to help design systems that are a very light power drain. There are no built-n stack commands in sipper, in an attempt to avoid having the language encourage programmers to shove data to the end of a stack and forget about it as a substitute for deletion. In contrast, Sipper is meant to promote looking for ways to re-use what might be discarded as garbage data. Another use for sipper is in simulating physical systems which involve mostly reversible interactions.

The nature of sipper means all functions are total as well as reversible, unless extended to allow infinite recursion. Infinite memory can be added as a wimp mode, but discouraged goes against the purpose of being fast and resoruce-light on real hardware. In addition, sipper is designed to produce functions that can be called from other languages, or be ran on a DSP,and requires all memory used in its functions be laid out ahead of time.

Whether a sipper file is a program or a library, code is preceded by a list of memory structure defenitions, distinguished by having {} and optionally [] but not (). Bit is the built-in memory unit and reffers to one bit. Structures must have unique full names, but can have non-unique local names. Including a structure without a name is the same as including it with its own name. Structures can also be grouped as arrays using [N].

Struct[]{ structs[] }

Setup comands: MEMORY(N) Takes a number N and uses that for the limit of memory.

Basic program commands: invert(list) Takes a list of variables and bitwise-inverts all of them. Swap(list,list) Takes two variable lists totalling the same length and swaps their content. if(list) then {code} Evaluates a conditional. If true, performs a block of code. Variables used in the conditional may not be refferenced inside the block, to preserve reversibility. function-name(list) calls a subroutine/function with the varables listed. Calls by value. May be used inside a conditional, in which case it will be refersed afterward.

Function structure: function-name(list){code} Defines a function with a list of all variables used inside of it and the block of code executed by it.

Cycle Commands: Map () to () Maps memory structures to others such that the value at the end of one cycle will overwrite the input value of the next. Values not overridden at the end or by inputs will retain the value from the last cycle.

Program example (bouncing ball):

Byte { Bit[8] }

Position{ x{[2]Byte} y{[2]Byte} }

Ball{ Position{Position} XSpeed{Byte} YSpeed{Byte} }

main(Ball) { if (Ball.Position.Y = 0) { invert(Ball.YSpeed) } Add(Ball.YSpeed,-1) if (Ball.YSpeed.Bit[0] != 0) /constants can only be used unaltered arguments. Add(Ball.Position.y.Bit, Ball.YSpeed.Bit[1-7]) /does not need to match because second argument is unaltered. }