Idvac

From Esolang
(Redirected from Iavac)
Jump to navigation Jump to search

Idvac is a language created by User:FireCubez. Idvac stands for Increment and decrement values and compare. It is an OISC. Since the language only has one instruction by nature of being an OISC, the instruction name is inferred. A program can be in either source or compiled form.

Source

An Idvac program's source code is a series addresses, separated by whitespace. Each address takes up a fixed amount of memory, which should be specified to the compiler by the user as a flag. The amount of addresses in a program must be a multiple of 2.

It is recommended for address sizes to be a power of 2 for storage in files, but they may be anything. Implementations are allowed to deny address sizes that are hard to implement.

The suffix for Idvac source code is .ivs

Compilation

Compiling Idvac is very simple:

  • First, there is a file header: the number of bits which an address consists of, followed by IVC. For example, 64IVC would be a header for a 64-bit address file.
  • Then, addresses are read from the source file, and simply inserted into the file as binary values, little-endian.

The suffix for compiled Idvac is .ivc

Execution

Execution is also very simple. Programs may be compiled to native executables for best performance, or emulated (interpreted). Either way, this is how execution is performed in pseudocode (assuming memory is initialized):

address ip = *0;
while(true) {
    if((***ip)++ == (***ip + 1)--) ip = ***ip;
    ip += 2;
    if(ip == 0) break;
    if(ip == -1) ip = input();
}

Memory is an array of integers, the integers being the same size as the addresses. Whether the integers are signed or not is irrelevant, since addition and subtraction is identical on signed and non-signed integers. The instruction pointer starts at the value defined by the first address in memory.

Special Addresses (memory mapping)

While there is no direct instruction for both IO and halting, these are memory mapped.

As seen in the implementation above, setting the instruction pointer to -2 (in 2's complement) will result in it being 0 after incrementation, which causes a halt. If the IP is -1 after incrementation, the IP will be set to the next chunk of input, where a chunk of input is min(8, addrsize) bits long. For example, if the input is 11110100 (little endian bits), and the address size is 5, the chunk will be 11110, and the next chunk will be 10000 (i.e. 1, converted to decimal using little endian).

As for output, setting address -1 (not the IP to -1) will print out a chunk (as described above) consisting of the IP's bits. Once we have enough chunks to go over 8 bits, those 8 bits are printed. For example, a chunk 11111 followed by a chunk 11100 (bits are little endian) would combine to be 1111111100 which is 8 bits. Those bits (11111111) will be printed and discarded, leaving 00. If a chunk 11000 were to come after that, we would have 0011000 (not 8 bits, so wouldn't print yet).