yamlscript 0.0.16 → 0.1.34

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2f2590c97f31dc5e9da44345db05a6c5670c50fa9acd075c798c706ad1bfd9d4
4
- data.tar.gz: c55d29ddf63979e7cdcbe6a567094c8d777f96b1084b333424eb0288b0b7ce74
3
+ metadata.gz: 2591c91f2c28552fedf3d3eed747049e3776b835b0761d81078b99bfb3539be1
4
+ data.tar.gz: f2484037d32174a29ecc9e01be62cbf2f3f2fa1c0485e8d87b5c64dbab9ec15c
5
5
  SHA512:
6
- metadata.gz: 641d0cf012bf55db5a3b8d87ca73228bd60ad7c1780b72b0e70408b85df6b4456f8257fa0deeaec03d42c291d13471e09f2fd535e6eb452ed4ecad8ce8608eb2
7
- data.tar.gz: '020280ad7ca3cd8cc36865b32427208587682ae32152e1fbdc29c151e7b3f06a26a591d21e744a4292f9881e00ac450cd5edfc2f6d0fb7d5384eb29bb344676b'
6
+ metadata.gz: 7c4d3a6d4da4674749869cc821eb5eeb0c9feca1b31dcd1a419d9ea41538b28232a852254e85b1ae3662c75b2fd748070fa2f74171aeaf4eb0ce13fbfbb3a982
7
+ data.tar.gz: c99ae20a38f1e3090371dee340331b00bfbd011896b42c08b03be8d26960fd17962e6a9d4e251a842e269a3454349af95faf0c7cf57fcf52817c6c86e4e06a05
data/.gitignore CHANGED
@@ -4,6 +4,7 @@
4
4
  /coverage/
5
5
  /doc/
6
6
  /pkg/
7
+ /.rake_tasks*
7
8
  /spec/reports/
8
9
  /tmp/
9
10
  /Gemfile.lock
data/Gemfile CHANGED
@@ -6,3 +6,4 @@ source "https://rubygems.org"
6
6
  gemspec
7
7
 
8
8
  gem "rake", "~> 13.0"
