User:MigoMipo/Migol10 Draft

From Esolang
Jump to navigation Jump to search

This page is completely outdated, see Migol 11 for the final result.

Migol 11 will be a redesign of Migol, adding support for simple I/O and multithreading.

Migol will still resemble a simplified assembly language. The goal is to enable preemptive multitasking and extended I/O operations, such as file operations and networking. Therefore, Migol 11 will add interrupts and memory-mapped I/O.

Changes to existing parts

Output statements and [@] input will work as before. The assignment operation will also be unchanged. Migol 11 will be fully compatible with Migol 09 programs who do not use the new planned feature.

There will be small changes to how the special variable [#] works. In Migol 09, 3<# is an illegal statement as # is not a proper value. Assigning to # is a special operation, and the program counter can't be addressed in any other way. In Migol 11, special variables will be accessed using negative memory address. The program counter will have the address -1. To maintain compatibility and readability, # will be an alias for -1. The same thing will happen to @ input, which will be assigned the address -5.

Special variables

address alias read write
-1 # Return program counter Set program counter to new value
-2 S Return software interrupt handler address Set software interrupt handler address
-3 R Return return address from interrupt Set return address from interrupt
-4 I Return 1 if interrupts are disabled, 0 otherwise If written value is 0, enable interrupts and force branch to [-3]

If written value is 1, disable interrupts and force branch to [-2].

-5 @ Return read byte from stdin, blocks until a value is available Nothing
-6 W Block program and wait for interrupt Nothing

These are just the basic special variables. I/O functions will be accessed with other special registers.

Interrupt

Whenever an interrupt occurs and the program is ready to handle new interrupts, the program will save the address of the instruction after the last executed instruction in -3 and force a branch to the interrupt handler routine. Where this address is stored may vary. The software interrupt address is stored in -2, but I/O systems can have separate handler routines addresses. While an interrupt is handled, all other interrupts are stored in a queue until interrupts are enabled again.

Software interrupts aren't very useful. They are triggered with the operation -4<1, which basically disables interrupts and branches to [-2]. Interrupts are much more useful when external sources, such as timers and I/O operations, interrupt the normal code flow.

I/O functions

All I/O functions except [@] will be nonblocking. [@] will block the Migol runtime and should not be used with interrupt-based programs. It can of course be used when you don't need complicated I/O features.

The first version of Migol 11 will support timer interrupts, and file and network I/O. How this will work is not specified yet.

Multi-threading

The timer interrupt can be used to implement preemptive multitasking. Context switching, thread scheduling and other related code must be manually implemented.