type group_position = UndefPos | LeftPos | RightPos ;; type cycle_type = UndefCycle | NoneCycle | AliphaticCycle | AromaticCycle | HeteroCycle ;; type group_type = OrgGroup | InorgGroup | NeighbourGroup of int ;; type group = { name : string ; position : group_position ; cycle : cycle_type ; grouptype : group_type ; link : int ; } ;;
type group_position = UndefPos | LeftPos | RightPos ;; type cycle_type = UndefCycle | NoneCycle | AliphaticCycle | AromaticCycle | HeteroCycle ;; type group_type = OrgGroup | InorgGroup | NeighbourGroup of int ;; type group = { name : string ; position : group_position ; cycle : cycle_type ; grouptype : group_type ; link : int ; } ;;
type group_position = UndefPos | LeftPos | RightPos ;; type cycle_type = UndefCycle | NoneCycle | AliphaticCycle | AromaticCycle | HeteroCycle ;; type group_type = OrgGroup | InorgGroup | NeighbourGroup of int ;; type group = { name : string ; position : group_position ; cycle : cycle_type ; grouptype : group_type ; link : int ; } ;;
type group_position = UndefPos | LeftPos | RightPos ;; type cycle_type = UndefCycle | NoneCycle | AliphaticCycle | AromaticCycle | HeteroCycle ;; type group_type = OrgGroup | InorgGroup | NeighbourGroup of int ;; type group = { name : string ; position : group_position ; cycle : cycle_type ; grouptype : group_type ; link : int ; } ;;
type group_position = UndefPos | LeftPos | RightPos ;; type cycle_type = UndefCycle | NoneCycle | AliphaticCycle | AromaticCycle | HeteroCycle ;; type group_type = OrgGroup | InorgGroup | NeighbourGroup of int ;; type group = { name : string ; position : group_position ; cycle : cycle_type ; grouptype : group_type ; link : int ; } ;;
type group_position = UndefPos | LeftPos | RightPos ;; type cycle_type = UndefCycle | NoneCycle | AliphaticCycle | AromaticCycle | HeteroCycle ;; type group_type = OrgGroup | InorgGroup | NeighbourGroup of int ;; type group = { name : string ; position : group_position ; cycle : cycle_type ; grouptype : group_type ; link : int ; } ;;
type group_position = UndefPos | LeftPos | RightPos ;; type cycle_type = UndefCycle | NoneCycle | AliphaticCycle | AromaticCycle | HeteroCycle ;; type group_type = OrgGroup | InorgGroup | NeighbourGroup of int ;; type group = { name : string ; position : group_position ; cycle : cycle_type ; grouptype : group_type ; link : int ; } ;;
type group_position = UndefPos | LeftPos | RightPos ;; type cycle_type = UndefCycle | NoneCycle | AliphaticCycle | AromaticCycle | HeteroCycle ;; type group_type = OrgGroup | InorgGroup | NeighbourGroup of int ;; type group = { name : string ; position : group_position ; cycle : cycle_type ; grouptype : group_type ; link : int ; } ;;
type group_position = UndefPos | LeftPos | RightPos ;; type cycle_type = UndefCycle | NoneCycle | AliphaticCycle | AromaticCycle | HeteroCycle ;; type group_type = OrgGroup | InorgGroup | NeighbourGroup of int ;; type group = { name : string ; position : group_position ; cycle : cycle_type ; grouptype : group_type ; link : int ; } ;;
type group_position = UndefPos | LeftPos | RightPos ;; type cycle_type = UndefCycle | NoneCycle | AliphaticCycle | AromaticCycle | HeteroCycle ;; type group_type = OrgGroup | InorgGroup | NeighbourGroup of int ;; type group = { name : string ; position : group_position ; cycle : cycle_type ; grouptype : group_type ; link : int ; } ;;
- let filter_org = List . filter ( fun r -> if r . grouptype = OrgGroup then true else false )
- let _ =
- Callback . register "filter_organic" filter_org ;
- ;;
- #include <vector>
- typedef enum _group_position {
- UndefPos = 0 ,
- LeftPos,
- Rightpos
- } group_position ;
- typedef enum _cycle_type {
- UndefCycle = 0 ,
- NoneCycle
- AliphaticCycle
- AromaticCycle
- Heterocycle
- } cycle_type ;
- typedef enum _group_pos {
- OrgGroup = - 2 ,
- InorgGroup = - 1
- } group_pos ;
- typedef struct _group {
- char * name ;
- group_position position ;
- cycle_type cycle ;
- int group_type ;
- int link ;
- } group ;
- void init_ocaml ( ) ;
- std :: vector < group > filter_org ( std :: vector < group > g ) ;
- #include "cpart.h"
- #ifdef __cplusplus
- extern "C"
- {
- #endif
- #include <caml / mlvalues.h>
- #include <caml / alloc.h>
- #include <caml / callback.h>
- #include <caml / fail.h>
- #include <caml / memory.h>
- #ifdef __cplusplus
- }
- #endif
- #include <string.h>
- void init_ocaml ( )
- {
- char * argv [ 1 ] ;
- argv [ 0 ] = NULL ;
- caml_main ( argv ) ;
- }
- std :: vector < group > filter_org ( std :: vector < group > g )
- {
- CAMLparam0 ( ) ;
- static value * closure_f = NULL ;
- if ( closure_f == NULL )
- closure_f = caml_named_value ( "filter_organic" ) ;
- CAMLlocal3 ( cli, cons, cb_res ) ;
- cli = Val_emptylist ;
- for ( std :: vector < group > :: iterator i = g. begin ( ) ; i ! = g. end ( ) ; ++ i )
- {
- cons = caml_alloc ( 2 , 0 ) ;
- Store_field ( cons, 0 , camlgroup_of_group ( & ( * i ) ) ) ;
- Store_field ( cons, 1 , cli ) ;
- cli = cons ;
- }
- cb_res = caml_callback ( * closure_f, cli ) ;
- std :: vector < group > result ;
- while ( cb_res ! = Val_emptylist )
- {
- result. push_back ( group_of_camlgroup ( Field ( cb_res, 0 ) ) ) ;
- cb_res = Field ( cb_res, 1 ) ;
- }
- return result ;
- }
- ocamlpart . o : ocamlpart . ml
- ocamlopt - g - output - obj $ ^ - o $ @
- ccamlpart . o : ccamlpart . cc
- g ++ - g - c - o $ @ - I "` ocamlc -where` " $ ^
- libchempart . a : ocamlpart . o ccamlpart . o
- ar rcs $ @ $ ^
- all : libchempart . a
- clean :
- rm - f *. o *. a *. cmi *. cmx
- PHP_MINIT_FUNCTION ( chemlib )
- {
- init_ocaml ( ) ;
- zend_class_entry chemlib_ce ;
- INIT_CLASS_ENTRY ( chemlib_ce, PHP_CHEMLIB_CLASS_NAME, chemlib_class_functions ) ;
- chemlib_class_entry = zend_register_internal_class ( & chemlib_ce TSRMLS_CC ) ;
- zend_declare_property_string ( chemlib_class_entry, ( char * ) "name" , 4 , ( char * ) "" , ZEND_ACC_PUBLIC TSRMLS_CC ) ;
- zend_declare_property_long ( chemlib_class_entry, ( char * ) "position" , 8 , 0 , ZEND_ACC_PUBLIC TSRMLS_CC ) ;
- zend_declare_property_long ( chemlib_class_entry, ( char * ) "cycle" , 5 , 0 , ZEND_ACC_PUBLIC TSRMLS_CC ) ;
- zend_declare_property_long ( chemlib_class_entry, ( char * ) "group_type" , 10 , 0 , ZEND_ACC_PUBLIC TSRMLS_CC ) ;
- zend_declare_property_long ( chemlib_class_entry, ( char * ) "link" , 4 , 0 , ZEND_ACC_PUBLIC TSRMLS_CC ) ;
- zend_declare_class_constant_long ( chemlib_class_entry, ( char * ) "UndefPos" , 8 , 0 TSRMLS_CC ) ;
- zend_declare_class_constant_long ( chemlib_class_entry, ( char * ) "LeftPos" , 7 , 1 TSRMLS_CC ) ;
- zend_declare_class_constant_long ( chemlib_class_entry, ( char * ) "RightPos" , 8 , 2 TSRMLS_CC ) ;
- zend_declare_class_constant_long ( chemlib_class_entry, ( char * ) "UndefCycle" , 10 , 0 TSRMLS_CC ) ;
- zend_declare_class_constant_long ( chemlib_class_entry, ( char * ) "NoneCycle" , 9 , 1 TSRMLS_CC ) ;
- zend_declare_class_constant_long ( chemlib_class_entry, ( char * ) "AliphaticCycle" , 14 , 2 TSRMLS_CC ) ;
- zend_declare_class_constant_long ( chemlib_class_entry, ( char * ) "AromaticCycle" , 13 , 3 TSRMLS_CC ) ;
- zend_declare_class_constant_long ( chemlib_class_entry, ( char * ) "HeteroCycle" , 11 , 4 TSRMLS_CC ) ;
- zend_declare_class_constant_long ( chemlib_class_entry, ( char * ) "OrgGroup" , 8 , - 2 TSRMLS_CC ) ;
- zend_declare_class_constant_long ( chemlib_class_entry, ( char * ) "InorgGroup" , 10 , - 1 TSRMLS_CC ) ;
- } ;
- zval * phpgroup_of_group ( group * gr )
- {
- zval * res ;
- ALLOC_INIT_ZVAL ( res ) ;
- object_init_ex ( res, chemlib_class_entry ) ;
- zend_update_property_string ( Z_OBJCE_P ( res ) , res, ( char * ) "name" , 4 , gr - > name TSRMLS_CC ) ;
- zend_update_property_long ( Z_OBJCE_P ( res ) , res, ( char * ) "position" , 8 , gr - > position TSRMLS_CC ) ;
- zend_update_property_long ( Z_OBJCE_P ( res ) , res, ( char * ) "cycle" , 5 , gr - > cycle TSRMLS_CC ) ;
- zend_update_property_long ( Z_OBJCE_P ( res ) , res, ( char * ) "group_type" , 10 , gr - > group_type TSRMLS_CC ) ;
- zend_update_property_long ( Z_OBJCE_P ( res ) , res, ( char * ) "link" , 4 , gr - > link TSRMLS_CC ) ;
- return res ;
- }
- group group_of_phpgroup ( zval * gr )
- {
- group res, def ;
- zval * x = zend_read_property ( chemlib_class_entry, gr, ( char * ) "name" , 4 , 1 TSRMLS_CC ) ;
- if ( Z_TYPE_P ( x ) ! = IS_STRING )
- return def ;
- res. name = estrdup ( Z_STRVAL_P ( x ) ) ;
- x = zend_read_property ( chemlib_class_entry, gr, ( char * ) "position" , 8 , 1 TSRMLS_CC ) ;
- if ( Z_TYPE_P ( x ) ! = IS_LONG )
- return def ;
- res. position = ( group_position ) Z_LVAL_P ( x ) ;
- x = zend_read_property ( chemlib_class_entry, gr, ( char * ) "cycle" , 5 , 1 TSRMLS_CC ) ;
- if ( Z_TYPE_P ( x ) ! = IS_LONG )
- return def ; li style = "font-weight: n
Source: https://habr.com/ru/post/98185/
All Articles