Skip to content

Instantly share code, notes, and snippets.

@hiiamboris
Created June 29, 2021 15:12
Show Gist options
  • Save hiiamboris/731218353cc275c080e2633fca0e68e8 to your computer and use it in GitHub Desktop.
Save hiiamboris/731218353cc275c080e2633fca0e68e8 to your computer and use it in GitHub Desktop.
try/keep crasher
Red []
;--- IRRELEVANT CODE ---
;--- IF IT DOESN'T CRASH TRY DUPLICATING SOME OR REMOVING ----
assert: function [contract [block!]][
set/any [cond msg] reduce contract
unless :cond [
print ["ASSERTION FAILURE:" mold/part contract 100] ;-- limit the output in case we have face trees or images
if none? :msg [set/any 'msg last contract]
if any [any-word? :msg any-path? :msg] [
msg: either function? get/any msg
[ rejoin ["" msg " result is unexpected"] ]
[ rejoin ["" msg " is " mold/part/flat get/any msg 200] ]
]
do make error! form :msg
]
]
do/expand []
prettify: function [
"Reformat CODE with new-lines to look readable"
code [block! paren!] "Modified in place, deeply"
][
new-line/all from: code no ;-- start flat
until [
new-line code yes ;-- add newline before each independent expression
if error? try/all [code: preprocessor/fetch-next code] [code: next code]
tail? code
]
attempt [ ;-- in case it recurses into itself ;)
parse from [any [p:
set w ['print | 'prin] block! if (word? w) ;-- do not mistake words for lit-/get-words
| set w ['function | 'func | 'routine] if (word? w) ;-- do not mistake words for lit-/get-words
ahead block! ( ;-- special case for function spec (not very reliable detection :/ )
new-line/all p/2 no ;-- flatten the spec
unless empty? p/2 [new-line p/2 yes] ;-- expand the spec block
) into [any [p:
all-word! (new-line p yes) ;-- new-lines before argument/refinement names
opt [if (/local == p/1) to end] ;-- stop after /local
| skip
]]
| [block! | paren!] (
new-line p no ;-- disable new-line before block start
prettify p/1 ;-- prettify the inner block/paren
)
| skip
]]
]
from
]
;--- RELEVANT CODE
recycle/on
try [loop 9999 [try/keep [1 / 0]]]
try [loop 9999 [try/keep [1 / 0]]]
try [loop 9999 [try/keep [1 / 0]]]
try [loop 9999 [try/keep [1 / 0]]]
try [loop 9999 [try/keep [1 / 0]]]
@dockimbel
Copy link

Is it compiled or interpreted?

@hiiamboris
Copy link
Author

I only tried interpreted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment