capricc-io 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1d1f3a3f131d30051c05dd7cc38f4335c0cc56f0db52b541c5e6bf300b35f6e8
4
+ data.tar.gz: f4204dd06e87ab48b65d6a7f0db61469394883d7c8148906dd545aedce8da9ad
5
+ SHA512:
6
+ metadata.gz: 28c5e04c2d21b0def29f99b0d75a026ff39d913a52af3d707cad10f4a4c41fa2594923a65a2ea48ea1411bb2e84b575f2e97d8875cd079025251f413e8654d32
7
+ data.tar.gz: de72819661343eb5efe56dd5e5df4e0c62116e9bcaa93247be507768fce2f6a2e2a412e34afe57adee9ef8ccae9ef8308c5758537c170990662a03ef5a102aff
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,106 @@
1
+ require:
2
+ - rubocop-performance
3
+ - rubocop-rspec
4
+
5
+ AllCops:
6
+ TargetRubyVersion: 2.5
7
+ NewCops: enable
8
+ Exclude:
9
+ - 'spec/dummy/bin/*'
10
+ - '*.md'
11
+ - lib/capriccio/parser/*
12
+ - vendor/bundle/**/*
13
+
14
+ Layout/SpaceInsideHashLiteralBraces:
15
+ EnforcedStyle: no_space
16
+
17
+ Gemspec/RequireMFA:
18
+ Enabled: false
19
+
20
+ Metrics/BlockLength:
21
+ Max: 100
22
+ Exclude:
23
+ - spec/**/*.rb
24
+ - capricc-io.gemspec
25
+
26
+ Metrics/BlockNesting:
27
+ Max: 4
28
+
29
+ Layout/LineLength:
30
+ Max: 120
31
+ AllowURI: true
32
+
33
+ Metrics/MethodLength:
34
+ CountComments: false
35
+ Max: 80
36
+
37
+ Metrics/ModuleLength:
38
+ Max: 250
39
+
40
+ Metrics/ClassLength:
41
+ Max: 350
42
+
43
+ Metrics/ParameterLists:
44
+ Max: 5
45
+ CountKeywordArgs: true
46
+
47
+ Metrics/AbcSize:
48
+ Enabled: false
49
+
50
+ Metrics/CyclomaticComplexity:
51
+ Enabled: false
52
+
53
+ Metrics/PerceivedComplexity:
54
+ Enabled: false
55
+
56
+ Style/CollectionMethods:
57
+ Enabled: true
58
+ PreferredMethods:
59
+ collect: 'map'
60
+ collect!: 'map!'
61
+ inject: 'reduce'
62
+ find: 'detect'
63
+ find_all: 'select'
64
+ delete: 'gsub'
65
+
66
+ Style/Documentation:
67
+ Enabled: false
68
+
69
+ Layout/DotPosition:
70
+ EnforcedStyle: trailing
71
+
72
+ Naming/FileName:
73
+ Enabled: false
74
+
75
+ Layout/AccessModifierIndentation:
76
+ Enabled: false
77
+
78
+ Style/TrailingCommaInArrayLiteral:
79
+ EnforcedStyleForMultiline: 'no_comma'
80
+
81
+ Style/TrailingCommaInHashLiteral:
82
+ EnforcedStyleForMultiline: 'no_comma'
83
+
84
+ RSpec/MultipleExpectations:
85
+ Max: 30
86
+
87
+ RSpec/ExampleLength:
88
+ Max: 35
89
+
90
+ RSpec/FilePath:
91
+ Enabled: false
92
+
93
+ RSpec/BeforeAfterAll:
94
+ Enabled: false
95
+
96
+ RSpec/NamedSubject:
97
+ Enabled: false
98
+
99
+ RSpec/MultipleMemoizedHelpers:
100
+ Max: 10
101
+
102
+ Style/StringLiterals:
103
+ EnforcedStyle: single_quotes
104
+
105
+ Style/StringLiteralsInInterpolation:
106
+ EnforcedStyle: single_quotes
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.2.0] - 2022-01-04
4
+
5
+ - Main functionality implemented
6
+
7
+ ## [0.1.0] - 2022-01-04
8
+
9
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at maximbarsukov@bk.ru. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Max Barsukov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,131 @@
1
+ # Capricc-Io
2
+
3
+ [![Build Status](https://github.com/maxbarsukov/capricc-io/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/maxbarsukov/capricc-io/actions/workflows/main.yml)
4
+ [![Codecov](https://codecov.io/gh/maxbarsukov/capricc-io/branch/master/graph/badge.svg?token=9L8Y4N4KKW)](https://codecov.io/gh/maxbarsukov/capricc-io)
5
+ ![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/maxbarsukov/capricc-io)
6
+
7
+ ***Capricc-Io*** is a tiny interpreted *prototyped-based* **homoiconic** and dynamic typing language with ***Io-like messages***.
8
+
9
+ - **Everything** is an **object** in *Capricc-Io*;
10
+ - Program is just a **series of messages**;
11
+ - Objects don’t have classes, but **prototypes**, their parent objects;
12
+ - Messages are the only data type and also parsing representation → ***homoiconicity***;
13
+
14
+ In [lib/capriccio/stdlib](https://github.com/maxbarsukov/capricc-io/tree/master/lib/capriccio/stdlib) you can see how you can define an **if** statement or **booleans** behavior directly in *Capric-Io*;
15
+
16
+ ## Installation
17
+
18
+ $ gem install capricc-io
19
+
20
+ ## Usage
21
+
22
+ Run REPL:
23
+ ```bash
24
+ capio
25
+ ```
26
+
27
+ or run file:
28
+ ```bash
29
+ capio your_code.cio
30
+ ```
31
+
32
+ ## Examples of code
33
+
34
+ Prototypes & OOP:
35
+ ```python
36
+ # comment
37
+
38
+ set("person", Object clone)
39
+ person set("name", "Max")
40
+ person name print
41
+ # => Max
42
+
43
+ person set("say_name", def(
44
+ arguments print
45
+ # => <Message @name="hello...">
46
+
47
+ eval_arg(0) print
48
+ # => hello...
49
+
50
+ self name print
51
+ # => Max
52
+ ))
53
+
54
+ person say_name("hello...")
55
+ ```
56
+
57
+ Conditions:
58
+ ```python
59
+ if(true,
60
+ "condition is true" print,
61
+ "nope" print
62
+ )
63
+ # => condition is true
64
+
65
+ if(false,
66
+ "nope" print,
67
+ "condition is false" print
68
+ )
69
+ # => condition is false
70
+ ```
71
+
72
+ Booleans:
73
+ ```python
74
+ "yo" or("hi") print
75
+ # => yo
76
+
77
+ nil or("hi") print
78
+ # => hi
79
+
80
+ "yo" and("hi") print
81
+ # => hi
82
+
83
+ 1 and(2 or(3)) print
84
+ # => 2
85
+ ```
86
+
87
+ ## Building
88
+
89
+ ### Pre-reqs
90
+
91
+ To build and run this app locally you will need a few things:
92
+
93
+ - Install [Ruby](https://www.ruby-lang.org/en/) *(tested on **2.6**)*;
94
+
95
+ ### Getting start
96
+
97
+ - Clone the repository
98
+ ```bash
99
+ git clone --depth=1 https://github.com/maxbarsukov/capricc-io.git
100
+ ```
101
+ - **Install dependencies**
102
+ ```bash
103
+ cd capricc-io
104
+ bundle install
105
+ ```
106
+ - **Run**
107
+ ```bash
108
+ ./bin/capriccio input.cio
109
+ # or
110
+ ./bin/capriccio
111
+ ````
112
+ - **RSpec**
113
+ ```bash
114
+ bundle exec rspec
115
+ ```
116
+ - **Rubocop**
117
+ ```bash
118
+ bundle exec rubocop
119
+ ```
120
+
121
+ ## Contributing
122
+
123
+ Bug reports and pull requests are welcome on GitHub at https://github.com/maxbarsukov/capricc-io. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/maxbarsukov/capricc-io/blob/master/CODE_OF_CONDUCT.md).
124
+
125
+ ## License
126
+
127
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
128
+
129
+ ## Code of Conduct
130
+
131
+ Everyone interacting in the Capricc-Io project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/maxbarsukov/capricc-io/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require 'rubocop/rake_task'
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/bin/capio ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'readline'
5
+ require_relative '../lib/capriccio'
6
+
7
+ if ARGV.first
8
+ CapriccIo.eval File.read(ARGV.first)
9
+ else
10
+ puts 'Capricc-Io REPL, CTRL+C to quit'
11
+ loop do
12
+ line = Readline.readline('>> ')
13
+ Readline::HISTORY.push(line)
14
+ value = CapriccIo.eval(line)
15
+ puts "=> #{value.inspect}"
16
+ end
17
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/capriccio/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'capricc-io'
7
+ spec.version = CapriccIo::VERSION
8
+ spec.authors = ['maxbarsukov']
9
+ spec.email = ['maximbarsukov@bk.ru']
10
+
11
+ spec.summary = ':white_large_square: Extremely minimalistic Io-like language'
12
+ spec.description = 'Extremely minimalistic prototype-based homoiconic Io-like language'
13
+ spec.homepage = 'https://rubygems.org/gems/capricc-io'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = '>= 2.5.0'
16
+
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ spec.metadata['source_code_uri'] = 'https://github.com/maxbarsukov/capricc-io'
19
+ spec.metadata['changelog_uri'] = 'https://github.com/maxbarsukov/capricc-io/blob/master/CHANGELOG.md'
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ `git ls-files -z`.split("\x0").reject do |f|
25
+ (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
26
+ end
27
+ end
28
+ spec.bindir = 'bin'
29
+ spec.executables << 'capio'
30
+ spec.require_paths = ['lib']
31
+
32
+ # Development dependencies
33
+ spec.add_development_dependency 'codecov', '~> 0.6.0'
34
+ spec.add_development_dependency 'rake', '~> 13.0'
35
+ spec.add_development_dependency 'rspec', '~> 3.0'
36
+ spec.add_development_dependency 'rubocop', '~> 1.21'
37
+ spec.add_development_dependency 'rubocop-performance', '~> 1.13'
38
+ spec.add_development_dependency 'rubocop-rake', '~> 0.6.0'
39
+ spec.add_development_dependency 'rubocop-rspec', '~> 2.7'
40
+ spec.add_development_dependency 'simplecov', '~> 0.21.2'
41
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './runtime/message'
4
+
5
+ module CapriccIo
6
+ class Parser
7
+ def self.parse(code, line)
8
+ code = code.strip
9
+ i = 0
10
+ message = nil
11
+ messages = []
12
+
13
+ while i < code.size
14
+ case code[i..-1]
15
+ when /\A("[^"]*")/, # string
16
+ /\A(\d+)/, # number
17
+ /\A(\.)+/, # dot
18
+ /\A(\n)+/, # line break
19
+ /\A(\w+)/ # name
20
+ m = Message.new(Regexp.last_match(1), line)
21
+ if messages.empty?
22
+ messages << m
23
+ else
24
+ message.next = m
25
+ end
26
+ line += Regexp.last_match(1).count("\n")
27
+ message = m
28
+ i += Regexp.last_match(1).size - 1
29
+
30
+ when /\A(\(\s*)/ # arguments
31
+ start = i + Regexp.last_match(1).size
32
+ level = 1
33
+ while level.positive? && i < code.size
34
+ i += 1
35
+ level += 1 if code[i] == '('
36
+ level -= 1 if code[i] == ')'
37
+ end
38
+ line += Regexp.last_match(1).count("\n")
39
+ code_chunk = code[start..i - 1]
40
+ message.args = parse(code_chunk, line)
41
+ line += code_chunk.count("\n")
42
+
43
+ when /\A,(\s*)/
44
+ line += Regexp.last_match(1).count("\n")
45
+ messages.concat parse(code[i + 1..-1], line)
46
+ break
47
+
48
+ when /\A(\s+)/, # ignore whitespace
49
+ /\A(#.*$)/ # ignore comments
50
+ line += Regexp.last_match(1).count("\n")
51
+ i += Regexp.last_match(1).size - 1
52
+
53
+ else
54
+ raise "Unknown char #{code[i].inspect} at line #{line}"
55
+ end
56
+ i += 1
57
+ end
58
+ messages
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CapriccIo
4
+ object = CObject.new
5
+
6
+ object.def 'clone' do |receiver, _context|
7
+ receiver.clone
8
+ end
9
+
10
+ object.def 'set' do |receiver, context, name, value|
11
+ receiver[name.call(context).value] = value.call(context)
12
+ end
13
+
14
+ object.def 'print' do |receiver, _context|
15
+ puts receiver.value
16
+ Runtime['nil']
17
+ end
18
+
19
+ Runtime = object.clone
20
+
21
+ Runtime['Runtime'] = Runtime
22
+ Runtime['Object'] = object
23
+ Runtime['nil'] = object.clone(nil)
24
+ Runtime['true'] = object.clone(true)
25
+ Runtime['false'] = object.clone(false)
26
+ Runtime['Number'] = object.clone(0)
27
+ Runtime['String'] = object.clone('')
28
+ Runtime['List'] = object.clone([])
29
+ Runtime['Message'] = object.clone
30
+ Runtime['Method'] = object.clone
31
+
32
+ Runtime.def 'def' do |_receiver, context, message|
33
+ Method.new(context, message)
34
+ end
35
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './object'
4
+ require_relative '../parser'
5
+
6
+ module CapriccIo
7
+ class Message < CapriccIo::CObject
8
+ attr_accessor :next, :name, :args, :line, :cached_value
9
+
10
+ def initialize(name, line)
11
+ @name = name
12
+ @args = []
13
+ @line = line
14
+ @cached_value = case @name
15
+ when /^\d+/
16
+ Runtime['Number'].clone(@name.to_i)
17
+ when /^"(.*)"$/
18
+ Runtime['String'].clone(Regexp.last_match(1))
19
+ end
20
+
21
+ @terminator = %W[. \n].include?(@name)
22
+ super(Runtime['Message'])
23
+ end
24
+
25
+ def call(receiver, context = receiver, *_args)
26
+ value = if @terminator
27
+ context
28
+ elsif @cached_value
29
+ @cached_value
30
+ else
31
+ receiver[name].call(receiver, context, *@args)
32
+ end
33
+
34
+ return @next.call(value, context) if @next
35
+
36
+ value
37
+ rescue CapriccIo::Error => e
38
+ e.current_message ||= self
39
+ raise
40
+ end
41
+
42
+ def to_s(level = 0)
43
+ s = ' ' * level
44
+ s << "<Message @name=#{@name}"
45
+ s << (", @args=#{@args.inspect}") unless @args.empty?
46
+ s << (", @next=\n#{@next.to_s(level + 1)}") if @next
47
+ "#{s}>"
48
+ end
49
+ alias inspect to_s
50
+
51
+ def self.parse(code)
52
+ Parser.parse(code, 1).last
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CapriccIo
4
+ class Method < CObject
5
+ def initialize(context, message)
6
+ @definition_context = context
7
+ @message = message
8
+ super(Runtime['Method'])
9
+ end
10
+
11
+ def call(receiver, calling_context, *args)
12
+ method_context = @definition_context.clone
13
+ method_context['self'] = receiver
14
+ method_context['arguments'] = Runtime['List'].clone(args)
15
+
16
+ method_context['eval_arg'] = proc do |_receiver, context, at|
17
+ (args[at.call(context).value] || Runtime['nil']).call(calling_context)
18
+ end
19
+ @message.call(method_context)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CapriccIo
4
+ class CObject
5
+ attr_accessor :slots, :proto, :value
6
+
7
+ def initialize(proto = nil, value = nil)
8
+ @proto = proto
9
+ @value = value
10
+ @slots = {}
11
+ end
12
+
13
+ def [](name)
14
+ return @slots[name] if @slots.key?(name)
15
+ return @proto[name] if @proto
16
+
17
+ raise CapriccIo::Error, "Missing slot: #{name.inspect}"
18
+ end
19
+
20
+ def []=(name, value)
21
+ @slots[name] = value
22
+ end
23
+
24
+ def def(name, &block)
25
+ @slots[name] = block
26
+ end
27
+
28
+ def call(*_args)
29
+ self
30
+ end
31
+
32
+ def clone(ruby_value = nil)
33
+ CObject.new(self, ruby_value)
34
+ end
35
+
36
+ def to_s(level = 0)
37
+ s = ' ' * level
38
+ s << '<CObject'
39
+ s << " @proto=#{@proto}" unless @proto.nil?
40
+ s << ", @value=#{@value.inspect}" unless @proto.nil?
41
+ s << ", @slots=#{@slots.keys}" unless @slots.empty?
42
+ "#{s}>"
43
+ end
44
+ alias inspect to_s
45
+ end
46
+ end
@@ -0,0 +1,16 @@
1
+ Object set("and", def(
2
+ eval_arg(0)
3
+ ))
4
+ Object set("or", def(
5
+ self
6
+ ))
7
+
8
+ nil set("and", nil)
9
+ nil set("or", def(
10
+ eval_arg(0)
11
+ ))
12
+
13
+ false set("and", false)
14
+ false set("or", def(
15
+ eval_arg(0)
16
+ ))
@@ -0,0 +1,9 @@
1
+ set("if", def(
2
+ set("condition", eval_arg(0))
3
+ condition and(
4
+ eval_arg(1)
5
+ )
6
+ condition or(
7
+ eval_arg(2)
8
+ )
9
+ ))
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CapriccIo
4
+ VERSION = '0.2.0'
5
+ end
data/lib/capriccio.rb ADDED
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'capriccio/version'
4
+ require_relative 'capriccio/parser'
5
+ require_relative 'capriccio/runtime/object'
6
+ require_relative 'capriccio/runtime/message'
7
+ require_relative 'capriccio/runtime/method'
8
+ require_relative 'capriccio/runtime/bootstrap'
9
+
10
+ module CapriccIo
11
+ class Error < RuntimeError
12
+ attr_accessor :current_message
13
+
14
+ def message
15
+ super + " in message `#{@current_message}` at line #{@current_message.line}"
16
+ end
17
+ end
18
+
19
+ def self.eval(code)
20
+ message = Message.parse(code)
21
+ message.call(Runtime)
22
+ end
23
+
24
+ def self.load(file)
25
+ self.eval File.read(File.join(File.dirname(__FILE__), "./capriccio/stdlib/#{file}"))
26
+ end
27
+
28
+ load 'boolean.cio'
29
+ load 'if.cio'
30
+ end
metadata ADDED
@@ -0,0 +1,178 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capricc-io
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - maxbarsukov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-01-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: codecov
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.6.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.6.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.21'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.21'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop-performance
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.13'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.13'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop-rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.6.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.6.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.7'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.7'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.21.2
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.21.2
125
+ description: Extremely minimalistic prototype-based homoiconic Io-like language
126
+ email:
127
+ - maximbarsukov@bk.ru
128
+ executables:
129
+ - capio
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - ".rspec"
134
+ - ".rubocop.yml"
135
+ - CHANGELOG.md
136
+ - CODE_OF_CONDUCT.md
137
+ - Gemfile
138
+ - LICENSE.txt
139
+ - README.md
140
+ - Rakefile
141
+ - bin/capio
142
+ - capricc-io.gemspec
143
+ - lib/capriccio.rb
144
+ - lib/capriccio/parser.rb
145
+ - lib/capriccio/runtime/bootstrap.rb
146
+ - lib/capriccio/runtime/message.rb
147
+ - lib/capriccio/runtime/method.rb
148
+ - lib/capriccio/runtime/object.rb
149
+ - lib/capriccio/stdlib/boolean.cio
150
+ - lib/capriccio/stdlib/if.cio
151
+ - lib/capriccio/version.rb
152
+ homepage: https://rubygems.org/gems/capricc-io
153
+ licenses:
154
+ - MIT
155
+ metadata:
156
+ homepage_uri: https://rubygems.org/gems/capricc-io
157
+ source_code_uri: https://github.com/maxbarsukov/capricc-io
158
+ changelog_uri: https://github.com/maxbarsukov/capricc-io/blob/master/CHANGELOG.md
159
+ post_install_message:
160
+ rdoc_options: []
161
+ require_paths:
162
+ - lib
163
+ required_ruby_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: 2.5.0
168
+ required_rubygems_version: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ requirements: []
174
+ rubygems_version: 3.2.22
175
+ signing_key:
176
+ specification_version: 4
177
+ summary: ":white_large_square: Extremely minimalistic Io-like language"
178
+ test_files: []