upl 0.2.2 → 0.2.4

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: a3f3986baaa4caf8654ae53619fc3606dd9f608f7f7722cd3860d6ec2af8a1fe
4
- data.tar.gz: 18e8d59804dd3802da05df95d667ffff47d71e73af82d3bbad509dc0ab4f2930
3
+ metadata.gz: 933b536ad1c58be9cf92e474272904b5752d9eef7f3004be1ec35a5623438aa6
4
+ data.tar.gz: 2d212a7ea47101d3fd9255b8b53bffcb8bf4ce8f15989b7a34a66dbc39b09cc9
5
5
  SHA512:
6
- metadata.gz: f34cf6fafe347a3f7494108bf286abbff5771e51450594858d455d13630ac7645f36f1b26c3f45757a611bdca52dbe604dbd5e4c63c54ee4cb3cf176d22de7a8
7
- data.tar.gz: c4524355fa328c53fe99c56a1a99553e0a9cecff4b31c177571f4c6b895bc229388829d406a714e34b61667f975b046dde2507236c473d565f415634a130f604
6
+ metadata.gz: 52b2a3376e96852df1e690e40f89d784c7f5100bf72b628264dec970b1b48b238cad425c5e51c469b7496d7bc7e8951eaa276285e40009cbf2d94bba9463d363
7
+ data.tar.gz: b1fa64877cf05ab1a507eb082c592494976d36611e534fb543b6e89854d9ba01326bf89c7ea035577d8e21111949ea3901c3e8da35bdf43c5fdec5acd0816818
@@ -0,0 +1,77 @@
1
+ name: rspecs
2
+
3
+ on:
4
+ workflow_dispatch: {}
5
+ push:
6
+ branches: [test-workflow]
7
+ tags: v*
8
+
9
+ jobs:
10
+ rspec:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ # note 20-Jul-2023 2.7.8 is EOL
15
+ ruby_version: ['2.7.8', '3.0.6', '3.1.4', '3.2.2']
16
+
17
+ steps:
18
+ - uses: actions/checkout@v3
19
+
20
+ - uses: ruby/setup-ruby@v1
21
+ with:
22
+ ruby-version: ${{ matrix.ruby_version }}
23
+
24
+ - run: bundle install
25
+
26
+ # install from ppa for up-to-date version
27
+ - name: update ubuntu packages
28
+ run: |
29
+ sudo apt-get update
30
+
31
+ # otherwise it prompts for timezone
32
+ sudo apt-get install -y tzdata
33
+ sudo apt-get install -y software-properties-common
34
+
35
+ - name: install swi-prolog from ppa
36
+ run: |
37
+ # Stable versions
38
+ sudo apt-add-repository -y ppa:swi-prolog/stable
39
+ sudo apt-get update
40
+ sudo apt-get install -y swi-prolog-nox
41
+
42
+ # Development versions
43
+ # sudo apt-add-repository ppa:swi-prolog/devel
44
+ # sudo apt-get update
45
+ # sudo apt-get install -y swi-prolog-nox
46
+
47
+ - run: rspec
48
+
49
+ rspec-macos:
50
+ runs-on: macos-latest
51
+ strategy:
52
+ matrix:
53
+ # note 20-Jul-2023 2.7.8 is EOL
54
+ ruby_version: ['2.7.8', '3.0.6', '3.1.4', '3.2.2']
55
+
56
+ steps:
57
+ - name: install swi-prolog
58
+ run: |
59
+ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
60
+ brew install swi-prolog
61
+
62
+ # for possible future debugging
63
+ # otool -L $(which swipl)
64
+ # swipl --dump-runtime-variables=sh
65
+ # env
66
+ # find /usr/local/Cellar/swi-prolog/9.0.4 -ls
67
+ # false
68
+
69
+ - uses: actions/checkout@v3
70
+
71
+ - uses: ruby/setup-ruby@v1
72
+ with:
73
+ ruby-version: ${{ matrix.ruby_version }}
74
+
75
+ - run: bundle install
76
+
77
+ - run: rspec
data/History.txt CHANGED
@@ -1,3 +1,10 @@
1
+ == 0.2.4
2
+ * should now find the dylib on macos
3
+ * run rspecs on multiple ruby versions
4
+
5
+ == 0.2.3
6
+ * update C value for >=swi-prolog-8.1.29
7
+
1
8
  == 0.2.2
2
9
  * restrict to <=swi-prolog-8.1.22
