;;;-*- Mode: Lisp; Package: XLE -*- ;;;; XLE-Web users are granted the rights to distribute and use this software ;;;; as governed by the terms of the Lisp Lesser GNU Public License ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL. ;;;; Author: Paul Meurer (paul.meurer@aksis.uib.no) ;;;; Aksis, Unifob, University of Bergen, Norway ;;;; http://www.aksis.uib.no (in-package :XLE) #+(and :sbcl :darwin) (eval-when (:compile-toplevel :load-toplevel :execute) (defparameter +xle-path+ "/usr/local/xledir/") (defparameter +xle-module-path+ "/usr/local/xledir/lib/libxlecore.dylib")) (eval-when (:compile-toplevel :load-toplevel :execute) (defun getenv (var) #+allegro(system:getenv var) #+sbcl(sb-sys::posix-getenv var))) ;; clean this up! #+(and :sbcl :x86-64) (eval-when (:compile-toplevel :load-toplevel :execute) (defparameter +xle-path+ (or (getenv "XLEDIR") "/usr/local/xledir/")) (defparameter +xle-module-path+ (cond ((getenv "XLELIB32DIR") ;; makes coexistence of 64bit and 32bit XLE libs easier (concatenate 'string (getenv "XLELIB64DIR") "/libxlecore.so")) ((getenv "XLEDIR") (concatenate 'string (getenv "XLEDIR") "/lib/libxlecore.so")) (t "/usr/local/xledir/lib/linux.x86.64/libxlecore.so")))) ;; remove! #+(and :sbcl :x86) (eval-when (:compile-toplevel :load-toplevel :execute) (defparameter +xle-path+ (or (getenv "XLEDIR") "/usr/local/xledir/")) (defparameter +xle-module-path+ (cond #+darwin (t "/usr/local/xledir/lib/libxlecore.dylib") ((getenv "XLELIB32DIR") ;; makes coexistence of 64bit and 32bit XLE libs easier (concatenate 'string (getenv "XLELIB32DIR") "/libxlecore.so")) ((getenv "XLEDIR") (concatenate 'string (getenv "XLEDIR") "/lib/libxlecore.so")) (t "/usr/local/xledir/lib/linux.x86.32/libxlecore.so")))) ;; remove! #-sbcl (eval-when (:compile-toplevel :load-toplevel :execute) (defconstant +xle-path+ (let* ((root #-:pargram(getenv "LOGONROOT")) (root (and root (string/= root "") (namestring (make-pathname :directory root)))) (xledir (or #+helge "/usr/local/xledir/" #-macosx (getenv "XLE") #+macosx "~/xledir/")) (path (or #-:logon xledir (format nil "~a/parc/xle/" root)))) (namestring (make-pathname :directory path)))) #+(and :allegro :macosx) (pushnew "bundle" excl::*load-foreign-types* :test #'string=) (defconstant +xle-module-path+ (concatenate 'string +xle-path+ "lib/" mk::%system-binaries% #+(and (not :macosx) (not :64bit) :paul) "/libxlecore.so" ;; "/xle-wrapper.so" #+(and (not :macosx) (or :64bit (not :paul))) #+ignore "/xle-wrapper.so" #-ignore "/libxlecore.so" ;;#+(and :macosx :paul) "/xle-wrapper.dylib" #+(and :macosx (not :paulxx)) "/libxlecore.dylib"))) ;; either set them here (works only for ACL) or in the environment that is inherited by Emacs #+allegroxx (setf (sys:getenv "TCLLIBPATH") (concatenate 'string +xle-path+ "lib/tcl8.4") (sys:getenv "TCL_LIBRARY") (concatenate 'string +xle-path+ "lib/tcl8.4") (sys:getenv "TK_LIBRARY") (concatenate 'string +xle-path+ "lib/tk8.4")) #+sbcl (eval-when (:compile-toplevel :load-toplevel :execute) (sb-alien::load-shared-object +xle-module-path+)) ;;; foreign function interface ;;; from xle.h ;;/* ----------------- */ ;;/* GENERAL INTERFACE */ ;;/* ----------------- */ ;; void init_xle(int run_Tk, int run_rcfiles); ;;/* init_xle must be called before doing anything else. */ ;;/* if run_Tk, then initialize the Tcl/Tk Tk interface. */ ;;/* if run_rcfiles, then load the .xlerc files in the */ ;;/* current directory and the user's home directory. */ (define-foreign-function "init_xle" ((run-Tk :unsigned-int) (run-rcfiles :unsigned-int) ) #+allegro :void #+sbcl ffc::void :lisp-name init-xle :module +xle-module-path+) ;; char *execute_tcl_command(char *command); ;;/* Passes the command to the Tcl interpreter. This has the */ ;;/* same effect as typing the command to the Tcl shell. The */ ;;/* result of the command is returned. To pass pointers, */ ;;/* give the type in parentheses and then use %x for the */ ;;/* address. For instance: */ ;;/* sprintf(buff, "show-solutions (Chart)%x", (int)parser); */ ;;/* execute_tcl_command(buff); */ (define-foreign-function "execute_tcl_command" ((command string-ptr) ) :unsigned-long :lisp-name execute-tcl-command :module +xle-module-path+) ;;/* ----------------- */ ;;/* PARSING INTERFACE */ ;;/* ----------------- */ ;; Chart *create_parser(char *grammar_name); ;;/* grammar_name is the name of the root grammar file. */ ;;/* There can only be one grammar loaded at a time. */ (define-foreign-function "create_parser" ((grammar-name string-ptr) ) :unsigned-long :lisp-name create-parser :module +xle-module-path+) ;; char *next_sentence_in_stream(FILE *stream, Chart *chart); ;;/* This returns the next sentence in the stream given. It uses */ ;;/* the BREAKTEXT transducer given in the grammar of chart. */ ;;/* The storage for the sentence comes from malloc. If NULL is */ ;;/* returned, then there are no more sentences. If you stop */ ;;/* before NULL is returned, call with a NULL stream to reset */ ;;/* the state of chart. */ ;; ... ;; Graph *parse_sentence(Chart *parser, char *sentence, char *root_cat); ;;/* root_cat is the category the sentence should be parsed to. */ ;;/* If it is NULL, then the root category of the grammar is used. */ ;;/* parse_sentence produces a contexted graph that has all of the */ ;;/* solutions packed in it. NB: parse_sentence resets the storage, */ ;;/* so the storage for sentence and root_cat must come from */ ;;/* somewhere else. */ (define-foreign-function "parse_sentence" ((parser :unsigned-long) (sentence #+allegro string-ptr #+sbcl(sb-alien::c-string :external-format :iso-8859-1)) (root-cat string-ptr) ) :unsigned-long :lisp-name parse-sentence :module +xle-module-path+) ;; Graph *most_probable_structure(Graph *graph, char *weightsFName); ;;/* Returns a Graph of the most probable structure in graph, where */ ;;/* graph is a packed representation. weightsFName is a file of weights. */ (define-foreign-function "most_probable_structure" ((graph :unsigned-long) (weights-f-name string-ptr) ) :unsigned-long :lisp-name most-probable-structure :module +xle-module-path+) ;;Graph *next_graph_solution(Graph *graph, Graph *prior); ;;/* next_graph_solution can be used to enumerate the solutions */ ;;/* in a packed graph. To use it, make prior be NULL the first */ ;;/* call and then make prior be the result of the last call from */ ;;/* then on. When there are no more solutions, NULL is returned. */ ;;/* It is better to operate on the packed representation */ ;;/* directly since there can be an exponential number of solutions. */ (define-foreign-function "next_graph_solution" ((graph :unsigned-long) (prior-graph :unsigned-long) ) :unsigned-long :lisp-name next-graph-solution :module +xle-module-path+) ;;void free_graph_solution(Graph *graph); ;;/* This frees the storage allocated by next_graph_solution. */ (define-foreign-function "free_graph_solution" ((graph :unsigned-long) ) #+allegro :void #+sbcl ffc::void :lisp-name free-graph-solution :module +xle-module-path+) ;;void print_prolog_graph(FILE *stream, Graph *graph, char *structures); ;;/* Print the graph as a Prolog term on stream. 'structures' */ ;;/* determines which structures should be included. If it is */ ;;/* NULL, then all of the structures will be printed. See the */ ;;/* documentation on print-prolog-chart-graph in xle.html for */ ;;/* more details. */ (define-foreign-function "print_prolog_graph" ((stream :unsigned-long) (graph :unsigned-long) (structures string-ptr) ) #+allegro :void #+sbcl ffc::void :lisp-name print-prolog-graph :module +xle-module-path+) ;;extern int normalize_chart_graphs; ;;/* If this variable is non-zero, then chart graphs are normalized. */ ;;/* The default is currently 1, but normalization is expensive. */ (define-foreign-variable normalize_chart_graphs :type #+allegro :unsigned-long32 #+sbcl :unsigned-long) ;;/* -------------------- */ ;;/* GENERATION INTERFACE */ ;;/* -------------------- */ ;; not tested ;; Chart *create_generator(char *grammar_name); ;;/* grammar_name is the name of the root grammar file. */ ;;/* There can only be one grammar loaded at a time. */ (define-foreign-function "create_generator" ((grammar-name string-ptr) ) :unsigned-long :lisp-name create-generator :module +xle-module-path+) ;; void set_gen_adds(Chart *chart, char *mode, char *attributes, char *OTmark); ;; /* if mode is "add", make the attributes addable. */ ;; /* if mode is "add", OTmark also gets added. */ ;; /* if mode is "remove", remove the attributes from the input. */ ;; /* if mode is "ignore", call set_gen_add with "add" and "remove". */ ;; Graph *read_prolog_graph(FILE *file, Chart *chart); ;; /* Reads a prolog graph file, using chart for storage. */ ;; /* read_prolog_graph does not call reset_storage. */ ;; /* The Graph result will be reclaimed the next time */ ;; /* that reset_storage is called. */ (define-foreign-function "read_prolog_graph" ((file :unsigned-long) (chart :unsigned-long) ) :unsigned-long :lisp-name read-prolog-graph :module +xle-module-path+) ;; NETptr generate_from_graph(Chart *generator, Graph *graph, ;; char *addable_attrs, ;; char *removable_attrs); ;;/* This returns a NETptr that represents the strings */ ;;/* that, when parsed, would produce the graph as one of its */ ;;/* solutions. The storage for the graph cannot be from the */ ;;/* generator, since generate_from_graph resets the storage. */ (define-foreign-function "generate_from_graph" ((generator :unsigned-long) (graph :unsigned-long) (addable-attrs string-ptr) (removable-attrs string-ptr) ) :unsigned-long :lisp-name generate-from-graph :module +xle-module-path+) ;;int print_genstrings(Chart *chart, NETptr net, FILE *file); ;;/* This prints the result of generate_from_graph. It calls */ ;;/* print_net_as_regexp unless chart->gen_selector is set. */ (define-foreign-function "print_genstrings" ((chart :unsigned-long) (net :unsigned-long) (file :unsigned-long) ) :unsigned-int :lisp-name print-genstrings :module +xle-module-path+) ;; int print_net_as_regexp(NETptr net, FILE *file, int normalize, int utf8); ;;/* This prints a NETptr as a regular expression to file. */ ;;/* If normalize is non-zero, then the regular expression */ ;;/* is massaged to make it more readable (this assumes that */ ;;/* it is not important to preserve spaces exactly). */ (define-foreign-function "print_net_as_regexp" ((net :unsigned-long) (file :unsigned-long) (normalize :unsigned-int) (utf8 :unsigned-int) ) :unsigned-int :lisp-name print-net-as-regexp :module +xle-module-path+) ;; RegExp *fsm_to_regexp(NETptr net, HEAPptr re_heap); ;;/* Convert an fsm to a regular expression with: */ ;;/* heap = init_heap(sizeof(RegExp), 100, "RegExp"); */ ;;/* regexp = fsm_to_regexp(net, heap); */ ;;/* ... */ ;;/* free_heap(heap); */ (define-foreign-function "fsm_to_regexp" ((net :unsigned-long) (re_heap :unsigned-long) ) :unsigned-long :lisp-name fsm-to-regexp :module +xle-module-path+) ;; From solutions-func.h ;; RestrictedSolution* get_edge_solutions(Graph *edge_graph, ;; Graph *mother_graph); ;;/* ----------------------------------------------------- */ ;;/* If mother_graph is NULL, then this returns a single */ ;;/* packed solution that contains all of the solutions to */ ;;/* edge_graph. Use first_dnf_solution and */ ;;/* next_dnf_solution to enumerate unpacked solutions. */ ;;/* ----------------------------------------------------- */ (define-foreign-function "get_edge_solutions" ((edge-graph :unsigned-long) (mother-graph :unsigned-long) ) :unsigned-long :lisp-name get-edge-solutions :module +xle-module-path+) ;; float count_restricted_solutions(RestrictedSolution*) ; (define-foreign-function "count_restricted_solutions" ((restricted-solution :unsigned-long) ) #+allegro :float #+sbcl double-float :lisp-name count-restricted-solutions :module +xle-module-path+) ;; void clear_solution_counts(RestrictedSolution *r); (define-foreign-function "clear_solution_counts" ((restricted-solution :unsigned-long) ) #+allegro :void #+sbcl ffc::void :lisp-name clear-solution-counts :module +xle-module-path+) ;; void clear_solution_marks(RestrictedSolution *r); ;; void clear_solution_contexts(RestrictedSolution *r); ;; float count_unoptimal_solutions(RestrictedSolution*); (define-foreign-function "count_unoptimal_solutions" ((restricted-solution :unsigned-long) ) #+allegro :float #+sbcl double-float :lisp-name count-unoptimal-solutions :module +xle-module-path+) ;; Interface to two stdio.h functions to be able to convert a Unix ;; file descriptor to a C stream (define-foreign-function "fdopen" ((fd :short) (mode string-ptr) ) :unsigned-long :module +xle-module-path+) (define-foreign-function "fflush" ((stream :unsigned-long) ) :short :module +xle-module-path+) (define-foreign-function "fclose" ((stream :unsigned-long) ) :unsigned-long :module +xle-module-path+) #+test (define-foreign-function "fconfigure" ((run-Tk :unsigned-int) (run-rcfiles :unsigned-int) ) #+allegro :void #+sbcl ffc::void :module +xle-module-path+) ;; Variables (define-foreign-variable timeout :type #+allegro :unsigned-long32 #+sbcl :unsigned-long) (define-foreign-variable start_skimming_when_scratch_storage_exceeds :type #+allegro :unsigned-long32 #+sbcl :unsigned-long) (define-foreign-variable start_skimming_when_total_events_exceed :type #+allegro :unsigned-long32 #+sbcl :unsigned-long) ;;(define-foreign-variable skimming_nogoods) ;;(define-foreign-variable normalize_chart_graphs) (define-foreign-variable max_new_events_per_graph_when_skimming :type #+allegro :unsigned-long32 #+sbcl :unsigned-long) (define-foreign-variable max_xle_scratch_storage :type #+allegro :unsigned-long32 #+sbcl :unsigned-long) (define-foreign-variable max_raw_subtrees :type #+allegro :unsigned-long32 #+sbcl :unsigned-long) (define-foreign-variable max_medial_constituent_weight :type #+allegro :unsigned-long32 #+sbcl :unsigned-long) (define-foreign-variable max_medial2_constituent_weight :type #+allegro :unsigned-long32 #+sbcl :unsigned-long) (define-foreign-variable max_selection_additional_storage :type #+allegro :unsigned-long32 #+sbcl :unsigned-long) ;; Structs (define-foreign-type Graph ;; DUCompState *compstate ; /* the global state for the parser or generator */ ; /* that is using this Graph */ (compstate :unsigned-long) ;; AVPair *attrs ; /* the list of top-level variables or meta-variables */ ; /* defined in this graph. Each top-level variable is an */ ; /* attribute-value tree of AVPairs. The AVPairs are */ ; /* never re-entrant: instead re-entrancy is handled by */ ; /* having explicit equality links between AVPairs. */ (attrs :unsigned-long) ;; Clause *context ; /* Whenever a subtree belongs to an edge with other */ ; /* valid subtrees, then its graph will get assigned a */ ; /* context that distinguishes it from the graphs of */ ; /* other subtrees. */ (context :unsigned-long) ;; Clause *nogoods ; /* a CONS list of nogoods asserted on this graph. */ (nogoods :unsigned-long) ;; unsigned int choice_id ; /* the last choice identifier used. */ (choice-id :unsigned-int) ;; unsigned int disj_id ; /* the last disjunction identifier used. */ (disj-id :unsigned-int) ;; unsigned short disjunctive : 1 ; /* The graph is attached to an edge */ ; /* that has multiple valid */ ; /* subtrees. It represents the OR */ ; /* of the subtree graphs. */ (disjunctive (#+allegro :bit #+sbcl integer 1)) ;; unsigned short prune : 1 ; /* whether the clause package should prune. */ (prune (#+allegro :bit #+sbcl integer 1)) ;; unsigned short prune_exported : 1 ; /* whether exported clauses should be pruned and simplified. */ (prune-exported (#+allegro :bit #+sbcl integer 1)) ;; unsigned short nogoods_pulled : 1; (nogoods-pulled (#+allegro :bit #+sbcl integer 1)) ;; unsigned short completeness_checked : 1 ; (completeness-checked (#+allegro :bit #+sbcl integer 1)) ;; unsigned short completeness_checked1 : 1; (completeness-checked1 (#+allegro :bit #+sbcl integer 1)) ;; unsigned short local_completeness : 1; /* Whether something in the graph was completed. */ (local-completeness (#+allegro :bit #+sbcl integer 1)) ;; unsigned short nogood : 1 ; /* The graph has no solutions. */ (nogood (#+allegro :bit #+sbcl integer 1)) ;; unsigned short inconsistent : 1 ; /* The graph has no solutions. */ (inconsistent (#+allegro :bit #+sbcl integer 1)) ;; unsigned short unreachable : 1 ; /* The graph cannot be reached */ ; /* because an aunt is nogood. */ (unreachable (#+allegro :bit #+sbcl integer 1)) ;; unsigned short goal_cons_mark : 1 ; (goal-cons-mark (#+allegro :bit #+sbcl integer 1)) ;; unsigned short chart_temp_mark : 1 ; (chart-temp-mark (#+allegro :bit #+sbcl integer 1)) ;; unsigned short mark : 1 ; /* a mark bit for temporary marks */ (mark (#+allegro :bit #+sbcl integer 1)) ;; unsigned short mark2 : 1 ; /* a mark bit for temporary marks */ (mark2 (#+allegro :bit #+sbcl integer 1)) ;; unsigned short beam_mark : 1; /* a mark bit for beam graphs */ ;(beam-mark (#+allegro :bit #+sbcl integer 1)) ;; new 11.06 ;; unsigned short beam_mark2 : 1; /* a mark bit for beam graphs */ ;(beam-mark2 (#+allegro :bit #+sbcl integer 1)) ;; new 11.06 ;; unsigned short open: 1 ; /* Make an open-world assumption. */ (open (#+allegro :bit #+sbcl integer 1)) ;; unsigned short ordinaryvars : 1 ; /* Indicates that the AVPairs in the attrs */ ; /* field are not metavars connecting */ ; /* different edges in the chart, */ ; /* but rather ordinary variables. This is */ ; /* used by extract_chart_graph. */ (ordinaryvars (#+allegro :bit #+sbcl integer 1)) ;; unsigned short chart_clauses : 1 ; /* The clauses are from a chart */ (chart-clauses (#+allegro :bit #+sbcl integer 1)) ;; unsigned short inert : 1 ; /* Don't do deductions. */ (inert (#+allegro :bit #+sbcl integer 1)) ;; unsigned short input : 1 ; /* graph read by read_prolog_graph */ (input (#+allegro :bit #+sbcl integer 1)) ;; unsigned short lexical : 1 ; /* This is a lexical graph. */ (lexical (#+allegro :bit #+sbcl integer 1)) ;; unsigned short truncated : 1 ; /* max_new_events_per_graph_when_skimming was exceeded. */ (truncated (#+allegro :bit #+sbcl integer 1)) ;; unsigned short unresourced : 1 ; /* used for off-line generability. */ (unresourced (#+allegro :bit #+sbcl integer 1)) ;; unsigned int normalized : 1; /* records normalize_chart_graphs */ (normalized (#+allegro :bit #+sbcl integer 1)) ;; ?? ;; unsigned int postpone_uncertainties: 1 ; (postpone-uncertainties (#+allegro :bit #+sbcl integer 1)) ;; unsigned int processing_queue: 1 ; (processing-queue (#+allegro :bit #+sbcl integer 1)) ;; unsigned int disjunctions_sorted: 1; (disjunctions-sorted (#+allegro :bit #+sbcl integer 1)) ;; unsigned int no_clause_cache: 1; (no-clause-cache (#+allegro :bit #+sbcl integer 1)) ;; unsigned int complete_selection: 1; (complete-selection (#+allegro :bit #+sbcl integer 1)) ;; new 11.06 ;; unsigned int add_choice_feature_weights: 1; (add-choice-feature-weights (#+allegro :bit #+sbcl integer 1)) ;; new 11.06 ;; DUProp *props ; /* a Lisp-style property list for extensions */ (props :unsigned-long) ;; UnificationQueue *queue ; /* Whenever a fact is asserted on a locked */ ; /* AVPair, the fact is added to this queue to be */ ; /* processed with the AVPair is unlocked. */ (queue :unsigned-long) ;; RestrictionSet *solution_sets ; /* The list of restriction sets and their */ ; /* solutions. */ (solution-sets :unsigned-long) ;; RestrictionSet *intermediate_solution_sets ; OBSOLETE ; /* The list of intermediaterestriction sets and their solutions. */ (intermediate_solution_sets :unsigned-long) ;; #ifdef notdef ;; /* Used by extract_nogood_clauses. */ ;; GraphClauses *imports ; /* The list of clauses imported from each daughter graph. */ ;;(imports :unsigned-long) ;; #endif ;; GraphList *consumers ; /* A list of Graphs that consume this graph in the */ ; /* chart. This is used in the completeness code. */ (consumers :unsigned-long) ;; struct Edge *edge ; /* The Edge that this Graph is part of, either */ ; /* on the edge or one of its subtrees. */ ; /* We use an incomplete type for Edge so that */ ; /* we can get type checking now and the parsing */ ; /* code can still give its own definition. */ (edge :unsigned-long) ;; Clause *clauses ; /* list of clauses allocated in this Graph */ (clauses :unsigned-long) ;; Disjunction *disjunctions ; /* list of disjunctions allocated in this */ ; /* Graph */ (disjunctions :unsigned-long) ;; Disjunction *last_disjunction; /* last disjunction in disjunctions */ (last_disjunction :unsigned-long) ;; Gensym *gensyms ; /* list of gensyms for this graph */ (gensyms :unsigned-long) ;; CopiedGensym *copiedgensyms ; /* list of gensyms that have been copied into this graph. */ (copiedgensyms :unsigned-long) ;; CopiedGensym *pushedgensyms ; /* list of gensyms that have been pushed onto this graph. */ (pushedgensyms :unsigned-long) ; OBSOLETE! ;; PushDef *pushdefs ; /* Defines pushed contexts. */ (pushdefs :unsigned-long) ; OBSOLETE! ;; AVPairList *pushed_avpairs ; /* List of AVPairs with pushed facts. */ (pushed-avpairs :unsigned-long) ; OBSOLETE! ;; SuppressionIndex *suppressions ; /* List of suppressed copy facts. */ (suppressions :unsigned-long) ;; unsigned int factcount : 16; /* AVPairs + CVPairs */ (factcount (#+allegro :bit #+sbcl integer 16)) ;; unsigned int nogoodcount : 16 ; /* number of nogoods */ (nogoodcount (#+allegro :bit #+sbcl integer 16)) ;; unsigned int clausecount ; (clausecount :unsigned-int) ;; int skimming_events ; /* Number of events processed while skimming */ (skimming-events :int) ;; int id ; /* a unique id used for debugging purposes */ (id :int) ;; PushedFU *pushedfus ; /* List of pushed functional uncertainties. */ (pushedfus :unsigned-long) ; OBSOLETE! ;; unsigned int pushedfus_processed ; /* Whether the pushed uncertainties have been processed. */ ;(pushedfus-processed :unsigned-int) ; OBSOLETE! ) (eval-when (:compile-toplevel :load-toplevel :execute) (defconstant +MAX_STOP_POINT_SIZE+ 10)) (define-foreign-type DUCompState ;; int max_heap ; /* number of heaps in the array below */ (max-heap :int) ;; HEAPptr *heaps ; /* array of fsm heap pointers */ (heaps :unsigned-long) ;; int graph_ct ; /* number of graphs allocated */ (graph-ct :int) ;; DUProp *props ; /* user defined properties ; (see graph.h for definition of DUProp) */ (props :unsigned-long) ;; Grammar *grammar ; /* the grammar being used */ (grammar :unsigned-long) ;; struct Chart *chart ; /* the chart being used */ (chart :unsigned-long) ;; unsigned int completing ; /* we have started to look for incomplete ; nogoods, and may generate some not ;clauses. */ (completing :unsigned-int) ;; unsigned int gen_goal_predicting ; /* this bit is set when the generator ; predicts new goal values, to prevent ; an optimization in the FU code */ (gen-goal-predicting :unsigned-int) ;; AVPair *goal_filter ; /* used by filter_constraint */ (goal-filter :unsigned-long) ;; AVPair *path_avpair ; /* used for instantiating off-path constraints. */ (path-avpair :unsigned-long) ;; void *path_arc ; /* used for determining which off-path attributes should ; be nonconstructive. */ (path-arc :unsigned-long) ;; unsigned int solving ; /* we have started to solve the nogood database. */ (solving :unsigned-int) ;; unsigned int prune ; /* whether or not clauses should be pruned. */ (prune :unsigned-int) ;; unsigned int debugging ; /* We are debugging. */ (debugging :unsigned-int) ;; int total_events ; /* Total events processed. */ (total-events :int) ;; unsigned shared_gensyms ; /* whether typed values that are equivalent */ ; /* should get the same gensym in overlapping */ ; /* contexts. This is used by check_disjuncts. */ (shared-gensyms :unsigned-int) ;; ?? ;; GlobalGensym *global_gensym ; /* data for each global gensym */ ;;(global-gensym :unsigned-long) ;; removed 2007 ;; unsigned int global_gensym_size ; /* size of global_gensym array */ ;;(global-gensym-size :unsigned-int) ;; removed 2007 ;; unsigned int next_global_gensym ; /* next global gensym */ (next-global-gensym :unsigned-int) ;; AVPair **attr_index ; /* This is an index of constraints by the attributes ; that they are stored on. It is used by the global ; completeness code. */ (attr-index :unsigned-long) ;; int attr_index_size ; /* The attr_index size. */ (attr-index-size :int) ;; AttrID *local_attr ; /* An array of local attributes. */ (local-attr :unsigned-long) ;; char **inverse_cat ; /* This is an array of categories that need to be ; added as REL_CAT_INVERSE. */ (inverse-cat :unsigned-long) ;; int next_inverse_cat ; /* The inverse_cat size. */ (next-inverse-cat :int) ;; ArgList *arglists ; /* Array of arglists encountered so far. */ (arglists :unsigned-long) ;; int arglists_size ; /* Size of the arglist array. */ (arglists-size :int) ;; int next_arglist ; /* The index of the next arglist available. */ (next-arglist :int) ;; int filler_counts_invalid ; /* We can't filter analyses based on filler ; counts because there was an unlicenced ; distribution encountered. */ (filler-counts-invalid :int) ;; /* ----------------------------------------------------------------- */ ;; /* Optimality Theory information is cached on the DUCompState rather */ ;; /* than the grammar so that it can vary between the parser and */ ;; /* the generator. */ ;; /* ----------------------------------------------------------------- */ ;; int num_OT_ranks ; /* The number of OT ranks stored in OT_rank */ (num-OT-ranks :int) ;; SExp **OT_rank ; ;; /* Array of lists of OT marks sorted by rank */ (OT-rank :unsigned-long) ;; StringList **ignored_OT_marks; /* Arrray of lists of ignored OT marks */ (ignored_OT_marks :unsigned-long) ;; HASH_TABLEptr OT_hash ; /* Hash from name to OTMark */ (OT-hash :unsigned-long) ;; HASH_TABLEptr edge_span_hash ; /* Used for local optimality marks */ (edge-span-hash :unsigned-long) ;; int neutral_OT_mark ; /* The position of the NEUTRAL OT mark. */ (neutral-OT-mark :int) ;; int nogood_OT_mark ; /* The position of the NOGOOD OT mark. */ (nogood-OT-mark :int) ;; int cstructure_OT_mark ; /* The position of the CSTRUCTURE OT mark. */ (cstructure-OT-mark :int) ;; int ungrammatical_OT_mark ; /* The position of the UNGRAMMATICAL OT mark. */ (ungrammatical-OT-mark :int) ;; int inconsistent_OT_mark ; /* The position of the INCONSISTENT OT mark. */ (inconsistent-OT-mark :int) ;; int incomplete_OT_mark ; /* The position of the INCOMPLETE OT mark. */ (incomplete-OT-mark :int) ;; int incoherent_OT_mark ; /* The position of the INCOHERENT OT mark. */ (incoherent-OT-mark :int) ;; int local_OT_mark ; /* whether there are any local OT marks. */ (local-OT-mark :int) ;; int fragment_OT_mark_override ; /* temporary position of Fragment mark */ ; /* (used by the fragment guide) */ (fragment-OT-mark-override :int) ;; int disable_OT ; /* Disable Optimality Theory. */ (disable-OT :int) ;; int OT_stop_point[MAX_STOP_POINT_SIZE] ; /* intermediate stopping points. */ (OT-stop-point #+allegro (:array :int #.+MAX_STOP_POINT_SIZE+) #+sbcl (array integer #.+MAX_STOP_POINT_SIZE+)) ;; int OT_stop_point_size ; /* the number of elements in the array above. */ (OT-stop-point-size :int) ;; int current_stop_point ; /* The mark that we are processing down to. */ (current-stop-point :int) ;; OTMark *OT_overrides ; /* User overrides for optimality marks. */ (OT-overrides :unsigned-long) ;; ?? ;; char *fieldlockfile[LAST_FIELD_NAME] ; /* file where field name locked. */ (fieldlockfile :unsigned-long) ;; ?? ;; int fieldlockline[LAST_FIELD_NAME] ; /* line where field name locked. */ (fieldlockline :int) ;; int queues ; /* number of graphs with non-empty queues. */ (queues :int) ;; int discharged_queue ; /* whether a queue got discharged. */ (discharged-queue :int) ;; HASH_TABLEptr constraint_hash ; /* Hash from SExp to data. */ (constraint-hash :unsigned-long) ;; HASH_TABLEptr attribute_hash ; /* Hash from strings to AttrID. */ (attribute-hash :unsigned-long) ;; int has_complex_sisters ; /* The chart has complex sisters (e.g */ ; /* (* RIGHT_SISTER RIGHT_SISTER). */ (has-complex-sisters :int) ;; int abbrev_contains_pred ; /* abbreviation attributes that contain preds. */ (abbrev-contains-pred :int) ;; int unlocks; (unlocks :int)) ;; struct Chart *get_compstate_chart(DUCompState *compstate); (define-foreign-function "get_compstate_chart" ((compstate :unsigned-long) ) :unsigned-long :lisp-name get-compstate-chart :module +xle-module-path+) (define-foreign-function "recompute_solutions" ((graph :unsigned-long) ) #+allegro :void #+sbcl ffc::void :lisp-name recompute-solutions :module +xle-module-path+) (define-foreign-function "get_root_graph" ((chart :unsigned-long) ) :unsigned-long :lisp-name get-top-graph :module +xle-module-path+) ;; NETptr label_fsm(char *symbol); (define-foreign-function "label_fsm" ((symbol string-ptr) ) :unsigned-long :lisp-name label-fsm :module +xle-module-path+) ;; NETptr concat(NETptr net1, NETptr net2); (define-foreign-function "concat" ((net1 :unsigned-long) (net2 :unsigned-long) ) :unsigned-long :lisp-name net-concat :module +xle-module-path+) ;; NETptr net_union(NETptr net1, NETptr net2); (define-foreign-function "net_union" ((net1 :unsigned-long) (net2 :unsigned-long) ) :unsigned-long :lisp-name net-union :module +xle-module-path+) ;; int parse_lattice(NETptr input, char *rootcat, Chart *parser); (define-foreign-function "parse_lattice" ((input :unsigned-long) (root-cat string-ptr) (parser :unsigned-long) ) :unsigned-long :lisp-name parse-lattice :module +xle-module-path+) ;; int parse_lattice(NETptr input, char *rootcat, Chart *parser); (define-foreign-function "init_performance_vars" ((chart :unsigned-long) ) #+allegro :void #+sbcl ffc::void :lisp-name init-performance-vars :module +xle-module-path+) ;; from graph-func.h ;; int graph_p(Graph *graph); ;; /* Graph is not NULL or Bad_Graph. */ (define-foreign-function "graph_p" ((graph :unsigned-long) ) :int :lisp-name graph-p :module +xle-module-path+) ;; void free_chart(Chart *chart); ;; /* This frees all of the storage associated with the chart. */ ;; /* If there are no more references to the grammar, it frees */ ;; /* the storage associated with the grammar too. */ (define-foreign-function "free_chart" ((chart :unsigned-long) ) #+allegro :void #+sbcl ffc::void :lisp-name free-chart :module +xle-module-path+) ;;void reset_storage(Chart *chart); ;; /* Each chart manages all of the storage associated with */ ;; /* parsing and generating, including the return values */ ;; /* (except for next_sentence_in_stream). See comments */ ;; /* on each procedure for details about storage use. */ ;; /* When you are done parsing or generating, you can call */ ;; /* reset_storage to make the storage available for the */ ;; /* next use of the chart. parse_sentence and */ ;; /* generate_from_graph call reset_storage. It doesn't */ ;; /* hurt if reset_storage is called twice. */ (define-foreign-function "reset_storage" ((chart :unsigned-long) ) #+allegro :void #+sbcl ffc::void :lisp-name reset-storage :module +xle-module-path+) ;; from chart-func.h ;; void *get_chart_prop(Chart *chart, char* propname); ;; /* Get chart's propname property value. */ (define-foreign-function "get_chart_prop" ((chart :unsigned-long) (propname string-ptr) ) :unsigned-long ;;#+allegro :void #+sbcl ffc::void :lisp-name get-chart-prop :module +xle-module-path+) ;; from clause-func.h ;; Clause *get_choice(Graph *graph, Disjunction *disj, int ith_choice); ;; /* Get the ith_choice of disj. */ (define-foreign-function "get_choice" ((graph :unsigned-long) (disj :unsigned-long) (ith_choice :int) ) :unsigned-long :lisp-name get-choice :module +xle-module-path+) ;; void select_choice(Clause *clause); (define-foreign-function "select_choice" ((clause :unsigned-long) ) #+allegro :void #+sbcl ffc::void :lisp-name select-choice :module +xle-module-path+) ;; double get_choice_weight(Clause *clause); (define-foreign-function "get_choice_weight" ((graph :unsigned-long) (clause :unsigned-long) ) :double :lisp-name get-choice-weight :module +xle-module-path+) ;; void set_choice_weight(Clause *clause, double weight); (define-foreign-function "set_choice_weight" ((graph :unsigned-long) (clause :unsigned-long) (weight :double) ) #+allegro :void #+sbcl ffc::void :lisp-name set-choice-weight :module +xle-module-path+) ;; char *print_clause(Clause *clause, char *buffer); ;; /* Print clause on buffer. If no buffer is given, a new one is created. */ ;; /* Calls print_clause_. */ (define-foreign-function "print_clause" ((clause :unsigned-long) (buffer string-ptr) ) :unsigned-long :lisp-name print-clause :module +xle-module-path+) ;; char *print_choice(Clause *choice, char *buffer); ;; /* Prints a choice as "a:1-3" or "b:2" */ (define-foreign-function "print_choice" ((clause :unsigned-long) (buffer string-ptr) ) :unsigned-long :lisp-name print-choice :module +xle-module-path+) ;; from f-structure-extract.h ;; Graph *extract_selected_fstructure(Graph *graph); (define-foreign-function "extract_selected_fstructure" ((graph :unsigned-long) ) :unsigned-long :lisp-name extract-selected-fstructure :module +xle-module-path+) ;; Graph *extract_fstructure(RestrictedSolution *solution, DUCompState *compstate, DTree *tree); (define-foreign-function "extract_fstructure" ((solution :unsigned-long) (compstate :unsigned-long) (tree :unsigned-long) ) :unsigned-long :lisp-name extract-fstructure :module +xle-module-path+) ;; RestrictedSolution *chosen_fschart_solution(Graph *graph); (define-foreign-function "chosen_fschart_solution" ((graph :unsigned-long) ) :unsigned-long :lisp-name chosen-fschart-solution :module +xle-module-path+) (define-foreign-function "chosen_solution" ((graph :unsigned-long) ) :unsigned-long :lisp-name chosen-solution :module +xle-module-path+) ;; not in *.h (define-foreign-function "choose_among_implied_choices" ((disj :unsigned-long) (noidea :int) ) :unsigned-long :lisp-name choose-among-implied-choices :module +xle-module-path+) (define-foreign-function "get_graph_prop" ((graph :unsigned-long) (prop string-ptr) ) :unsigned-long :lisp-name get_graph_prop :module +xle-module-path+) ;; from clause.h #+test (let ((x 11068)) (loop for i from 0 to 31 do (format t "~d" (logand x 1)) (setf x (ash x -1)))) ;; struct Disjunction { (define-foreign-type Disjunction ;; unsigned int n_choices ; /* the number of choices are represented by */ ;; /* this disjunction and its internal */ ;; /* disjunctions */ (n-choices :unsigned-int) #+sbcl (bits :unsigned-int) ;; unsigned int id : 20; /* identifier used for printing. */ #+allegro (id (#+allegro :bit #+sbcl integer 20)) ;; unsigned short internal : 1; /* is this an internal disjunction? */ #+allegro (internal (#+allegro :bit #+sbcl integer 1)) ;; unsigned short mark : 3; /* a temporary mark bit */ #+allegro (mark (#+allegro :bit #+sbcl integer 3)) ;; unsigned short mark1 : 1; /* a temporary mark bit */ #+allegro (mark1 (#+allegro :bit #+sbcl integer 1)) ;; unsigned short mark2 : 1; /* a temporary mark bit */ #+allegro (mark2 (#+allegro :bit #+sbcl integer 1)) ;; unsigned short all1 : 1; /* used by conjoin_chart_clauses. */ #+allegro (all1 (#+allegro :bit #+sbcl integer 1)) ;; unsigned short all2 : 1; /* used by conjoin_chart_clauses. */ #+allegro (all2 (#+allegro :bit #+sbcl integer 1)) ;; unsigned short split : 1; /* Whether the Disjunction has been split. */ #+allegro (split (#+allegro :bit #+sbcl integer 1)) ;; unsigned short dependent_of_least_upper_bound : 1; #+allegro (dependent_of_least_upper_bound (#+allegro :bit #+sbcl integer 1)) ;; Clause *context; /* context in which disj is constructed */ (context :unsigned-long) ;; Clause *root_context; /* root context (first non-choice) */ (root-context :unsigned-long) ;; int root_depth; /* depth to root context */ (root-depth :int) ;; Clause *arm[2]; /* the two choices of this disjunction (all */ ; /* disjunctions are binary disjunctions; */ ; /* n-ary disjunctions are reduced to binary */ ; /* disjunctions, some of which are */ ; /* internal.) */ (arm #+allegro(:array :unsigned-long 2) #+sbcl (array sb-alien:unsigned-long 2)) ;; char *label[2]; /* Label for each arm. */ (label #+allegro(:array :unsigned-long 2) #+sbcl (array sb-alien:unsigned-long 2)) ;; void *labeldata[2]; /* Label data for each arm. */ (labeldata #+allegro(:array :unsigned-long 2) #+sbcl (array sb-alien:unsigned-long 2)) ;; ChoiceLabelType labeltype[2]; /* Data type of label data. */ (labeltype #+allegro (:array :int 2) #+sbcl (array :int 2)) ;; void *labelavp[2]; /* AVPair of the choice. */ (labelavp #+allegro(:array :unsigned-long 2) #+sbcl (array sb-alien:unsigned-long 2)) ;; Disjunction *disj[2]; /* the internal disjunctions needed for */ ; /* n_choices > 2. the context of disj[0] */ ; /* is arm[0], the context of disj[1] is */ ; /* arm[1] */ (disj #+allegro(:array :unsigned-long 2) #+sbcl (array sb-alien:unsigned-long 2)) ;; DisjunctionList *dependents[2]; /* The dependents of each choice. */ (dependents #+allegro(:array :unsigned-long 2) #+sbcl (array sb-alien:unsigned-long 2)) ;; Disjunction *next; /* the next disjunction in graph's list of */ ; /* disjunctions */ (next :unsigned-long) ;; DUProp *props; /* a Lisp-style property list for extensions */ (props :unsigned-long)) ;; }; ;;/* ----------------------------------------------------------------- */ ;;/* Note that the order here is not completely arbitrary -- refer to */ ;;/* `clause_cache_order' and 'compound_clause' for more details. */ ;;/* CT_FALSE is never actually used. It is here only for completeness.*/ ;;/* Instead falsity is indicated by a NULL 'Clause' pointer. */ ;;/* ----------------------------------------------------------------- */ ;; struct Clause { (define-foreign-type Clause #|| union { /* CHOICE */ struct ChoiceClause { Disjunction *disj; /* the disjunction this choice belongs to */ int id; /* the id for this choice */ } choice; /* AND/OR/CONS */ struct BooleanClause { Clause *item; /* the first item in the compound */ Clause *next; /* the rest of the items (never NULL) */ } compound; /* OPAQUE */ struct OpaqueClause { Clause *clause; /* the imported clause */ Graph *graph; /* the graph the clause was imported from */ } opaque; /* JUSTIFIED */ struct JustifiedClause { Clause *clause; /* the justified clause */ Justification *justification; /* its justification */ } justified; /* NOT */ Clause *not_clause; /* the clause that was negated */ } body; ||# (union1 :unsigned-long) ;;(int1 :int) (union2 :unsigned-long) ;;(union3 :unsigned-long) ;;(union4 :unsigned-short) ;;(union5 :unsigned-short) ;; unsigned short selected: 1; /* selected by the user. */ (selected (#+allegro :bit #+sbcl integer 1)) ;; unsigned short changeable: 1; /* this Clause can be destructively ; modified. */ (changeable (#+allegro :bit #+sbcl integer 1)) ;; unsigned short mark : 1; /* a temporary mark bit */ (mark (#+allegro :bit #+sbcl integer 1)) ;; unsigned short mark1 : 1; /* a temporary mark bit */ (mark1 (#+allegro :bit #+sbcl integer 1)) ;; unsigned short mark2 : 1; /* a temporary mark bit */ (mark2 (#+allegro :bit #+sbcl integer 1)) ;; unsigned short mark3 : 1; /* a temporary mark bit */ (mark3 (#+allegro :bit #+sbcl integer 1)) ;; unsigned short disjoint : 1; /* This clause is disjoint */ (disjoint (#+allegro :bit #+sbcl integer 1)) ;; unsigned short value : 1; /* Whether this clause should evaluate */ ; /* to True or False. */ (value (#+allegro :bit #+sbcl integer 1)) ;; unsigned short all1 : 1; /* used by conjoin_chart_clauses. */ (all1 (#+allegro :bit #+sbcl integer 1)) ;; unsigned short all2 : 1; /* used by conjoin_chart_clauses. */ (all2 (#+allegro :bit #+sbcl integer 1)) ;; unsigned short new : 1; /* used by conjoin_chart_clauses. */ (new (#+allegro :bit #+sbcl integer 1)) ;; unsigned short exported : 1; /* this clause has been imported by another */ ; /* graph */ (exported (#+allegro :bit #+sbcl integer 1)) ;; unsigned short nogood : 1; /* this clause is nogood */ (nogood (#+allegro :bit #+sbcl integer 1)) ;; unsigned short skip : 1; /* This nogood should be skipped ; when enumerating bad solutions. */ (skip (#+allegro :bit #+sbcl integer 1)) ;; unsigned int embedded_in_nogood: 1; /* This opaque clause is embedded */ ; /* in a nogood somewhere. */ (embedded-in-nogood (#+allegro :bit #+sbcl integer 1)) ;; unsigned int non_local : 1; /* Used by local_subtract_clause */ (non_local (#+allegro :bit #+sbcl integer 1)) ;; unsigned int data : 2; /* this choice appears somewhere in the data */ (data (#+allegro :bit #+sbcl integer 2)) ;; unsigned int offset : 5; /* used by disjoin_clause_trees */ (offset (#+allegro :bit #+sbcl integer 5)) ;; unsigned int indexed_cache: 1;/* the cache has been indexed */ (indexed-cache (#+allegro :bit #+sbcl integer 1)) ;; unsigned int segment : 6; /* If indexed_cache is 1, then this is the ; segment of the cache index. Otherwise, ; it is the number of items in the cache. */ #||(segment1 (#+allegro :bit #+sbcl integer 1)) (segment2 (#+allegro :bit #+sbcl integer 1)) (segment3 (#+allegro :bit #+sbcl integer 1)) (segment4 (#+allegro :bit #+sbcl integer 1)) (segment5 (#+allegro :bit #+sbcl integer 1)) (segment6 (#+allegro :bit #+sbcl integer 1))||# (segment (#+allegro :bit #+sbcl integer 6)) ;; unsigned int type: 5; /* Same as ClauseType, but saves storage */ #||(type1 (#+allegro :bit #+sbcl integer 1)) (type2 (#+allegro :bit #+sbcl integer 1)) (type3 (#+allegro :bit #+sbcl integer 1)) (type4 (#+allegro :bit #+sbcl integer 1)) (type5 (#+allegro :bit #+sbcl integer 1))||# (type (#+allegro :bit #+sbcl integer 5)) ;; Graph *graph; /* pointer to containing graph */ (graph :unsigned-long) ;; Clause *pruned; /* the pruned version of this clause */ (pruned :unsigned-long) ;; void *cache; /* cache of previously computed ; operations on clauses. This will be a ; ClauseCache if Clause->segment is 0 and ; a ClauseCacheIndex otherwise. */ (cache :unsigned-long) ;; Clause *next; /* the next clause in graph's list of clause */ (next :unsigned-long) ;; unsigned int prefix; /* used in clause trees */ (prefix :unsigned-int) ;; #ifdef CLAUSEID ;; unsigned int id; /* used for debugging */ (id :unsigned-int) ;; #endif ) ;; }; :eof