Skip to content

Instantly share code, notes, and snippets.

@rocky
Last active October 4, 2017 21:30
Show Gist options
  • Save rocky/abc7b8ba12cfe50af32d785a1fdd0261 to your computer and use it in GitHub Desktop.
Save rocky/abc7b8ba12cfe50af32d785a1fdd0261 to your computer and use it in GitHub Desktop.
Amazing emacs decompilation
# preprocessed disassembly. Fake "LABEL" and "COME_FROM" instructions have been added
0 VARREF a
1 VARREF b
2 GTR
3 GOTO-IF-NIL 1
6 VARREF a
7 VARBIND c
8 VARREF b
9 VARSET a
10 VARREF c
11 VARSET b
12 UNBIND 1
13 COME_FROM 3
13 LABEL :1
13:1 VARREF a
14 CONSTANT 0
15 LSS
16 GOTO-IF-NIL 2
19 CONSTANT nil
20 RETURN
21 COME_FROM 16
21 LABEL :2
21:2 VARREF b
22 VARREF a
23 DIFF
24 CONSTANT 0
25 EQLSIGN
26 GOTO-IF-NOT-NIL 3
29 VARREF a
30 CONSTANT 1
31 EQLSIGN
32 GOTO-IF-NIL 4
35 COME_FROM 26
35 LABEL :3
35:3 VARREF a
36 RETURN
37 COME_FROM 32
37 LABEL :4
37:4 CONSTANT gcd
38 VARREF b
39 VARREF a
40 DIFF
41 VARREF a
42 CALL_3 3
43 RETURN
fn_body (2)
0. body
exprs (2)
0. expr_stmt (2)
0. expr
if_expr (5)
0. expr
binary_expr (3)
0. expr
name_expr
0 VARREF a
1. expr
name_expr
1 VARREF b
2. binary_op
2 GTR
1. 3 GOTO-IF-NIL 1
2. expr
let_expr_star (3)
0. varlist
varbind (2)
0. expr
name_expr
6 VARREF a
1. 7 VARBIND c
1. body
exprs (2)
0. expr_stmt (2)
0. expr
setq_expr (2)
0. expr
name_expr
8 VARREF b
1. 9 VARSET a
1. opt_discard
1. expr_stmt (2)
0. expr
setq_expr (2)
0. expr
name_expr
10 VARREF c
1. 11 VARSET b
1. opt_discard
2. 12 UNBIND 1
3. 13 COME_FROM 3
4. 13 LABEL :1
1. opt_discard
1. expr_stmt (2)
0. expr
cond_expr (3)
0. clause (3)
0. condition (4)
0. expr
binary_expr (3)
0. expr
name_expr
13:1 VARREF a
1. expr
name_expr
14 CONSTANT 0
2. binary_op
15 LSS
1. 16 GOTO-IF-NIL 2
2. opt_come_from
3. opt_label
1. body
exprs
expr_stmt (2)
0. expr
name_expr
19 CONSTANT nil
1. opt_discard
2. end_clause (2)
20 RETURN
1. 21 COME_FROM 16
1. labeled_clauses (2)
0. labeled_clauses
labeled_clause (2)
21 LABEL :2
1. clause (3)
0. condition (4)
0. expr
or_expr (5)
0. expr
binary_expr (3)
0. expr
binary_expr (3)
0. expr
name_expr
21:2 VARREF b
1. expr
name_expr
22 VARREF a
2. binary_op
23 DIFF
1. expr
name_expr
24 CONSTANT 0
2. binary_op
25 EQLSIGN
1. 26 GOTO-IF-NOT-NIL 3
2. expr
binary_expr (3)
0. expr
name_expr
29 VARREF a
1. expr
name_expr
30 CONSTANT 1
2. binary_op
31 EQLSIGN
3. opt_come_from
4. opt_label
1. 32 GOTO-IF-NIL 4
2. opt_come_from
35 COME_FROM 26
3. opt_label
35 LABEL :3
1. body
exprs
expr_stmt (2)
0. expr
name_expr
35:3 VARREF a
1. opt_discard
2. end_clause (2)
36 RETURN
1. 37 COME_FROM 32
1. labeled_clause (2)
37 LABEL :4
1. clause (3)
0. opt_label
1. body
exprs
expr_stmt (2)
0. expr
call_exprn (4)
0. expr
name_expr
37:4 CONSTANT gcd
1. expr
binary_expr (3)
0. expr
name_expr
38 VARREF b
1. expr
name_expr
39 VARREF a
2. binary_op
40 DIFF
2. expr
name_expr
41 VARREF a
3. 42 CALL_3 3
1. opt_discard
2. end_clause
43 RETURN
2. opt_label
1. opt_discard
1. opt_return
(defun gcd(a b)
"Greatest Common Divisor of A and B"
(if (> a b)
(let ((c a)
(setq a b)
(setq b c)))
(cond
((< a 0) nil)
((or (= (- b a) 0) (= a 1)) a)
(t (gcd (- b a) a))))
(defun gcd(a b)
"Greatest Common Divisor of A and B"
;; Make a < b
(if (> a b)
(let ((c a))
(setq a b)
(setq b c)))
(cond
((< a 0) nil)
((or (= 0 (- b a)) (= a 1)) a)
(t (gcd (- b a) a))
)
)
# Emacs LAP bytecode for gcd.el
byte code for gcd:
doc-start 34: Greatest Common Divisor of A and B
args: (a b)
0 varref a
1 varref b
2 gtr
3 goto-if-nil 1
6 varref a
7 varbind c
8 varref b
9 varset a
10 varref c
11 varset b
12 unbind 1
13:1 varref a
14 constant 0
15 lss
16 goto-if-nil 2
19 constant nil
20 return
21:2 varref b
22 varref a
23 diff
24 constant 0
25 eqlsign
26 goto-if-not-nil 3
29 varref a
30 constant 1
31 eqlsign
32 goto-if-nil 4
35:3 varref a
36 return
37:4 constant gcd
38 varref b
39 varref a
40 diff
41 varref a
42 call 2
43 return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment