Created
December 26, 2009 07:47
-
-
Save lsparrish/263874 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
( This is an attempt at creating some rather sophisticated macros ) | |
( using fori/nexti. It does not work yet. ) | |
{{ | |
variable addr | |
: pad ( - ) addr @ @ 6 for dup base @ r pow <if 32 emit then next ; | |
: .wrap ( - ) ." ( " later ." )" ; | |
: .name ( a- ) .wrap d->name type ; | |
: resolve ( - ) last @ repeat dup d->xt @ addr @ @ =if .name ;then 0; @ again ; | |
: token ( "- ) 32 accept tib keepString literal, ; | |
: .op ( a- ) dup getLength swap type 6 swap - 0; for 32 emit next ; | |
: .symbol ( "- ) token ` .op ` drop ; immediate | |
: .value ( - ) addr ++ addr @ @ . pad resolve drop ; | |
: sym: ( "- ) ` over ` =if ` .symbol ` ;then ; immediate | |
: sym+: ( "- ) ` over ` =if ` .symbol ` .value ` ;then ; immediate | |
: .ascii ( c- ) dup 32 128 within if 39 emit emit 39 emit then ; | |
create list 1 , 7 , 8 , 10 , 11 , 12 , 13 , 0 , | |
: member ( n-f ) list getLength fori | |
list + @ over =if pop 2drop TRUE ;then nexti drop FALSE ; | |
: sym? member if ` sym+: ;then ` sym: ; immediate | |
: enum fori literal, sym? nexti ; immediate | |
: decompile ( - ) | |
addr @ @ | |
30 enum nop lit dup drop swap push pop call | |
jump ; >jump <jump !jump =jump | |
@ ! + - * /mod and or xor << >> | |
0; 1+ 1- in out | |
." Unknown: " dup . .ascii | |
; | |
: header? addr @ @ 9 =if addr @ 1+ @ 30 >if addr @ . decompile pop pop 2drop then then ; | |
: vector? addr @ @ 0 =if addr @ 1+ @ 0 =if pop pop 2drop then then ; | |
: more? header? vector? ; | |
---reveal--- | |
: see ( "- ) ' addr ! cr repeat addr @ . decompile cr addr ++ more? again ; | |
}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment