Created
December 21, 2021 19:35
-
-
Save dockimbel/3ebf48b58acdb3781c6e8f7adefe2959 to your computer and use it in GitHub Desktop.
Tracing handler for extracting top expressions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Red [] | |
detect: function [ | |
event [word!] | |
code [any-block! none!] | |
offset [integer!] | |
value [any-type!] | |
ref [any-type!] | |
frame [pair!] | |
][ | |
range: [] | |
stack: [] | |
switch event [ | |
set return exit fetch [ | |
if find [set return] event [take/last stack] | |
if empty? stack [ | |
if event = 'exit [append range offset] | |
either 1 >= length? range [append range offset][ | |
if range/1 < range/2 [ | |
code: head code | |
print ["expr:" mold copy/part at code range/1 + 1 range/2 - range/1] | |
] | |
remove range | |
] | |
] | |
] | |
open [append/only stack :value] | |
] | |
] | |
mark-expr: function [code][do/trace :code :detect] | |
mark-expr [print a: 1 b: 3 print either a > 2 [a + 3][a - 1]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment