flea 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/build.yml +30 -0
  3. data/.gitignore +3 -0
  4. data/.rspec +2 -0
  5. data/.rubocop.yml +30 -0
  6. data/Gemfile +5 -0
  7. data/Gemfile.lock +65 -0
  8. data/MIT-LICENSE +1 -1
  9. data/README.md +345 -0
  10. data/bin/flea +17 -15
  11. data/flea-language-spec/{README.rdoc → README.md} +2 -2
  12. data/flea-language-spec/test-cases/01-display-and-basic-literals/05-display-list-literal-using-quote.scm +1 -1
  13. data/flea-language-spec/test-cases/02-variables/05-define-with-list.scm +1 -1
  14. data/flea-language-spec/test-cases/04-quoting/01-quoting.scm +5 -0
  15. data/flea.gemspec +34 -0
  16. data/lib/flea/environment.rb +20 -18
  17. data/lib/flea/interpreter.rb +44 -44
  18. data/lib/flea/standard_library/display.scm +7 -1
  19. data/lib/flea/standard_library/null.scm +1 -1
  20. data/lib/flea/standard_library/read.scm +1 -1
  21. data/lib/flea/version.rb +5 -0
  22. data/lib/flea.rb +6 -4
  23. metadata +110 -138
  24. data/README.rdoc +0 -274
  25. data/Rakefile +0 -36
  26. data/VERSION +0 -1
  27. data/flea-language-spec/test-cases/04-comma-quoting/01-comma-quoting.scm +0 -5
  28. data/spec/flea/environment_spec.rb +0 -114
  29. data/spec/flea/interpreter_spec.rb +0 -85
  30. data/spec/flea/standard_library/addition_operator_spec.rb +0 -23
  31. data/spec/flea/standard_library/append_spec.rb +0 -17
  32. data/spec/flea/standard_library/begin_spec.rb +0 -20
  33. data/spec/flea/standard_library/car_spec.rb +0 -17
  34. data/spec/flea/standard_library/cdr_spec.rb +0 -17
  35. data/spec/flea/standard_library/cons_spec.rb +0 -25
  36. data/spec/flea/standard_library/display_spec.rb +0 -36
  37. data/spec/flea/standard_library/division_operator_spec.rb +0 -29
  38. data/spec/flea/standard_library/equality_operator_spec.rb +0 -45
  39. data/spec/flea/standard_library/gets_spec.rb +0 -23
  40. data/spec/flea/standard_library/greater_than_spec.rb +0 -29
  41. data/spec/flea/standard_library/if_spec.rb +0 -59
  42. data/spec/flea/standard_library/lambda_spec.rb +0 -70
  43. data/spec/flea/standard_library/less_than_spec.rb +0 -29
  44. data/spec/flea/standard_library/list_predicate_spec.rb +0 -25
  45. data/spec/flea/standard_library/list_spec.rb +0 -24
  46. data/spec/flea/standard_library/list_tail_spec.rb +0 -17
  47. data/spec/flea/standard_library/mutiplication_operator_spec.rb +0 -23
  48. data/spec/flea/standard_library/null_spec.rb +0 -26
  49. data/spec/flea/standard_library/quote_spec.rb +0 -20
  50. data/spec/flea/standard_library/rand_spec.rb +0 -25
  51. data/spec/flea/standard_library/read_spec.rb +0 -23
  52. data/spec/flea/standard_library/set_spec.rb +0 -23
  53. data/spec/flea/standard_library/string_to_num_spec.rb +0 -28
  54. data/spec/flea/standard_library/subtraction_operator_spec.rb +0 -24
  55. data/spec/spec_helper.rb +0 -10
