Toi (programming language): Difference between revisions

Content deleted Content added
m Typo fixing, replaced: assosiated → associated (2) using AWB
m Add nowiki tags to avoid misparsing as HTML
Tag: nowiki added
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 144:
* 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 156:
TOS - 'Top Of Stack' The top element
TBI - 'To be Implemented'
S<nowiki><[variable]></nowiki> - Static Argument.
N<nowiki><[variable]></nowiki> - Name.
A<nowiki><[variable]></nowiki> - Address Argument.
D<nowiki><[variable]></nowiki> - Dynamic bytecode argument.
----
Hex | Memnonic | arguments - description
Line 167:
These subroutines operate on the current-working stack(1).
----
10 POP S<nowiki><n></nowiki> - pops the stack n times.
11 ROT - rotates top of stack
12 DUP - duplicates the top of the stack
Line 174:
'''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
22 STV S<nowiki><scope></nowiki> N - stores TOS to reference variable
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'''
Line 186:
----
30 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'''
Line 237:
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
73 ELSE - Chained with an IFDO statement, if IFDO fails, execute ELSE
Line 250:
'''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
Object on TOS, Variable on TOS1
82 CALLM N<nowiki><name></nowiki> - Calls method in object
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
the return value, D<nowiki><args></nowiki> is the args.
 
FE DECLASS ND<args> - Defines a class.
Line 272:
----
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.
03 DEBUG - Toggle debug mode
Line 287:
abstract notation for the code will be broken down into a binary tree as so:
 
<nowiki><node></nowiki>
/\
/ \
/ \
<nowiki><arg></nowiki> <nowiki><next></nowiki>
 
node> can be an argument of its parent node, or the next instruction.
Line 320:
The various instruction nodes are as follows:
 
* def <nowiki><type></nowiki> <nowiki><name></nowiki>
** Define a named space in memory with the type specified
*** See the 'TYPES' section under 'OVERVIEW'