Skip to content

Instantly share code, notes, and snippets.

@qtxie
Last active February 8, 2021 03:45
Show Gist options
  • Save qtxie/e321ac4d1c737fc6e5d843f67cbb7de4 to your computer and use it in GitHub Desktop.
Save qtxie/e321ac4d1c737fc6e5d843f67cbb7de4 to your computer and use it in GitHub Desktop.
REBOL []
Red []
do {
src: [
#switch OS [
Windows [#define LIBREDRT-file "libRedRT.dll"]
macOS [#define LIBREDRT-file "libRedRT.dylib"]
#default [#define LIBREDRT-file "libRedRT.so"]
]
print LIBREDRT-file
]
defs: make block! 100
insert defs <no-match>
stack: append/only clear [] make block! 100
append stack/1 1 ;-- insert root header starting size
header: none
check-condition: func [type [word!] payload [block!]][
case [
type = 'switch [
any [
select payload/2 'Windows
select payload/2 #default
]
]
payload/2 = 'contains [
do bind/copy
compose/deep [all [(payload/1) find (payload/1) (payload/3)]]
job
]
'else [do bind/copy payload job]
]
]
rule-blk: [
some [
defs
| s: #define set name word! (args: none) [
set args paren! set value [block! | paren!]
| set value skip
] e: (
print [mold name #":" mold value]
if word? value [value: to lit-word! value]
rule: copy/deep [s: _ e: (e: change/part s _ e) :s]
rule/4/4: :value
rule/2: to lit-word! name
either tag? defs/1 [remove defs][append defs '|]
append defs rule
remove/part s e
) :s
| s: #switch set name word! set cases block! e: (
either body: check-condition 'switch reduce [name cases][
change/part s body e
][
remove/part s e
]
) :s
| s: (if any [block? s/1 paren? s/1][append/only stack copy [1]])
p: [block! | paren!] :p into blk
s: (
if any [block? s/-1 paren? s/-1][
header: last stack
change header length? header ;-- update header size
s/-1: insert copy s/-1 header ;-- insert hidden header
remove back tail stack
]
)
| skip
]
]
}
either Rebol [
parse/all/case src rule-blk
][
parse/case src rule-blk
]
?? src
halt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment