Skip to content

Commit c7044cd

Browse files
committed
Merge branch 'master' into crypt
2 parents 77aac4f + 756721a commit c7044cd

35 files changed

+725
-43
lines changed

src/boot/actions.reb

+12-12
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ find: action [
208208
series [series! gob! port! bitset! typeset! object! map! none!]
209209
value [any-type!]
210210
/part {Limits the search to a given length or position}
211-
length [number! series! pair!]
211+
range [number! series! pair!]
212212
/only {Treats a series value as only a single value}
213213
/case {Characters are case-sensitive}
214214
/same {Use "same?" as comparator}
@@ -228,7 +228,7 @@ select: action [
228228
series [series! port! map! object! module! none!]
229229
value [any-type!]
230230
/part {Limits the search to a given length or position}
231-
length [number! series! pair!]
231+
range [number! series! pair!]
232232
/only {Treats a series value as only a single value}
233233
/case {Characters are case-sensitive}
234234
/same {Use "same?" as comparator}
@@ -266,8 +266,8 @@ to: action [
266266
copy: action [
267267
{Copies a series, object, or other value.}
268268
value [series! port! map! object! bitset! any-function! error!] {At position}
269-
/part {Limits to a given length or position}
270-
length [number! series! pair!]
269+
/part {Limits to a given length or end position}
270+
range [number! series! pair!]
271271
/deep {Also copies series values within the block}
272272
/types {What datatypes to copy}
273273
kinds [typeset! datatype!]
@@ -277,7 +277,7 @@ take: action [
277277
{Removes and returns one or more elements.}
278278
series [series! port! gob! none!] {At position (modified)}
279279
/part {Specifies a length or end position}
280-
length [number! series! pair!]
280+
range [number! series! pair!]
281281
/deep {Also copies series values within the block}
282282
/last {Take it from the tail end}
283283
]
@@ -295,7 +295,7 @@ insert: action [
295295
series [series! port! map! gob! object! bitset!] {At position (modified)}
296296
value [any-type!] {The value to insert}
297297
/part {Limits to a given length or position}
298-
length [number! series! pair!]
298+
range [number! series! pair!]
299299
/only {Only insert a block as a single value (not the contents of the block)}
300300
/dup {Duplicates the insert a specified number of times}
301301
count [number! pair!]
@@ -306,7 +306,7 @@ append: action [
306306
series [series! port! map! gob! object! bitset!] {Any position (modified)}
307307
value [any-type!] {The value to insert}
308308
/part {Limits to a given length or position}
309-
length [number! series! pair!]
309+
range [number! series! pair!]
310310
/only {Only insert a block as a single value (not the contents of the block)}
311311
/dup {Duplicates the insert a specified number of times}
312312
count [number! pair!]
@@ -316,7 +316,7 @@ remove: action [
316316
{Removes element(s); returns same position.}
317317
series [series! gob! port! bitset! none! map!] {At position (modified)}
318318
/part {Removes multiple elements or to a given position}
319-
length [number! series! pair! char!]
319+
range [number! series! pair! char!]
320320
/key {Removes a key from map.}
321321
key-arg [any-type!]
322322
]
@@ -326,7 +326,7 @@ change: action [
326326
series [series! gob! port! struct!]{At position (modified)}
327327
value [any-type!] {The new value}
328328
/part {Limits the amount to change to a given length or position}
329-
length [number! series! pair!]
329+
range [number! series! pair!]
330330
/only {Only change a block as a single value (not the contents of the block)}
331331
/dup {Duplicates the change a specified number of times}
332332
count [number! pair!]
@@ -365,7 +365,7 @@ reverse: action [
365365
{Reverses the order of elements; returns at same position.}
366366
series [series! gob! tuple! pair!] {At position (modified)}
367367
/part {Limits to a given length or position}
368-
length [number! series!]
368+
range [number! series!]
369369
]
370370

371371
sort: action [
@@ -376,8 +376,8 @@ sort: action [
376376
size [integer!] {Size of each record}
377377
/compare {Comparator offset, block or function}
378378
comparator [integer! block! any-function!]
379-
/part {Sort only part of a series}
380-
length [number! series!] {Length of series to sort}
379+
/part {Limits the sorting to a given length or position}
380+
range [number! series!]
381381
/all {Compare all fields}
382382
/reverse {Reverse sort order}
383383
]

src/core/l-types.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,9 @@ bad_hex: Trap0(RE_INVALID_CHARS);
303303
if (!dig) return 0;
304304
if (*cp == 'E' || *cp == 'e') {
305305
*ep++ = *cp++;
306-
dig = 0;
306+
dig = 1;
307307
if (*cp == '-' || *cp == '+') *ep++ = *cp++;
308-
while (IS_LEX_NUMBER(*cp)) *ep++ = *cp++, dig=1;
309-
if (!dig) return 0;
308+
while (IS_LEX_NUMBER(*cp)) *ep++ = *cp++;
310309
}
311310
if (*cp == '%') {
312311
if (dec_only) return 0;
@@ -372,7 +371,9 @@ bad_hex: Trap0(RE_INVALID_CHARS);
372371
if (len > 19) return 0;
373372

374373
// Convert, check, and return:
374+
errno = 0;
375375
n = CHR_TO_INT(buf);
376+
if (errno != 0) return 0; //overflow
376377
if ((n > 0 && neg) || (n < 0 && !neg)) return 0;
377378
SET_INTEGER(value, n);
378379
return cp;

src/core/t-bitset.c

+12-3
Original file line numberDiff line numberDiff line change
@@ -700,9 +700,18 @@
700700
Trap_Arg(arg);
701701

702702
case A_REMOVE: // #"a" "abc" remove/key bs "abcd"
703-
if (D_REF(ARG_REMOVE_PART)) Trap0(RE_BAD_REFINES);
704-
if (!D_REF(ARG_REMOVE_KEY)) Trap0(RE_MISSING_ARG); // /key required
705-
if (Set_Bits(VAL_SERIES(value), D_ARG(ARG_REMOVE_KEY_ARG), FALSE)) break;
703+
if (D_REF(ARG_REMOVE_KEY)) {
704+
if (D_REF(ARG_REMOVE_PART))
705+
Trap0(RE_BAD_REFINES);
706+
arg = D_ARG(ARG_REMOVE_KEY_ARG);
707+
} else if (D_REF(ARG_REMOVE_PART)) {
708+
arg = D_ARG(ARG_REMOVE_RANGE);
709+
// remove/part is allowed only with block, string, binary and char
710+
if (!(IS_BLOCK(arg) || IS_STRING(arg) || IS_BINARY(arg) || IS_CHAR(arg)))
711+
Trap_Arg(arg);
712+
}
713+
else Trap0(RE_MISSING_ARG); // /key or /part is required
714+
if (Set_Bits(VAL_SERIES(value), arg, FALSE)) break;
706715
Trap_Arg(D_ARG(3));
707716

708717
case A_COPY:

src/core/t-block.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ static struct {
686686
case A_TAKE:
687687
// take/part:
688688
if (D_REF(ARG_TAKE_PART)) {
689-
len = Partial1(value, D_ARG(ARG_TAKE_LENGTH));
689+
len = Partial1(value, D_ARG(ARG_TAKE_RANGE));
690690
if (len == 0) {
691691
zero_blk:
692692
Set_Block(D_RET, Make_Block(0));
@@ -749,7 +749,7 @@ static struct {
749749
args = Find_Refines(ds, ALL_FIND_REFS);
750750
// if (ANY_BLOCK(arg) || args) {
751751
len = ANY_BLOCK(arg) ? VAL_BLK_LEN(arg) : 1;
752-
if (args & AM_FIND_PART) tail = index + Partial1(value, D_ARG(ARG_FIND_LENGTH));
752+
if (args & AM_FIND_PART) tail = index + Partial1(value, D_ARG(ARG_FIND_RANGE));
753753
ret = 1;
754754
if (args & AM_FIND_SKIP) ret = Int32s(D_ARG(ARG_FIND_SIZE), 1);
755755
ret = Find_Block(ser, index, tail, arg, len, args, ret);
@@ -801,7 +801,7 @@ static struct {
801801
case A_COPY: // /PART len /DEEP /TYPES kinds
802802
#if 0
803803
args = D_REF(ARG_COPY_DEEP) ? COPY_ALL : 0;
804-
len = Partial1(value, D_ARG(ARG_COPY_LENGTH));
804+
len = Partial1(value, D_ARG(ARG_COPY_RANGE));
805805
index = (REBINT)VAL_INDEX(value);
806806
// VAL_SERIES(value) = (len > 0) ? Copy_Block_Deep(ser, index, len, args) : Make_Block(0);
807807
VAL_INDEX(value) = 0;
@@ -816,7 +816,7 @@ static struct {
816816
if (IS_DATATYPE(arg)) types |= TYPESET(VAL_DATATYPE(arg));
817817
else types |= VAL_TYPESET(arg);
818818
}
819-
len = Partial1(value, D_ARG(ARG_COPY_LENGTH));
819+
len = Partial1(value, D_ARG(ARG_COPY_RANGE));
820820
VAL_SERIES(value) = Copy_Block_Values(ser, VAL_INDEX(value), VAL_INDEX(value)+len, types);
821821
VAL_INDEX(value) = 0;
822822
}

src/core/t-event.c

+3-5
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,8 @@
379379
value = D_ARG(1);
380380
arg = D_ARG(2);
381381

382-
if (action == A_MAKE) {
383-
// Clone an existing event?
384-
if (IS_EVENT(value)) return R_ARG1;
385-
else if (IS_DATATYPE(value)) {
382+
if (action == A_MAKE || action == A_TO) {
383+
if (IS_EVENT(value) || IS_DATATYPE(value)) {
386384
if (IS_EVENT(arg)) return R_ARG2;
387385
//Trap_Make(REB_EVENT, value);
388386
VAL_SET(D_RET, REB_EVENT);
@@ -392,7 +390,7 @@
392390
is_arg_error:
393391
Trap_Types(RE_EXPECT_VAL, REB_EVENT, VAL_TYPE(arg));
394392

395-
// Initialize GOB from block:
393+
// Initialize event from block:
396394
if (IS_BLOCK(arg)) Set_Event_Vars(D_RET, VAL_BLK_DATA(arg));
397395
else goto is_arg_error;
398396
}

src/core/t-object.c

+5
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,11 @@ static REBSER *Trim_Object(REBSER *obj)
396396
break; // returns obj
397397
}
398398
}
399+
else if (IS_ERROR(value)) {
400+
Make_Error_Object(arg, value); // arg is block/string, returns value
401+
type = 0;
402+
break; // returns value
403+
}
399404
Trap_Make(VAL_TYPE(value), value);
400405

401406
case A_TO:

src/core/t-string.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ static struct {
633633

634634
if (ANY_BINSTR(arg)) len = VAL_LEN(arg);
635635

636-
if (args & AM_FIND_PART) tail = index + Partial(value, 0, D_ARG(ARG_FIND_LENGTH), 0);
636+
if (args & AM_FIND_PART) tail = index + Partial(value, 0, D_ARG(ARG_FIND_RANGE), 0);
637637
ret = 1; // skip size
638638
if (args & AM_FIND_SKIP) {
639639
ret = Partial(value, 0, D_ARG(ARG_FIND_SIZE), 0);

src/include/reb-c.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ enum {
213213
**
214214
***********************************************************************/
215215

216-
#define MAX_INT_LEN 21
216+
#define MAX_INT_LEN 25
217217
#define MAX_HEX_LEN 16
218218

219219
#ifdef ITOA64 // Integer to ascii conversion

src/mezz/mezz-debug.reb

+137
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ REBOL [
33
Title: "REBOL 3 Mezzanine: Debug"
44
Rights: {
55
Copyright 2012 REBOL Technologies
6+
Copyright 2012-2022 Rebol Open Source Contributors
67
REBOL is a trademark of REBOL Technologies
78
}
89
License: {
@@ -15,6 +16,7 @@ dt: delta-time: function [
1516
{Delta-time - returns the time it takes to evaluate the block.}
1617
block [block!]
1718
][
19+
recycle ; force GC, so there is less chance that it is fired in `do block`
1820
start: stats/timer
1921
do block
2022
stats/timer - start
@@ -99,3 +101,138 @@ speed?: function [
99101
]
100102
result
101103
]
104+
105+
;@@ time formating and print table are probably originally made by https://github.com/toomasv
106+
107+
format-time: function [
108+
"Convert a time value to a human readable string"
109+
time [time!]
110+
] [
111+
if time >= 0:00:01 [
112+
return form round/to time 0:0.001
113+
]
114+
units: ["ms" "μs" "ns"]
115+
foreach u units [
116+
time: time * 1000
117+
if time >= 0:00:01 [
118+
time: to integer! round time
119+
return append form time u
120+
]
121+
]
122+
"1ns" ; the lowest time in Rebol
123+
]
124+
125+
print-table: function [
126+
"Print a block of blocks as an ASCII table"
127+
headers [block!]
128+
block [block!]
129+
] [
130+
format: clear []
131+
header: clear []
132+
sep: []
133+
i: 1
134+
unless parse headers [
135+
some [
136+
(text: width: fmt-func: none)
137+
set text string! any [set width integer! | set fmt-func word! | set fmt-func path!]
138+
(
139+
append header sep
140+
append header as-yellow either width [pad text width] [text]
141+
either width [
142+
either fmt-func [
143+
append format compose [(sep) pad (fmt-func) pick block (i) (width)]
144+
] [
145+
append format compose [(sep) pad pick block (i) (width)]
146+
]
147+
] [
148+
either fmt-func [
149+
append format compose [(sep) (fmt-func) pick block (i)]
150+
] [
151+
append format compose [(sep) pick block (i)]
152+
]
153+
]
154+
sep: "|"
155+
i: i + 1
156+
)
157+
]
158+
] [
159+
cause-error "Invalid headers spec"
160+
]
161+
print header
162+
format: func [block] reduce ['print format]
163+
foreach row block [format row]
164+
]
165+
166+
print-horizontal-line: does [
167+
loop -1 + any [query/mode system/ports/output 'window-cols 76][ prin #"-" ] prin lf
168+
]
169+
170+
;@@ profile idea is based on code from https://gist.github.com/giesse/1232d7f71a15a3a8417ec6f091398811
171+
172+
profile: function [
173+
"Profile code"
174+
blocks [block!] "Block of code values (block, word, or function) to profile"
175+
/times "Running the test code multiple times, results are average"
176+
count [integer!] "Default value is 10, minimum is 2 and maximum 1000"
177+
/quiet "Don't print results, return [time evaluations series-made series-expanded memory source] results instead"
178+
][
179+
; limit the number of code runs. There is GC forced between each run, which may be time consuming!
180+
; As the output is counted as an average of each run result, it does not make sense to have too many of them.
181+
count: min max any [count 10] 2 1000
182+
unless quiet [
183+
print ["^/Running" as-green length? blocks "code blocks" as-green count "times."]
184+
print-horizontal-line
185+
]
186+
res: collect [
187+
foreach blk blocks [
188+
case [
189+
block? :blk [code: :blk]
190+
all [word? :blk block? code: get/any :blk][]
191+
code: to block! :blk
192+
]
193+
; to get the most precise results, make a deep copy for each test!
194+
; GC is done in `delta-profile` call.
195+
test: copy/deep :code
196+
data: try [delta-profile :test]
197+
if error? data [
198+
keep/only reduce [0:0:0 0 0 0 0 :blk]
199+
continue
200+
]
201+
loop count - 1 [
202+
test: copy/deep :code
203+
temp: delta-profile :test
204+
foreach [k v] data [ data/(k): v + temp/:k ]
205+
]
206+
keep/only reduce [
207+
data/timer / count
208+
to integer! data/evals / count
209+
to integer! round/ceiling data/series-made / count
210+
to integer! round/ceiling data/series-expanded / count
211+
to integer! data/series-bytes / count
212+
:blk
213+
]
214+
]
215+
]
216+
sort res ; sort by time
217+
either quiet [
218+
new-line/all res on ; return formatted results
219+
][
220+
unless empty? res [
221+
reference: res/1/1
222+
]
223+
fmt-time: function [time] [
224+
if time < 0:00:00.000000001 [return "error"]
225+
rel: time / (max reference 0:00:00.000000001)
226+
ajoin [round/to rel 0.01 "x (" format-time time ")"]
227+
]
228+
print-table [
229+
"Time" 18 fmt-time
230+
"Evals" 6
231+
"S.made" 6
232+
"S.expa" 6
233+
"Memory" 11
234+
"Code" mold/flat
235+
] res
236+
print-horizontal-line
237+
]
238+
]

src/mezz/mezz-save.reb

+2-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ save: function [
113113
file? where [write where data] ; WRITE converts to UTF-8, saves overhead
114114
url? where [write where data] ; But some schemes don't support it
115115
none? where [data] ; just return the UTF-8 binary
116-
'else [append where data] ; string! or binary!, insert data
116+
binary? where [append where data]
117+
'else [append where mold data] ; Using mold when appending data to string!
117118
]
118119
]
119120

0 commit comments

Comments
 (0)