forsta 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fdd1aac2a20e29a420662e369652a80763a2c448
4
+ data.tar.gz: 0baef0c543ec790278ec570fc21412c300967a3f
5
+ SHA512:
6
+ metadata.gz: 82e3955707f83bcde46df7979b04314b0d86f80358ffe1bfee18bdbd6f04eb39843f9cb7b15d693043e4b2596f5110aa21ebab6ede371f9e9b4dc68ff517cb10
7
+ data.tar.gz: e8afdc03ea8ff1b22c51bf2f55f657277d5c926a91b75566e18d183f196f90d4d76ff1cf583bbfe06857452e204d4defdc1ab9c071adf29648bf68054a1b1146
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ *.swp
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.4
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 David Boot
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,33 @@
1
+ [![Build Status](https://travis-ci.org/kodnin/forsta.svg?branch=master)](https://travis-ci.org/kodnin/forsta)
2
+
3
+ # Forsta
4
+
5
+ A Lisp implementation written in Ruby.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'forsta'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install forsta
22
+
23
+ ## Usage
24
+
25
+ Forsta is under active development, examples will be provided soon.
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it ( https://github.com/kodnin/forsta/fork )
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create a new Pull Request
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.test_files = FileList['test/*_test.rb']
6
+ end
7
+
8
+ task default: :test
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'forsta/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'forsta'
8
+ spec.version = Forsta::VERSION
9
+ spec.authors = ['David Boot']
10
+ spec.email = ['kodnin@gmail.com']
11
+ spec.summary = %q{Lisp implementation.}
12
+ spec.description = %q{Lisp implementation written in Ruby.}
13
+ spec.homepage = 'https://github.com/kodnin/forsta'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.7'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'minitest', '~> 5.4.2'
24
+ end
@@ -0,0 +1,9 @@
1
+ require 'forsta/array'
2
+ require 'forsta/construct'
3
+ require 'forsta/environment'
4
+ require 'forsta/object'
5
+ require 'forsta/symbol'
6
+ require 'forsta/version'
7
+
8
+ module Forsta
9
+ end
@@ -0,0 +1,6 @@
1
+ class Array
2
+ def to_construct
3
+ map { |x| x.to_construct }.reverse.
4
+ inject(:nil) { |cdr, car| Construct.new(car, cdr) }
5
+ end
6
+ end
@@ -0,0 +1,24 @@
1
+ class Construct
2
+ attr_reader :car, :cdr
3
+
4
+ def initialize(car, cdr)
5
+ @car, @cdr = car, cdr
6
+ end
7
+
8
+ def construct_list?
9
+ cdr.construct_list?
10
+ end
11
+
12
+ def to_array
13
+ construct_list? ? [car] + cdr.to_array : self
14
+ end
15
+
16
+ def lisp_eval(environment, forms)
17
+ if forms.defined?(car)
18
+ # TODO implement and test
19
+ else
20
+ car.lisp_eval(environment, forms).
21
+ call(*cdr.to_array.map { |x| x.lisp_eval(environment, forms) })
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,31 @@
1
+ class Environment
2
+ attr_reader :parent, :defaults
3
+
4
+ def initialize(parent=nil, defaults={})
5
+ @parent = parent
6
+ @defaults = defaults
7
+ end
8
+
9
+ def define(symbol, value)
10
+ defaults[symbol] = value
11
+ end
12
+
13
+ def defined?(symbol)
14
+ defaults.has_key?(symbol) || (parent && parent.defined?(symbol))
15
+ end
16
+
17
+ def lookup(symbol)
18
+ defaults[symbol] || (parent && parent.lookup(symbol)) ||
19
+ raise("#{symbol} is undefined")
20
+ end
21
+
22
+ def set(symbol, value)
23
+ if defaults.has_key?(symbol)
24
+ defaults[symbol] = value
25
+ elsif parent.nil?
26
+ raise("#{symbol} was undefined")
27
+ else
28
+ parent.set(symbol, value)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,17 @@
1
+ class Object
2
+ def construct_list?
3
+ false
4
+ end
5
+
6
+ def to_array
7
+ self
8
+ end
9
+
10
+ def to_construct
11
+ self
12
+ end
13
+
14
+ def lisp_eval(environment, forms)
15
+ self
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ class Symbol
2
+ def construct_list?
3
+ self == :nil
4
+ end
5
+
6
+ def to_array
7
+ construct_list? ? [] : self
8
+ end
9
+
10
+ def lisp_eval(environment, forms)
11
+ environment.lookup(self)
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module Forsta
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,17 @@
1
+ require_relative './test_helper'
2
+
3
+ class TestArray < Minitest::Test
4
+ def setup
5
+ @array = [1, 2]
6
+ end
7
+
8
+ def test_to_construct
9
+ assert_instance_of Construct, @array.to_construct
10
+ assert_equal 1, @array.to_construct.car
11
+ assert_equal 2, @array.to_construct.cdr.car
12
+ assert_equal :nil, @array.to_construct.cdr.cdr
13
+
14
+ # requires implementation of == for Construct
15
+ # assert_equal Construct.new(1, Construct.new(2, :nil)), @array.to_construct
16
+ end
17
+ end
@@ -0,0 +1,45 @@
1
+ require_relative './test_helper'
2
+
3
+ class TestConstruct < Minitest::Test
4
+ def setup
5
+ @child = Construct.new('child', :nil)
6
+ @parent = Construct.new('parent', @child)
7
+ end
8
+
9
+ def test_initialize
10
+ assert_instance_of Construct, @child
11
+ assert_instance_of Construct, @parent
12
+ end
13
+
14
+ def test_car
15
+ assert_equal 'child', @child.car
16
+ assert_equal 'parent', @parent.car
17
+ end
18
+
19
+ def test_cdr
20
+ assert_equal :nil, @child.cdr
21
+ assert_instance_of Construct, @parent.cdr
22
+ assert_equal @child, @parent.cdr
23
+ assert_equal @child.car, @parent.cdr.car
24
+ assert_equal @child.cdr, @parent.cdr.cdr
25
+ end
26
+
27
+ def test_construct_list?
28
+ assert @child.construct_list?
29
+ assert @parent.construct_list?
30
+ end
31
+
32
+ def test_to_array
33
+ assert_instance_of Array, @parent.to_array
34
+ assert_equal ['parent', 'child'], @parent.to_array
35
+ flat_construct = Construct.new(1, 2)
36
+ assert_equal flat_construct, flat_construct.to_array
37
+ end
38
+
39
+ def test_lisp_eval
40
+ construct = Construct.new(:+, Construct.new(1, Construct.new(2, :nil)))
41
+ environment = Environment.new(nil, { :+ => lambda { |x, y| x + y } })
42
+
43
+ assert_equal 3, construct.lisp_eval(environment, Environment.new)
44
+ end
45
+ end
@@ -0,0 +1,49 @@
1
+ require_relative './test_helper'
2
+
3
+ class TestEnvironment < Minitest::Test
4
+ def setup
5
+ @parent = Environment.new(nil, { language: 'ruby' })
6
+ @child = Environment.new(@parent, { test_framework: 'minitest' })
7
+ end
8
+
9
+ def test_initialize
10
+ assert_instance_of Environment, @parent
11
+ assert_instance_of Environment, @child
12
+ end
13
+
14
+ def test_parent
15
+ assert_nil @parent.parent
16
+ assert_instance_of Environment, @child.parent
17
+ assert_equal @parent, @child.parent
18
+ end
19
+
20
+ def test_defaults
21
+ assert_instance_of Hash, @parent.defaults
22
+ assert_instance_of Hash, @child.defaults
23
+ end
24
+
25
+ def test_define
26
+ assert_equal 'vim', @child.define(:editor, 'vim')
27
+ assert_equal 'vim', @child.defaults[:editor]
28
+ end
29
+
30
+ def test_defined?
31
+ assert @child.defined?(:test_framework)
32
+ assert @child.defined?(:language)
33
+ refute @child.defined?(:version_control)
34
+ end
35
+
36
+ def test_lookup
37
+ assert_equal 'minitest', @child.lookup(:test_framework)
38
+ assert_equal 'ruby', @child.lookup(:language)
39
+ assert_raises(RuntimeError) { @child.lookup(:version_control) }
40
+ end
41
+
42
+ def test_set
43
+ assert_equal 'rspec', @child.set(:test_framework, 'rspec')
44
+ assert_equal 'rspec', @child.lookup(:test_framework)
45
+ assert_equal 'lisp', @child.set(:language, 'lisp')
46
+ assert_equal 'lisp', @child.lookup(:language)
47
+ assert_raises(RuntimeError) { @child.set(:version_control, 'git') }
48
+ end
49
+ end
@@ -0,0 +1,28 @@
1
+ require_relative './test_helper'
2
+
3
+ class TestObject < Minitest::Test
4
+ def setup
5
+ @string = 'ruby'
6
+ @integer = 1
7
+ end
8
+
9
+ def test_construct_list?
10
+ refute @string.construct_list?
11
+ refute @integer.construct_list?
12
+ end
13
+
14
+ def test_to_array
15
+ assert_equal @string, @string.to_array
16
+ assert_equal @integer, @integer.to_array
17
+ end
18
+
19
+ def test_to_construct
20
+ assert_equal @string, @string.to_construct
21
+ assert_equal @integer, @integer.to_construct
22
+ end
23
+
24
+ def test_lisp_eval
25
+ assert_equal @string, @string.lisp_eval(nil, nil)
26
+ assert_equal @integer, @integer.lisp_eval(nil, nil)
27
+ end
28
+ end
@@ -0,0 +1,22 @@
1
+ require_relative './test_helper'
2
+
3
+ class TestSymbol < Minitest::Test
4
+ def test_construct_list?
5
+ assert :nil.construct_list?
6
+ refute :language.construct_list?
7
+ end
8
+
9
+ def test_to_array
10
+ assert_equal [], :nil.to_array
11
+ assert_equal :language, :language.to_array
12
+ end
13
+
14
+ def test_lisp_eval
15
+ environment = Environment.new
16
+ environment.define(:language, 'ruby')
17
+ environment.define(:number, 1)
18
+
19
+ assert_equal 'ruby', :language.lisp_eval(environment, nil)
20
+ assert_equal 1, :number.lisp_eval(environment, nil)
21
+ end
22
+ end
@@ -0,0 +1,2 @@
1
+ require 'minitest/autorun'
2
+ require_relative '../lib/forsta'
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: forsta
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - David Boot
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 5.4.2
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 5.4.2
55
+ description: Lisp implementation written in Ruby.
56
+ email:
57
+ - kodnin@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".travis.yml"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - forsta.gemspec
69
+ - lib/forsta.rb
70
+ - lib/forsta/array.rb
71
+ - lib/forsta/construct.rb
72
+ - lib/forsta/environment.rb
73
+ - lib/forsta/object.rb
74
+ - lib/forsta/symbol.rb
75
+ - lib/forsta/version.rb
76
+ - test/array_test.rb
77
+ - test/construct_test.rb
78
+ - test/environment_test.rb
79
+ - test/object_test.rb
80
+ - test/symbol_test.rb
81
+ - test/test_helper.rb
82
+ homepage: https://github.com/kodnin/forsta
83
+ licenses:
84
+ - MIT
85
+ metadata: {}
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 2.4.2
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: Lisp implementation.
106
+ test_files:
107
+ - test/array_test.rb
108
+ - test/construct_test.rb
109
+ - test/environment_test.rb
110
+ - test/object_test.rb
111
+ - test/symbol_test.rb
112
+ - test/test_helper.rb