Skip to content

Commit

Permalink
CHANGE: when using block as a query field, get-words are required t…
Browse files Browse the repository at this point in the history
…o get just the value

related to: Oldes/Rebol-issues#2607
  • Loading branch information
Oldes committed Jul 19, 2024
1 parent cd8df5c commit 4e052bc
Show file tree
Hide file tree
Showing 17 changed files with 82 additions and 45 deletions.
2 changes: 1 addition & 1 deletion src/core/c-frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,7 @@
*/ REBSER* Get_Object_Words(REBVAL *object)
/*
** Returns block of object's words converted to simple word (not set-word)
** Note: used in query/mode function to return default modes
** Note: used in query function to return default modes
**
***********************************************************************/
{
Expand Down
5 changes: 3 additions & 2 deletions src/core/p-console.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,11 @@
REBVAL *word = VAL_BLK_DATA(info);
for (; NOT_END(word); word++) {
if (ANY_WORD(word)) {
if (IS_SET_WORD(word)) {
// keep the set-word in result
if (!IS_GET_WORD(word)) {
// keep the word as a key (converted to the set-word) in the result
val = Append_Value(values);
*val = *word;
VAL_TYPE(val) = REB_SET_WORD;
VAL_SET_LINE(val);
}
val = Append_Value(values);
Expand Down
11 changes: 6 additions & 5 deletions src/core/p-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,21 +170,22 @@
Trap1(RE_INVALID_ARG, info);
} else if (IS_BLOCK(info)) {
// example:
// query/mode file [type size] ;== [file 1234]
// query file [:type :size] ;== [file 1234]
// or:
// query/mode file [type: size:] ;== [type: file size: 1234]
// query file [type size] ;== [type: file size: 1234]
// or combined:
// query/mode file [type: size] ;== [type: file 1234]
// query file [type: :size] ;== [type: file 1234]
// When not supported word is used, if will throw an error

REBSER *values = Make_Block(2 * BLK_LEN(VAL_SERIES(info)));
REBVAL *word = VAL_BLK_DATA(info);
for (; NOT_END(word); word++) {
if(ANY_WORD(word)) {
if (IS_SET_WORD(word)) {
// keep the set-word in result
if (!IS_GET_WORD(word)) {
// keep the word as a key (converted to the set-word) in the result
val = Append_Value(values);
*val = *word;
VAL_TYPE(val) = REB_SET_WORD;
VAL_SET_LINE(val);
}
val = Append_Value(values);
Expand Down
5 changes: 3 additions & 2 deletions src/core/p-midi.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,11 @@
REBVAL *word = VAL_BLK_DATA(field);
for (; NOT_END(word); word++) {
if (ANY_WORD(word)) {
if (IS_SET_WORD(word)) {
// keep the set-word in result
if (!IS_GET_WORD(word)) {
// keep the word as a key (converted to the set-word) in the result
val = Append_Value(values);
*val = *word;
VAL_TYPE(val) = REB_SET_WORD;
VAL_SET_LINE(val);
}
val = Append_Value(values);
Expand Down
11 changes: 6 additions & 5 deletions src/core/p-net.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,22 @@ enum Transport_Types {
}
else if (IS_BLOCK(info)) {
// example:
// query/mode port [remote-ip remote-port] ;== [127.0.0.1 1234]
// query port [:remote-ip :remote-port] ;== [127.0.0.1 1234]
// or:
// query/mode port [remote-ip: remote-port:] ;== [remote-ip: 127.0.0.1 remote-port: 1234]
// query port [remote-ip remote-port] ;== [remote-ip: 127.0.0.1 remote-port: 1234]
// or combined:
// query/mode file [remote-ip: remote-port] ;== [remote-ip: 127.0.0.1 1234]
// query file [remote-ip: :remote-port] ;== [remote-ip: 127.0.0.1 1234]
// When not supported word is used, if will throw an error

REBSER *values = Make_Block(2 * BLK_LEN(VAL_SERIES(info)));
REBVAL *word = VAL_BLK_DATA(info);
for (; NOT_END(word); word++) {
if (ANY_WORD(word)) {
if (IS_SET_WORD(word)) {
// keep the set-word in result
if (!IS_GET_WORD(word)) {
// keep the word as a key (converted to the set-word) in the result
val = Append_Value(values);
*val = *word;
VAL_TYPE(val) = REB_SET_WORD;
VAL_SET_LINE(val);
}
val = Append_Value(values);
Expand Down
7 changes: 4 additions & 3 deletions src/core/t-date.c
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@ static const REBI64 DAYS_OF_JAN_1ST_1970 = 719468; // number of days for 1st Jan
case A_QUERY:
spec = Get_System(SYS_STANDARD, STD_DATE_INFO);
if (!IS_OBJECT(spec)) Trap_Arg(spec);
REBVAL *field = D_ARG(3);
REBVAL *field = D_ARG(ARG_QUERY_FIELD);
if(IS_WORD(field)) {
switch(VAL_WORD_CANON(field)) {
case SYM_WORDS:
Expand All @@ -1067,10 +1067,11 @@ static const REBI64 DAYS_OF_JAN_1ST_1970 = 719468; // number of days for 1st Jan
REBVAL *word = VAL_BLK_DATA(field);
for (; NOT_END(word); word++) {
if (ANY_WORD(word)) {
if (IS_SET_WORD(word)) {
// keep the set-word in result
if (!IS_GET_WORD(word)) {
// keep the word as a key (converted to the set-word) in the result
out = Append_Value(values);
*out = *word;
VAL_TYPE(out) = REB_SET_WORD;
VAL_SET_LINE(out);
}
out = Append_Value(values);
Expand Down
5 changes: 3 additions & 2 deletions src/core/t-handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ extern void RXI_To_Value(REBVAL *val, RXIARG arg, REBCNT type); // f-extension.c
//TODO: this code could be made resusable with other types!
spec = Get_System(SYS_STANDARD, STD_HANDLE_INFO);
if (!IS_OBJECT(spec)) Trap_Arg(spec);
REBVAL *field = D_ARG(3);
REBVAL *field = D_ARG(ARG_QUERY_FIELD);
if (IS_WORD(field)) {
switch (VAL_WORD_CANON(field)) {
case SYM_WORDS:
Expand All @@ -198,10 +198,11 @@ extern void RXI_To_Value(REBVAL *val, RXIARG arg, REBCNT type); // f-extension.c
REBVAL *word = VAL_BLK_DATA(field);
for (; NOT_END(word); word++) {
if (ANY_WORD(word)) {
if (IS_SET_WORD(word)) {
if (!IS_GET_WORD(word)) {
// keep the set-word in result
out = Append_Value(values);
*out = *word;
VAL_TYPE(out) = REB_SET_WORD;
VAL_SET_LINE(out);
}
out = Append_Value(values);
Expand Down
5 changes: 3 additions & 2 deletions src/core/t-vector.c
Original file line number Diff line number Diff line change
Expand Up @@ -842,10 +842,11 @@ static void reverse_vector(REBVAL *value, REBCNT len)
REBVAL *word = VAL_BLK_DATA(field);
for (; NOT_END(word); word++) {
if (ANY_WORD(word)) {
if (IS_SET_WORD(word)) {
// keep the set-word in result
if (!IS_GET_WORD(word)) {
// keep the word as a key (converted to the set-word) in the result
val = Append_Value(values);
*val = *word;
VAL_TYPE(val) = REB_SET_WORD;
VAL_SET_LINE(val);
}
val = Append_Value(values);
Expand Down
2 changes: 1 addition & 1 deletion src/mezz/mezz-files.reb
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ list-dir: closure/with [
value depth
/local info date time size
][
info: query value [name size date]
info: query value [:name :size :date]
unless info [
return ajoin [
"^[[1;35m *** Invalid symbolic link: ^[[0;35m"
Expand Down
2 changes: 1 addition & 1 deletion src/mezz/prot-tls.reb
Original file line number Diff line number Diff line change
Expand Up @@ -2035,7 +2035,7 @@ TLS-server-awake: func [event /local port info serv] [
accept [
serv: event/port
port: first serv
info: query port [remote-ip: remote-port:]
info: query port [remote-ip remote-port]
;? info
;? serv
port/extra: make TLS-context [
Expand Down
6 changes: 3 additions & 3 deletions src/modules/httpd.reb
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ sys/make-scheme [
return Actor/On-List-Dir ctx target
]
]
info: query path [modified: size:]
info: query path [modified size]
; prepare modified date of the target
modified: info/modified
modified/timezone: 0 ; converted to UTC
Expand Down Expand Up @@ -417,7 +417,7 @@ sys/make-scheme [
append files dirs

foreach file files [
set [size date] query/mode dir/:file [size date]
set [size date] query dir/:file [:size :date]
append out ajoin [
{<a href="} file {">} file {</a> }
pad copy "" 50 - length? file
Expand Down Expand Up @@ -846,7 +846,7 @@ sys/make-scheme [

New-Client: func[port [port!] /local client info err][
client: first port
info: query client [remote-ip: remote-port:]
info: query client [remote-ip remote-port]
unless Actor/On-Accept info [
; connection not allowed
log-more ["Client not accepted:^[[22m" info/remote-ip]
Expand Down
2 changes: 1 addition & 1 deletion src/tests/test-midi.r3
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Rebol [
Needs: 3.11.0
]

midi: query midi:// [devices-in: devices-out:]
midi: query midi:// [devices-in devices-out]
unless block? midi [ print as-purple "No MIDI available!" quit]

print [as-yellow "Input devices: " length? midi/devices-in]
Expand Down
2 changes: 1 addition & 1 deletion src/tests/test-raw-tcp-read.r3
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ wp/awake: func [event /local port] [
read [print ["^/read:" length? port/data] read port]
wrote [read port]
lookup [
print query port [remote-ip: remote-port:]
print query port [remote-ip remote-port]
open port
]
connect [write port http-request]
Expand Down
38 changes: 34 additions & 4 deletions src/tests/units/date-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -358,13 +358,43 @@ Rebol [
all-date-words: words-of system/standard/date-info
--assert all-date-words = query date none
--assert date/time = query date 'time
--assert [2020 4] = query date [year month]
--assert [month: 4 year: 2020] = query date [month: year:]
--assert equal? query date all-date-words [2020 4 8 12:04:32 8-Apr-2020 2:00 12 4 32 3 99 2:00 8-Apr-2020/10:04:32 2458947.91981481]
--assert [2020 4] = query date [:year :month]
--assert [month: 4 year: 2020] = query date [month year]
--assert equal? query date all-date-words [
year: 2020
month: 4
day: 8
time: 12:04:32
date: 8-Apr-2020
zone: 2:00
hour: 12
minute: 4
second: 32
weekday: 3
yearday: 99
timezone: 2:00
utc: 8-Apr-2020/10:04:32
julian: 2458947.91981481
]

--test-- "query date"
date: 8-Apr-2020 ; no time!
--assert equal? query date all-date-words [2020 4 8 #(none) 2020-04-08 #(none) #(none) #(none) #(none) 3 99 #(none) 2020-04-08 2458948.0]
--assert equal? query date all-date-words [
year: 2020
month: 4
day: 8
time: #(none)
date: 8-Apr-2020
zone: #(none)
hour: #(none)
minute: #(none)
second: #(none)
weekday: 3
yearday: 99
timezone: #(none)
utc: 8-Apr-2020
julian: 2458948.0
]

===end-group===

Expand Down
2 changes: 1 addition & 1 deletion src/tests/units/file-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ if find [Linux macOS] system/platform [
===start-group=== "QUERY"
--test-- "query dates"
write %query-test "test"
probe fields: [modified created accessed]
fields: [:modified :created :accessed]
--assert all [
block? probe dates1: query %query-test fields
date? dates1/1
Expand Down
14 changes: 7 additions & 7 deletions src/tests/units/port-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ if system/platform = 'Windows [
--assert 'file = query file 'type
--assert date? query file 'modified
--assert 51732 = query file 'size
--assert [file 51732] = query file [type size]
--assert [type: file size: 51732] = query file [type: size:]
--assert [file 51732] = query file [:type :size]
--assert [type: file size: 51732] = query file [type size]

--test-- "query file name"
;@@ https://github.com/Oldes/Rebol-issues/issues/2442
Expand All @@ -250,8 +250,8 @@ if system/platform = 'Windows [
--assert 'file = query file 'type
--assert date? query file 'modified
--assert 51732 = query file 'size
--assert [file 51732] = query file [type size]
--assert [type: file size: 51732] = query file [type: size:]
--assert [file 51732] = query file [:type :size]
--assert [type: file size: 51732] = query file [type size]
close file

--test-- "write/lines"
Expand Down Expand Up @@ -695,7 +695,7 @@ if all [
--assert (words-of system/standard/console-info)
= m: query system/ports/input none
--assert block? v: query system/ports/input m
--assert 4 = length? v
--assert 8 = length? v
===end-group===
]

Expand Down Expand Up @@ -733,8 +733,8 @@ if all [
--assert all [
port? wait [port 1] ;= wait for lookup, so remote-ip is resolved
8.8.8.8 = query port 'remote-ip
[80 8.8.8.8] = query port [remote-port remote-ip]
[local-ip: 0.0.0.0 local-port: 0] = query port [local-ip: local-port:]
[80 8.8.8.8] = query port [:remote-port :remote-ip]
[local-ip: 0.0.0.0 local-port: 0] = query port [local-ip local-port]
]
try [close port]
===end-group===
Expand Down
8 changes: 4 additions & 4 deletions src/tests/units/vector-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ Rebol [
3 4
]}

--test-- "QUERY on vector"
--test-- "QUERY on vector as object"
;@@ https://github.com/Oldes/Rebol-issues/issues/2352
v: make vector! [unsigned integer! 16 2]
o: query v object!
Expand All @@ -167,10 +167,10 @@ Rebol [
--assert o/type = 'integer!
--assert o/size = 16
--assert o/length = 2
--test-- "QUERY/MODE on vector"
--test-- "QUERY on vector"
--assert [signed type size length] = query v none
--assert [16 integer!] = query v [size type]
--assert block? b: query v [signed: length:]
--assert [16 integer!] = query v [:size :type]
--assert block? b: query v [signed length]
--assert all [not b/signed b/length = 2]
--assert 16 = query v 'size
--assert 16 = size? v
Expand Down

0 comments on commit 4e052bc

Please sign in to comment.