Вы находитесь на странице: 1из 10

Ring Documentation, Release 1.

Factor > new <Identifier>


Factor > <AnonymousFunction>
Factor > call <identifier> { . <Identifier> } ( <Parameters> )
List > [ [ <Expr> { , <Expr> } ] ]
Mixer > { . <Identifier> }
Mixer > [ <Expr> ]
Mixer > ( [ <Expr> [ { , <Expr> }] ] )
Mixer > { {Statement} }
AnonymousFunction > func|def| [<ParaList>] { {Statement} }

69.6 Virtual Machine (VM) Instructions

Definitions :-
VM : Virtual Machine
Stack : VM Stack
IR : Instruction Register
PC : Program Counter
VP : Variable Pointer
Stack[nSize] : Last Item in the Stack (Last In - First Out)
VV : Variable Value (We have a Pointer to a variable, And we access this variable value)
(Stack and Variables)

69.6. Virtual Machine (VM) Instructions 818


Ring Documentation, Release 1.3

Operation Description
Add string from the IR to the stack
ICO_PUSHC

Add number from the IR to the stack


ICO_PUSHN

Replace VP in the stack[nSize] with the variable value


ICO_PUSHV

Read variable name from the IR, push VP to the stack


ICO_LOADADDRESS

Stack[nSize-1] VV = Stack[nSize] VV , POP


ICO_ASSIGNMENT
Stack[nSize]
Increment Number in Stack[nSize] by 1
ICO_INC

The same as ICO_LOADADDRESS then ICO_PUSHV


ICO_LOADAPUSHV

Store new line number (debug info)


ICO_NEWLINE

Remove all items from the stack , nSize = 0


ICO_FREESTACK

Store the source code file name (debug info)


ICO_FILENAME

Free the Scope List of the current Expression


ICO_FREELOADASCOPE

(Jump)
Operation Description
Set PC to new value from the IR
ICO_JUMP

If Stack[nSize] is a number = 0 then Set PC to new value


ICO_JUMPZERO
from the IR
End of for loop
ICO_JUMPFOR

If Stack[nSize] is a number = 1 then Set PC to new value


ICO_JUMPONE
from the IR
As ICO_JUMPZERO but add 1 to the stack (required
ICO_JUMPZERO2
for many AND conditions)
As ICO_JUMPONE but add 1 to the stack (required for
ICO_JUMPONE2
many OR conditions)

(Compare)

69.6. Virtual Machine (VM) Instructions 819


Ring Documentation, Release 1.3

Operation Description
If stack[nSize-1] <= stack[nSize] , POP stack[nSize], set
ICO_LESSEQUAL
Stack[nSize-1] = 1 else set Stack[nSize-1] = 0
If stack[nSize-1] = stack[nSize] , POP stack[nSize], set
ICO_EQUAL
Stack[nSize-1] = 1 else set Stack[nSize-1] = 0
If stack[nSize-1] < stack[nSize] , POP stack[nSize], set
ICO_LESS
Stack[nSize-1] = 1 else set Stack[nSize-1] = 0
If stack[nSize-1] > stack[nSize] , POP stack[nSize], set
ICO_GREATER
Stack[nSize-1] = 1 else set Stack[nSize-1] = 0
If stack[nSize-1] >= stack[nSize] , POP stack[nSize], set
ICO_GREATEREQUAL
Stack[nSize-1] = 1 else set Stack[nSize-1] = 0
If stack[nSize-1] != stack[nSize] , POP stack[nSize], set
ICO_NOTEQUAL
Stack[nSize-1] = 1 else set Stack[nSize-1] = 0

