Module: Upl::Extern

Extended by:
Fiddle::Importer
Defined in:
lib/upl/extern.rb

Overview

ffi bindings for swipl.so

Defined Under Namespace

Modules: Convert, ExtStatus, Flags

Constant Summary collapse

TRUE =
(1)
FALSE =
(0)
PL_VARIABLE =
(1)
PL_ATOM =
(2)
PL_INTEGER =
(3)
PL_FLOAT =
(4)
PL_STRING =
(5)
PL_TERM =
(6)
PL_NIL =
(7)
PL_BLOB =
(8)
PL_LIST_PAIR =
(9)
PL_FUNCTOR =
(10)
PL_LIST =
(11)
PL_CHARS =
(12)
PL_POINTER =
(13)
PL_CODE_LIST =
(14)
PL_CHAR_LIST =
(15)
PL_BOOL =
(16)
PL_FUNCTOR_CHARS =
(17)
PL_SHORT =
(19)
PL_INT =
(20)
PL_LONG =
(21)
PL_DOUBLE =
(22)
PL_NCHARS =
(23)
PL_UTF8_CHARS =
(24)
PL_UTF8_STRING =
(25)
PL_INT64 =
(26)
PL_NUTF8_CHARS =
(27)
PL_NUTF8_CODES =
(29)
PL_NUTF8_STRING =
(30)
PL_NWCHARS =
(31)
PL_NWCODES =
(32)
PL_NWSTRING =
(33)
PL_MBCHARS =
(34)
PL_MBCODES =
(35)
PL_MBSTRING =
(36)
PL_INTPTR =
(37)
PL_CHAR =
(38)
PL_CODE =
(39)
PL_BYTE =
(40)
PL_PARTIAL_LIST =
(41)
PL_CYCLIC_TERM =
(42)
PL_NOT_A_LIST =
(43)
PL_DICT =
(44)
PL_FA_NOTRACE =

Foreign predicate flags

(0x01)
PL_FA_NONDETERMINISTIC =

PL_FA_TRANSPARENT = (0x02) # foreign is module transparent. Deprecated.

(0x04)
PL_FA_VARARGS =

call using t0, ac, ctx

(0x08)
PL_FA_CREF =

Internal: has clause-reference

(0x10)
PL_FA_ISO =

Internal: ISO core predicate

(0x20)
PL_FA_META =

Additional meta-argument spec

(0x40)

Class Method Summary collapse

Class Method Details

.ruby_free_fnObject



38
39
40
# File 'lib/upl/extern.rb', line 38

def self.ruby_free_fn
  @ruby_free_fn ||= Fiddle::Function.new Fiddle::RUBY_FREE, [Fiddle::TYPE_VOIDP], Fiddle::TYPE_VOID
end

.so_pathObject

use swipl config to find the .so file should result in something like

/usr/lib64/swipl-7.7.18/lib/x86_64-linux/libswipl.so

which should actually exist



27
28
29
30
31
32
33
34
# File 'lib/upl/extern.rb', line 27

def self.so_path
  values = swipl_config_values
  p = Pathname "#{values['PLBASE']}/lib/#{values['PLARCH']}/#{values['PLLIB'].gsub('-l', 'lib')}.#{values['PLSOEXT']}"
  p.realpath.to_s
rescue Errno::ENOENT => ex
  puts "problem with library #{p.to_s}: #{ex.message}"
  exit 1
end

.swipl_config_valuesObject

fetch config values from swipl executable



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/upl/extern.rb', line 11

def self.swipl_config_values
  swipl_exe = 'swipl'
  values = `#{swipl_exe} --dump-runtime-variables=sh`.each_line.with_object Hash.new do |line,ha|
    # split by = and for rhs strip surrounding quotes and trailing ;
    line =~ /^([^=]+)="([^"]*)";\s*$/
    ha[$1] = $2.strip
  end
rescue Errno::ENOENT => ex
  puts "#{swipl_exe} not found on path #{ENV['PATH']}"
  exit 1
end

.swipl_free_fnObject



42
43
44
# File 'lib/upl/extern.rb', line 42

def self.swipl_free_fn
  @swipl_free_fn ||= Fiddle::Function.new self['PL_free'], [Fiddle::TYPE_VOIDP], Fiddle::TYPE_VOID
end