• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2003. Vladimir Prus
2  * Distributed under the Boost Software License, Version 1.0.
3  * (See accompanying file LICENSE_1_0.txt or copy at
4  * http://www.boost.org/LICENSE_1_0.txt)
5  */
6 
7 #include "native.h"
8 
9 #include "hash.h"
10 
11 #include <assert.h>
12 
13 
declare_native_rule(char const * module,char const * rule,char const ** args,LIST * (* f)(FRAME *,int),int version)14 void declare_native_rule( char const * module, char const * rule,
15     char const * * args, LIST * (*f)( FRAME *, int ), int version )
16 {
17     OBJECT * const module_obj = module ? object_new( module ) : 0 ;
18     module_t * m = bindmodule( module_obj );
19     if ( module_obj )
20         object_free( module_obj );
21     if ( !m->native_rules )
22         m->native_rules = hashinit( sizeof( native_rule_t ), "native rules" );
23 
24     {
25         OBJECT * const name = object_new( rule );
26         int found;
27         native_rule_t * const np = (native_rule_t *)hash_insert(
28             m->native_rules, name, &found );
29         np->name = name;
30         assert( !found );
31         np->procedure = function_builtin( f, 0, args );
32         np->version = version;
33     }
34 }
35