]>
Commit | Line | Data |
---|---|---|
8ff4c670 MG |
1 | #!/usr/bin/perl |
2 | use strict; | |
3 | use warnings; | |
4 | ||
5 | use Test::More tests => 11; | |
6 | BEGIN { use_ok('App::Scheme79asm::Compiler', qw/pretty_print/) }; | |
7 | ||
8 | sub is_sexp { | |
9 | my ($expr, $expected, $name) = @_; | |
10 | is pretty_print($expr), $expected, $name; | |
11 | } | |
12 | ||
13 | sub to_sexp { | |
14 | my ($string) = @_; | |
15 | scalar Data::SExpression->new({fold_lists => 0, use_symbol_class => 1})->read($string) | |
16 | } | |
17 | ||
18 | sub new { | |
19 | App::Scheme79asm::Compiler->new; | |
20 | } | |
21 | ||
22 | sub is_toplevel { | |
23 | my ($string, $expected) = @_; | |
24 | is_sexp new->process_toplevel(to_sexp $string), $expected, "process_toplevel $string"; | |
25 | } | |
26 | ||
27 | is_sexp new->process_quoted(to_sexp '5'), '(symbol 3)', 'process_quoted 5'; | |
28 | is_sexp new->process_quoted(to_sexp '()'), '(list 0)', 'process_quoted ()'; | |
29 | is_sexp new->process_quoted(to_sexp '(5 foo)'), '(list (list (list 0) (symbol 3)) (symbol 4))', 'process_quoted (5 foo)'; | |
30 | is_sexp new->process_quoted(to_sexp '(((5)))'), '(list (list 0) (list (list 0) (list (list 0) (symbol 3))))', 'process_quoted (((5)))'; | |
31 | ||
32 | is_toplevel '(quote 5)', '(symbol 3)'; | |
33 | is_toplevel '(if t \'(2 3) \'x)', '(if (list (symbol 5) (list (list (list 0) (symbol 3)) (symbol 4))) (symbol 2))'; | |
34 | is_toplevel '(car \'(1 2))', '(call (car 0) (list (list (list 0) (symbol 3)) (symbol 4)))'; | |
35 | is_toplevel '(lambda id (x) x)', '(proc (var -2))'; | |
36 | is_toplevel '((lambda id (x) x) 5)', '(call (more (funcall 0) (proc (var -2))) (symbol 3))'; | |
37 | is_toplevel '(lambda append (x y) (if (atom x) y (cons (car x) (append (cdr x) y))))', '(proc (if (list (call (more (cons 0) (call (more (more (funcall 0) (var -1)) (var -2)) (call (cdr 0) (var -3)))) (call (car 0) (var -3))) (var -2)) (call (atom 0) (var -3))))'; |