heist 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. data/History.txt +12 -0
  2. data/{README.txt → README.rdoc} +131 -148
  3. data/bin/heist +35 -10
  4. data/lib/heist.rb +3 -3
  5. data/lib/heist/builtin/compiled_library.rb +1 -0
  6. data/lib/heist/builtin/lib/character.scm +74 -0
  7. data/lib/heist/builtin/lib/list.scm +149 -0
  8. data/lib/heist/builtin/lib/logic.scm +17 -0
  9. data/lib/heist/builtin/lib/numeric.scm +184 -0
  10. data/lib/heist/builtin/lib/string.scm +117 -0
  11. data/lib/heist/builtin/lib/util.scm +18 -0
  12. data/lib/heist/builtin/lib/vector.scm +27 -0
  13. data/lib/{builtin → heist/builtin}/primitives.rb +0 -0
  14. data/lib/{builtin → heist/builtin}/syntax.scm +52 -52
  15. data/lib/{parser → heist/parser}/nodes.rb +0 -0
  16. data/lib/{parser → heist/parser}/ruby.rb +0 -0
  17. data/lib/{parser → heist/parser}/scheme.rb +0 -0
  18. data/lib/{parser → heist/parser}/scheme.tt +0 -0
  19. data/lib/{repl.rb → heist/repl.rb} +0 -0
  20. data/lib/{runtime → heist/runtime}/binding.rb +5 -0
  21. data/lib/{runtime → heist/runtime}/callable/continuation.rb +6 -1
  22. data/lib/{runtime → heist/runtime}/callable/function.rb +0 -0
  23. data/lib/{runtime → heist/runtime}/callable/macro.rb +1 -1
  24. data/lib/{runtime → heist/runtime}/callable/macro/expansion.rb +0 -0
  25. data/lib/{runtime → heist/runtime}/callable/macro/matches.rb +0 -0
  26. data/lib/{runtime → heist/runtime}/callable/macro/tree.rb +0 -0
  27. data/lib/{runtime → heist/runtime}/callable/syntax.rb +0 -0
  28. data/lib/{runtime → heist/runtime}/data/character.rb +0 -0
  29. data/lib/{runtime → heist/runtime}/data/cons.rb +0 -0
  30. data/lib/{runtime → heist/runtime}/data/expression.rb +0 -0
  31. data/lib/{runtime → heist/runtime}/data/identifier.rb +0 -0
  32. data/lib/heist/runtime/data/value.rb +14 -0
  33. data/lib/{runtime → heist/runtime}/data/vector.rb +0 -0
  34. data/lib/{runtime → heist/runtime}/frame.rb +3 -0
  35. data/lib/{runtime → heist/runtime}/runtime.rb +2 -2
  36. data/lib/{runtime → heist/runtime}/scope.rb +0 -0
  37. data/lib/{runtime → heist/runtime}/stack.rb +0 -0
  38. data/lib/{runtime → heist/runtime}/stackless.rb +0 -0
  39. data/lib/{stdlib → heist/stdlib}/benchmark.scm +0 -0
  40. data/lib/{stdlib → heist/stdlib}/birdhouse.scm +0 -0
  41. data/lib/{trie.rb → heist/trie.rb} +0 -0
  42. data/spec/heist_spec.rb +88 -0
  43. data/{test → spec}/helpers/lib.scm +0 -0
  44. data/{test → spec}/helpers/macro-helpers.scm +0 -0
  45. data/{test → spec}/helpers/vars.scm +0 -0
  46. data/{test → spec}/plt-macros.txt +0 -0
  47. data/{test → spec}/scheme_tests/arithmetic.scm +0 -0
  48. data/{test → spec}/scheme_tests/benchmarks.scm +0 -0
  49. data/{test → spec}/scheme_tests/booleans.scm +0 -0
  50. data/{test → spec}/scheme_tests/closures.scm +0 -0
  51. data/{test → spec}/scheme_tests/conditionals.scm +0 -0
  52. data/{test → spec}/scheme_tests/continuations.scm +14 -1
  53. data/{test → spec}/scheme_tests/define_functions.scm +0 -0
  54. data/{test → spec}/scheme_tests/define_values.scm +0 -0
  55. data/{test → spec}/scheme_tests/delay.scm +0 -0
  56. data/{test → spec}/scheme_tests/equivalence.scm +0 -0
  57. data/{test → spec}/scheme_tests/file_loading.scm +0 -0
  58. data/{test → spec}/scheme_tests/functional.scm +3 -0
  59. data/{test → spec}/scheme_tests/hygienic.scm +0 -0
  60. data/{test → spec}/scheme_tests/let.scm +0 -0
  61. data/{test → spec}/scheme_tests/lists.scm +0 -0
  62. data/{test → spec}/scheme_tests/macros.scm +0 -0
  63. data/{test → spec}/scheme_tests/numbers.scm +0 -0
  64. data/{test → spec}/scheme_tests/protection.scm +0 -0
  65. data/spec/scheme_tests/quoting.scm +14 -0
  66. data/{test → spec}/scheme_tests/strings.scm +0 -0
  67. data/{test → spec}/scheme_tests/unhygienic.scm +0 -0
  68. data/{test → spec}/scheme_tests/vectors.scm +0 -0
  69. data/spec/spec_helper.rb +4 -0
  70. metadata +98 -113
  71. data/Manifest.txt +0 -64
  72. data/Rakefile +0 -43
  73. data/lib/bin_spec.rb +0 -25
  74. data/lib/builtin/library.rb +0 -1
  75. data/lib/builtin/library.scm +0 -605
  76. data/test/test_heist.rb +0 -148
