Sunteți pe pagina 1din 10

Ring Documentation, Release 1.

144 PushC sety


145 Call 0
146 NoOperation
147 PushV
148 JumpZ 167
149 NewLine 2
150 LoadA ring_gettemp_var 0
151 LoadMethod sety
152 LoadA ring_settemp_var 0
153 PushV
154 Call 0 1
155 AfterCallMethod
156 PushV
157 FreeStack
158 NewLine 3
159 LoadA ring_tempflag_var 0 163
160 AssignmentPointer
161 PushN 0.000000
162 BeforeEqual 0
163 Assignment 0 0
164 FreeStack
165 NewLine 4
166 Jump 175
167 NewLine 5
168 PushP 007D37D8 0 172
169 AssignmentPointer
170 PushN 1.000000
171 BeforeEqual 0
172 Assignment 0 0
173 FreeStack
174 NewLine 6
175 Return
176 LoadFunc ismethod
177 LoadA ring_gettemp_var 0
178 PushV
179 PushC setz
180 Call 0
181 NoOperation
182 PushV
183 JumpZ 202
184 NewLine 2
185 LoadA ring_gettemp_var 0
186 LoadMethod setz
187 LoadA ring_settemp_var 0
188 PushV
189 Call 0 1
190 AfterCallMethod
191 PushV
192 FreeStack
193 NewLine 3
194 LoadA ring_tempflag_var 0 198
195 AssignmentPointer
196 PushN 0.000000
197 BeforeEqual 0
198 Assignment 0 0
199 FreeStack
200 NewLine 4
201 Jump 210

65.4. Printing Final Intermediate Code 695


Ring Documentation, Release 1.5

202 NewLine 5
203 PushP 007D37D8 0 207
204 AssignmentPointer
205 PushN 1.000000
206 BeforeEqual 0
207 Assignment 0 0
208 FreeStack
209 NewLine 6
210 Return

===================================================

65.5 CGI Support

Command:
ring test.ring -cgi

65.6 No Run

Command:
ring test.ring -norun

65.7 Printing Instruction Operation Code

Command:
ring test.ring -ins

Output:
===================================================

Operation : ReturnNull
PC : 1
Line Number : 1 , File test.ring

SP (After) : 0 - FuncSP : 0
LineNumber 1
===================================================
.....
.....
.....

Tip: Output removed from the previous example because its very large!

65.8 Performance

Command:

65.5. CGI Support 696


Ring Documentation, Release 1.5

ring test.ring -performance

Output:
===================================================
Date : 2015/09/15 Time : 15:56:17
Clock : 0
===================================================
Hello World
1
2
3
4
5
6
7
8
9
10
welcome
x: 10.000000
y: 20.000000
z: 30.000000

===================================================
Date : 2015/09/15 Time : 15:56:17
Clock : 0
===================================================

65.9 Generate Object File

You can generate object file (.ringo) from your source code file (.ring) using -go option

Tip: You will get one object file to use for distributing/running your application which may contains one or many
ring source files that you can keep or distribute based on the application (commercial or open source).

Command:
ring test.ring -go

To run the compiled object file


ring test.ringo

65.9. Generate Object File 697


CHAPTER

SIXTYSIX

LOW LEVEL FUNCTIONS

In this chapter we will learn about the low level functions provided by Ring
callgc()
varptr()
space()
nullpointer()
object2pointer()
pointer2object()
ptrcmp()
ringvm_cfunctionslist()
ringvm_functionslist()
ringvm_classeslist()
ringvm_packageslist()
ringvm_memorylist()
ringvm_calllist()
ringvm_fileslist()
ringvm_settrace()
ringvm_tracedata()
ringvm_traceevent()
ringvm_tracefunc()
ringvm_scopescount()
ringvm_evalinscope()
ringvm_passerror()
ringvm_hideerrorMsg()
ringvm_callfunc()

698
Ring Documentation, Release 1.5

66.1 callgc() function

Use this function to force calling the garbage collector during function execution when you use a loop that create temp.
variables that you dont free using the assignment operation.
Its very rare to need this function but its useful when you create something like event-loop for your game engine and
start creating lists on the fly when you call functions.
Example
While True

# process events
# call functions using temp. lists like myfunc(["temp list"])

# call the garbage collector


callgc()
End

Tip: In Ring the garbage collector works automatically in the end of function execution or when you use the assign-
ment statement.

66.2 varptr() function

Use the varptr() function when you need to pass a pointer to a C/C++ function.
Syntax:
varptr(cVariableName,cPointerType) > Low Level Object (C Pointer)
example:
r = 10
z = 20
see r + nl
see varptr("r","int")
see varptr("z","int")

Output:
10
00E3C740
int
2
00E3BEC0
int
2

Note: the low level object is a list contains three items (The Pointer, The Type, The Status)

66.3 space() function

Use the space function to allocate a specific number of bytes in Memory.

66.1. callgc() function 699


