Skip to content

Instantly share code, notes, and snippets.

@dockimbel
Created March 4, 2013 16:13
Show Gist options
  • Save dockimbel/5083357 to your computer and use it in GitHub Desktop.
Save dockimbel/5083357 to your computer and use it in GitHub Desktop.
Show how to achieve R2 source rewriting suitable for evaluation using R3 interpreter.
REBOL [
Author: "Nenad Rakocevic"
Date: 04/03/2013
Purpose: {
Show how to achieve R2 source rewriting suitable for evaluation
using R3 interpreter.
}
]
context [
do*: s: none
path-rewrite: [
some [
s: integer! (if negative? s/1 [s/1: s/1 + 1])
;| handle other indexed-access cases here
| skip
]
]
patched-do: func [value /arg /local saved rule mark][
unless file? :value [return do* value]
saved: system/script/path
change-dir first split-path :value
value: load second split-path :value
parse value rule: [
any [
mark: [path! | set-path! | lit-path!] :mark into path-rewrite
;; | mark: string! :mark into string-rewrite
;; add more rewritting rules here
| mark: any-block! :mark into rule
| skip
]
]
also
do* value
system/script/path: saved
]
set 'do-r3 func [blk [block!]][
do*: :do
set 'do :patched-do
do blk
set 'do :do*
]
]
do-r2 [
do %red/compiler.r
]
save %red.new red
halt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment