Wise

From Esolang
Jump to navigation Jump to search
Wise
Paradigm(s) procedural, imperative
Designed by User:DivergentClouds
Appeared in 2023
Memory system stack-based
Dimensions one-dimensional
Computational class Unknown
Reference implementation Zig
File extension(s) .wise, .wis

Wise is a stack-based language based on an extension of bitwise operations for bases ≥ 2.

Overview

There are 3 main registers (A, B,C) and 2 stacks (X, Y). In addition there is the base register, which notates the current base. All numbers are unbounded non-negative integers. A digit of A is notated as a and B as b.

A, B and C are all initialized to 0, and base is initialized to 2.

Operators

The digit-wise operators operate on each of the least-significant C digits of A and B (or just A in the case of ~). Any remaining digits of A are preserved in the result. The result is then pushed to X.

Digit-wise operators
Command Description
~ (base - 1) - a
| min(a + b, (base - 1))
^ (a + b) mod base
& min(a × b, (base - 1))
* (a × b) mod base

The shift operators operate on all of A and B. They can be thought of as shifting all digits of A by B. The result is then pushed to X.

Shift Operators
Command Description
< A × pow(base, B)
> floor(A ÷ pow(base, B))

The digit count operator returns the number of digits in A, not including leading zeroes. The result is then pushed to X.

Digit Count Operator
Command Description
/ if (A == 0): 0, else: log_base(A) + 1

The final math operator is the base operator, which is used to set base. Attempting to set base to a value < 2 is an error.

Base Operator
Command Description
_ A → base

The cycling operators are used to change register and stack references.

Cycling Operators
Command Description
$ Swap the stacks; X becomes Y, and Y becomes X
% Cycle the main registers; A becomes B, B becomes C, and C becomes A

The stack operators all modify X. Popping from an empty stack is an error.

Stack Operators
Command Description
@ Push A, does not modify A
! Pop into A
0 Push 0
1 Push 1

The branching operators are used for conditional execution. The program is treated as an implicit block. If C is 0, then A and B are treated as 0.

Branching Operators
Command Description
? If a ≤ b for the first C digits, go to the end of the innermost block
" If a > b for the first C digits, go to the start of the innermost block
( Start a block, must have a matching )
) End a block, must have a matching (

The I/O operators treat numbers outside the program as base-10.

I/O Operators
Command Description
i Get a base-10 number as input and push it to the stack, converting to the current base. Waits for input
o Output A, converting from the current base to base-10

Comments last until the end of line.

Comments
Command Description
# Start a comment which lasts until the end of the line