9
+ gem "minitest", "~> 5.20.0"
data/Makefile ADDED
@@ -0,0 +1,25 @@
1
+ include ../common/base.mk
2
+ include $(COMMON)/binding.mk
3
+
4
+ RUBY := $(shell command -v bundle)
5
+
6
+ RAKE_CMDS := \
7
+ build \
8
+ clean \
9
+ release \
10
+ test \
11
+
12
+ #------------------------------------------------------------------------------
13
+
14
+ ifdef RUBY
15
+ update:
16
+ bundle install
17
+
18
+ $(RAKE_CMDS)::
19
+ bundle exec rake $@
20
+
21
+ endif
22
+
23
+ clean::
24
+ $(RM) Gemfile.lock .rake_tasks*
25
+ $(RM) -r pkg
data/Rakefile CHANGED
@@ -1,4 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "bundler/gem_tasks"
4
- task default: %i[]
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.warning = false
10
+ t.test_globs = ["test/**/*_test.rb"]
11
+ end
12
+
13
+ task :default => :test
data/ReadMe.md ADDED
@@ -0,0 +1,140 @@
1
+ YAMLScript
2
+ ==========
3
+
4
+ Program in YAML
5
+
6
+
7
+ ## Synopsis
8
+
9
+ ```yaml
10
+ #!/usr/bin/env ys-0
11
+
12
+ defn main(name):
13
+ say: "Hello, $name!"
14
+ ```
15
+
16
+
17
+ ## Description
18
+
19
+ YAMLScript is a functional programming language with a stylized YAML syntax.
20
+
21
+ YAMLScript can be used for:
22
+
23
+ * Writing new programs and applications
24
+ * Run with `ys file.ys`
25
+ * Or compile to binary executable with `ys -C file.ys`
26
+ * Enhancing ordinary YAML files with new functional magics
27
+ * Import parts of other YAML files to any node
28
+ * String interpolation including function calls
29
+ * Any other functionality you can dream up!
30
+ * Writing reusable shared libraries
31
+ * High level code instead of C
32
+ * Bindable to almost any programming language
33
+
34
+ YAMLScript should be a drop-in replacement for your YAML loader!
35
+
36
+ Most existing YAML files are already valid YAMLScript files.
37
+ This means that YAMLScript works as a normal YAML loader, but can also evaluate
38
+ functional expressions if asked to.
39
+
40
+ Under the hood, YAMLScript code compiles to the Clojure programming language.
41
+ This makes YAMLScript a complete functional programming language right out of
42
+ the box.
43
+
44
+ Even though YAMLScript compiles to Clojure, and Clojure compiles to Java, there
45
+ is no dependency on Java or the JVM.
46
+ YAMLScript is compiled to a native shared library (`libyamlscript.so`) that can
47
+ be used by any programming language that can load shared libraries.
48
+
49
+ To see the Clojure code that YAMLScript compiles to, you can use the YAMLScript
50
+ command line utility, `ys`, to run:
51
+
52
+ ```text
53
+ $ ys --compile file.ys
54
+ ```
55
+
56
+
57
+ ## Ruby Usage
58
+
59
+ File `prog.rb`:
60
+
61
+ ```ruby
62
+ require 'yamlscript'
63
+ input = IO.read('file.ys')
64
+ ys = YAMLScript.new
65
+ data = ys.load(input)
66
+ puts data
67
+ ```
68
+
69
+ File `file.ys`:
70
+
71
+ ```yaml
72
+ !yamlscript/v0
73
+
74
+ name =: "World"
75
+
76
+ =>::
77
+ foo: [1, 2, ! inc(41)]
78
+ bar:: load("other.yaml")
79
+ baz:: "Hello, $name!"
80
+ ```
81
+
82
+ File `other.yaml`:
83
+
84
+ ```yaml
85
+ oh: Hello
86
+ ```
87
+
88
+ Run:
89
+
90
+ ```text
91
+ $ ruby prog.rb
92
+ {"foo"=>[1, 2, 42], "bar"=>{"oh"=>"Hello"}, "baz"=>"Hello, World!"}
93
+ ```
94
+
95
+
96
+ ## Installation
97
+
98
+ You can install this module like any other Ruby module:
99
+
100
+ ```bash
101
+ $ gem install yamlscript
102
+ ```
103
+
104
+ but you will need to have a system install of `libyamlscript.so`.
105
+
106
+ One simple way to do that is with:
107
+
108
+ ```bash
109
+ $ curl https://yamlscript.org/install | sudo PREFIX=/usr/local bash
110
+ ```
111
+
112
+ > Note: The above command will install the latest version of the YAMLScript
113
+ command line utility, `ys`, and the shared library, `libyamlscript.so`, into
114
+ `/usr/local/bin` and `/usr/local/lib` respectively.
115
+
116
+ See https://github.com/yaml/yamlscript?#installing-yamlscript for more info.
117
+
118
+
119
+ ## See Also
120
+
121
+ * [The YAMLScript Web Site](https://yamlscript.org)
122
+ * [The YAMLScript Blog](https://yamlscript.org/blog)
123
+ * [The YAMLScript Source Code](https://github.com/yaml/yamlscript)
124
+ * [YAML](https://yaml.org)
125
+ * [Clojure](https://clojure.org)
126
+
127
+
128
+ ## Authors
129
+
130
+ * [Ingy döt Net](https://github.com/ingydotnet)
131
+ * [Delon R.Newman](https://github.com/delonnewman)
132
+
133
+
134
+ ## License & Copyright
135
+
136
+ Copyright 2022-2024 Ingy döt Net <ingy@ingy.net>
137
+
138
+ This project is licensed under the terms of the `MIT` license.
139
+ See [LICENSE](https://github.com/yaml/yamlscript/blob/main/License) for
140
+ more details.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Yamlscript
4
- VERSION = "0.0.16"
3
+ class YAMLScript
4
+ VERSION = "0.1.34"
5
5
  end
data/lib/yamlscript.rb CHANGED
@@ -1,8 +1,109 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "yamlscript/version"
3
+ # Copyright 2023-2024 Ingy dot Net
4
+ # This code is licensed under MIT license (See License for details)
4
5
 
5
- module Yamlscript
6
- class Error < StandardError; end
7
- # Your code goes here...
6
+ require 'fiddle'
7
+ require 'fiddle/import'
8
+ require 'json'
9
+
10
+ require_relative 'yamlscript/version'
11
+
12
+ # Ruby binding for the libyamlscript shared library.
13
+ class YAMLScript
14
+ Error = Class.new(StandardError)
15
+
16
+ # TODO: This value is automatically updated by 'make bump'.
17
+ # The version number is used to find the correct shared library file.
18
+ # We currently only support binding to an exact version of libyamlscript.
19
+ YAMLSCRIPT_VERSION = '0.1.34'
20
+
21
+ # A low-level interface to the native library
22
+ module LibYAMLScript
23
+ extend Fiddle::Importer
24
+
25
+ def self.extension
26
+ case RUBY_PLATFORM
27
+ when /darwin/
28
+ 'dylib'
29
+ when /linux/
30
+ 'so'
31
+ else
32
+ raise Error, "Unsupported platform #{RUBY_PLATFORM} for yamlscript."
33
+ end
34
+ end
35
+
36
+ def self.filename
37
+ "libyamlscript.#{extension}.#{YAMLSCRIPT_VERSION}"
38
+ end
39
+
40
+ # Returns an array of library paths extracted from the LD_LIBRARY_PATH
41
+ # environment variable.
42
+ # If the environment variable is not set will return an array with
43
+ # `/usr/local/lib` only.
44
+ def self.ld_library_paths
45
+ env_value = ENV.fetch('LD_LIBRARY_PATH', '')
46
+ paths = env_value.split(':')
47
+ paths << '/usr/local/lib'
48
+ end
49
+
50
+ # Find the libyamlscript shared library file path
51
+ def self.path
52
+ name = filename
53
+ path = ld_library_paths.map {
54
+ |dir| File.join(dir, name) }.detect { |file| File.exist?(file)
55
+ }
56
+
57
+ raise Error, "Shared library file `#{name}` not found" unless path
58
+
59
+ path
60
+ end
61
+
62
+ dlload path
63
+
64
+ extern \
65
+ 'int graal_create_isolate(void* params, void** isolate, void** thread)'
66
+ extern 'int graal_tear_down_isolate(void* thread)'
67
+ extern 'char* load_ys_to_json(void* thread, char* yamlscript)'
68
+ end
69
+
70
+ # Interface with the libyamlscript shared library.
71
+ #
72
+ # @example
73
+ # require 'yamlscript'
74
+ #
75
+ # YAMLScript.load(IO.read('file.ys'))
76
+ def self.load(ys_code, **options)
77
+ new(**options).load(ys_code)
78
+ end
79
+
80
+ attr_reader :options, :error
81
+
82
+ def initialize(**options)
83
+ # config not used yet
84
+ @options = options
85
+
86
+ # Create a new GraalVM isolate for life of the YAMLScript instance
87
+ @isolate = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP)
88
+ @error = nil
89
+ end
90
+
91
+ # Compile and eval a YAMLScript string and return the result
92
+ def load(ys_code)
93
+ # Create a new GraalVM isolate thread for each call to load()
94
+ thread = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP)
95
+ LibYAMLScript.graal_create_isolate(nil, @isolate.ref, thread.ref)
96
+
97
+ # Call 'load_ys_to_json' function in libyamlscript shared library
98
+ json_data = LibYAMLScript.load_ys_to_json(thread, ys_code)
99
+ resp = JSON.parse(json_data.to_s)
100
+ raise Error, 'Failed to tear down isolate' \
101
+ unless LibYAMLScript.graal_tear_down_isolate(thread).zero?
102
+ raise Error, @error['cause'] if (@error = resp['error'])
103
+ data = resp.fetch('data') do
104
+ raise Error, 'Unexpected response from libyamlscript'
105
+ end
106
+
107
+ data
108
+ end
8
109
  end
data/yamlscript.gemspec CHANGED
@@ -4,9 +4,9 @@ require_relative "lib/yamlscript/version"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "yamlscript"
7
- spec.version = Yamlscript::VERSION
8
- spec.authors = ["Ingy döt Net"]
9
- spec.email = ["ingy@ingy.net"]
7
+ spec.version = YAMLScript::VERSION
8
+ spec.authors = ["Ingy döt Net", "Delon Newman"]
9
+ spec.email = ["ingy@ingy.net", "contact@delonnewman.name"]
10
10
 
11
11
  spec.summary = "Program in YAML"
12
12
  spec.description = "Program in YAML"
@@ -15,18 +15,17 @@ Gem::Specification.new do |spec|
15
15
 
16
16
  spec.metadata["homepage_uri"] = spec.homepage
17
17
  spec.metadata["source_code_uri"] = spec.homepage
18
- spec.metadata["changelog_uri"] = "https://github.com/yaml/yamlscript/tree/main/ruby/ChangeLog.md"
18
+ spec.metadata["changelog_uri"] = \
19
+ "https://github.com/yaml/yamlscript/tree/main/ruby/ChangeLog.md"
19
20
 
20
21
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
22
+ `git ls-files -z`.split("\x0").reject {
23
+ |f| f.match(%r{\A(?:test|spec|features)/})
24
+ }
22
25
  end
23
26
  spec.bindir = "exe"
24
27
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
25
28
  spec.require_paths = ["lib"]
26
29
 
27
- # Uncomment to register a new dependency of your gem
28
- # spec.add_dependency "example-gem", "~> 1.0"
29
-
30
- # For more information and examples about making a new gem, checkout our
31
- # guide at: https://bundler.io/guides/creating_gem.html
30
+ spec.add_dependency "minitest", "~> 5.20.0"
32
31
  end
metadata CHANGED
@@ -1,18 +1,34 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yamlscript
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.1.34
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ingy döt Net
8
+ - Delon Newman
8
9
  autorequire:
9
10
  bindir: exe
10
11
  cert_chain: []
11
- date: 2022-08-01 00:00:00.000000000 Z
12
- dependencies: []
12
+ date: 2024-01-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: minitest
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 5.20.0
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 5.20.0
13
28
  description: Program in YAML
14
29
  email:
15
30
  - ingy@ingy.net
31
+ - contact@delonnewman.name
16
32
  executables: []
17
33
  extensions: []
18
34
  extra_rdoc_files: []
@@ -20,10 +36,9 @@ files:
20
36
  - ".gitignore"
21
37
  - ChangeLog.md
22
38
  - Gemfile
23
- - README.md
39
+ - Makefile
24
40
  - Rakefile
25
- - bin/console
26
- - bin/setup
41
+ - ReadMe.md
27
42
  - lib/yamlscript.rb
28
43
  - lib/yamlscript/version.rb
29
44
  - yamlscript.gemspec
data/README.md DELETED
@@ -1,35 +0,0 @@
1
- # Yamlscript
2
-
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/yamlscript`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'yamlscript'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle install
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install yamlscript
22
-
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
-
33
- ## Contributing
34
-
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/yamlscript.
data/bin/console DELETED
@@ -1,15 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require "bundler/setup"
5
- require "yamlscript"
6
-
7
- # You can add fixtures and/or initialization code here to make experimenting
8
- # with your gem easier. You can also use a different console, if you like.
9
-
10
- # (If you use this, don't forget to add pry to your Gemfile!)
11
- # require "pry"
12
- # Pry.start
13
-
14
- require "irb"
15
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here