Ring Documentation, Release 1.5

Syntax:
Space(nBytesCount) ---> String

Example:
mystring = space(200)
See "String Size : " + len(mystring) + nl
See "String : " + mystring + nl
See "String Pointer : "
See varptr("mystring","char *")

Output:
String Size : 200
String :
String Pointer : 00FF8FE8
char *
2

Note: You may need the space() and VarPtr() functions to pass buffers to C functions.

66.4 nullpointer() function

You may need to pass the NULL pointer to a C function that may expect a pointer as parameter and accept NULL
pointers for optional parameters.
Example:
The next example uses the SDL_BlitSurface() function from the LibSDL Library through RingSDL The function
accept SDL_Rect pointers in the second and the last parameter. Also the function accept NULL pointers, so we can
pass them using the NULLPointer() Function.
SDL_BlitSurface(text, nullpointer(), surface, nullpointer())

Note: The previous code doesnt work alone, you need to learn how to use RingSDL first.

Tip: We can pass NULL as parameter instead of using NULLPointer()

66.5 object2pointer() function

Use this function to get a C pointer for Ring lists and objects
Syntax:
object2pointer(List|Object) --> Low Level Object ( C Pointer )

66.6 pointer2object() function

Use this function to get the Ring list and/or object from the low level object (C Pointer)

66.4. nullpointer() function 700


Ring Documentation, Release 1.5

Syntax:
pointer2object(Low Level Object) ---> List|Object

Example:
# Create the list
mylist = 1:5

# Create pointer to the list


x = object2pointer(mylist)
see x

see nl

# Add items to the list


mylist + "welcome"

# print the list items


y = pointer2object(x)
see y

Output:
0069A5D8
OBJECTPOINTER
0

1
2
3
4
5
welcome

Note: In Ring the assignment operator copy lists and objects by value, to copy by reference Just use the ob-
ject2pointer() and pointer2object() functions.

Tip: The object2pointer() and pointer2object() are used in the stdlib - Tree Class implementation to create a reference
for the parent node (object) in the child node (another object).

66.7 ptrcmp() function

We can compare between two pointers (C Objects) using the ptrcmp() function.
Syntax:
ptrcmp(oObject1,oObject2) ---> value = 1 if oObject1 = oObject2
value = 0 if oObject1 != oObject2

Example:
fp = fopen("ptrcmp.ring","r")
fp2 = fp
fp3 = fopen("ptrcmp.ring","r")

66.7. ptrcmp() function 701


Ring Documentation, Release 1.5

see ptrcmp(fp,fp2) + nl
see ptrcmp(fp,fp3) + nl

fclose(fp)
fclose(fp3)

Output:
1
0

66.8 ringvm_cfunctionslist() function

The Function return a list of functions written in C.


Syntax:
RingVM_CFunctionsList() ---> List

Example:
See RingVM_CFunctionsList()

66.9 ringvm_functionslist() function

The Function return a list of functions written in Ring.


Each List Member is a list contains the next items
Function Name
Program Counter (PC) - Function Position in Byte Code.
Source Code File Name
Private Flag (For Private Methods in Classes)
Syntax:
RingVM_FunctionsList() ---> List

Example:
test()

func test
see ringvm_functionslist()

Output:
test
8
B:/ring/tests/scripts/functionslist.ring
0

66.8. ringvm_cfunctionslist() function 702


Ring Documentation, Release 1.5

66.10 ringvm_classeslist() function

The Function return a list of Classes.


Each List Member is a list contains the next items
Class Name
Program Counter (PC) - Class Position in Byte Code.
Parent Class Name
Methods List
Flag (Is parent class information collected)
Pointer to the package (or NULL if no package is used)
Syntax:
RingVM_ClassesList() ---> List

Example:
see ringvm_classeslist()

class class1
func f1
class class2 from class1
class class3 from class1

Output:
class1
9

f1
13
B:/ring/tests/scripts/classeslist.ring
0
0
00000000
class2
16
class1
0
00000000
class3
20
class1
0
00000000

66.11 ringvm_packageslist() function

The Function return a list of Packages.


Each List Member is a list contains the next items
Package Name

66.10. ringvm_classeslist() function 703


Ring Documentation, Release 1.5

Classes List
Syntax:
RingVM_PackagesList() ---> List

Example:
see ringvm_packageslist()

package package1
class class1

package package2
class class1

package package3
class class1

Output:
package1
class1
11

0
00FEF838
package2
class1
17

0
00FEF978
package3
class1
23

0
00FEFF68

66.12 ringvm_memorylist() function

The Function return a list of Memory Scopes and Variables.


Each List Member is a list contains variables in a different scope.
Each Item in the scope list is a list contains the next items
Variable Name
Variable Type
Variable Value
Pointer Type (List/Item) if the value is a list
Private Flag (if the variable is an attribute in a Class)
Syntax:

66.12. ringvm_memorylist() function 704

S-ar putea să vă placă și