(Math)
Operation Description
Stack[nSize-1] = Stack[nSize-1] + Stack[nSize] , POP
ICO_SUM
stack[nSize]
Stack[nSize-1] = Stack[nSize-1] - Stack[nSize] , POP
ICO_SUB
stack[nSize]
Stack[nSize-1] = Stack[nSize-1] * Stack[nSize] , POP
ICO_MUL
stack[nSize]
Stack[nSize-1] = Stack[nSize-1] / Stack[nSize] , POP
ICO_DIV
stack[nSize]
Stack[nSize-1] = Stack[nSize-1] % Stack[nSize] , POP
ICO_MOD
stack[nSize]
Stack[nSize] = - Stack[nSize-1]
ICO_NEG

Stack[nSize] = Stack[nSize] + 1
ICO_PLUSPLUS

Stack[nSize] = Stack[nSize] - 1
ICO_MINUSMINUS

(Logic)
Operation Description
Stack[nSize-1] = Stack[nSize-1] && Stack[nSize] ,
ICO_AND
POP stack[nSize]
Stack[nSize-1] = Stack[nSize-1] || Stack[nSize] , POP
ICO_OR
stack[nSize]
Stack[nSize] = ! Stack[nSize]
ICO_NOT

(Lists)

69.6. Virtual Machine (VM) Instructions 820


Ring Documentation, Release 1.3

Operation Description
Start New List in Temp. Memory
ICO_LISTSTART

Add List Item


ICO_LISTITEM

End List
ICO_LISTEND

Stack[nSize-1] = Stack[nSize-1] VV [ Stack[nSize] ] ,


ICO_LOADINDEXADDRESS
POP stack[nSize]

(Functions)
Operation Description
Find function
ICO_LOADFUNC

Call function
ICO_CALL

Return from function


ICO_RETURN

Return NULl from function


ICO_RETNULL

Return after eval()


ICO_RETFROMEVAL

Return the list item reference - not the value


ICO_RETITEMREF

Start new function


ICO_NEWFUNC

Flag to determine where to jump later (after


ICO_BLOCKFLAG
ICO_RETURN)
Start executing function
ICO_FUNCEXE

End function execution


ICO_ENDFUNCEXE

Anonymous function
ICO_ANONYMOUS

(User Interface)
Operation Description
Print value to the standard output
ICO_PRINT

Get input from the keyboard


ICO_GIVE

(End Program/Loop)

69.6. Virtual Machine (VM) Instructions 821


Ring Documentation, Release 1.3

Operation Description
End execution of VM
ICO_BYE

Place to exit to from a loop


ICO_EXITMARK

Remove exit mark


ICO_POPEXITMARK

Break from one loop or more


ICO_EXIT

Continue to next loop


ICO_LOOP

(For Better Performance)


Operation Description
Push pointer to the stack
ICO_PUSHP

Increment variable value using pointer


ICO_INCP

Push value of variable using variable pointer


ICO_PUSHPV

Increment then jump


ICO_INCJUMP

Increment using pointer then jump


ICO_INCPJUMP

Jump if variable value is <= numeric value


ICO_JUMPVARLENUM

Jump if variable value (using pointer) <= numeric value


ICO_JUMPVARPLENUM

Push function pointer


ICO_LOADFUNCP

Push pointer to local variable


ICO_PUSHPLOCAL

Increment value using pointer to local variable then


ICO_INCLPJUMP
jump
Jump if the variable value (using pointer) <= numeric
ICO_JUMPVARLPLENUM
value
Increment value using variable pointer then jump (for
ICO_INCPJUMPSTEP1
loop step = 1)
Increment value using variable pointer then jump (for
ICO_JUMPVARPLENUMSTEP1
loop step = 1)

(Try-Catch-Done)

69.6. Virtual Machine (VM) Instructions 822


Ring Documentation, Release 1.3

Operation Description
Start try region
ICO_TRY

End try region


ICO_DONE

(Duplicate and Range)


Operation Description
Duplicate stack value
ICO_DUPLICATE

Create list from value to value


ICO_RANGE

(OOP)
Operation Description
Create new object, get class name from the IR, push ob-
ICO_NEWOBJ
ject pointer to the stack.
Called after creating new object, set the active scope to
ICO_SETSCOPE
be the object scope.
Get object attribute, push the pointer to the stack.
ICO_LOADSUBADDRESS