3
10
 
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ ![rspecs](https://github.com/djellemah/upl/actions/workflows/build.yml/badge.svg)
2
+
1
3
  # Upl
2
4
 
3
5
  Use SWI-Prolog from ruby.
@@ -8,6 +10,12 @@ Define foreign predicates in ruby, so prolog can call back into ruby code.
8
10
 
9
11
  Assert facts containing ruby objects, so prolog can query ruby data by calling ruby methods.
10
12
 
13
+ ## versions
14
+
15
+ Works on ruby-2.7.8 ruby-3.0, ruby-3.1, ruby-3.2
16
+
17
+ and swipl-8.1.29 to swipl-9.1.2
18
+
11
19
  ## Tutorial
12
20
 
13
21
  The query api always returns an ```Enumerable``` of all values which satisfy the query.
@@ -0,0 +1,7 @@
1
+ version: '3.8'
2
+
3
+ services:
4
+ linux:
5
+ container_name: upl-linux
6
+ image: ubuntu:latest
7
+ command: sleep 14400
data/lib/upl/extern.rb CHANGED
@@ -26,18 +26,28 @@ module Upl
26
26
  # should result in something like
27
27
  # /usr/lib64/swipl-7.7.18/lib/x86_64-linux/libswipl.so
28
28
  # which should actually exist
29
- def self.so_path
29
+ def self.calculate_so_path
30
30
  values = swipl_config_values
31
- p = Pathname "#{values['PLBASE']}/lib/#{values['PLARCH']}/#{values['PLLIB'].gsub('-l', 'lib')}.#{values['PLSOEXT']}"
31
+ p = if easy_so = values['PLLIBSWIPL']
32
+ Pathname easy_so
33
+ else
34
+ # figure it out the hard way - this was prior to 8.1 or thereabouts
35
+ Pathname "#{values['PLBASE']}/lib/#{values['PLARCH']}/#{values['PLLIB'].gsub('-l', 'lib')}.#{values['PLSOEXT']}"
36
+ end
32
37
  p.realpath.to_s
33
38
  rescue Errno::ENOENT => ex
34
39
  puts "problem with library #{p.to_s}: #{ex.message}"
35
40
  exit 1
36
41
  end
37
42
 
38
- if (version = swipl_config_values['PLVERSION']) >= '80100'
39
- # 801xx seems to have changed some calls. Not sure yet what they are.
40
- raise "unsupported version #{version}"
43
+ # where is the so/dylib
44
+ # overridable by env var SWIPL_SO_PATH
45
+ def self.so_path
46
+ ENV['SWIPL_SO_PATH'] || calculate_so_path
47
+ end
48
+
49
+ if (version = swipl_config_values['PLVERSION']) < '80129'
50
+ raise "unsupported version <#{version}"
41
51
  end
42
52
 
43
53
  dlload so_path
@@ -105,30 +115,31 @@ module Upl
105
115
  PL_VARIABLE = (1)
106
116
  PL_ATOM = (2)
107
117
  PL_INTEGER = (3)
108
- PL_FLOAT = (4)
109
- PL_STRING = (5)
110
- PL_TERM = (6)
111
- PL_NIL = (7)
112
- PL_BLOB = (8)
113
- PL_LIST_PAIR = (9)
114
- PL_FUNCTOR = (10)
115
- PL_LIST = (11)
116
- PL_CHARS = (12)
117
- PL_POINTER = (13)
118
- PL_CODE_LIST = (14)
119
- PL_CHAR_LIST = (15)
120
- PL_BOOL = (16)
121
- PL_FUNCTOR_CHARS = (17)
122
- _PL_PREDICATE_INDICATOR = (18)
123
- PL_SHORT = (19)
124
- PL_INT = (20)
125
- PL_LONG = (21)
126
- PL_DOUBLE = (22)
127
- PL_NCHARS = (23)
128
- PL_UTF8_CHARS = (24)
129
- PL_UTF8_STRING = (25)
130
- PL_INT64 = (26)
131
- PL_NUTF8_CHARS = (27)
118
+ PL_RATIONAL = (4)
119
+ PL_FLOAT = (5)
120
+ PL_STRING = (6)
121
+ PL_TERM = (7)
122
+ PL_NIL = (8)
123
+ PL_BLOB = (9)
124
+ PL_LIST_PAIR = (10)
125
+ PL_FUNCTOR = (11)
126
+ PL_LIST = (12)
127
+ PL_CHARS = (13)
128
+ PL_POINTER = (14)
129
+ PL_CODE_LIST = (15)
130
+ PL_CHAR_LIST = (16)
131
+ PL_BOOL = (17)
132
+ PL_FUNCTOR_CHARS = (18)
133
+ PL_PREDICATE_INDICATOR = (19)
134
+ PL_SHORT = (20)
135
+ PL_INT = (21)
136
+ PL_LONG = (22)
137
+ PL_DOUBLE = (23)
138
+ PL_NCHARS = (24)
139
+ PL_UTF8_CHARS = (25)
140
+ PL_UTF8_STRING = (26)
141
+ PL_INT64 = (27)
142
+ PL_NUTF8_CHARS = (28)
132
143
  PL_NUTF8_CODES = (29)
133
144
  PL_NUTF8_STRING = (30)
134
145
  PL_NWCHARS = (31)
@@ -159,27 +170,34 @@ module Upl
159
170
 
160
171
  # /usr/lib64/swipl/include/SWI-Prolog.h
161
172
  module Convert
162
- BUF_DISCARDABLE = 0x0000
163
- BUF_RING = 0x0100
164
- BUF_MALLOC = 0x0200
165
- BUF_ALLOW_STACK = 0x0400
166
-
167
- REP_ISO_LATIN_1 = 0x0000
168
- REP_UTF8 = 0x1000
169
- REP_MB = 0x2000
170
-
171
- CVT_ATOM = 0x0001
172
- CVT_STRING = 0x0002
173
- CVT_LIST = 0x0004
174
- CVT_INTEGER = 0x0008
175
- CVT_FLOAT = 0x0010
176
- CVT_VARIABLE = 0x0020
177
- CVT_NUMBER = CVT_INTEGER|CVT_FLOAT
178
- CVT_ATOMIC = CVT_NUMBER|CVT_ATOM|CVT_STRING
179
- CVT_WRITE = 0x0040
180
- CVT_WRITE_CANONICAL = 0x0080
181
- CVT_WRITEQ = 0x00C0
182
- CVT_ALL = CVT_ATOMIC|CVT_LIST
173
+ BUF_DISCARDABLE = 0x00000000 # Store in single thread-local buffer
174
+ BUF_RING = 0x00010000 # Store in ring of 16 buffers
175
+ BUF_MALLOC = 0x00020000 # Store using PL_malloc()
176
+ BUF_ALLOW_STACK = 0x00040000 # Allow pointer into (global) stack
177
+ BUF_NORING = 0x00080000 # Do not store in ring
178
+
179
+ # output representation
180
+ REP_ISO_LATIN_1 = 0x00000000
181
+ REP_UTF8 = 0x00100000
182
+ REP_MB = 0x00200000
183
+
184
+ CVT_ATOM = 0x00000001
185
+ CVT_STRING = 0x00000002
186
+ CVT_LIST = 0x00000004
187
+ CVT_INTEGER = 0x00000008
188
+ CVT_RATIONAL = 0x00000010
189
+ CVT_FLOAT = 0x00000020
190
+ CVT_VARIABLE = 0x00000040
191
+ CVT_NUMBER = (CVT_RATIONAL|CVT_FLOAT)
192
+ CVT_ATOMIC = (CVT_NUMBER|CVT_ATOM|CVT_STRING)
193
+ CVT_WRITE = 0x00000080
194
+ CVT_WRITE_CANONICAL = 0x00000080
195
+ CVT_WRITEQ = 0x000000C0
196
+ CVT_ALL = (CVT_ATOMIC|CVT_LIST)
197
+ CVT_MASK = 0x00000fff
198
+
199
+ CVT_EXCEPTION = 0x00001000 # throw exception on error
200
+ CVT_VARNOFAIL = 0x00002000 # return 2 if argument is unbound
183
201
  end
184
202
 
185
203
  extern 'predicate_t PL_pred(functor_t f, module_t m)'
data/lib/upl/query.rb CHANGED
@@ -47,7 +47,7 @@ module Upl
47
47
  call.map do |row|
48
48
  # TODO this assume the if statement is faster than a call to a default ->i{i}
49
49
  if @map_blk
50
- blk.call @map_blk[row]
50
+ blk.call @map_blk[**row]
51
51
  else
52
52
  blk.call row
53
53
  end
data/lib/upl/runtime.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'fiddle'
2
+ require 'pp'
2
3
 
3
4
  require_relative 'extern'
4
5
 
data/lib/upl/tree.rb CHANGED
@@ -53,6 +53,9 @@ module Upl
53
53
  bytes = double_ptr[0,8]
54
54
  bytes.unpack('D').first
55
55
 
56
+ when Extern::PL_RATIONAL
57
+ raise NotImplemented, 'convert to rational'
58
+
56
59
  when Extern::PL_STRING
57
60
  # TODO could possibly get away with BUF_DISCARDABLE here?
58
61
 
data/lib/upl/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Upl
2
- VERSION = '0.2.2'
2
+ VERSION = '0.2.4'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: upl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Anderson
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-24 00:00:00.000000000 Z
11
+ date: 2023-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -87,6 +87,7 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
+ - ".github/workflows/build.yml"
90
91
  - ".gitignore"
91
92
  - ".rspec"
92
93
  - ".travis.yml"
@@ -97,6 +98,7 @@ files:
97
98
  - Rakefile
98
99
  - bin/console
99
100
  - bin/setup
101
+ - docker-compose.yml
100
102
  - lib/upl.rb
101
103
  - lib/upl/atom.rb
102
104
  - lib/upl/dict.rb
@@ -118,7 +120,7 @@ licenses:
118
120
  - MIT
119
121
  metadata:
120
122
  allowed_push_host: https://rubygems.org
121
- post_install_message:
123
+ post_install_message:
122
124
  rdoc_options: []
123
125
  require_paths:
124
126
  - lib
@@ -133,8 +135,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
135
  - !ruby/object:Gem::Version
134
136
  version: '0'
135
137
  requirements: []
136
- rubygems_version: 3.1.2
137
- signing_key:
138
+ rubygems_version: 3.4.6
139
+ signing_key:
138
140
  specification_version: 4
139
141
  summary: Access SWI-Prolog engine from ruby
140
142
  test_files: []