@@ -1,148 +0,0 @@
1
- $VERBOSE = nil
2
- $dir = File.expand_path(File.dirname(__FILE__))
3
-
4
- $args = ARGV.map { |opt| "-#{opt}" }
5
-
6
- require $dir + "/../lib/heist"
7
- require $dir + "/../lib/bin_spec"
8
- require "test/unit"
9
-
10
- Class.new(Test::Unit::TestCase) do
11
- @env = nil
12
-
13
- def setup
14
- return @env if @env
15
- @env = Heist::Runtime.new(Heist::BIN_SPEC.parse($args))
16
-
17
- puts @env.info unless defined?(@@info_printed)
18
- @@info_printed = true
19
-
20
- @env.define('assert') do |value|
21
- assert(value)
22
- end
23
- @env.define('assert-equal') do |expected, actual|
24
- assert_equal(expected, actual)
25
- end
26
- @env.syntax('assert-raise') do |scope, cells|
27
- exception = Heist.const_get(cells.car.to_s)
28
- assert_raise(exception) { scope.eval(cells.cdr.car) }
29
- end
30
- end
31
-
32
- %w[ booleans
33
- numbers
34
- lists
35
- vectors
36
- strings
37
- equivalence
38
- arithmetic
39
- define_values
40
- define_functions
41
- closures
42
- functional
43
- let
44
- conditionals
45
- file_loading
46
- macros
47
- delay
48
- protection
49
-
50
- ].each do |test|
51
- define_method('test_' + test) do
52
- @env.run($dir + '/scheme_tests/' + test + '.scm')
53
- end
54
- end
55
-
56
- def test_cons
57
- cons = Heist::Runtime::Cons
58
-
59
- empty = cons[[]]
60
- assert empty.list?
61
- assert !empty.pair?
62
- assert_equal cons::NULL, empty
63
- assert_equal 0, empty.length
64
-
65
- single = cons[[4]]
66
- assert single.list?
67
- assert single.pair?
68
- assert_equal 1, single.length
69
-
70
- multi = cons[[2,4,7]]
71
- assert multi.list?
72
- assert multi.pair?
73
- assert_equal 3, multi.length
74
-
75
- multi.tail.cdr = 8
76
- assert multi.pair?
77
- assert !multi.list?
78
- assert_raise(Heist::TypeError) { multi.size }
79
-
80
- nested = cons[[2,4,6,cons.new(7,8)]]
81
- assert nested.list?
82
- assert nested.pair?
83
- assert_equal 4, nested.length
84
- assert !nested.cdr.cdr.cdr.car.list?
85
- assert nested.cdr.cdr.cdr.car.pair?
86
- assert_equal 8, nested.cdr.cdr.cdr.car.cdr
87
- end
88
-
89
- def test_macro_hygiene
90
- @env.run($dir + '/scheme_tests/' + (@env.hygienic? ? 'hygienic' : 'unhygienic') + '.scm')
91
- end
92
-
93
- def test_continuations
94
- return if @env.stackless?
95
- @env.run($dir + '/scheme_tests/continuations.scm')
96
- end
97
-
98
- def test_quotation
99
- cons = Heist::Runtime::Cons
100
- c = cons.method(:new)
101
-
102
- assert_equal 7, @env.eval("(+ 3 4)")
103
- assert_equal [:+, 3, 4], @env.eval("'(+ 3 4)").to_ruby
104
- assert cons === @env.eval("'(+ 3 4)")
105
- assert_equal 7, @env.eval("(+ '3 4)")
106
- assert_equal c[1,8], @env.eval("'(1 . 8)")
107
- assert_equal c[1,8], @env.eval("`(1 . 8)")
108
- assert_equal [:+, [:-, 7, 9], 4], @env.eval("'(+ (- 7 9) 4)").to_ruby
109
- assert_equal [7, 9, 6], @env.eval("`(7 ,(+ 4 5) 6)").to_ruby
110
- assert cons === @env.eval("`(7 ,(+ 4 5) 6)")
111
- assert_equal [3, 7, 6, 2, 6, 9], @env.eval("`(3 7 6 ,@((lambda () '(2 6))) 9)").to_ruby
112
- assert_equal [1, 2, 10], @env.eval("`(1 2 ,(+ 4 6))").to_ruby
113
- assert_equal [3, 2, 9, 8], @env.eval("`(,(/ 9 3) 2 ,@(list 9 8))").to_ruby
114
- assert_equal [1, 2, 4, 9, 8, 5], @env.eval("`(,@(list 1 2) 4 ,@(list 9 8) 5)").to_ruby
115
- assert_equal c[9,c[8,c[5,7]]], @env.eval("`(,@(list 9 8) 5 . 7)")
116
- assert_equal c[9,c[8,24]], @env.eval("`(,@(list 9 8) . ,(* 4 6))")
117
- assert_equal [:quote, []], @env.eval("''()").to_ruby
118
- end
119
-
120
- def test_birdhouse
121
- return unless @env.lazy?
122
- @env.eval('(load "birdhouse")')
123
-
124
- @env.eval <<-CODE
125
- (define factorial (Y
126
- (lambda (rec)
127
- (lambda (x)
128
- (if (= x 0) 1 (* x (rec (- x 1))))))))
129
- CODE
130
- assert_equal (1..6).inject { |a,b| a*b },
131
- @env.eval("(factorial 6)")
132
-
133
- assert_equal 45, @env.eval("((K 45) 6)")
134
- end
135
-
136
- def test_ruby_execution
137
- expr = [[:lambda, [:x], [:+, 1, :x]], 3]
138
- assert_equal 4, @env.exec(expr)
139
- list = Heist.parse(expr)
140
- assert Heist::Runtime::Cons === list
141
- assert_equal expr, list.to_ruby
142
-
143
- cons = Heist::Runtime::Cons.method(:new)
144
- assert_equal cons[3,cons[4,5]], Heist.parse([3, 4, :'.', 5])
145
- assert_equal [3, 4, :'.', 5], cons[3,cons[4,5]].to_ruby
146
- end
147
- end
148
-