gloss 0.1.1 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +41 -0
- data/.gloss.yml +1 -0
- data/Gemfile.lock +12 -10
- data/README.md +24 -27
- data/Rakefile +4 -2
- data/ext/gloss/Makefile +6 -10
- data/ext/gloss/lib/cr_ruby.cr +5 -4
- data/ext/gloss/src/gloss.cr +7 -2
- data/gloss.gemspec +4 -3
- data/lib/gloss.rb +4 -8
- data/lib/gloss/cli.rb +3 -3
- data/lib/gloss/config.rb +14 -11
- data/lib/gloss/errors.rb +2 -3
- data/lib/gloss/initializer.rb +2 -3
- data/lib/gloss/logger.rb +7 -3
- data/lib/gloss/parser.rb +2 -3
- data/lib/gloss/prog_loader.rb +55 -36
- data/lib/gloss/runtime.rb +25 -0
- data/lib/gloss/scope.rb +2 -3
- data/lib/gloss/source.rb +2 -3
- data/lib/gloss/type_checker.rb +18 -9
- data/lib/gloss/utils.rb +12 -14
- data/lib/gloss/version.rb +4 -5
- data/lib/gloss/visitor.rb +22 -8
- data/lib/gloss/watcher.rb +14 -8
- data/lib/gloss/writer.rb +38 -22
- data/logo.svg +6 -0
- data/src/lib/gloss.gl +2 -2
- data/src/lib/gloss/cli.gl +1 -0
- data/src/lib/gloss/config.gl +11 -7
- data/src/lib/gloss/logger.gl +3 -1
- data/src/lib/gloss/prog_loader.gl +38 -27
- data/src/lib/gloss/runtime.gl +20 -0
- data/src/lib/gloss/type_checker.gl +17 -6
- data/src/lib/gloss/utils.gl +7 -5
- data/src/lib/gloss/version.gl +1 -1
- data/src/lib/gloss/visitor.gl +18 -7
- data/src/lib/gloss/watcher.gl +10 -4
- data/src/lib/gloss/writer.gl +28 -12
- metadata +27 -11
- data/.github/workflows/crystal_specs.yml +0 -26
- data/.github/workflows/ruby_specs.yml +0 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9239f0e7898094d7957a2e1eae3b980ff57f94be27eea836f00561262eb8f8d4
|
4
|
+
data.tar.gz: 0ffa974e3146f699a9280878a412f589005cc4723f262c377a215aacd5cae146
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97ef28c0abd86a51f35224661765950f9aab162cb119f7a0d2b05e3d985464f25c58546b0c191cd69fc537a1b921c22ebd8d7c2d4bd446257d17e9b6a454c346
|
7
|
+
data.tar.gz: a9c9b94fbe5ec96b3be1a5c67d5149219d0e138ef7081190c133676c784865fb90d3c1b86b250b0eb207d890c67120a86f27763c5de105baadf550bc158a464f
|
@@ -0,0 +1,41 @@
|
|
1
|
+
name: Tests
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ master ]
|
8
|
+
env:
|
9
|
+
ImageOS: ubuntu18
|
10
|
+
jobs:
|
11
|
+
build:
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
container:
|
14
|
+
image: johansenja/gloss:latest
|
15
|
+
steps:
|
16
|
+
- name: Checkout
|
17
|
+
uses: actions/checkout@v2
|
18
|
+
- uses: actions/cache@v2
|
19
|
+
id: gems-cache
|
20
|
+
with:
|
21
|
+
path: vendor/bundle
|
22
|
+
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
|
23
|
+
restore-keys: |
|
24
|
+
${{ runner.os }}-gems-
|
25
|
+
- name: install Bundler
|
26
|
+
run: gem install bundler:2.2.3
|
27
|
+
- name: install gems
|
28
|
+
run: bundle install --jobs 4 --retry 3
|
29
|
+
- name: Compile extension
|
30
|
+
run: make
|
31
|
+
working-directory: ext/gloss
|
32
|
+
- name: Run tests
|
33
|
+
run: rake
|
34
|
+
- name: Install dependencies
|
35
|
+
run: shards install
|
36
|
+
working-directory: ext/gloss
|
37
|
+
- name: Run tests
|
38
|
+
run: crystal spec
|
39
|
+
working-directory: ext/gloss
|
40
|
+
- name: Build self with current state
|
41
|
+
run: exe/gloss build
|
data/.gloss.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
gloss (0.1.
|
4
|
+
gloss (0.1.6)
|
5
5
|
fast_blank
|
6
6
|
listen
|
7
|
-
rbs
|
8
|
-
steep
|
7
|
+
rbs (= 1.0.4)
|
8
|
+
steep (= 0.41.0)
|
9
9
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
12
12
|
specs:
|
13
|
-
activesupport (6.1.1)
|
13
|
+
activesupport (6.1.3.1)
|
14
14
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
15
15
|
i18n (>= 1.6, < 2)
|
16
16
|
minitest (>= 5.1)
|
17
17
|
tzinfo (~> 2.0)
|
18
18
|
zeitwerk (~> 2.3)
|
19
|
-
ast (2.4.
|
19
|
+
ast (2.4.2)
|
20
20
|
ast_utils (0.4.0)
|
21
21
|
parser (>= 2.7.0)
|
22
22
|
byebug (11.1.3)
|
@@ -24,15 +24,15 @@ GEM
|
|
24
24
|
concurrent-ruby (1.1.8)
|
25
25
|
diff-lcs (1.4.4)
|
26
26
|
fast_blank (1.0.0)
|
27
|
-
ffi (1.
|
28
|
-
i18n (1.8.
|
27
|
+
ffi (1.15.0)
|
28
|
+
i18n (1.8.9)
|
29
29
|
concurrent-ruby (~> 1.0)
|
30
|
-
language_server-protocol (3.15.0.
|
31
|
-
listen (3.
|
30
|
+
language_server-protocol (3.15.0.2)
|
31
|
+
listen (3.5.0)
|
32
32
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
33
33
|
rb-inotify (~> 0.9, >= 0.9.10)
|
34
34
|
method_source (1.0.0)
|
35
|
-
minitest (5.14.
|
35
|
+
minitest (5.14.4)
|
36
36
|
parallel (1.20.1)
|
37
37
|
parser (2.7.2.0)
|
38
38
|
ast (~> 2.4.1)
|
@@ -77,6 +77,7 @@ GEM
|
|
77
77
|
rubocop-ast (1.4.0)
|
78
78
|
parser (>= 2.7.1.5)
|
79
79
|
ruby-progressbar (1.11.0)
|
80
|
+
rufo (0.12.0)
|
80
81
|
steep (0.41.0)
|
81
82
|
activesupport (>= 5.1)
|
82
83
|
ast_utils (>= 0.4.0)
|
@@ -99,6 +100,7 @@ DEPENDENCIES
|
|
99
100
|
rake-compiler
|
100
101
|
rspec
|
101
102
|
rubocop
|
103
|
+
rufo
|
102
104
|
|
103
105
|
BUNDLED WITH
|
104
106
|
2.2.3
|
data/README.md
CHANGED
@@ -1,13 +1,10 @@
|
|
1
|
-
# Gloss
|
1
|
+
# ![Gloss](./logo.svg "Gloss")
|
2
2
|
[![Gem Version](https://badge.fury.io/rb/gloss.svg)](https://rubygems.org/gems/gloss)
|
3
|
-
[![
|
4
|
-
[![
|
5
|
-
[![Total Downloads](http://ruby-gem-downloads-badge.herokuapp.com/gloss?type=total&color=green&metric=true&label=downloads%20(total)&total_label=)](https://rubygems.org/gems/gloss)
|
3
|
+
[![Tests](https://github.com/johansenja/gloss/workflows/Tests/badge.svg)](https://github.com/johansenja/gloss/actions?query=workflow%3ATests)
|
4
|
+
[![Total Downloads](http://ruby-gem-downloads-badge.herokuapp.com/gloss?type=total&color=green&label=downloads%20(total)&total_label=)](https://rubygems.org/gems/gloss)
|
6
5
|
[![Current Version](http://ruby-gem-downloads-badge.herokuapp.com/gloss?color=green&label=downloads%20(current%20version)&metric=true)](https://rubygems.org/gems/gloss)
|
7
|
-
[![Total Views](https://counter.gofiber.io/badge/johansenja/gloss)](https://rubygems.org/gems/gloss)
|
8
6
|
|
9
|
-
[Gloss](https://en.wikipedia.org/wiki/Gloss_(annotation)) is a
|
10
|
-
efficiency, and to enhance ruby's goal of developer happiness and productivity.
|
7
|
+
[Gloss](https://en.wikipedia.org/wiki/Gloss_(annotation)) is a language project inspired by [Crystal](https://github.com/crystal-lang/crystal), Ruby's [RBS](https://github.com/ruby/rbs), [Steep](https://github.com/soutaro/steep) and [TypeScript](https://github.com/microsoft/TypeScript). It compiles to pure Ruby.
|
11
8
|
|
12
9
|
### Current features
|
13
10
|
|
@@ -22,23 +19,6 @@ efficiency, and to enhance ruby's goal of developer happiness and productivity.
|
|
22
19
|
|
23
20
|
This project is at a stage where the core non-crystal parts are written in Gloss and compile to ruby (essentially self-hosting), albeit with the type checking being fairly loose. However the project is still in the very early stages; with (as of yet) no Linux support nor error handling (see roadmap below). Use at your own discretion!
|
24
21
|
|
25
|
-
### Approx. roadmap:
|
26
|
-
|
27
|
-
- Improve error handling and logging (currently almost non-existant)
|
28
|
-
- Address Linux compatibility (currently more or less non-existant)
|
29
|
-
- Implement different strictnesses of type checking
|
30
|
-
- Metaprogramming helpers/safety:*
|
31
|
-
- Abstract classes and methods
|
32
|
-
- Method lookup/existence checking at compile time
|
33
|
-
- Method overloading
|
34
|
-
|
35
|
-
#### Related items:
|
36
|
-
|
37
|
-
- Rails helpers; probably some time away*
|
38
|
-
- Editor plugins/syntax highlighting/langserver; probably some time away*
|
39
|
-
|
40
|
-
*__Dependent on popularity__
|
41
|
-
|
42
22
|
## Examples:
|
43
23
|
|
44
24
|
#### Type checking:
|
@@ -137,7 +117,7 @@ class Language
|
|
137
117
|
TS = "TypeScript"
|
138
118
|
P = "Python"
|
139
119
|
end
|
140
|
-
|
120
|
+
|
141
121
|
def favourite_language(language : Lang)
|
142
122
|
puts "my favourite language is #{language}"
|
143
123
|
end
|
@@ -213,7 +193,7 @@ end
|
|
213
193
|
```crystal
|
214
194
|
abstract class BaseClass
|
215
195
|
attr_reader :var
|
216
|
-
|
196
|
+
|
217
197
|
def initialize(@var); end
|
218
198
|
end
|
219
199
|
|
@@ -227,7 +207,14 @@ BaseClass.new(123) # Error - can't instantiate abstract class
|
|
227
207
|
Child.new(123).what_is_var # Ok - "var is 123"
|
228
208
|
```
|
229
209
|
|
230
|
-
##
|
210
|
+
## Getting started:
|
211
|
+
|
212
|
+
**Note: This gem currently requires Crystal to be installed. If you don't wish to install it, or run into other installation problems, consider using the Docker image:**
|
213
|
+
|
214
|
+
```dockerfile
|
215
|
+
FROM johansenja/gloss:latest
|
216
|
+
# ...
|
217
|
+
```
|
231
218
|
|
232
219
|
```ruby
|
233
220
|
# Gemfile
|
@@ -250,8 +237,18 @@ then
|
|
250
237
|
|
251
238
|
then
|
252
239
|
|
240
|
+
`vi .gloss.yml # set entrypoint to src/hello_world.gl`
|
241
|
+
|
242
|
+
then
|
243
|
+
|
253
244
|
`gloss build`
|
254
245
|
|
255
246
|
then
|
256
247
|
|
257
248
|
`ruby ./hello_world.rb`
|
249
|
+
|
250
|
+
## Example Projects:
|
251
|
+
|
252
|
+
- This one! Gloss is mostly self-hosting, so check out the `./src` and `./.gloss.yml`, or the generated output in `./lib`
|
253
|
+
- [onefiveone](https://github.com/johansenja/onefiveone) - A Roman Numeral CLI. Read the accompanying article [here](https://johansenja.medium.com/ruby-crystal-pt-ii-a-simple-app-using-gloss-368ff849db67)
|
254
|
+
- More to come (including web apps)! Also check out `Used by` section in the sidebar
|
data/Rakefile
CHANGED
@@ -17,8 +17,10 @@ RSpec::Core::RakeTask.new :spec do |spec|
|
|
17
17
|
spec.pattern = 'spec/**/*_spec.rb'
|
18
18
|
end
|
19
19
|
|
20
|
-
task :
|
20
|
+
task :build_gem do
|
21
21
|
sh "cd", "ext/gloss", "&&", "make", "all", "&&", "cd", "-"
|
22
22
|
end
|
23
23
|
|
24
|
-
task :
|
24
|
+
task build: [:build_gem]
|
25
|
+
|
26
|
+
task default: [:spec]
|
data/ext/gloss/Makefile
CHANGED
@@ -3,16 +3,8 @@ PLATFORM = $(shell uname -s)
|
|
3
3
|
|
4
4
|
ifeq "$(PLATFORM)" "Darwin"
|
5
5
|
TARGET = ../../lib/gls.bundle
|
6
|
-
|
7
|
-
clean:
|
8
|
-
rm -f $(TARGET) $(TARGET).dwarf
|
9
|
-
endif
|
10
|
-
|
11
|
-
ifeq "$(PLATFORM)" "Linux"
|
6
|
+
else
|
12
7
|
TARGET = ../../lib/gls.so
|
13
|
-
|
14
|
-
clean:
|
15
|
-
rm -f $(TARGET)
|
16
8
|
endif
|
17
9
|
|
18
10
|
install: all
|
@@ -23,4 +15,8 @@ shards:
|
|
23
15
|
shards
|
24
16
|
|
25
17
|
build: ./src/gloss.cr
|
26
|
-
$(CRYSTAL) build --link-flags "-shared -
|
18
|
+
$(CRYSTAL) build --link-flags "-shared -Wl,-undefined,dynamic_lookup" $< -o $(TARGET) --release
|
19
|
+
|
20
|
+
clean:
|
21
|
+
rm -f $(TARGET)
|
22
|
+
rm -f $(TARGET).dwarf
|
data/ext/gloss/lib/cr_ruby.cr
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
lib CrRuby
|
2
2
|
# every ruby Object is a VALUE
|
3
3
|
type VALUE = Void*
|
4
|
-
# ruby method typing
|
5
|
-
type METHOD_FUNC = VALUE, VALUE -> VALUE
|
6
4
|
|
7
5
|
# a ruby Class is a VALUE
|
8
6
|
$rb_cObject : VALUE
|
@@ -28,8 +26,11 @@ lib CrRuby
|
|
28
26
|
fun rb_define_module(name: UInt8*) : VALUE
|
29
27
|
|
30
28
|
# define ruby method in C
|
31
|
-
fun rb_define_method(klass: VALUE, name: UInt8*, func:
|
29
|
+
fun rb_define_method(klass: VALUE, name: UInt8*, func: Proc(CrRuby::VALUE, CrRuby::VALUE,
|
30
|
+
CrRuby::VALUE), argc: Int32)
|
32
31
|
|
33
32
|
# define singleton ruby method in C
|
34
|
-
fun rb_define_singleton_method(klass: VALUE, name: UInt8*, func:
|
33
|
+
fun rb_define_singleton_method(klass: VALUE, name: UInt8*, func: Proc(CrRuby::VALUE,
|
34
|
+
CrRuby::VALUE,
|
35
|
+
CrRuby::VALUE), argc: Int32)
|
35
36
|
end
|
data/ext/gloss/src/gloss.cr
CHANGED
@@ -4,7 +4,7 @@ require "./cr_ast"
|
|
4
4
|
require "./rb_ast"
|
5
5
|
require "./parser"
|
6
6
|
|
7
|
-
def parse_string(
|
7
|
+
def parse_string(_self : CrRuby::VALUE, str : CrRuby::VALUE)
|
8
8
|
st = CrRuby.rb_str_to_str(str)
|
9
9
|
string = String.new(CrRuby.rb_string_value_cstr(pointerof(st)))
|
10
10
|
|
@@ -21,5 +21,10 @@ fun init = Init_gls
|
|
21
21
|
GC.init
|
22
22
|
LibCrystalMain.__crystal_main(0, Pointer(Pointer(UInt8)).null)
|
23
23
|
gloss = CrRuby.rb_define_module("Gloss");
|
24
|
-
CrRuby.rb_define_singleton_method(
|
24
|
+
CrRuby.rb_define_singleton_method(
|
25
|
+
gloss,
|
26
|
+
"parse_buffer",
|
27
|
+
->parse_string(CrRuby::VALUE, CrRuby::VALUE),
|
28
|
+
1
|
29
|
+
);
|
25
30
|
end
|
data/gloss.gemspec
CHANGED
@@ -17,11 +17,12 @@ Gem::Specification.new do |s|
|
|
17
17
|
|
18
18
|
s.add_runtime_dependency "fast_blank"
|
19
19
|
s.add_runtime_dependency "listen"
|
20
|
-
s.add_runtime_dependency "rbs"
|
21
|
-
s.add_runtime_dependency "steep"
|
20
|
+
s.add_runtime_dependency "rbs", "1.0.4"
|
21
|
+
s.add_runtime_dependency "steep", "0.41.0"
|
22
22
|
|
23
|
+
s.add_development_dependency "pry-byebug"
|
23
24
|
s.add_development_dependency "rake-compiler"
|
24
25
|
s.add_development_dependency "rspec"
|
25
|
-
s.add_development_dependency "pry-byebug"
|
26
26
|
s.add_development_dependency "rubocop"
|
27
|
+
s.add_development_dependency "rufo"
|
27
28
|
end
|
data/lib/gloss.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
|
3
2
|
##### This file was generated by Gloss; any changes made here will be overwritten.
|
4
|
-
##### See
|
3
|
+
##### See / to make changes
|
5
4
|
|
6
5
|
require "rbs"
|
7
6
|
require "json"
|
@@ -22,11 +21,8 @@ require "gloss/errors"
|
|
22
21
|
require "gloss/logger"
|
23
22
|
require "gloss/prog_loader"
|
24
23
|
require "gloss/utils"
|
25
|
-
|
26
|
-
|
27
|
-
unless is_ci
|
28
|
-
require "gls"
|
29
|
-
end
|
24
|
+
require "gloss/runtime"
|
25
|
+
require "gls"
|
30
26
|
EMPTY_ARRAY = Array.new
|
31
27
|
.freeze
|
32
28
|
EMPTY_HASH = {}.freeze
|
data/lib/gloss/cli.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
|
3
2
|
##### This file was generated by Gloss; any changes made here will be overwritten.
|
4
|
-
##### See
|
3
|
+
##### See / to make changes
|
5
4
|
|
6
5
|
require "optparse"
|
7
6
|
module Gloss
|
@@ -27,6 +26,7 @@ case command
|
|
27
26
|
when "version", "--version", "-v"
|
28
27
|
puts(Gloss::VERSION)
|
29
28
|
when "watch", "build"
|
29
|
+
Gloss.load_config
|
30
30
|
type_checker = ProgLoader.new
|
31
31
|
.run
|
32
32
|
(if command.==("watch")
|
data/lib/gloss/config.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
|
3
2
|
##### This file was generated by Gloss; any changes made here will be overwritten.
|
4
|
-
##### See
|
3
|
+
##### See / to make changes
|
5
4
|
|
6
5
|
require "ostruct"
|
7
6
|
require "yaml"
|
@@ -10,14 +9,18 @@ module Gloss
|
|
10
9
|
Config = OpenStruct.new(default_config: {:frozen_string_literals => true,
|
11
10
|
:src_dir => "src",
|
12
11
|
:entrypoint => nil,
|
13
|
-
:strict_require => false
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
:strict_require => false,
|
13
|
+
:type_checking_strictness => "lenient",
|
14
|
+
:prettify_output_executable_path => nil}.freeze)
|
15
|
+
def self.load_config()
|
16
|
+
user_config = (if File.exist?(File.absolute_path(File.join(Dir.pwd, CONFIG_PATH)))
|
17
|
+
YAML.safe_load(File.read(CONFIG_PATH))
|
18
|
+
else
|
19
|
+
Config.default_config
|
20
|
+
end)
|
17
21
|
Config.default_config
|
18
|
-
end)
|
19
|
-
Config.default_config
|
20
22
|
.each() { |k, v|
|
21
|
-
|
22
|
-
|
23
|
+
Config.send(:"#{k}=", user_config.[](k.to_s) || v)
|
24
|
+
}
|
25
|
+
end
|
23
26
|
end
|
data/lib/gloss/errors.rb
CHANGED
data/lib/gloss/initializer.rb
CHANGED
data/lib/gloss/logger.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
|
3
2
|
##### This file was generated by Gloss; any changes made here will be overwritten.
|
4
|
-
##### See
|
3
|
+
##### See / to make changes
|
5
4
|
|
6
5
|
module Gloss
|
7
6
|
def self.logger()
|
@@ -24,6 +23,11 @@ nil => nil,
|
|
24
23
|
else
|
25
24
|
IO::NULL
|
26
25
|
end))
|
26
|
+
.tap() { |l|
|
27
|
+
(if real_log_level
|
28
|
+
l.level=(real_log_level)
|
29
|
+
end)
|
30
|
+
}
|
27
31
|
end)
|
28
32
|
end
|
29
33
|
end
|