Find object method


ICO_LOADMETHOD

Used after calling a method - normal case


ICO_AFTERCALLMETHOD

Used after calling a method - second case


ICO_AFTERCALLMETHOD2

Start new class region


ICO_NEWCLASS

Open brace
ICO_BRACESTART

End brace
ICO_BRACEEND

Import package
ICO_IMPORT

start private attributes region


ICO_PRIVATE

set attribute value - check for setter.


ICO_SETPROPERTY

call call init() method.


ICO_CALLCLASSINIT

(Other)

69.6. Virtual Machine (VM) Instructions 823


Ring Documentation, Release 1.3

Operation Description
Copy by reference
ICO_SETREFERENCE

Remove reference
ICO_KILLREFERENCE

Determine the left side variable


ICO_ASSIGNMENTPOINTER

Determine operators like += , -= , ... etc


ICO_BEFOREEQUAL

(Bitwise Operators)
Operation Description
Stack[nSize-1] = Stack[nSize-1] & Stack[nSize] , POP
ICO_BITAND
stack[nSize]
Stack[nSize-1] = Stack[nSize-1] | Stack[nSize] , POP
ICO_BITOR
stack[nSize]
Stack[nSize-1] = Stack[nSize-1] ^ Stack[nSize] , POP
ICO_BITXOR
stack[nSize]
Stack[nSize] = ! Stack[nSize]
ICO_BITNOT

Stack[nSize-1] = Stack[nSize-1] << Stack[nSize] , POP


ICO_BITSHL
stack[nSize]
Stack[nSize-1] = Stack[nSize-1] >> Stack[nSize] , POP
ICO_BITSHR
stack[nSize]

(For Step)
Operation Description
Determine step number in for loop
ICO_STEPNUMBER

POP step number from steps stack


ICO_POPSTEP

Load the first address of variable name


ICO_LOADAFIRST

69.6. Virtual Machine (VM) Instructions 824


CHAPTER

SEVENTY

RESOURCES

In this section you will find resources about the language

70.1 Ring Language Website

For news about the language check the website


http://ring-lang.net
http://ring-lang.sf.net

70.2 Ring Group

For questions use the Ring Group (English)


https://groups.google.com/forum/#!forum/ring-lang

70.3 Contact the Authors

Name : Eng. Mahmoud Samir Fayed


Country : Egypt
Email : msfclipper@yahoo.com
Facebook : https://facebook.com/mahmoudfayed1986
LinkedIn : https://sa.linkedin.com/in/mahmoudfayed1986
Name : Dr. Atif M. Alamri
Country : Saudi Arabia
Email : atif@ksu.edu.sa
LinkedIn : https://sa.linkedin.com/in/dr-atif-alamri-8b341747
Ring Team : http://ring-lang.sourceforge.net/team.html

825
INDEX

Access List Items by String Index TicTacToe Game, 3


