You are on page 1of 10

Ring Documentation, Release 1.5.

28 IncLPJump x 18
29 POPExitMark
30 POPStep
31 NewLine 6
32 LoadFuncP test
33 Call 0
34 NoOperation
35 NewLine 8
36 PushV
37 FreeStack
38 ReturnNull
39 Func test
40 NewLine 9
41 FuncExE
42 PushC welcome
43 PushP 007D3670 0
44 PushV
45 SUM 0
46 Print
47 NewLine 10
48 PushPLocal o1 0
49 AssignmentPointer
50 New point
51 SetScope
52 PushV
53 BraceStart
54 LoadA x 0 58
55 AssignmentPointer
56 PushN 10.000000
57 BeforeEqual 0
58 SetProperty 0 106
59 FreeStack
60 LoadA y 0 64
61 AssignmentPointer
62 PushN 20.000000
63 BeforeEqual 0
64 SetProperty 0 141
65 FreeStack
66 LoadA z 0 70
67 AssignmentPointer
68 PushN 30.000000
69 BeforeEqual 0
70 SetProperty 0 176
71 FreeStack
72 LoadFunc ismethod
73 LoadA self 0
74 PushV
75 PushC braceend
76 Call
77 NoOperation
78 PushV
79 JumpZ 85
80 LoadFunc braceend
81 Call
82 NoOperation
83 PushV
84 FreeStack
85 BraceEnd

65.4. Printing Final Intermediate Code 735


Ring Documentation, Release 1.5.4

86 FreeStack
87 NewLine 11
88 FuncExE
89 PushPLocal o1 0
90 PushV
91 Print
92 NewLine 13
93 ReturnNull
94 Class point 007D8470
95 NewLabel
96 LoadA x 0
97 PushV
98 FreeStack
99 LoadA y 0
100 PushV
101 FreeStack
102 LoadA z 0
103 PushV
104 FreeStack
105 ReturnNull
106 LoadFunc ismethod
107 LoadA ring_gettemp_var 0
108 PushV
109 PushC setx
110 Call 0
111 NoOperation
112 PushV
113 JumpZ 132
114 NewLine 2
115 LoadA ring_gettemp_var 0
116 LoadMethod setx
117 LoadA ring_settemp_var 0
118 PushV
119 Call 0 1
120 AfterCallMethod
121 PushV
122 FreeStack
123 NewLine 3
124 LoadA ring_tempflag_var 0 128
125 AssignmentPointer
126 PushN 0.000000
127 BeforeEqual 0
128 Assignment 0 0
129 FreeStack
130 NewLine 4
131 Jump 140
132 NewLine 5
133 PushP 007D37D8 0 137
134 AssignmentPointer
135 PushN 1.000000
136 BeforeEqual 0
137 Assignment 0 0
138 FreeStack
139 NewLine 6
140 Return
141 LoadFunc ismethod
142 LoadA ring_gettemp_var 0
143 PushV

65.4. Printing Final Intermediate Code 736


Ring Documentation, Release 1.5.4

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 737


Ring Documentation, Release 1.5.4

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 it’s very large!

65.8 Performance

Command:

65.5. CGI Support 738


Ring Documentation, Release 1.5.4

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 739


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()

740
Ring Documentation, Release 1.5.4

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 don’t free using the assignment operation.
It’s very rare to need this function but it’s 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 741


Ring Documentation, Release 1.5.4

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 doesn’t 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 742


Ring Documentation, Release 1.5.4

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 743


Ring Documentation, Release 1.5.4

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 744

You might also like