Toi (programming language): Difference between revisions

Content deleted Content added
m Add nowiki tags to avoid misparsing as HTML
Tag: nowiki added
m Reverted edits by Elahemood (talk) (HG) (3.4.13)
 
(13 intermediate revisions by 10 users not shown)
Line 1:
'''Toi''' is an imperative, type-sensitive language that provides the basic functionality of a [[programming language]]. The language was designed and developed from the ground-up by Paul Longtine.<ref>{{cite web|url=https://github.com/bannana/language/blob/master/doc/OVERVIEW|title=bannana/language|website=[[GitHub]]|date=17 February 2021|publisher=}}</ref> Written in C, Toi was created with the intent to be an educational experience and serves as a learning tool (or toy, hence the name) for those looking to familiarize themselves with the inner-workings of a programming language.<ref>{{cite web|url=https://banna.tech/projects/post/toy_language/|title=banna - useless things|publisher=|access-date=2016-10-23|archive-date=2016-10-24|archive-url=https://web.archive.org/web/20161024151620/https://banna.tech/projects/post/toy_language/|url-status=dead}}</ref>
 
== Specification<ref>{{cite web|url=https://github.com/bannana/language/blob/master/doc/SPECIFICATION|title=bannana/language|website=[[GitHub]]|date=17 February 2021|publisher=}}</ref><ref>{{Cite web|url=http://dev.nanner.co/language/file/doc/SPECIFICATION.html|title=SPECIFICATION - language - some fools attempt at an interpreted language}}</ref> ==
 
=== [[Type (computer science)|Types]] ===
Line 64:
Scopes are handled by referencing to either the Global Scope or the Local Scope.
The Local Scope is denoted by '0' in the scope argument when referring to names,
and this scope is initialized when evaluating any new block of code. When a different block of code is called, a new scope is added as a new Namespace level. Namespace levels act as context switches within function contexts. For example, the local namespace must be 'returned to' if that local namespace context needs to be preserved on return. Pushing 'Namespace levels' ensures that for every ''n'' function calls, you can traverse ''n'' instances of previous namespaces. For example, take this namespace level graphic, where each Level is a namespace instance:
 
Level 0: Global namespace, LSB == '1'.
Line 129:
Bytecode is arranged in the following order:
 
<nowiki><opcode>, <arg 0>, <arg 1>, <arg 2></nowiki>
 
Where the <opcode> is a single byte denoting which subroutine to call with the
Line 135:
lengths, some having 0 arguments, and others having 3 arguments.
 
'''===== Interpreting Bytecode Instructions''' =====
 
A bytecode instruction is a single-byte opcode, followed by at maximum 3
arguments, which can be in the following forms:
 
* Static (single byte)
* Name (single word)
* Address (depending on runtime state, usually a word)
* Dynamic (size terminated by NULL, followed by (size)*bytes of data)
** i.e. FF FF 00 <nowiki><0xFFFF bytes of data></nowiki>,
** 01 00 <nowiki><0x1 bytes of data></nowiki>,
** 06 00 <nowiki><0x6 bytes of data></nowiki>, etc.
 
Below is the specification of all the instructions with a short description for
Line 161:
D<nowiki><[variable]></nowiki> - Dynamic bytecode argument.
----
Hex | MemnonicMnemonic | arguments - description
 
----
'''1 -==== Stack manipulation''' ====
 
These subroutines operate on the current-working stack(1).
Line 171:
12 DUP - duplicates the top of the stack
13 ROT_THREE - rotates top three elements of stack
 
----
'''2 -==== Variable management''' ====
----
20 DEC S<nowiki><scope></nowiki> S<nowiki><type></nowiki> N - declare variable of type
21 LOV S<nowiki><scope></nowiki> N - loads reference variable on to stack
Line 179 ⟶ 178:
23 CTV S<nowiki><scope></nowiki> N D<nowiki><data></nowiki> - loads constant into variable
24 CTS D<nowiki><data></nowiki> - loads constant into stack
 
----
'''3 -==== Type management''' ====
 
Types are in the air at this moment. I'll detail what types there are when
the time comes
----
30 [[typeof|TYPEOF]] - pushes type of TOS on to the stack TBI
31 CAST S<nowiki><type></nowiki> - Tries to cast TOS to <nowiki><type></nowiki> TBI
 
----
'''4 -==== Binary Ops''' ====
 
OPS take the two top elements of the stack, perform an operation and push
Line 208 ⟶ 207:
4D OR - or's TBI
4E XOR - xor's TBI
4F NAND - and's TBI
 
----
'''5 -==== [[Conditional (computer programming)|Conditional Expressions]]''' ====
 
Things for comparison, < > = ! and so on and so forth.
Line 225 ⟶ 224:
57 OR - Boolean OR
58 AND - Boolean AND
 
----
'''6 -==== Loops''' ====
----
60 STARTL - Start of loop
61 CLOOP - Conditional loop. If TOS is true, continue looping, else break
6E BREAK - Breaks out of loop
6F ENDL - End of loop
 
----
'''7 -==== Code flow''' ====
 
These instructions dictate code flow.
----
70 [[GOTO]] A<nowiki><addr></nowiki> - Goes to address
71 JUMPF A<nowiki><n></nowiki> - Goes forward <n> lines
72 IFDO - If TOS is TRUE, do until done, if not, jump to done
Line 247 ⟶ 245:
7E DONE - End of block
7F CALL N - Calls function, pushes return value on to STACK.
 
----
'''8 -==== Generic object interface. Expects object on TOS''' ====
----
80 GETN N<nowiki><name></nowiki> - Returns variable associated with name in object
81 SETN N<nowiki><name></nowiki> - Sets the variable associated with name in object
Line 256 ⟶ 253:
83 INDEXO - Index an object, uses argument stack
84 MODO S<nowiki><OP></nowiki> - Modify an object based on op. [+, -, *, /, %, ^ .. etc.]
 
----
'''==== F - Functions/classes''' ====
 
----
FF DEFUN NS<nowiki><type></nowiki> D<nowiki><args></nowiki> - Un-funs everything. no, no- it defines a
function. D is its name, S<nowiki><type></nowiki> is
Line 268 ⟶ 265:
F1 NEW S<scope> N - Instantiates class
F0 RETURN - Returns from function
 
----
'''0 -==== Special Bytes''' ====
00 [[Null character|NULL]] - No-op
----
00 NULL - No-op
01 LC N<nowiki><name></nowiki> - Calls OS function library, i.e. I/O, opening files, etc. TBI
02 PRINT - Prints whatever is on the TOS.