@@ -1,29 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
-
3
- describe "Standard Library" do
4
- describe "division operator" do
5
- before :each do
6
- @interpreter = Flea::Interpreter.new
7
- end
8
-
9
- it "should divide several integers" do
10
- result = @interpreter.run('(/ 10 2 2)')
11
- result.should == 2
12
- end
13
-
14
- it "should divide several floats" do
15
- result = @interpreter.run('(/ 10.0 2 2)')
16
- result.should == 2.5
17
- end
18
-
19
- it "should evaluate its arguments before dividing them" do
20
- result = @interpreter.run('
21
- (define a 2)
22
- (define b 10)
23
- (/ b a a)
24
- ')
25
- result.should == 2
26
- end
27
-
28
- end
29
- end
@@ -1,45 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
-
3
- describe "Standard Library" do
4
- describe "equality operator" do
5
- before :each do
6
- @interpreter = Flea::Interpreter.new
7
- end
8
-
9
- context "for an expression that should evaluate to true" do
10
- it "should return the equality of several arguments" do
11
- result = @interpreter.run('
12
- (= 2 2 2)
13
- ')
14
- result.should == true
15
- end
16
-
17
- it "should evaluate its arguments before comparing them" do
18
- result = @interpreter.run('
19
- (define a 2)
20
- (= a a a)
21
- ')
22
- result.should == true
23
- end
24
- end
25
-
26
- context "for an expression that should evaluate to false" do
27
- it "should return the equality of several arguments" do
28
- result = @interpreter.run('
29
- (= 2 2 4)
30
- ')
31
- result.should == false
32
- end
33
-
34
- it "should evaluate its arguments before comparing them" do
35
- result = @interpreter.run('
36
- (define a 2)
37
- (define b 3)
38
- (= a a b)
39
- ')
40
- result.should == false
41
- end
42
- end
43
-
44
- end
45
- end
@@ -1,23 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
-
3
- describe "Standard Library" do
4
- describe "gets" do
5
- before :each do
6
- @interpreter = Flea::Interpreter.new
7
- @old_stdin = $stdin
8
- @buffer = StringIO.new
9
- $stdin = @buffer
10
- end
11
-
12
- it "should get input from STDIN" do
13
- @buffer.string = "test\n"
14
- result = @interpreter.run('(gets)')
15
- result.should == "test\n"
16
- end
17
-
18
- after :each do
19
- $stdin = @old_stdin
20
- end
21
-
22
- end
23
- end
@@ -1,29 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
-
3
- describe "Standard Library" do
4
- describe "greater-than?" do
5
- before :each do
6
- @interpreter = Flea::Interpreter.new
7
- end
8
-
9
- it "return true if it's first argument is larger than all the others" do
10
- result = @interpreter.run('(greater-than? 10 1 2 3 4)')
11
- result.should == true
12
- end
13
-
14
- it "return false if it's first argument is not larger than all the others" do
15
- result = @interpreter.run('(greater-than? 10 1 2 3 45)')
16
- result.should == false
17
- end
18
-
19
- it "should evaluate its arguments" do
20
- result = @interpreter.run('
21
- (define a 2)
22
- (define b 10)
23
- (greater-than? b a a)
24
- ')
25
- result.should == true
26
- end
27
-
28
- end
29
- end
@@ -1,59 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
-
3
- describe "Standard Library" do
4
- describe "if" do
5
- before :each do
6
- @interpreter = Flea::Interpreter.new
7
- end
8
-
9
- context "only with consequent" do
10
- it "should execute consequent" do
11
- @interpreter.run('
12
- (if #t
13
- (define consequent 1))
14
- ')
15
- @interpreter.base_environment.should have_variable :consequent
16
- end
17
-
18
- it "should not execute consequent" do
19
- @interpreter.run('
20
- (if #f
21
- (define consequent 1))
22
- ')
23
- @interpreter.base_environment.should_not have_variable :consequent
24
- end
25
-
26
- it "should evaluate arguments before deciding on execution" do
27
- @interpreter.run('
28
- (define test #t)
29
- (if test
30
- (define consequent 1))
31
- ')
32
- @interpreter.base_environment.should have_variable :consequent
33
- end
34
- end
35
-
36
- context "with consequent and alternative" do
37
- it "should execute alternative" do
38
- @interpreter.run('
39
- (if #f
40
- (define consequent 1)
41
- (define alternative 1))
42
- ')
43
- @interpreter.base_environment.should_not have_variable :consequent
44
- @interpreter.base_environment.should have_variable :alternative
45
- end
46
-
47
- it "should execute consequent" do
48
- @interpreter.run('
49
- (if #t
50
- (define consequent 1)
51
- (define alternative 1))
52
- ')
53
- @interpreter.base_environment.should have_variable :consequent
54
- @interpreter.base_environment.should_not have_variable :alternative
55
- end
56
- end
57
-
58
- end
59
- end
@@ -1,70 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
-
3
- describe "Standard Library" do
4
- describe "lambda" do
5
- before :each do
6
- @interpreter = Flea::Interpreter.new
7
- @old_stdout = $stdout
8
- @buffer = StringIO.new
9
- $stdout = @buffer
10
- end
11
-
12
- after :each do
13
- $stdout = @old_stdout
14
- end
15
-
16
- it "should create a lambda that takes no arguments" do
17
- result = @interpreter.run('
18
- (lambda () ())
19
- ')
20
- result.should be_a Proc
21
- end
22
-
23
- it "should create and execute a lambda that takes no arguments" do
24
- result = @interpreter.run('
25
- ((lambda ()
26
- (display 1)))
27
- ')
28
- result.should == 1
29
- end
30
-
31
- it "should create a lambda that takes a single argument" do
32
- result = @interpreter.run('
33
- (lambda a ())
34
- ')
35
- result.should be_a Proc
36
- end
37
-
38
- it "should take list as single argument" do
39
- result = @interpreter.run('
40
- ((lambda a
41
- (display a)) 1 2 3)
42
- ')
43
- result.should == [1, 2, 3]
44
- end
45
-
46
- it "should create a lambda that takes multiple arguments" do
47
- result = @interpreter.run('
48
- (lambda (a b c) ())
49
- ')
50
- result.should be_a Proc
51
- end
52
-
53
- it "should create aand execute a lambda that takes multiple arguments" do
54
- result = @interpreter.run('
55
- ((lambda (a b c)
56
- (display (+ a b c))) 1 2 3)
57
- ')
58
- result.should == 6
59
- end
60
-
61
- it "should raise an error when lamda is defined using same argument name more than once" do
62
- lambda {
63
- @interpreter.run('
64
- (lambda (a a a) ())
65
- ')
66
- }.should raise_error
67
- end
68
-
69
- end
70
- end
@@ -1,29 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
-
3
- describe "Standard Library" do
4
- describe "less-than?" do
5
- before :each do
6
- @interpreter = Flea::Interpreter.new
7
- end
8
-
9
- it "return true if it's first argument is smaller than all the others" do
10
- result = @interpreter.run('(less-than? 5 10 15 20)')
11
- result.should == true
12
- end
13
-
14
- it "return false if it's first argument is not smaller than all the others" do
15
- result = @interpreter.run('(less-than? 10 1 2 3 45)')
16
- result.should == false
17
- end
18
-
19
- it "should evaluate its arguments" do
20
- result = @interpreter.run('
21
- (define a 2)
22
- (define b 10)
23
- (less-than? b a a)
24
- ')
25
- result.should == false
26
- end
27
-
28
- end
29
- end
@@ -1,25 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
-
3
- describe "Standard Library" do
4
- describe "list?" do
5
- before :each do
6
- @interpreter = Flea::Interpreter.new
7
- end
8
-
9
- it "should should return true for an empty list" do
10
- result = @interpreter.run("(list? '())")
11
- result.should == true
12
- end
13
-
14
- it "return true for a populated list" do
15
- result = @interpreter.run("(list? '(a b c))")
16
- result.should == true
17
- end
18
-
19
- it "should return false for an atom" do
20
- result = @interpreter.run("(list? 'a)")
21
- result.should == false
22
- end
23
-
24
- end
25
- end
@@ -1,24 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
-
3
- describe "Standard Library" do
4
- describe "list" do
5
- before :each do
6
- @interpreter = Flea::Interpreter.new
7
- end
8
-
9
- it "should create a list from it's arguments" do
10
- result = @interpreter.run('(list 9 2 2)')
11
- result.should == [9, 2, 2]
12
- end
13
-
14
- it "should evaluate its arguments before creating the list" do
15
- result = @interpreter.run('
16
- (define a 2)
17
- (define b 9)
18
- (list b a a)
19
- ')
20
- result.should == [9, 2, 2]
21
- end
22
-
23
- end
24
- end
@@ -1,17 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
-
3
- describe "Standard Library" do
4
- describe "list-tail" do
5
- before :each do
6
- @interpreter = Flea::Interpreter.new
7
- end
8
-
9
- it "should return trailing subset of list" do
10
- result = @interpreter.run('
11
- (list-tail (quote (1 2 3 4 5)) 2)
12
- ')
13
- result.should == [3, 4, 5]
14
- end
15
-
16
- end
17
- end
@@ -1,23 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
-
3
- describe "Standard Library" do
4
- describe "multiplication operator" do
5
- before :each do
6
- @interpreter = Flea::Interpreter.new
7
- end
8
-
9
- it "should multiply several numbers" do
10
- result = @interpreter.run('(* 2 2 2)')
11
- result.should == 8
12
- end
13
-
14
- it "should evaluate its arguments before multiplying them" do
15
- result = @interpreter.run('
16
- (define a 2)
17
- (* a a a)
18
- ')
19
- result.should == 8
20
- end
21
-
22
- end
23
- end
@@ -1,26 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
-
3
- describe "Standard Library" do
4
- describe "null?" do
5
- before :each do
6
- @interpreter = Flea::Interpreter.new
7
- end
8
-
9
- it "should return true for an empty list" do
10
- result = @interpreter.run('
11
- (null? \'())
12
- ')
13
- result.should == true
14
- end
15
-
16
- ["1", '"abc"', "(1 2 3)"].each do |value|
17
- it "should return false for #{value}" do
18
- result = @interpreter.run("
19
- (null? (quote #{value}))
20
- ")
21
- result.should == false
22
- end
23
- end
24
-
25
- end
26
- end
@@ -1,20 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
-
3
- describe "Standard Library" do
4
- describe "quote" do
5
- before :each do
6
- @interpreter = Flea::Interpreter.new
7
- end
8
-
9
- it "should quote a list" do
10
- result = @interpreter.run('(quote (1 2 3))')
11
- result.should == [1, 2, 3]
12
- end
13
-
14
- it "should quote a single literal" do
15
- result = @interpreter.run('(quote 1)')
16
- result.should == 1
17
- end
18
-
19
- end
20
- end
@@ -1,25 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
-
3
- describe "Standard Library" do
4
- describe "rand" do
5
- before :each do
6
- @interpreter = Flea::Interpreter.new
7
- end
8
-
9
- 10.times do
10
- it "should return a random number lower than or equal to 10" do
11
- result = @interpreter.run('(rand 10)')
12
- result.should < 11
13
- end
14
-
15
- it "should evaluate its arguments" do
16
- result = @interpreter.run('
17
- (define a 10)
18
- (rand a)
19
- ')
20
- result.should < 11
21
- end
22
- end
23
-
24
- end
25
- end
@@ -1,23 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
-
3
- describe "Standard Library" do
4
- describe "read" do
5
- before :each do
6
- @interpreter = Flea::Interpreter.new
7
- @old_stdin = $stdin
8
- @buffer = StringIO.new
9
- $stdin = @buffer
10
- end
11
-
12
- it "should read data structure from STDIN" do
13
- @buffer.string = "(1 2.0 test (1 2 3))\n"
14
- result = @interpreter.run('(read)')
15
- result.should == [[1, 2.0, :test, [1, 2, 3]]]
16
- end
17
-
18
- after :each do
19
- $stdin = @old_stdin
20
- end
21
-
22
- end
23
- end
@@ -1,23 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
-
3
- describe "Standard Library" do
4
- describe "set!" do
5
- before :each do
6
- @interpreter = Flea::Interpreter.new
7
- end
8
-
9
- it "should change the value of an existing variable" do
10
- @interpreter.run('
11
- (define test 1)
12
- (set! test 2)')
13
- @interpreter.base_environment.find(:test).should == 2
14
- end
15
-
16
- it "should raise error when attempting to set unbound variable" do
17
- lambda {
18
- @interpreter.run('(set! test 1)')
19
- }.should raise_error
20
- end
21
-
22
- end
23
- end
@@ -1,28 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
-
3
- describe "Standard Library" do
4
- describe "string-to-num" do
5
- before :each do
6
- @interpreter = Flea::Interpreter.new
7
- end
8
-
9
- it "should convert string to integer" do
10
- result = @interpreter.run('(string-to-num "10")')
11
- result.should == 10
12
- end
13
-
14
- it "should convert string to float" do
15
- result = @interpreter.run('(string-to-num "23.0")')
16
- result.should == 23.0
17
- end
18
-
19
- it "should evaluate its arguments" do
20
- result = @interpreter.run('
21
- (define a 2)
22
- (string-to-num a)
23
- ')
24
- result.should == 2
25
- end
26
-
27
- end
28
- end
@@ -1,24 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
-
3
- describe "Standard Library" do
4
- describe "subtraction operator" do
5
- before :each do
6
- @interpreter = Flea::Interpreter.new
7
- end
8
-
9
- it "should subtract several numbers" do
10
- result = @interpreter.run('(- 9 2 2)')
11
- result.should == 5
12
- end
13
-
14
- it "should evaluate its arguments before subtracting them" do
15
- result = @interpreter.run('
16
- (define a 2)
17
- (define b 9)
18
- (- b a a)
19
- ')
20
- result.should == 5
21
- end
22
-
23
- end
24
- end
data/spec/spec_helper.rb DELETED
@@ -1,10 +0,0 @@
1
- require 'rubygems'
2
- require 'rspec'
3
- require 'stringio'
4
-
5
- require_files = []
6
- require_files << File.join(File.dirname(__FILE__), '..', 'lib', 'flea.rb')
7
-
8
- require_files.each do |file|
9
- require File.expand_path(file)
10
- end