2 single: Reference; Introduction
8 In this chapter we will learn about
16 * Virtual Machine (VM) Instructions
19 pair: Reference; Language Keywords
77 pair: Reference; Language Functions
86 acos() add() addattribute() adddays()
87 addmethod() ascii() asin() assert()
88 atan() atan2() attributes() binarysearch()
89 bytes2double() bytes2float() bytes2int() callgc()
90 ceil() cfunctions() char() chdir()
91 classes() classname() clearerr() clock()
92 clockspersecond() closelib() copy() cos()
93 cosh() currentdir() date() dec()
94 decimals() del() diffdays() dir()
95 double2bytes() eval() exefilename() exefolder()
96 exp() fabs() fclose() feof()
97 ferror() fexists() fflush() fgetc()
98 fgetpos() fgets() filename() find()
99 float2bytes() floor() fopen() fputc()
100 fputs() fread() freopen() fseek()
101 fsetpos() ftell() functions() fwrite()
102 getattribute() getchar() globals() hex()
103 hex2str() input() insert() int2bytes()
104 intvalue() isalnum() isalpha() isandroid()
105 isattribute() iscfunction() isclass() iscntrl()
106 isdigit() isfreebsd() isfunction() isglobal()
107 isgraph() islinux() islist() islocal()
108 islower() ismacosx() ismethod() ismsdos()
109 isnull() isnumber() isobject() ispackage()
110 ispackageclass() ispointer() isprint() isprivateattribute()
111 isprivatemethod() ispunct() isspace() isstring()
112 isunix() isupper() iswindows() iswindows64()
113 isxdigit() left() len() lines()
114 list() list2str() loadlib() locals()
115 log() log10() lower() max()
116 mergemethods() methods() min() murmur3hash()
117 nullpointer() number() object2pointer() objectid()
118 packageclasses() packagename() packages() perror()
119 pointer2object() pow() prevfilename() ptrcmp()
120 raise() random() read() remove()
121 rename() reverse() rewind() right()
122 ring_give() ring_see()
123 ring_state_delete() ring_state_filetokens()
124 ring_state_findvar() ring_state_init() ring_state_main()
125 ring_state_mainfile() ring_state_new() ring_state_newvar()
126 ring_state_runcode() ring_state_runfile() ring_state_runobjectfile()
127 ring_state_setvar() ringvm_callfunc() ringvm_calllist()
128 ringvm_cfunctionslist() ringvm_classeslist() ringvm_evalinscope()
129 ringvm_fileslist() ringvm_functionslist() ringvm_genarray()
130 ringvm_give() ringvm_hideerrormsg() ringvm_info()
131 ringvm_memorylist() ringvm_packageslist() ringvm_passerror()
132 ringvm_scopescount() ringvm_see() ringvm_settrace()
133 ringvm_tracedata() ringvm_traceevent() ringvm_tracefunc()
134 setattribute() shutdown() sin() sinh()
135 sort() space() sqrt() srandom()
136 str2hex() str2hexcstyle() str2list() strcmp()
137 string() substr() swap() sysget()
138 system() tan() tanh() tempfile()
139 tempname() time() timelist() trim()
140 type() ungetc() unsigned() upper()
141 varptr() version() windowsnl() write()
144 pair: Reference; Compiler Errors
149 * Error (C1) : Error in parameters list, expected identifier
150 * Error (C2) : Error in class name
151 * Error (C3) : Unclosed control strucutre, 'ok' is missing
152 * Error (C4) : Unclosed control strucutre, 'end' is missing
153 * Error (C5) : Unclosed control strucutre, next is missing
154 * Error (C6) : Error in function name
155 * Error (C7) : Error in list items
156 * Error (C8) : Parentheses ')' is missing
157 * Error (C9) : Brackets ']' is missing
158 * Error (C10) : Error in parent class name
159 * Error (C11) : Error in expression operator
160 * Error (C12) : No class definition
161 * Error (C13) : Error in variable name
162 * Error (C14) : Try/Catch miss the Catch keyword!
163 * Error (C15) : Try/Catch miss the Done keyword!
164 * Error (C16) : Error in Switch statement expression!
165 * Error (C17) : Switch statement without OFF
166 * Error (C18) : Missing closing brace for the block opened!
167 * Error (C19) : Numeric Overflow!
168 * Error (C20) : Error in package name
169 * Error (C21) : Unclosed control strucutre, 'again' is missing
170 * Error (C22) : Function redefinition, function is already defined!
171 * Error (C23) : Using '(' after number!
172 * Error (C24) : The parent class name is identical to the subclass name
173 * Error (C25) : Trying to access the self reference after the object name
174 * Error (C26) : Class redefinition, class is already defined!
176 * Warning (W1) : Duplication in file name
177 * Warning (W2) : The Compiler command ChangeRingKeyword requires two words as parameters
178 * Warning (W3) : Compiler command ChangeRingKeyword - Keyword not found !
179 * Warning (W4) : The Compiler command ChangeRingOperator requires two words as parameters
180 * Warning (W5) : Compiler command ChangeRingOperator - Operator not found !
181 * Warning (W6) : Using the EXIT command outside loop!"
182 * Warning (W7) : Using the LOOP command outside loop!"
185 pair: Reference; Runtime Errors
190 * Error (R1) : Cann't divide by zero !
191 * Error (R2) : Array Access (Index out of range) !
192 * Error (R3) : Calling Function without definition !
193 * Error (R4) : Stack Overflow !
194 * Error (R5) : Can't access the list item, Object is not list !
195 * Error (R6) : Variable is required
196 * Error (R7) : Can't assign to a string letter more than one character
197 * Error (R8) : Variable is not a string
198 * Error (R9) : Using exit command outside loops
199 * Error (R10) : Using exit command with number outside the range
200 * Error (R11) : Error in class name, class not found!
201 * Error (R12) : Error in property name, property not found!
202 * Error (R13) : Object is required
203 * Error (R14) : Calling Method without definition !
204 * Error (R15) : Error in parent class name, class not found!
205 * Error (R16) : Using braces to access unknown object !
206 * Error (R17) : Error, using 'Super' without parent class!
207 * Error (R18) : Numeric Overflow!
208 * Error (R19) : Calling function with less number of parameters!
209 * Error (R20) : Calling function with extra number of parameters!
210 * Error (R21) : Using operator with values of incorrect type
211 * Error (R22) : Using loop command outside loops
212 * Error (R23) : Using loop command with number outside the range
213 * Error (R24) : Using uninitialized variable
214 * Error (R25) : Error in package name, Package not found!
215 * Error (R26) : Calling private method from outside the class
216 * Error (R27) : Using private attribute from outside the class
217 * Error (R28) : Using bad data type as step value
218 * Error (R29) : Using bad data type in for loop
219 * Error (R30) : Parent class name is identical to child class name
220 * Error (R31) : Trying to destory the object using the self reference
221 * Error (R32) : The CALL command expect a variable contains string!
222 * Error (R33) : Bad decimals number (correct range >= 0 and <=14) !
223 * Error (R34) : Variable is required for the assignment operation
224 * Error (R35) : Can't create/open the file!
225 * Error (R36) : The column number is not correct! It's greater than the number of columns in the list
226 * Error (R37) : Sorry, The command is not supported in this context
227 * Error (R38) : Runtime Error in loading the dynamic library!
228 * Error (R39) : Error occurred creating unique filename
231 pair: Reference; Environment Errors
236 * Error (E1) : Caught SegFault
237 * Error (E2) : Out of Memory
238 * Error (E3) : Deleting scope while no scope!
239 * Error (E4) : Long VM Instruction!
240 * Error (E5) : The file type is not correct - the VM expect a ring object file
241 * Error (E6) : The Ring Object File version is not correct!
242 * Error (E7) : Internal error in using sscanf() function!
243 * Error (E8) : Internal error in using fscanf() function!
246 pair: Reference; Language Grammar
251 Program ---> {statement}
253 Statement ---> 'package' <Identifier> { '.' <Identifier> } ['{' {statement} '}'] ['end'|'endpackage']
255 Statement ---> 'class' <Identifier> [ 'from'|':'|'<' <Identifier> ] ['{' {statement} '}']['end'|'endclass']
257 Statement ---> 'func'|'def' <Identifier> [ParaList] ['{' {statement} '}']['end'|'endfunc']
259 Statement ---> 'import' <Identifier> { '.' <Identifier> }
261 Statement ---> 'private'
263 Statement ---> 'load' ['package'|'again'] <Literal>
265 Statement ---> 'loadsyntax' <Literal>
267 Statement ---> 'changeringkeyword' <OldKeyword> <NewKeyword>
269 Statement ---> 'changeringoperator' <OldOperator> <NewOperator>
271 Statement ---> 'see'|'put' <Expr>
273 Statement ---> 'give'|'get' <Identifier>
275 Statement ---> 'if' <Expr> ['{'] {statement} [ {'but'|'elseif' <Expr> {Statement} } ] ['else' {Statement} ] 'ok'|'end'|'}'
277 Statement ---> 'Switch' <Expr> ['{'] { 'on'|'case' <Expr> {statement} } ['other' {Statement} ] 'off'|'end'|'}'
279 Statement ---> 'for' <Identifier> '=' <Expr> 'to' <Expr> [ 'step' <Expr> ] ['{'] {Statement} 'next'|'end'|'}'
281 Statement ---> 'for' <Identifier> 'in' <Expr> [ 'step' <Expr> ] ['{'] {statement} 'next'|'end'|'}'
283 Statement ---> 'while' <Expr> ['{'] {statement} 'end'|'}'
285 Statement ---> 'do' {statement} 'again' <Expr>
287 Statement ---> 'try' {statement} ['{'] 'catch' {statement} 'done'|'end'|'}'
289 Statement ---> 'return' <Expr>
293 Statement ---> 'exit'
295 Statement ---> 'loop'
297 Statement ---> <Expr>
299 Statement ---> epslion
301 ParaList ---> epslion
303 ParaList ---> ['('] <Identifier> [{ ',' <Identifier> }] [')']
305 Expr ---> <LogicNot> [{ 'and'|'or' <LogicNot> }]
307 LogicNot --> ['not'] <EqualOrNot>
309 EqualOrNot --> [ '='|'!=' ] <Compare>
311 Compare ---> <BitOrXor> [ { '<' | '>' | '<=' | '>=' <BitOrXor> } ]
313 BitOrXor ---> <BitAnd> [ { '|' | '^' <BitAnd> } ]
315 BitAnd ---> <BitShift> [ { '&' <BitShift> } ]
317 BitShift ---> <Arithmetic> [ { '<<' | '>>' <Arithmetic> } ]
319 Arithmetic ---> <Term> [ { '+' | '-' <Term> } ]
321 Term ---> <Range> [ { '*' | '/' | '%' <Range> } ]
323 Range ---> <Factor> [ ':' <Factor> ]
325 Factor ---> <Identifier> [ {Mixer} ] [ '=' <Expr> ]
329 Factor ---> <Literal>
331 Factor ---> ':' <Identifier>
333 Factor ---> '-' <Factor>
335 Factor ---> '(' <Expr> ')'
339 Factor ---> 'new' <Identifier>
341 Factor ---> <AnonymousFunction>
343 Factor ---> 'call' <identifier> { '.' <Identifier> } '(' <Parameters> ')'
345 List ---> '[' [ <Expr> { ',' <Expr> } ] ']'
347 Mixer ---> { '.' <Identifier> }
349 Mixer ---> '[' <Expr> ']'
351 Mixer ---> '(' [ <Expr> [ { ',' <Expr> }] ] ')'
353 Mixer ---> '{' {Statement} '}'
355 AnonymousFunction ---> 'func'|'def'| [<ParaList>] '{' {Statement} '}'
358 pair: Reference; Virtual Machine Instructions
360 Virtual Machine (VM) Instructions
361 =================================
365 * VM : Virtual Machine
367 * IR : Instruction Register
368 * PC : Program Counter
369 * VP : Variable Pointer
370 * Stack[nSize] : Last Item in the Stack (Last In - First Out)
371 * VV : Variable Value (We have a Pointer to a variable, And we access this variable value)
372 (Stack and Variables)
374 ======================= ============================================================================
375 Operation Description
376 ======================= ============================================================================
377 * ICO_PUSHC Add string from the IR to the stack
378 * ICO_PUSHN Add number from the IR to the stack
379 * ICO_PUSHV Replace VP in the stack[nSize] with the variable value
380 * ICO_LOADADDRESS Read variable name from the IR, push VP to the stack
381 * ICO_ASSIGNMENT Stack[nSize-1] VV = Stack[nSize] VV , POP Stack[nSize]
382 * ICO_INC Increment Number in Stack[nSize] by 1
383 * ICO_LOADAPUSHV The same as ICO_LOADADDRESS then ICO_PUSHV
384 * ICO_NEWLINE Store new line number (debug info)
385 * ICO_FREESTACK Remove all items from the stack , nSize = 0
386 * ICO_FILENAME Store the source code file name (debug info)
387 * ICO_FREELOADASCOPE Free the Scope List of the current Expression
388 ======================= ============================================================================
392 ======================= ============================================================================
393 Operation Description
394 ======================= ============================================================================
395 * ICO_JUMP Set PC to new value from the IR
396 * ICO_JUMPZERO If Stack[nSize] is a number = 0 then Set PC to new value from the IR
397 * ICO_JUMPFOR End of for loop
398 * ICO_JUMPONE If Stack[nSize] is a number = 1 then Set PC to new value from the IR
399 * ICO_JUMPZERO2 As ICO_JUMPZERO but add 1 to the stack (required for many 'AND' conditions)
400 * ICO_JUMPONE2 As ICO_JUMPONE but add 1 to the stack (required for many 'OR' conditions)
401 ======================= ============================================================================
405 ======================= ==========================================================================================================
406 Operation Description
407 ======================= ==========================================================================================================
408 * ICO_LESSEQUAL If stack[nSize-1] <= stack[nSize] , POP stack[nSize], set Stack[nSize-1] = 1 else set Stack[nSize-1] = 0
409 * ICO_EQUAL If stack[nSize-1] = stack[nSize] , POP stack[nSize], set Stack[nSize-1] = 1 else set Stack[nSize-1] = 0
410 * ICO_LESS If stack[nSize-1] < stack[nSize] , POP stack[nSize], set Stack[nSize-1] = 1 else set Stack[nSize-1] = 0
411 * ICO_GREATER If stack[nSize-1] > stack[nSize] , POP stack[nSize], set Stack[nSize-1] = 1 else set Stack[nSize-1] = 0
412 * ICO_GREATEREQUAL If stack[nSize-1] >= stack[nSize] , POP stack[nSize], set Stack[nSize-1] = 1 else set Stack[nSize-1] = 0
413 * ICO_NOTEQUAL If stack[nSize-1] != stack[nSize] , POP stack[nSize], set Stack[nSize-1] = 1 else set Stack[nSize-1] = 0
414 ======================= ==========================================================================================================
418 ======================= ============================================================================
419 Operation Description
420 ======================= ============================================================================
421 * ICO_SUM Stack[nSize-1] = Stack[nSize-1] + Stack[nSize] , POP stack[nSize]
422 * ICO_SUB Stack[nSize-1] = Stack[nSize-1] - Stack[nSize] , POP stack[nSize]
423 * ICO_MUL Stack[nSize-1] = Stack[nSize-1] * Stack[nSize] , POP stack[nSize]
424 * ICO_DIV Stack[nSize-1] = Stack[nSize-1] / Stack[nSize] , POP stack[nSize]
425 * ICO_MOD Stack[nSize-1] = Stack[nSize-1] % Stack[nSize] , POP stack[nSize]
426 * ICO_NEG Stack[nSize] = - Stack[nSize-1]
427 * ICO_PLUSPLUS Stack[nSize] = Stack[nSize] + 1
428 * ICO_MINUSMINUS Stack[nSize] = Stack[nSize] - 1
429 ======================= ============================================================================
433 ======================= ============================================================================
434 Operation Description
435 ======================= ============================================================================
436 * ICO_AND Stack[nSize-1] = Stack[nSize-1] && Stack[nSize] , POP stack[nSize]
437 * ICO_OR Stack[nSize-1] = Stack[nSize-1] || Stack[nSize] , POP stack[nSize]
438 * ICO_NOT Stack[nSize] = ! Stack[nSize]
439 ======================= ============================================================================
443 ======================= ============================================================================
444 Operation Description
445 ======================= ============================================================================
446 * ICO_LISTSTART Start New List in Temp. Memory
447 * ICO_LISTITEM Add List Item
448 * ICO_LISTEND End List
449 * ICO_LOADINDEXADDRESS Stack[nSize-1] = Stack[nSize-1] VV [ Stack[nSize] ] , POP stack[nSize]
450 ======================= ============================================================================
454 ======================= ============================================================================
455 Operation Description
456 ======================= ============================================================================
457 * ICO_LOADFUNC Find function
458 * ICO_CALL Call function
459 * ICO_RETURN Return from function
460 * ICO_RETNULL Return NULl from function
461 * ICO_RETFROMEVAL Return after eval()
462 * ICO_RETITEMREF Return the list item reference - not the value
463 * ICO_NEWFUNC Start new function
464 * ICO_BLOCKFLAG Flag to determine where to jump later (after ICO_RETURN)
465 * ICO_FUNCEXE Start executing function
466 * ICO_ENDFUNCEXE End function execution
467 * ICO_ANONYMOUS Anonymous function
468 ======================= ============================================================================
472 ======================= ============================================================================
473 Operation Description
474 ======================= ============================================================================
475 * ICO_PRINT Print value to the standard output
476 * ICO_GIVE Get input from the keyboard
477 ======================= ============================================================================
481 ======================= ============================================================================
482 Operation Description
483 ======================= ============================================================================
484 * ICO_BYE End execution of VM
485 * ICO_EXITMARK Place to exit to from a loop
486 * ICO_POPEXITMARK Remove exit mark
487 * ICO_EXIT Break from one loop or more
488 * ICO_LOOP Continue to next loop
489 ======================= ============================================================================
491 (For Better Performance)
493 ======================== ============================================================================
494 Operation Description
495 ======================== ============================================================================
496 * ICO_PUSHP Push pointer to the stack
497 * ICO_INCP Increment variable value using pointer
498 * ICO_PUSHPV Push value of variable using variable pointer
499 * ICO_INCJUMP Increment then jump
500 * ICO_INCPJUMP Increment using pointer then jump
501 * ICO_JUMPVARLENUM Jump if variable value is <= numeric value
502 * ICO_JUMPVARPLENUM Jump if variable value (using pointer) <= numeric value
503 * ICO_LOADFUNCP Push function pointer
504 * ICO_PUSHPLOCAL Push pointer to local variable
505 * ICO_INCLPJUMP Increment value using pointer to local variable then jump
506 * ICO_JUMPVARLPLENUM Jump if the variable value (using pointer) <= numeric value
507 * ICO_INCPJUMPSTEP1 Increment value using variable pointer then jump (for loop step = 1)
508 * ICO_JUMPVARPLENUMSTEP1 Increment value using variable pointer then jump (for loop step = 1)
509 ======================== ============================================================================
513 ======================= ============================================================================
514 Operation Description
515 ======================= ============================================================================
516 * ICO_TRY Start try region
517 * ICO_DONE End try region
518 ======================= ============================================================================
520 (Duplicate and Range)
522 ======================= ============================================================================
523 Operation Description
524 ======================= ============================================================================
525 * ICO_DUPLICATE Duplicate stack value
526 * ICO_RANGE Create list from value to value
527 ======================= ============================================================================
531 ======================= ============================================================================
532 Operation Description
533 ======================= ============================================================================
534 * ICO_NEWOBJ Create new object, get class name from the IR, push object pointer to the stack.
535 * ICO_SETSCOPE Called after creating new object, set the active scope to be the object scope.
536 * ICO_LOADSUBADDRESS Get object attribute, push the pointer to the stack.
537 * ICO_LOADMETHOD Find object method
538 * ICO_AFTERCALLMETHOD Used after calling a method - normal case
539 * ICO_AFTERCALLMETHOD2 Used after calling a method - second case
540 * ICO_NEWCLASS Start new class region
541 * ICO_BRACESTART Open brace
542 * ICO_BRACEEND End brace
543 * ICO_IMPORT Import package
544 * ICO_PRIVATE start private attributes region
545 * ICO_SETPROPERTY set attribute value - check for setter.
546 * ICO_CALLCLASSINIT call class init() method.
547 ======================= ============================================================================
551 ======================= ============================================================================
552 Operation Description
553 ======================= ============================================================================
554 * ICO_SETREFERENCE Copy by reference
555 * ICO_KILLREFERENCE Remove reference
556 * ICO_ASSIGNMENTPOINTER Determine the left side variable
557 * ICO_BEFOREEQUAL Determine operators like += , -= , ... etc
558 ======================= ============================================================================
562 ======================= ============================================================================
563 Operation Description
564 ======================= ============================================================================
565 * ICO_BITAND Stack[nSize-1] = Stack[nSize-1] & Stack[nSize] , POP stack[nSize]
566 * ICO_BITOR Stack[nSize-1] = Stack[nSize-1] | Stack[nSize] , POP stack[nSize]
567 * ICO_BITXOR Stack[nSize-1] = Stack[nSize-1] ^ Stack[nSize] , POP stack[nSize]
568 * ICO_BITNOT Stack[nSize] = ! Stack[nSize]
569 * ICO_BITSHL Stack[nSize-1] = Stack[nSize-1] << Stack[nSize] , POP stack[nSize]
570 * ICO_BITSHR Stack[nSize-1] = Stack[nSize-1] >> Stack[nSize] , POP stack[nSize]
571 ======================= ============================================================================
575 ======================= ============================================================================
576 Operation Description
577 ======================= ============================================================================
578 * ICO_STEPNUMBER Determine step number in for loop
579 * ICO_POPSTEP POP step number from steps stack
580 * ICO_LOADAFIRST Load the first address of variable name
581 ======================= ============================================================================
583 (Custom Global Scope)
585 ======================= ============================================================================
586 Operation Description
587 ======================= ============================================================================
588 * ICO_NEWGLOBALSCOPE Start new custom global scope - used by 'load package' command
589 * ICO_ENDGLOBALSCOPE End of custom global scope - used by 'load package' command
590 * ICO_SETGLOBALSCOPE Set the current global scope
591 ======================= ============================================================================