heist 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/History.txt +21 -0
  2. data/Manifest.txt +53 -0
  3. data/README.txt +274 -0
  4. data/Rakefile +12 -0
  5. data/bin/heist +16 -0
  6. data/lib/bin_spec.rb +25 -0
  7. data/lib/builtin/library.scm +95 -0
  8. data/lib/builtin/primitives.rb +306 -0
  9. data/lib/builtin/syntax.rb +166 -0
  10. data/lib/builtin/syntax.scm +155 -0
  11. data/lib/heist.rb +47 -0
  12. data/lib/parser/nodes.rb +105 -0
  13. data/lib/parser/scheme.rb +1081 -0
  14. data/lib/parser/scheme.tt +80 -0
  15. data/lib/repl.rb +112 -0
  16. data/lib/runtime/binding.rb +31 -0
  17. data/lib/runtime/callable/continuation.rb +24 -0
  18. data/lib/runtime/callable/function.rb +55 -0
  19. data/lib/runtime/callable/macro.rb +170 -0
  20. data/lib/runtime/callable/macro/expansion.rb +15 -0
  21. data/lib/runtime/callable/macro/matches.rb +77 -0
  22. data/lib/runtime/callable/macro/splice.rb +56 -0
  23. data/lib/runtime/data/expression.rb +23 -0
  24. data/lib/runtime/data/identifier.rb +20 -0
  25. data/lib/runtime/data/list.rb +36 -0
  26. data/lib/runtime/frame.rb +118 -0
  27. data/lib/runtime/runtime.rb +61 -0
  28. data/lib/runtime/scope.rb +121 -0
  29. data/lib/runtime/stack.rb +60 -0
  30. data/lib/runtime/stackless.rb +49 -0
  31. data/lib/stdlib/benchmark.scm +12 -0
  32. data/lib/stdlib/birdhouse.scm +82 -0
  33. data/test/arithmetic.scm +57 -0
  34. data/test/benchmarks.scm +27 -0
  35. data/test/booleans.scm +6 -0
  36. data/test/closures.scm +16 -0
  37. data/test/conditionals.scm +55 -0
  38. data/test/continuations.scm +144 -0
  39. data/test/define_functions.scm +27 -0
  40. data/test/define_values.scm +28 -0
  41. data/test/delay.scm +8 -0
  42. data/test/file_loading.scm +9 -0
  43. data/test/hygienic.scm +39 -0
  44. data/test/let.scm +42 -0
  45. data/test/lib.scm +2 -0
  46. data/test/macro-helpers.scm +19 -0
  47. data/test/macros.scm +343 -0
  48. data/test/numbers.scm +19 -0
  49. data/test/plt-macros.txt +40 -0
  50. data/test/test_heist.rb +84 -0
  51. data/test/unhygienic.scm +11 -0
  52. data/test/vars.scm +2 -0
  53. metadata +138 -0