Lists, 110 Werdy Application, 4
Access Objects Using Braces apppath()
Object Oriented Programming, 185 Stdlib Functions, 219
Access String Letters Arithmetic Operators
Strings, 112 Operators, 79
Accessing the class attributes from braces inside class Ascii()
methods Data Type, 127
Scope Rules, 525 Assert()
Add Items Eval() and Debugging, 152
Lists, 104 Assignment Operators
addattribute() Operators, 80
Reflection and Meta-programming, 212 attributes()
AddDays() Reflection and Meta-programming, 209
Date and Time, 120
Adding code to the generated code Better Call Command
Code Generator, 591 What is new in Ring 1.2?, 40
Adding Hyperlink to QLabel Better Code Generator for Extensions
Desktop and Mobile Development, 433 What is new in Ring 1.1?, 50
addmethod() Better Documentation
Reflection and Meta-programming, 212 What is new in Ring 1.1?, 50
Animate Class Better Functions
Game Engine for 2D Games, 354 What is new in Ring 1.2?, 37
Animate Events Better Loop|Exit Command
Game Engine for 2D Games, 365 What is new in Ring 1.3?, 31
Animation Better Natural Language Programming Support
Game Engine for 2D Games, 359 What is new in Ring 1.1?, 42
Animation and Functions Better Quality
Game Engine for 2D Games, 360 What is new in Ring 1.2?, 40
Anonymous and Nested Functions Better Ring Notepad
Functional Programming, 198 What is new in Ring 1.2?, 37
Application Class What is new in Ring 1.3?, 27
Web Development (CGI Library), 319 Better RingQt
Applications What is new in Ring 1.2?, 37
How to contribute?, 57 What is new in Ring 1.3?, 23
Applications developed in little hours Better StdLib
FetchStockData Application, 2 What is new in Ring 1.3?, 31
Fifteen Puzzle Game, 3 binarydigits()
Introduction, 1 Stdlib Functions, 228
Quotes about Ring, 1 Bitwise Operators
Samples in this book, 5 Operators, 79
Squares Puzzle Game, 4 BraceError() Method
Natural Language Programming, 269

826
Ring Documentation, Release 1.3

BraceExprEval Method Command Line Options, 562


Natural Language Programming, 268 Change Focus
BraceStart and BraceEnd Methods Desktop and Mobile Development, 467
Natural Language Programming, 267 Change Language Keywords
Branching Syntax Flexibility, 538
Control Structures, 82 Change Language Operators
Control Structures - Second Style, 89 Syntax Flexibility, 539
Control Structures - Third Style, 92 Change the = operator to is
Building From Source Code Natural Language Programming, 265
Building using CMake, 54 Change the Ring Keyword And
Building using MacOS X, 54 Natural Language Programming, 263
Building using Microsoft Windows, 52 Change the Ring Operator +
Building using Ubuntu Linux, 53 Natural Language Programming, 264
Introduction, 51 changestring()
Building Games For Android Stdlib Functions, 230
Building the project, 401 Char()
Download Requirements and Update the Android Data Type, 127
SDK, 400 ChDir() Function
Introduction, 399 System Functions, 149
Project Folder, 400 Check Character
Building RingQt Applications for Mobile Data Type, 122
Comments about developing for Android using Check Data Type
RingQt, 504 Data Type, 121
Download Requirements, 503 Check Parameters Count
Install Qt for Android, 503 Extension, 578
Introduction, 502 Check Parameters Type
Update the Android SDK, 503 Extension, 579
Building the project Classes and Objects
Building Games For Android, 401 Object Oriented Programming, 183
Building using CMake Classes and their Methods to use the default events
Building From Source Code, 54 Desktop and Mobile Development, 497
Building using MacOS X classes()
Building From Source Code, 54 Reflection and Meta-programming, 206
Building using Microsoft Windows classname()
Building From Source Code, 52 Reflection and Meta-programming, 208
Building using Ubuntu Linux Clean Natural Code
Building From Source Code, 53 Natural Language Programming, 270
Clearerr()
Call Functions Files, 139
Functions, 99 clock()
callgc() Date and Time, 118
Low Level Functions, 564 Close Window Event
Calling a function sharing the name with a method in the RingLibSDL, 346
current class ClosPerSecond()
Scope Rules for Functions and Methods, 536 Date and Time, 118
Can I connect to dbase/harbour database? Code Generator
Frequently Asked Questions, 805 Adding code to the generated code, 591
Can Ring work on Windows XP? Comments in configuration file, 593
Frequently Asked Questions, 807 Configuration file, 589
capitalized() Configuration file for the Allegro library, 594
Stdlib Functions, 222 Configuration Files Examples, 607
cfunctions() Defining Constants, 592
Reflection and Meta-programming, 202 Determine Structure Members Types, 592
CGI Support Enum and Numbers, 593

Index 827

Вам также может понравиться