cryolite 0.1.0 → 0.2.0
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 +4 -4
- data/LICENSE +21 -0
- data/lib/cryolite.rb +2 -47
- data/src/cryolite.cr +44 -0
- metadata +3 -2
- data/lib/cryolite/version.rb +0 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7b60d96ddbde97178a4e1c74a8a45899b694ace8430502b8a40c0eb866d2711b
|
|
4
|
+
data.tar.gz: 2aea3670e4764957f1b0ff71a8a134765dac28c4625056213789f6bb4a89468f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b09a9bd9691f927b868f4e6b277a1b44f9b5a1825f44b280f713079c7c1c449af2be644d00785406c66c2cdf3dd007c71df33893248dc155f09dc5f16fce1b34
|
|
7
|
+
data.tar.gz: ba7dd3d37a62491d718a17fa1088f153573c811c90450660c786051e77f9a98aa255c0c63a33865b35376ed3d47c77011e5e597c0bbe6df1661d40cb777dc581
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Siarhiej Siamaška
|
|
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 all
|
|
13
|
+
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 THE
|
|
21
|
+
SOFTWARE.
|
data/lib/cryolite.rb
CHANGED
|
@@ -1,47 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
module Cryolite
|
|
4
|
-
# This is how runing under Crystal can be detected.
|
|
5
|
-
COMPILED_BY_CRYSTAL = (((1 / 2) * 2) != 0)
|
|
6
|
-
|
|
7
|
-
# Monkey-patch Ruby to make it recognize the Crystal's .to_i128 method
|
|
8
|
-
class ::Integer def to_i128() to_i end end
|
|
9
|
-
|
|
10
|
-
# An 8-bit zero constant to hint the use of UInt8 instead of Int32 for Crystal
|
|
11
|
-
U8_0 = "\0".bytes.first
|
|
12
|
-
|
|
13
|
-
# A 64-bit zero constant to hint the use of Int64 instead of Int32 for Crystal
|
|
14
|
-
I64_0 = (0x3FFFFFFFFFFFFFFF & 0)
|
|
15
|
-
|
|
16
|
-
# A 128-bit zero constant to hint the use of Int128 instead of Int32 for Crystal
|
|
17
|
-
I128_0 = 0.to_i128
|
|
18
|
-
|
|
19
|
-
# This is a Ruby-compatible trick to create a Crystal's lightweight tuple
|
|
20
|
-
def tuple2(a, b) return a, b end
|
|
21
|
-
def tuple3(a, b, c) return a, b, c end
|
|
22
|
-
|
|
23
|
-
# This icky blob of code aliases the Ruby's "respond_to?" method to "responds_to?",
|
|
24
|
-
# making it easier to maintain the source level compatibility with Crystal. And
|
|
25
|
-
# also provides access to the "eval_if_run_by_ruby" function, which does "eval"
|
|
26
|
-
# when the code is run by Ruby, but does nothing when the code is compiled by
|
|
27
|
-
# Crystal. It can be used to define additional aliases necessary for Ruby/Crystal
|
|
28
|
-
# compatibility.
|
|
29
|
-
module ::Kernel def method_missing(name, *args) true end end
|
|
30
|
-
if (k5324534 = ::Kernel).responds_to? :eval ; k5324534.eval "class ::Object alias
|
|
31
|
-
responds_to? respond_to? end ; module ::Kernel undef method_missing end" end
|
|
32
|
-
def self.eval_if_run_by_ruby(src) if (k = ::Kernel).responds_to? :eval ; k.eval src end end
|
|
33
|
-
# See https://bugs.ruby-lang.org/issues/13551#note-3
|
|
34
|
-
eval_if_run_by_ruby "module ::Kernel def alias_singleton_method(new_name, old_name)
|
|
35
|
-
singleton_class.class_exec { alias_method new_name, old_name } end end"
|
|
36
|
-
# A convenient wrapper
|
|
37
|
-
def self.ruby_class_method_alias(classname, from, to) eval_if_run_by_ruby "class
|
|
38
|
-
#{classname} alias_singleton_method :#{to}, :#{from} end" end
|
|
39
|
-
|
|
40
|
-
# Emulate "File.exists?" for Ruby 3.2.0 and newer, see
|
|
41
|
-
# https://www.reddit.com/r/ruby/comments/1196wti/psa_and_a_little_rant_fileexists_direxists
|
|
42
|
-
ruby_class_method_alias("::File", "exist?", "exists?")
|
|
43
|
-
# Emulate the availability of Crystal's Regex for Ruby (the name is slightly off)
|
|
44
|
-
eval_if_run_by_ruby "Regex = Regexp"
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
Object.include(Cryolite)
|
|
1
|
+
# Just load the Crystal source file in order to avoid code duplication
|
|
2
|
+
load File.join(File.dirname(__dir__), "src", "cryolite.cr")
|
data/src/cryolite.cr
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# This helper module allows to use a common subset of Ruby and Crystal programming languages
|
|
2
|
+
module Cryolite
|
|
3
|
+
# This is how runing under Crystal can be detected.
|
|
4
|
+
COMPILED_BY_CRYSTAL = (((1 / 2) * 2) != 0)
|
|
5
|
+
|
|
6
|
+
# Monkey-patch Ruby to make it recognize the Crystal's .to_i128 method
|
|
7
|
+
class ::Integer def to_i128() to_i end end
|
|
8
|
+
|
|
9
|
+
# An 8-bit zero constant to hint the use of UInt8 instead of Int32 for Crystal
|
|
10
|
+
U8_0 = "\0".bytes.first
|
|
11
|
+
|
|
12
|
+
# A 64-bit zero constant to hint the use of Int64 instead of Int32 for Crystal
|
|
13
|
+
I64_0 = (0x3FFFFFFFFFFFFFFF & 0)
|
|
14
|
+
|
|
15
|
+
# A 128-bit zero constant to hint the use of Int128 instead of Int32 for Crystal
|
|
16
|
+
I128_0 = 0.to_i128
|
|
17
|
+
|
|
18
|
+
# This is a Ruby-compatible trick to create a Crystal's lightweight tuple
|
|
19
|
+
def tuple2(a, b) return a, b end
|
|
20
|
+
def tuple3(a, b, c) return a, b, c end
|
|
21
|
+
|
|
22
|
+
# This icky blob of code aliases the Ruby's "respond_to?" method to "responds_to?",
|
|
23
|
+
# making it easier to maintain the source level compatibility with Crystal. And
|
|
24
|
+
# also provides access to the "eval_if_run_by_ruby" function, which does "eval"
|
|
25
|
+
# when the code is run by Ruby, but does nothing when the code is compiled by
|
|
26
|
+
# Crystal. It can be used to define additional aliases necessary for Ruby/Crystal
|
|
27
|
+
# compatibility.
|
|
28
|
+
module ::Kernel def method_missing(name, *args) true end end
|
|
29
|
+
if (k5324534 = ::Kernel).responds_to? :eval ; k5324534.eval "class ::Object alias
|
|
30
|
+
responds_to? respond_to? end ; module ::Kernel undef method_missing end" end
|
|
31
|
+
def self.eval_if_run_by_ruby(src) if (k = ::Kernel).responds_to? :eval ; k.eval src end end
|
|
32
|
+
# See https://bugs.ruby-lang.org/issues/13551#note-3
|
|
33
|
+
eval_if_run_by_ruby "module ::Kernel def alias_singleton_method(new_name, old_name)
|
|
34
|
+
singleton_class.class_exec { alias_method new_name, old_name } end end"
|
|
35
|
+
# A convenient wrapper
|
|
36
|
+
def self.ruby_class_method_alias(classname, from, to) eval_if_run_by_ruby "class
|
|
37
|
+
#{classname} alias_singleton_method :#{to}, :#{from} end" end
|
|
38
|
+
|
|
39
|
+
# Emulate "File.exists?" for Ruby 3.2.0 and newer, see
|
|
40
|
+
# https://www.reddit.com/r/ruby/comments/1196wti/psa_and_a_little_rant_fileexists_direxists
|
|
41
|
+
ruby_class_method_alias("::File", "exist?", "exists?")
|
|
42
|
+
# Emulate the availability of Crystal's Regex for Ruby (the name is slightly off)
|
|
43
|
+
eval_if_run_by_ruby "Regex = Regexp"
|
|
44
|
+
end ; include Cryolite
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cryolite
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Siarhiej Siamaška
|
|
@@ -15,9 +15,10 @@ executables: []
|
|
|
15
15
|
extensions: []
|
|
16
16
|
extra_rdoc_files: []
|
|
17
17
|
files:
|
|
18
|
+
- LICENSE
|
|
18
19
|
- README.md
|
|
19
20
|
- lib/cryolite.rb
|
|
20
|
-
-
|
|
21
|
+
- src/cryolite.cr
|
|
21
22
|
homepage: https://github.com/ssvb/cryolite
|
|
22
23
|
licenses:
|
|
23
24
|
- MIT
|
data/lib/cryolite/version.rb
DELETED