Language::XSB::Base - XSB SLG-WAN access


Language-XSB documentation Contained in the Language-XSB distribution.

Index


Code Index:

NAME

Top

Language::XSB::Base - XSB SLG-WAN access

SYNOPSIS

Top

  # use Language::XSB::Base;
  # better... :-)
  use Language::XSB;




ABSTRACT

Top

This module provides direct access to the XSB SLG-WAM.

DESCRIPTION

Top

This module lets get and set the XSB SLG-WAM registers converting data between Prolog and Perl formats.

It also has methods to initialize XSB and to make it run.

It should be noted that registers in XSB are indexed from 1, but in Perl they are indexed from 0!

EXPORT

xsb_init()
setreg($index, $term)
setreg_int($index, $integer)
getreg($index)
getreg_int($index)
regtype($index)
go()

SEE ALSO

Top

AUTHOR

Top

Salvador Fandiņo, <sfandino@yahoo.com>

COPYRIGHT AND LICENSE

Top


Language-XSB documentation Contained in the Language-XSB distribution.

package Language::XSB::Base;

our $VERSION;
BEGIN {
    $VERSION = '0.11';
}

use strict;
use warnings;

require Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw( xsb_init
		  setreg
		  setreg_int
		  getreg
		  getreg_int
		  regtype
		  go );

use Language::XSB::Config;

use Inline C => Config => MYEXTLIB => $XsbConfig{XSB_O},
                INC => "-I$XsbConfig{CONFDIR} -I$XsbConfig{EMUDIR}";
                # CCFLAGS => "-g -O0";

# my $pkg;
# BEGIN { $pkg=__PACKAGE__ }

use Inline C => qq
{

  #include "Base.h"

  int my_xsb_init(char *xsbloader) {
          char *xsb_argv[3]={ "$XsbConfig{CONFDIR}/bin/xsb",
			 			 xsbloader,
			 			 NULL, };
          int xsb_argc=2;
          converter=GvSV(gv_fetchpv(PKG "::converter", GV_ADDMULTI, SVt_PV));
          xsb(0, xsb_argc, xsb_argv);
          xsb(1,0,0);
  }

  SV *my_getreg(int index) {
          if (index < 0 || index >= 255 )
	 	 die ("invalid index \%d for xsb_reg_term", index);
          return term2sv(reg_term(index+1));
  }

  SV *my_getreg_int(int index) {
          if (index < 0 || index >= 255 )
	 	 die ("invalid index \%d for xsb_reg_term", index);
          return getreg_int(index+1);
  }

  int my_regtype(int index) {
          if (index < 0 || index >= 255 )
	 	 die ("invalid index \%d for xsb_reg_term", index);
          return regtype(index+1);
  }

  SV *my_setreg(int index, SV *term) {
          return setreg(index+1, term);
  }

  void my_setreg_int(int index, int value) {
          if (index < 0 || index >= 255 )
	 	 die ("invalid index \%d for xsb_reg_term", index);
          setreg_int(index+1, value);
  }

  int my_go() {
          xsb(1,0,0);
  }

}, NAME => __PACKAGE__, VERSION => $VERSION, PREFIX => 'my_', OPTIMIZE => '-g';


# conversions between Perl and Prolog implemented in Converter module
use Language::Prolog::Types::Converter;
our $converter='Language::Prolog::Types::Converter';

1;
__END__