-
Notifications
You must be signed in to change notification settings - Fork 418
Expand file tree
/
Copy pathhandle.reds
More file actions
214 lines (197 loc) · 4.3 KB
/
handle.reds
File metadata and controls
214 lines (197 loc) · 4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
Red/System [
Title: "Handle! datatype runtime functions"
Author: "Nenad Rakocevic, Oldes"
File: %handle.reds
Tabs: 4
Rights: "Copyright (C) 2011-2018 Red Foundation. All rights reserved."
License: {
Distributed under the Boost Software License, Version 1.0.
See https://github.com/red/red/blob/master/BSL-License.txt
}
]
handle: context [
verbose: 0
#enum handle-classes! [
CLASS_NULL ;-- null class (to be removed)
CLASS_FD ;-- file descriptor
CLASS_MONITOR ;-- display monitor handle
CLASS_WINDOW ;-- window handle
CLASS_FONT ;-- font handle
CLASS_RICHTEXT ;-- rich-text handle
]
names: ["null" "fd" "monitor" "window" "font" "rich-text"]
box: func [
value [integer!]
type [integer!]
return: [red-handle!]
][
make-at stack/arguments value type
]
make-in: func [
parent [red-block!]
value [integer!]
type [integer!]
return: [red-handle!]
][
#if debug? = yes [if verbose > 0 [print-line "handle/make-in"]]
make-at ALLOC_TAIL(parent) value type
]
make-at: func [
slot [red-value!]
value [integer!]
type [integer!]
return: [red-handle!]
/local
h [red-handle!]
][
h: as red-handle! slot
h/header: TYPE_HANDLE
h/type: type
h/value: value
h/extID: -1
h
]
push: func [
value [handle!]
type [integer!]
return: [red-handle!]
][
#if debug? = yes [if verbose > 0 [print-line "handle/push"]]
make-at stack/push* as integer! value type
]
push-null: func [return: [red-handle!]][push as handle! 0 CLASS_NULL]
;-- Actions --
form: func [
h [red-handle!]
buffer [red-string!]
arg [red-value!]
part [integer!]
return: [integer!]
/local
formed [c-string!]
][
#if debug? = yes [if verbose > 0 [print-line "handle/form"]]
formed: string/to-hex h/value false
string/concatenate-literal buffer formed
string/append-char GET_BUFFER(buffer) as-integer #"h"
part - 9
]
mold: func [
h [red-handle!]
buffer [red-string!]
only? [logic!]
all? [logic!]
flat? [logic!]
arg [red-value!]
part [integer!]
indent [integer!]
return: [integer!]
/local
type [integer!]
][
#if debug? = yes [if verbose > 0 [print-line "handle/mold"]]
either all? [
string/concatenate-literal buffer "#[handle! "
part: form h buffer arg part
type: h/type
if type > 0 [
string/append-char GET_BUFFER(buffer) as-integer space
string/concatenate-literal buffer as-c-string names/type
part: part + 1 + length? as-c-string names/type
]
string/append-char GET_BUFFER(buffer) as-integer #"]"
part + 11
][
string/concatenate-literal buffer "handle!"
part + 7
]
]
compare: func [
value1 [red-handle!] ;-- first operand
value2 [red-handle!] ;-- second operand
op [integer!] ;-- type of comparison
return: [integer!]
/local
left [integer!]
right [integer!]
][
#if debug? = yes [if verbose > 0 [print-line "handle/compare"]]
if TYPE_OF(value2) <> TYPE_HANDLE [return 1]
SIGN_COMPARE_RESULT(value1/value value2/value)
]
init: does [
names: names + 1 ;-- make this array 0-based
datatype/register [
TYPE_HANDLE
TYPE_INTEGER
"handle!"
;-- General actions --
null ;make
null ;random
null ;reflect
null ;to
:form
:mold
null ;eval-path
null ;set-path
:compare
;-- Scalar actions --
null ;absolute
null ;add
null ;divide
null ;multiply
null ;negate
null ;power
null ;remainder
null ;round
null ;subtract
null ;even?
null ;odd?
;-- Bitwise actions --
null ;and~
null ;complement
null ;or~
null ;xor~
;-- Series actions --
null ;append
null ;at
null ;back
null ;change
null ;clear
null ;copy
null ;find
null ;head
null ;head?
null ;index?
null ;insert
null ;length?
null ;move
null ;next
null ;pick
null ;poke
null ;put
null ;remove
null ;reverse
null ;select
null ;sort
null ;skip
null ;swap
null ;tail
null ;tail?
null ;take
null ;trim
;-- I/O actions --
null ;create
null ;close
null ;delete
null ;modify
null ;open
null ;open?
null ;query
null ;read
null ;rename
null ;update
null ;write
]
]
]