@@ -0,0 +1,19 @@
1
+ (assert (eqv? 42 42))
2
+ (assert (not (eqv? 42 #f)))
3
+ (assert (not (eqv? 42 42.0)))
4
+ (assert (= 42 42))
5
+ (assert (= 42 42.0))
6
+
7
+ (assert (number? 42))
8
+ (assert (not (number? #t)))
9
+ ;(assert (complex? 2+3i))
10
+ ;(assert (not (real? 2+3i)))
11
+ (assert (real? 3.1416))
12
+ (assert (real? 22/7))
13
+ (assert (real? 42))
14
+ ;(assert (not (rational? 2+3i)))
15
+ ;(assert (not (rational? 3.1416)))
16
+ ;(assert (rational? 22/7))
17
+ (assert (not (integer? 22/7)))
18
+ (assert (integer? 42))
19
+
@@ -0,0 +1,40 @@
1
+ This is output from mzscheme REPL on running some convoluted macros
2
+
3
+ > (define-syntax convoluted
4
+ (syntax-rules (with)
5
+ [(_ (with (value ...) ...) ... (obj ...))
6
+ '((obj ((value ...) (value value) ...) ... (obj obj)) ...)]))
7
+
8
+ > (convoluted (with (a u) (j e n k l) () (q c y n)) (with)
9
+ (with (b) (d f)) (with (k l e) (s) (u n) (f i k w) (p))
10
+ (foo bar baz what))
11
+
12
+ ((foo
13
+ ((a u) (a a) (u u))
14
+ ((j e n k l) (j j) (e e) (n n) (k k) (l l))
15
+ (())
16
+ ((q c y n) (q q) (c c) (y y) (n n))
17
+ (foo foo))
18
+ (bar (bar bar))
19
+ (baz ((b) (b b)) ((d f) (d d) (f f)) (baz baz))
20
+ (what
21
+ ((k l e) (k k) (l l) (e e))
22
+ ((s) (s s))
23
+ ((u n) (u u) (n n))
24
+ ((f i k w) (f f) (i i) (k k) (w w))
25
+ ((p) (p p))
26
+ (what what)))
27
+
28
+ > (define-syntax convoluted
29
+ (syntax-rules (with)
30
+ [(_ thing ((name ...) ...) obj ...)
31
+ '((((name name) ... obj obj (obj (name ...))) ...))]))
32
+
33
+ > (convoluted thing ((8 3 2 9) (2 3) (1 0 4) (8 3 2 1 7))
34
+ foo bar baz what)
35
+
36
+ ((((8 8) (3 3) (2 2) (9 9) foo foo (foo (8 3 2 9)))
37
+ ((2 2) (3 3) bar bar (bar (2 3)))
38
+ ((1 1) (0 0) (4 4) baz baz (baz (1 0 4)))
39
+ ((8 8) (3 3) (2 2) (1 1) (7 7) what what (what (8 3 2 1 7)))))
40
+
@@ -0,0 +1,84 @@
1
+ $VERBOSE = nil
2
+ $dir = 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
+ Heist.info(@@env)
17
+
18
+ @@env.define('assert') do |value|
19
+ assert(value)
20
+ end
21
+ @@env.define('assert-equal') do |expected, actual|
22
+ assert_equal(expected, actual)
23
+ end
24
+ @@env.syntax('assert-raise') do |scope, name, expression|
25
+ exception = Heist.const_get(name.to_s)
26
+ assert_raise(exception) { @@env.eval(expression) }
27
+ end
28
+ end
29
+
30
+ %w[ booleans
31
+ numbers
32
+ arithmetic
33
+ define_values
34
+ define_functions
35
+ closures
36
+ let
37
+ conditionals
38
+ file_loading
39
+ macros
40
+ delay
41
+
42
+ ].each do |test|
43
+ define_method('test_' + test) do
44
+ @@env.run($dir + '/' + test)
45
+ end
46
+ end
47
+
48
+ def test_macro_hygiene
49
+ @@env.run($dir + '/' + (@@env.hygienic? ? 'hygienic' : 'unhygienic'))
50
+ end
51
+
52
+ def test_continuations
53
+ return if @@env.stackless?
54
+ @@env.run($dir + '/continuations')
55
+ end
56
+
57
+ def test_quotes
58
+ assert_equal 7, @@env.eval("(+ 3 4)")
59
+ assert_equal [:+, 3, 4], @@env.eval("'(+ 3 4)").to_a
60
+ assert Heist::Runtime::List === @@env.eval("'(+ 3 4)")
61
+ assert_equal 7, @@env.eval("(+ '3 4)")
62
+ assert_equal [:+, [:-, 7, 9], 4], @@env.eval("'(+ (- 7 9) 4)").to_a
63
+ assert_equal [7, 9, 6], @@env.eval("`(7 ,(+ 4 5) 6)").to_a
64
+ assert Heist::Runtime::List === @@env.eval("`(7 ,(+ 4 5) 6)")
65
+ assert_equal [3, 7, 6, 2, 6, 9], @@env.eval("`(3 7 6 ,@((lambda () '(2 6))) 9)").to_a
66
+ end
67
+
68
+ def test_birds
69
+ return unless @@env.lazy?
70
+ @@env.eval('(load "birdhouse")')
71
+
72
+ @@env.eval <<-CODE
73
+ (define factorial (Y
74
+ (lambda (rec)
75
+ (lambda (x)
76
+ (if (= x 0) 1 (* x (rec (- x 1))))))))
77
+ CODE
78
+ assert_equal (1..6).inject { |a,b| a*b },
79
+ @@env.eval("(factorial 6)")
80
+
81
+ assert_equal 45, @@env.eval("((K 45) 6)")
82
+ end
83
+ end
84
+
@@ -0,0 +1,11 @@
1
+ (load "macro-helpers")
2
+
3
+ (assert-equal 4 (let ([first 9])
4
+ (square-sum 1 first)))
5
+
6
+ (let ([temp 5]
7
+ [other 6])
8
+ (swap temp other) ; (let ([temp temp])
9
+ (assert-equal 5 temp) ; (set! temp other)
10
+ (assert-equal 6 other)) ; (set! other temp))
11
+
@@ -0,0 +1,2 @@
1
+ (define alpha 1/137)
2
+
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: heist
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Coglan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-02-24 00:00:00 +00:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: oyster
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: treetop
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: hoe
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.8.2
44
+ version:
45
+ description: ""
46
+ email:
47
+ - jcoglan@googlemail.com
48
+ executables:
49
+ - heist
50
+ extensions: []
51
+
52
+ extra_rdoc_files:
53
+ - History.txt
54
+ - Manifest.txt
55
+ - README.txt
56
+ - test/plt-macros.txt
57
+ files:
58
+ - History.txt
59
+ - Manifest.txt
60
+ - README.txt
61
+ - Rakefile
62
+ - bin/heist
63
+ - lib/heist.rb
64
+ - lib/bin_spec.rb
65
+ - lib/repl.rb
66
+ - lib/builtin/primitives.rb
67
+ - lib/builtin/syntax.rb
68
+ - lib/builtin/syntax.scm
69
+ - lib/builtin/library.scm
70
+ - lib/parser/scheme.tt
71
+ - lib/parser/scheme.rb
72
+ - lib/parser/nodes.rb
73
+ - lib/runtime/runtime.rb
74
+ - lib/runtime/data/expression.rb
75
+ - lib/runtime/data/identifier.rb
76
+ - lib/runtime/data/list.rb
77
+ - lib/runtime/callable/function.rb
78
+ - lib/runtime/callable/macro.rb
79
+ - lib/runtime/callable/macro/matches.rb
80
+ - lib/runtime/callable/macro/splice.rb
81
+ - lib/runtime/callable/macro/expansion.rb
82
+ - lib/runtime/callable/continuation.rb
83
+ - lib/runtime/stack.rb
84
+ - lib/runtime/stackless.rb
85
+ - lib/runtime/frame.rb
86
+ - lib/runtime/scope.rb
87
+ - lib/runtime/binding.rb
88
+ - lib/stdlib/benchmark.scm
89
+ - lib/stdlib/birdhouse.scm
90
+ - test/test_heist.rb
91
+ - test/arithmetic.scm
92
+ - test/benchmarks.scm
93
+ - test/booleans.scm
94
+ - test/closures.scm
95
+ - test/conditionals.scm
96
+ - test/continuations.scm
97
+ - test/define_functions.scm
98
+ - test/define_values.scm
99
+ - test/delay.scm
100
+ - test/file_loading.scm
101
+ - test/let.scm
102
+ - test/lib.scm
103
+ - test/macro-helpers.scm
104
+ - test/macros.scm
105
+ - test/hygienic.scm
106
+ - test/unhygienic.scm
107
+ - test/plt-macros.txt
108
+ - test/numbers.scm
109
+ - test/vars.scm
110
+ has_rdoc: true
111
+ homepage: Heist is a Scheme interpreter written in Ruby. It provides an executable
112
+ post_install_message:
113
+ rdoc_options:
114
+ - --main
115
+ - README.txt
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: "0"
123
+ version:
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: "0"
129
+ version:
130
+ requirements: []
131
+
132
+ rubyforge_project: heist
133
+ rubygems_version: 1.3.1
134
+ signing_key:
135
+ specification_version: 2
136
+ summary: ""
137
+ test_files:
138
+ - test/test_heist.rb