Wild Life  2.30
 All Data Structures Files Functions Variables Typedefs Macros
Macros | Functions | Variables
modules.c File Reference

modules More...

Go to the source code of this file.

Macros

#define MAKE_PUBLIC   1
 
#define MAKE_PRIVATE   2
 
#define MAKE_FEATURE_PRIVATE   3
 

Functions

void init_modules ()
 init_modules More...
 
ptr_module find_module (char *module)
 find_module More...
 
ptr_module create_module (char *module)
 ptr_module create_module(char *module) More...
 
ptr_module set_current_module (ptr_module module)
 set_current_module More...
 
ptr_module extract_module_from_name (char *str)
 extract_module_from_name More...
 
char * strip_module_name (char *str)
 strip_module_name More...
 
char * string_val (ptr_psi_term term)
 string_val More...
 
char * make_module_token (ptr_module module, char *str)
 make_module_token More...
 
ptr_definition new_definition (ptr_keyword key)
 new_definition More...
 
ptr_definition update_symbol (ptr_module module, char *symbol)
 update_symbol More...
 
char * print_symbol (ptr_keyword k)
 print_symbol More...
 
void pretty_symbol (ptr_keyword k)
 pretty_symbol More...
 
void pretty_quote_symbol (ptr_keyword k)
 pretty_quote_symbol More...
 
long c_set_module ()
 c_set_module More...
 
long c_open_module ()
 c_open_module More...
 
void open_module_tree (ptr_node n, int *onefailed)
 open_module_tree More...
 
void open_module_one (ptr_psi_term t, int *onefailed)
 open_module_one More...
 
long make_public (ptr_psi_term term, long bool)
 make_public More...
 
void traverse_tree (ptr_node n, int flag)
 traverse_tree More...
 
long c_public ()
 c_public More...
 
long c_private ()
 c_private More...
 
long c_display_modules ()
 c_display_modules More...
 
long c_display_persistent ()
 c_display_persistent More...
 
long c_trace_input ()
 c_trace_input More...
 
void rec_replace (ptr_definition, ptr_definition, ptr_psi_term)
 rec_replace More...
 
void replace_attr (ptr_node, ptr_psi_term, ptr_definition, ptr_definition)
 replace_attr More...
 
void replace (ptr_definition old, ptr_definition new, ptr_psi_term term)
 replace More...
 
long c_replace ()
 c_replace More...
 
long c_current_module ()
 c_current_module More...
 
long c_module_access ()
 c_module_access More...
 
int global_unify_attr (ptr_node, ptr_node)
 global_unify_attr More...
 
int global_unify (ptr_psi_term u, ptr_psi_term v)
 global_unify More...
 
long c_alias ()
 c_alias More...
 
int get_module (ptr_psi_term psi, ptr_module *module)
 get_module More...
 
int make_feature_private (ptr_psi_term term)
 make_feature_private More...
 
long c_private_feature ()
 c_private_feature More...
 
ptr_definition update_feature (ptr_module module, char *feature)
 update_feature More...
 
long all_public_symbols ()
 all_public_symbols More...
 

Variables

ptr_node module_table =NULL
 
ptr_module current_module =NULL
 
ptr_module no_module =NULL
 
ptr_module bi_module =NULL
 
ptr_module syntax_module =NULL
 
ptr_module sys_module =NULL
 
ptr_module user_module =NULL
 
ptr_module x_module = NULL
 
long display_modules =TRUE
 

Detailed Description

modules

RM: Jan 7 1993

This file implements a variation of the LIFE module system as specified by Dinesh Katiyar.

Definition in file modules.c.

Macro Definition Documentation

#define MAKE_FEATURE_PRIVATE   3

Definition at line 645 of file modules.c.

#define MAKE_PRIVATE   2

Definition at line 644 of file modules.c.

#define MAKE_PUBLIC   1

Definition at line 643 of file modules.c.

Function Documentation

long all_public_symbols ( )

all_public_symbols

ALL_PUBLIC_SYMBOLS Returns all public symbols from all modules or a specific module.

Definition at line 1363 of file modules.c.

References wl_goal::aaaa_1, aim, wl_psi_term::attr_list, wl_goal::bbbb_1, deref_ptr, first_definition, get_module(), get_two_args(), wl_definition::keyword, wl_keyword::module, wl_definition::next, NULL, wl_keyword::public, push_goal(), stack_cons(), stack_nil(), stack_psi_term(), TRUE, wl_psi_term::type, and unify.

1364 {
1365  ptr_psi_term arg1,arg2,funct,result;
1366  ptr_psi_term list;
1367  ptr_psi_term car;
1368  ptr_module module=NULL;
1369  ptr_definition d;
1370 
1371  funct=aim->aaaa_1;
1372  deref_ptr(funct);
1373  result=aim->bbbb_1;
1374  get_two_args(funct->attr_list,(ptr_psi_term *)&arg1,(ptr_psi_term *)&arg2);
1375 
1376  if(arg1) {
1377  deref_ptr(arg1);
1378  (void)get_module(arg1,&module);
1379  }
1380  else
1381  module=NULL;
1382 
1383  list=stack_nil();
1384 
1385  for(d=first_definition;d;d=d->next)
1386  if(d->keyword->public && (!module || d->keyword->module==module)) {
1387  car=stack_psi_term(4);
1388  car->type=d;
1389  list=stack_cons(car,list);
1390  }
1391 
1392  push_goal(unify,result,list,NULL);
1393 
1394  return TRUE;
1395 }
ptr_psi_term aaaa_1
Definition: def_struct.h:239
void get_two_args(ptr_node t, ptr_psi_term *a, ptr_psi_term *b)
get_two_args
Definition: login.c:47
ptr_psi_term stack_cons(ptr_psi_term head, ptr_psi_term tail)
stack_cons
Definition: built_ins.c:46
void push_goal(goals t, ptr_psi_term a, ptr_psi_term b, GENERIC c)
push_goal
Definition: login.c:600
ptr_definition first_definition
All definition are stores in a linked list starting at first_definition.
Definition: def_glob.h:13
ptr_keyword keyword
Definition: def_struct.h:147
#define NULL
Definition: def_const.h:533
ptr_definition next
Definition: def_struct.h:164
#define deref_ptr(P)
Definition: def_macro.h:100
#define TRUE
Standard boolean.
Definition: def_const.h:268
ptr_psi_term stack_psi_term(long stat)
stack_psi_term
Definition: lefun.c:21
ptr_psi_term stack_nil()
stack_nil
Definition: built_ins.c:26
ptr_goal aim
Definition: def_glob.h:1024
#define unify
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1058
ptr_module module
Definition: def_struct.h:117
ptr_definition type
Definition: def_struct.h:181
int get_module(ptr_psi_term psi, ptr_module *module)
get_module
Definition: modules.c:1226
ptr_psi_term bbbb_1
Definition: def_struct.h:240
ptr_node attr_list
Definition: def_struct.h:187
long c_alias ( )

c_alias

C_ALIAS Alias one keyword to another.

Definition at line 1180 of file modules.c.

References wl_goal::aaaa_1, aim, wl_psi_term::attr_list, wl_keyword::combined_name, wl_keyword::definition, deref_ptr, Errorline(), FALSE, get_two_args(), hash_lookup(), wl_definition::keyword, wl_module::module_name, wl_keyword::symbol, wl_module::symbol_table, TRUE, wl_psi_term::type, and warningline().

1181 {
1182  long success=TRUE;
1183  ptr_psi_term arg1,arg2,g;
1184  ptr_keyword key;
1185 
1186  g=aim->aaaa_1;
1187 
1188  deref_ptr(g);
1189  get_two_args(g->attr_list,(ptr_psi_term *)&arg1,(ptr_psi_term *)&arg2);
1190  if (arg1 && arg2) {
1191  deref_ptr(arg1);
1192  deref_ptr(arg2);
1193 
1195  if(key) {
1196  if(key->definition!=arg2->type) {
1197  warningline("alias: '%s' has now been overwritten by '%s'\n",
1198  key->combined_name,
1199  arg2->type->keyword->combined_name);
1200 
1201  key->definition=arg2->type;
1202  }
1203  }
1204  else
1205  Errorline("module violation: cannot alias '%s' from module \"%s\"\n",
1206  key->combined_name,
1208  }
1209  else {
1210  success=FALSE;
1211  Errorline("argument(s) missing in '%P'\n",g);
1212  }
1213 
1214  return success;
1215 }
ptr_psi_term aaaa_1
Definition: def_struct.h:239
ptr_keyword hash_lookup(ptr_hash_table table, char *symbol)
HASH_LOOKUP.
Definition: hash_table.c:131
void get_two_args(ptr_node t, ptr_psi_term *a, ptr_psi_term *b)
get_two_args
Definition: login.c:47
char * combined_name
Definition: def_struct.h:119
ptr_definition definition
Definition: def_struct.h:122
ptr_hash_table symbol_table
Definition: def_struct.h:110
ptr_keyword keyword
Definition: def_struct.h:147
ptr_module current_module
Definition: modules.c:15
char * symbol
Definition: def_struct.h:118
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
#define deref_ptr(P)
Definition: def_macro.h:100
#define TRUE
Standard boolean.
Definition: def_const.h:268
#define FALSE
Standard boolean.
Definition: def_const.h:275
ptr_goal aim
Definition: def_glob.h:1024
char * module_name
Definition: def_struct.h:106
void warningline(char *format,...)
warningline
Definition: error.c:371
ptr_definition type
Definition: def_struct.h:181
ptr_node attr_list
Definition: def_struct.h:187
long c_current_module ( )

c_current_module

C_CURRENT_MODULE Return the current module.

Definition at line 974 of file modules.c.

References wl_goal::aaaa_1, aim, wl_goal::bbbb_1, deref_ptr, heap_copy_string(), wl_module::module_name, NULL, push_goal(), quoted_string, resid_aim, stack_psi_term(), TRUE, wl_psi_term::type, unify, and wl_psi_term::value_3.

975 {
976  long success=TRUE;
977  ptr_psi_term result,g,other;
978 
979  g=aim->aaaa_1;
980  deref_ptr(g);
981  result=aim->bbbb_1;
982  deref_ptr(result);
983 
984  other=stack_psi_term(4);
985  /* PVR 24.1.94 */
986  other->type=quoted_string;
988  /*
989  update_symbol(current_module,
990  current_module->module_name)
991  ->keyword->symbol
992  );
993 */ /* RM: 2/15/1994 */
994  /* other->type=update_symbol(current_module,current_module->module_name); */
995  resid_aim=NULL;
996  push_goal(unify,result,other,NULL);
997 
998  return success;
999 }
ptr_psi_term aaaa_1
Definition: def_struct.h:239
void push_goal(goals t, ptr_psi_term a, ptr_psi_term b, GENERIC c)
push_goal
Definition: login.c:600
#define NULL
Definition: def_const.h:533
ptr_module current_module
Definition: modules.c:15
ptr_goal resid_aim
Definition: def_glob.h:865
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
#define deref_ptr(P)
Definition: def_macro.h:100
char * heap_copy_string(char *s)
heap_copy_string
Definition: trees.c:172
#define TRUE
Standard boolean.
Definition: def_const.h:268
ptr_psi_term stack_psi_term(long stat)
stack_psi_term
Definition: lefun.c:21
GENERIC value_3
Definition: def_struct.h:186
ptr_goal aim
Definition: def_glob.h:1024
char * module_name
Definition: def_struct.h:106
#define unify
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1058
ptr_definition type
Definition: def_struct.h:181
ptr_psi_term bbbb_1
Definition: def_struct.h:240
ptr_definition quoted_string
symbol in bi module
Definition: def_glob.h:368
long c_display_modules ( )

c_display_modules

C_DISPLAY_MODULES(); Set the display modules switch.

Definition at line 739 of file modules.c.

References wl_goal::aaaa_1, aim, wl_psi_term::attr_list, deref_ptr, display_modules, Errorline(), FALSE, get_two_args(), lf_false, lf_true, TRUE, and wl_psi_term::type.

740 {
741  ptr_psi_term arg1,arg2;
742  ptr_psi_term call;
743  int success=TRUE;
744 
745 
746  call=aim->aaaa_1;
747  deref_ptr(call);
748  get_two_args(call->attr_list,(ptr_psi_term *)&arg1,(ptr_psi_term *)&arg2);
749 
750  if(arg1) {
751  deref_ptr(arg1);
752  if(arg1->type==lf_true)
754  else
755  if(arg1->type==lf_false)
757  else {
758  Errorline("argument should be boolean in '%P'\n",call);
759  success=FALSE;
760  }
761  }
762  else /* No argument: toggle */
764 
765  return success;
766 }
ptr_psi_term aaaa_1
Definition: def_struct.h:239
void get_two_args(ptr_node t, ptr_psi_term *a, ptr_psi_term *b)
get_two_args
Definition: login.c:47
long display_modules
Definition: modules.c:25
ptr_definition lf_false
symbol in bi module
Definition: def_glob.h:284
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
#define deref_ptr(P)
Definition: def_macro.h:100
#define TRUE
Standard boolean.
Definition: def_const.h:268
#define FALSE
Standard boolean.
Definition: def_const.h:275
ptr_goal aim
Definition: def_glob.h:1024
ptr_definition lf_true
symbol in bi module
Definition: def_glob.h:410
ptr_definition type
Definition: def_struct.h:181
ptr_node attr_list
Definition: def_struct.h:187
long c_display_persistent ( )

c_display_persistent

C_DISPLAY_PERSISTENT(); Set the display persistent switch.

Definition at line 775 of file modules.c.

References wl_goal::aaaa_1, aim, wl_psi_term::attr_list, deref_ptr, display_persistent, Errorline(), FALSE, get_two_args(), lf_false, lf_true, TRUE, and wl_psi_term::type.

776 {
777  ptr_psi_term arg1,arg2;
778  ptr_psi_term call;
779  int success=TRUE;
780 
781  call=aim->aaaa_1;
782  deref_ptr(call);
783  get_two_args(call->attr_list,(ptr_psi_term *)&arg1,(ptr_psi_term *)&arg2);
784 
785  if(arg1) {
786  deref_ptr(arg1);
787  if(arg1->type==lf_true)
789  else
790  if(arg1->type==lf_false)
792  else {
793  Errorline("argument should be boolean in '%P'\n",call);
794  success=FALSE;
795  }
796  }
797  else /* No argument: toggle */
799 
800  return success;
801 }
ptr_psi_term aaaa_1
Definition: def_struct.h:239
void get_two_args(ptr_node t, ptr_psi_term *a, ptr_psi_term *b)
get_two_args
Definition: login.c:47
ptr_definition lf_false
symbol in bi module
Definition: def_glob.h:284
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
#define deref_ptr(P)
Definition: def_macro.h:100
#define TRUE
Standard boolean.
Definition: def_const.h:268
#define FALSE
Standard boolean.
Definition: def_const.h:275
ptr_goal aim
Definition: def_glob.h:1024
long display_persistent
if true print persistent values preceded by "$"
Definition: def_glob.h:748
ptr_definition lf_true
symbol in bi module
Definition: def_glob.h:410
ptr_definition type
Definition: def_struct.h:181
ptr_node attr_list
Definition: def_struct.h:187
long c_module_access ( )

c_module_access

C_MODULE_ACCESS Return the psi-term Module::Symbol

Definition at line 1008 of file modules.c.

References wl_goal::aaaa_1, aim, deref_ptr, FALSE, and warningline().

1009 {
1010  long success=FALSE;
1011  // ptr_psi_term result,module,symbol,call,other;
1012  ptr_psi_term call;
1013 
1014 
1015  call=aim->aaaa_1;
1016  deref_ptr(call);
1017 
1018  /*
1019  result=aim->bbbb_1;
1020  deref_ptr(result);
1021  get_two_args(call,(ptr_psi_term *)&module,(ptr_psi_term *)&symbol);
1022 
1023  if(module && symbol) {
1024  other=stack_psi_term(4);
1025  other->type=update_symbol(module_access,module_access->module_name);
1026  resid_aim=NULL;
1027  push_goal(unify,result,other,NULL);
1028 
1029  }
1030  */
1031 
1032  warningline("%P not implemented yet...\n",call);
1033 
1034  return success;
1035 }
ptr_psi_term aaaa_1
Definition: def_struct.h:239
#define deref_ptr(P)
Definition: def_macro.h:100
#define FALSE
Standard boolean.
Definition: def_const.h:275
ptr_goal aim
Definition: def_glob.h:1024
void warningline(char *format,...)
warningline
Definition: error.c:371
long c_open_module ( )

c_open_module

C_OPEN_MODULE() Open one or more modules, that is, alias all the public words in the current module to the definitions in the argument. An error message is printed for each module that is not successfully opened. If at least one module was not successfully opened, the routine fails.

Definition at line 519 of file modules.c.

References wl_goal::aaaa_1, aim, wl_psi_term::attr_list, deref_ptr, Errorline(), FALSE, and open_module_tree().

520 {
521  ptr_psi_term call;
522  int onefailed=FALSE;
523  call=aim->aaaa_1;
524  deref_ptr(call);
525  if (call->attr_list) {
526  open_module_tree(call->attr_list, &onefailed);
527  }
528  else {
529  Errorline("argument missing in '%P'\n",call);
530  }
531 
532  return !onefailed;
533 }
ptr_psi_term aaaa_1
Definition: def_struct.h:239
void open_module_tree(ptr_node n, int *onefailed)
open_module_tree
Definition: modules.c:542
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
#define deref_ptr(P)
Definition: def_macro.h:100
#define FALSE
Standard boolean.
Definition: def_const.h:275
ptr_goal aim
Definition: def_glob.h:1024
ptr_node attr_list
Definition: def_struct.h:187
long c_private ( )

c_private

C_PRIVATE() The argument is a single symbol or a list of symbols. Make them private in the current module if they belong to it.

Definition at line 714 of file modules.c.

References wl_goal::aaaa_1, aim, wl_psi_term::attr_list, deref_ptr, Errorline(), FALSE, MAKE_PRIVATE, traverse_tree(), and TRUE.

715 {
716  ptr_psi_term call;
717  int success;
718 
719  call=aim->aaaa_1;
720  deref_ptr(call);
721  if (call->attr_list) {
723  success=TRUE;
724  } else {
725  Errorline("argument missing in '%P'\n",call);
726  success=FALSE;
727  }
728 
729  return success;
730 }
ptr_psi_term aaaa_1
Definition: def_struct.h:239
void traverse_tree(ptr_node n, int flag)
traverse_tree
Definition: modules.c:656
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
#define MAKE_PRIVATE
Definition: modules.c:644
#define deref_ptr(P)
Definition: def_macro.h:100
#define TRUE
Standard boolean.
Definition: def_const.h:268
#define FALSE
Standard boolean.
Definition: def_const.h:275
ptr_goal aim
Definition: def_glob.h:1024
ptr_node attr_list
Definition: def_struct.h:187
long c_private_feature ( )

c_private_feature

C_PRIVATE_FEATURE() The argument is a single symbol or a list of symbols. Make this feature private to the current module.

Definition at line 1302 of file modules.c.

References wl_goal::aaaa_1, aim, wl_psi_term::attr_list, deref_ptr, Errorline(), FALSE, MAKE_FEATURE_PRIVATE, traverse_tree(), and TRUE.

1303 {
1304  // ptr_psi_term arg1,arg2;
1305  ptr_psi_term call;
1306  int success;
1307 
1308  call=aim->aaaa_1;
1309  deref_ptr(call);
1310  if (call->attr_list) {
1312  success=TRUE;
1313  } else {
1314  Errorline("argument missing in '%P'\n",call);
1315  success=FALSE;
1316  }
1317 
1318  return success;
1319 }
ptr_psi_term aaaa_1
Definition: def_struct.h:239
void traverse_tree(ptr_node n, int flag)
traverse_tree
Definition: modules.c:656
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
#define deref_ptr(P)
Definition: def_macro.h:100
#define TRUE
Standard boolean.
Definition: def_const.h:268
#define FALSE
Standard boolean.
Definition: def_const.h:275
ptr_goal aim
Definition: def_glob.h:1024
#define MAKE_FEATURE_PRIVATE
Definition: modules.c:645
ptr_node attr_list
Definition: def_struct.h:187
long c_public ( )

c_public

C_PUBLIC() The argument(s) are symbols. Make them public in the current module if they belong to it.

Definition at line 687 of file modules.c.

References wl_goal::aaaa_1, aim, wl_psi_term::attr_list, deref_ptr, Errorline(), FALSE, MAKE_PUBLIC, traverse_tree(), and TRUE.

688 {
689  // ptr_psi_term arg1,arg2;
690  ptr_psi_term call;
691  int success;
692 
693  call=aim->aaaa_1;
694  deref_ptr(call);
695  if (call->attr_list) {
697  success=TRUE;
698  } else {
699  Errorline("argument missing in '%P'\n",call);
700  success=FALSE;
701  }
702 
703  return success;
704 }
ptr_psi_term aaaa_1
Definition: def_struct.h:239
void traverse_tree(ptr_node n, int flag)
traverse_tree
Definition: modules.c:656
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
#define deref_ptr(P)
Definition: def_macro.h:100
#define TRUE
Standard boolean.
Definition: def_const.h:268
#define FALSE
Standard boolean.
Definition: def_const.h:275
ptr_goal aim
Definition: def_glob.h:1024
#define MAKE_PUBLIC
Definition: modules.c:643
ptr_node attr_list
Definition: def_struct.h:187
long c_replace ( )

c_replace

C_REPLACE() Replace all occurrences of type ARG1 with ARG2 in ARG3.

Definition at line 936 of file modules.c.

References wl_goal::aaaa_1, aim, wl_psi_term::attr_list, wl_node::data, deref_ptr, Errorline(), FALSE, FEATCMP, find(), get_two_args(), NULL, replace(), three, TRUE, and wl_psi_term::type.

937 {
938  ptr_psi_term arg1=NULL;
939  ptr_psi_term arg2=NULL;
940  ptr_psi_term arg3=NULL;
941  ptr_psi_term call;
942  int success=FALSE;
943  ptr_node n;
944 
945  call=aim->aaaa_1;
946  deref_ptr(call);
947 
948  get_two_args(call->attr_list,(ptr_psi_term *)&arg1,(ptr_psi_term *)&arg2);
949  n=find(FEATCMP,three,call->attr_list);
950  if (n)
951  arg3=(ptr_psi_term)n->data;
952 
953  if(arg1 && arg2 && arg3) {
954  deref_ptr(arg1);
955  deref_ptr(arg2);
956  deref_ptr(arg3);
957  replace(arg1->type,arg2->type,arg3);
958  success=TRUE;
959  }
960  else {
961  Errorline("argument missing in '%P'\n",call);
962  }
963 
964  return success;
965 }
ptr_psi_term aaaa_1
Definition: def_struct.h:239
void get_two_args(ptr_node t, ptr_psi_term *a, ptr_psi_term *b)
get_two_args
Definition: login.c:47
#define FEATCMP
indicates to use featcmp for comparison (in trees.c)
Definition: def_const.h:979
struct wl_psi_term * ptr_psi_term
quotedStackCopy
Definition: def_struct.h:62
GENERIC data
Definition: def_struct.h:201
#define NULL
Definition: def_const.h:533
char * three
Definition: def_glob.h:893
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
#define deref_ptr(P)
Definition: def_macro.h:100
#define TRUE
Standard boolean.
Definition: def_const.h:268
void replace(ptr_definition old, ptr_definition new, ptr_psi_term term)
replace
Definition: modules.c:851
#define FALSE
Standard boolean.
Definition: def_const.h:275
ptr_goal aim
Definition: def_glob.h:1024
ptr_node find(long comp, char *keystr, ptr_node tree)
find
Definition: trees.c:394
ptr_definition type
Definition: def_struct.h:181
ptr_node attr_list
Definition: def_struct.h:187
long c_set_module ( )

c_set_module

C_SET_MODULE() This routine retrieves the necessary psi-term to determine the current state of the module mechanism from the heap.

Definition at line 488 of file modules.c.

References wl_goal::aaaa_1, aim, wl_psi_term::attr_list, create_module(), deref_ptr, Errorline(), FALSE, get_two_args(), set_current_module(), string_val(), and TRUE.

489 {
490  ptr_psi_term arg1,arg2;
491  ptr_psi_term call;
492 
493  call=aim->aaaa_1;
494  deref_ptr(call);
495  get_two_args(call->attr_list,(ptr_psi_term *)&arg1,(ptr_psi_term *)&arg2);
496 
497  if(arg1) {
499  return TRUE;
500  }
501  else {
502  Errorline("argument missing in '%P'\n",call);
503  return FALSE;
504  }
505 }
ptr_psi_term aaaa_1
Definition: def_struct.h:239
void get_two_args(ptr_node t, ptr_psi_term *a, ptr_psi_term *b)
get_two_args
Definition: login.c:47
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
#define deref_ptr(P)
Definition: def_macro.h:100
#define TRUE
Standard boolean.
Definition: def_const.h:268
#define FALSE
Standard boolean.
Definition: def_const.h:275
ptr_goal aim
Definition: def_glob.h:1024
ptr_module create_module(char *module)
ptr_module create_module(char *module)
Definition: modules.c:72
char * string_val(ptr_psi_term term)
string_val
Definition: modules.c:169
ptr_module set_current_module(ptr_module module)
set_current_module
Definition: modules.c:100
ptr_node attr_list
Definition: def_struct.h:187
long c_trace_input ( )

c_trace_input

C_TRACE_INPUT(); Set the trace_input switch.

Definition at line 810 of file modules.c.

References wl_goal::aaaa_1, aim, wl_psi_term::attr_list, deref_ptr, Errorline(), FALSE, get_two_args(), lf_false, lf_true, trace_input, TRUE, and wl_psi_term::type.

811 {
812  ptr_psi_term arg1,arg2;
813  ptr_psi_term call;
814  int success=TRUE;
815 
816  call=aim->aaaa_1;
817  deref_ptr(call);
818  get_two_args(call->attr_list,(ptr_psi_term *)&arg1,(ptr_psi_term *)&arg2);
819 
820  if(arg1) {
821  deref_ptr(arg1);
822  if(arg1->type==lf_true)
824  else
825  if(arg1->type==lf_false)
827  else {
828  Errorline("argument should be boolean in '%P'\n",call);
829  success=FALSE;
830  }
831  }
832  else /* No argument: toggle */
834 
835  return success;
836 }
ptr_psi_term aaaa_1
Definition: def_struct.h:239
void get_two_args(ptr_node t, ptr_psi_term *a, ptr_psi_term *b)
get_two_args
Definition: login.c:47
ptr_definition lf_false
symbol in bi module
Definition: def_glob.h:284
long trace_input
whether to echo characters read
Definition: def_glob.h:756
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
#define deref_ptr(P)
Definition: def_macro.h:100
#define TRUE
Standard boolean.
Definition: def_const.h:268
#define FALSE
Standard boolean.
Definition: def_const.h:275
ptr_goal aim
Definition: def_glob.h:1024
ptr_definition lf_true
symbol in bi module
Definition: def_glob.h:410
ptr_definition type
Definition: def_struct.h:181
ptr_node attr_list
Definition: def_struct.h:187
ptr_module create_module ( char *  module)

ptr_module create_module(char *module)

CREATE_MODULE(module) Create a new module.

Definition at line 72 of file modules.c.

References find_module(), hash_create(), HEAP_ALLOC, heap_copy_string(), heap_insert(), input_file_name, NULL, and STRCMP.

73 {
74  ptr_module new;
75 
76 
77  new=find_module(module);
78  if(!new) {
79  new=HEAP_ALLOC(struct wl_module);
80  new->module_name=(char *)heap_copy_string(module);
81  new->source_file=(char *)heap_copy_string(input_file_name);
82  new->open_modules=NULL;
83  new->inherited_modules=NULL;
84  new->symbol_table=hash_create(16); /* RM: Feb 3 1993 */
85 
86  (void)heap_insert(STRCMP,new->module_name,&module_table,(GENERIC)new);
87 
88  }
89  return new;
90 }
ptr_node module_table
Definition: modules.c:14
string input_file_name
Definition: def_glob.h:1016
ptr_hash_table hash_create(int size)
HASH_CREATE.
Definition: hash_table.c:25
#define NULL
Definition: def_const.h:533
ptr_node heap_insert(long comp, char *keystr, ptr_node *tree, GENERIC info)
heap_insert
Definition: trees.c:320
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
char * heap_copy_string(char *s)
heap_copy_string
Definition: trees.c:172
#define STRCMP
indicates to use strcmp for comparison (c function)
Definition: def_const.h:963
ptr_module find_module(char *module)
find_module
Definition: modules.c:54
#define HEAP_ALLOC(A)
Definition: def_macro.h:20
ptr_module extract_module_from_name ( char *  str)

extract_module_from_name

Parameters
str- char *str

EXTRACT_MODULE_FROM_NAME Return the module corresponding to "module#symbol". Return NULL if only "#symbol".

Definition at line 116 of file modules.c.

References create_module(), legal_in_name(), and NULL.

117 {
118  char *s;
119  ptr_module result=NULL;
120 
121  s=str;
122  while(legal_in_name(*s))
123  s++;
124  if(s!=str && *s=='#' /* && *(s+1)!=0 */) {
125  *s=0;
126  result=create_module(str);
127  *s='#';
128  /*
129  printf("Extracted module name '%s' from '%s'\n",result->module_name,str);
130  */
131  }
132 
133  return result;
134 }
long legal_in_name(long c)
legal_in_name
Definition: token.c:980
#define NULL
Definition: def_const.h:533
ptr_module create_module(char *module)
ptr_module create_module(char *module)
Definition: modules.c:72
ptr_module find_module ( char *  module)

find_module

Parameters
modulechar *module

FIND_MODULE(module) Return a module if it exists.

Definition at line 54 of file modules.c.

References wl_node::data, FEATCMP, find(), and NULL.

55 {
56  ptr_node nodule;
57 
58  nodule=find(FEATCMP,(char *)module,module_table);
59  if(nodule)
60  return (ptr_module)(nodule->data);
61  else
62  return NULL;
63 }
ptr_node module_table
Definition: modules.c:14
#define FEATCMP
indicates to use featcmp for comparison (in trees.c)
Definition: def_const.h:979
GENERIC data
Definition: def_struct.h:201
#define NULL
Definition: def_const.h:533
ptr_node find(long comp, char *keystr, ptr_node tree)
find
Definition: trees.c:394
int get_module ( ptr_psi_term  psi,
ptr_module module 
)

get_module

Parameters
psi- ptr_psi_term psi
module- ptr_module *module

GET_MODULE(psi,module,resid) Convert a psi-term to a module. The psi-term must be a string.

Definition at line 1226 of file modules.c.

References deref_ptr, Errorline(), FALSE, find_module(), wl_definition::keyword, NULL, overlap_type(), quoted_string, wl_keyword::symbol, TRUE, wl_psi_term::type, and wl_psi_term::value_3.

1227 {
1228  int success=TRUE;
1229  char *s;
1230 
1231  *module=NULL;
1232 
1233  deref_ptr(psi);
1234  if(overlap_type(psi->type,quoted_string) && psi->value_3)
1235  s=(char *)psi->value_3;
1236  else
1237  s=psi->type->keyword->symbol;
1238 
1239  *module=find_module(s);
1240  if(!(*module)) {
1241  Errorline("undefined module \"%s\"\n",s);
1242  success=FALSE;
1243  }
1244 
1245  return success;
1246 }
ptr_keyword keyword
Definition: def_struct.h:147
#define NULL
Definition: def_const.h:533
char * symbol
Definition: def_struct.h:118
long overlap_type(ptr_definition t1, ptr_definition t2)
overlap_type
Definition: types.c:1579
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
#define deref_ptr(P)
Definition: def_macro.h:100
#define TRUE
Standard boolean.
Definition: def_const.h:268
#define FALSE
Standard boolean.
Definition: def_const.h:275
GENERIC value_3
Definition: def_struct.h:186
ptr_module find_module(char *module)
find_module
Definition: modules.c:54
ptr_definition type
Definition: def_struct.h:181
ptr_definition quoted_string
symbol in bi module
Definition: def_glob.h:368
int global_unify ( ptr_psi_term  u,
ptr_psi_term  v 
)

global_unify

Parameters
u- ptr_psi_term u
v- ptr_psi_term v

GLOBAL_UNIFY(u,v) Unify two psi-terms, where it is known that V is on the heap (a persistent variable).

This routine really matches U and V, it will only succeed if V is more general than U. U will then be bound to V.

Definition at line 1053 of file modules.c.

References wl_psi_term::attr_list, c_abort(), wl_psi_term::coref, deref_ptr, Errorline(), FALSE, glb(), global_unify_attr(), heap_pointer, overlap_type(), push_psi_ptr_value(), quoted_string, REAL, real, release_resid(), wl_psi_term::resid, traceline(), TRUE, wl_psi_term::type, and wl_psi_term::value_3.

1054 {
1055  int success=TRUE;
1056  int compare;
1057  ptr_definition new_type;
1058  ptr_int_list new_code;
1059 
1060  deref_ptr(u);
1061  deref_ptr(v);
1062 
1063  traceline("match persistent %P with %P\n",u,v);
1064 
1065  /* printf("u=%ld, v=%ld, heap_pointer=%ld\n",u,v,heap_pointer);*/
1066 
1067  /* printf("u=%s, v=%s\n",
1068  u->type->keyword->symbol,
1069  v->type->keyword->symbol); */
1070 
1071  if((GENERIC)u>=heap_pointer) {
1072  Errorline("cannot unify persistent values\n");
1073  return c_abort();
1074  }
1075 
1076  /**** U is on the stack, V is on the heap ****/
1077 
1078  /**** Calculate their Greatest Lower Bound and compare them ****/
1079  compare=glb(u->type,v->type,&new_type,&new_code);
1080 
1081  /* printf("compare=%d\n",compare); */
1082 
1083  if (compare==1 || compare==3) { /* Match only */
1084 
1085  /**** Check for values ****/
1086  if(v->value_3) {
1087  if(u->value_3) {
1088  if(u->value_3!=v->value_3) { /* One never knows */
1089  if (overlap_type(v->type,real))
1090  success=(*((REAL *)u->value_3)==(*((REAL *)v->value_3)));
1091  else if (overlap_type(v->type,quoted_string))
1092  success=(strcmp((char *)u->value_3,(char *)v->value_3)==0);
1093  else
1094  return FALSE; /* Don't unify CUTs and STREAMs and things */
1095  }
1096  }
1097  }
1098  else
1099  if(u->value_3)
1100  return FALSE;
1101 
1102  if(success) {
1103  /**** Bind the two psi-terms ****/
1104  push_psi_ptr_value(u,(GENERIC *)&(u->coref));
1105  u->coref=v;
1106 
1107  /**** Match the attributes ****/
1108  success=global_unify_attr(u->attr_list,v->attr_list);
1109 
1110  /*
1111  if(!success)
1112  warningline("attributes don't unify in %P and %P\n",u,v);
1113  */
1114 
1115  if(success && u->resid)
1116  release_resid(u);
1117  }
1118  }
1119  else
1120  success=FALSE;
1121 
1122  return success;
1123 }
ptr_residuation resid
Definition: def_struct.h:189
GENERIC heap_pointer
used to allocate from heap - size allocated subtracted - adj for alignment
Definition: def_glob.h:55
long glb(ptr_definition t1, ptr_definition t2, ptr_definition *t3, ptr_int_list *c3)
glb
Definition: types.c:1481
int global_unify_attr(ptr_node, ptr_node)
global_unify_attr
Definition: modules.c:1135
void push_psi_ptr_value(ptr_psi_term q, GENERIC *p)
push_psi_ptr_value
Definition: login.c:474
long c_abort()
c_abort
Definition: built_ins.c:2247
#define REAL
Which C type to use to represent reals and integers in Wild_Life.
Definition: def_const.h:132
long overlap_type(ptr_definition t1, ptr_definition t2)
overlap_type
Definition: types.c:1579
void release_resid(ptr_psi_term t)
release_resid
Definition: lefun.c:445
void traceline(char *format,...)
traceline
Definition: error.c:186
ptr_definition real
symbol in bi module
Definition: def_glob.h:375
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
#define deref_ptr(P)
Definition: def_macro.h:100
#define TRUE
Standard boolean.
Definition: def_const.h:268
#define FALSE
Standard boolean.
Definition: def_const.h:275
GENERIC value_3
Definition: def_struct.h:186
ptr_psi_term coref
Definition: def_struct.h:188
ptr_definition type
Definition: def_struct.h:181
ptr_node attr_list
Definition: def_struct.h:187
ptr_definition quoted_string
symbol in bi module
Definition: def_glob.h:368
int global_unify_attr ( ptr_node  u,
ptr_node  v 
)

global_unify_attr

Parameters
u- ptr_node u
v- ptr_node v

GLOBAL_UNIFY_ATTR(u,v) Unify the attributes of two terms, one on the heap, one on the stack. This is really matching, so all features of U must appear in V.

Definition at line 1135 of file modules.c.

References wl_node::data, dummy_printf(), FALSE, featcmp(), global_unify(), wl_node::key, wl_node::left, NULL, wl_node::right, and TRUE.

1136 {
1137  int success=TRUE;
1138  ptr_node temp;
1139  long cmp;
1140 
1141  if(u)
1142  if(v) {
1143  /* RM: Feb 16 1993 Avoid C optimiser bug */
1144  (void)dummy_printf("%s %s\n",u->key,v->key);
1145 
1146  cmp=featcmp(u->key,v->key);
1147  if(cmp<0) {
1148  temp=u->right;
1149  u->right=NULL;
1150  success=global_unify_attr(u,v->left) && global_unify_attr(temp,v);
1151  u->right=temp;
1152  }
1153  else
1154  if(cmp>0) {
1155  temp=u->left;
1156  u->left=NULL;
1157  success=global_unify_attr(u,v->right) && global_unify_attr(temp,v);
1158  u->left=temp;
1159  }
1160  else {
1161  success=
1162  global_unify_attr(u->left,v->left) &&
1163  global_unify_attr(u->right,v->right) &&
1165  }
1166  }
1167  else
1168  success=FALSE;
1169 
1170  return success;
1171 }
int global_unify_attr(ptr_node, ptr_node)
global_unify_attr
Definition: modules.c:1135
int global_unify(ptr_psi_term u, ptr_psi_term v)
global_unify
Definition: modules.c:1053
GENERIC data
Definition: def_struct.h:201
#define NULL
Definition: def_const.h:533
ptr_node left
Definition: def_struct.h:199
char * key
Definition: def_struct.h:198
#define TRUE
Standard boolean.
Definition: def_const.h:268
#define FALSE
Standard boolean.
Definition: def_const.h:275
int dummy_printf(char *f, char *s, char *t)
dummy_printf
Definition: login.c:2617
long featcmp(char *str1, char *str2)
featcmp
Definition: trees.c:106
ptr_node right
Definition: def_struct.h:200
void init_modules ( )

init_modules

INIT_MODULES() Initialize the module system.

Definition at line 34 of file modules.c.

References create_module(), and set_current_module().

35 {
36  bi_module=create_module("built_ins");
37  no_module=create_module("no_module");
39  syntax_module=create_module("syntax");
40  user_module=create_module("user"); /* RM: Jan 27 1993 */
42 
44 }
ptr_module user_module
Definition: modules.c:22
ptr_module sys_module
Definition: modules.c:19
ptr_module bi_module
Definition: modules.c:17
ptr_module create_module(char *module)
ptr_module create_module(char *module)
Definition: modules.c:72
ptr_module x_module
Definition: modules.c:23
ptr_module no_module
Definition: modules.c:16
ptr_module set_current_module(ptr_module module)
set_current_module
Definition: modules.c:100
ptr_module syntax_module
Definition: modules.c:18
int make_feature_private ( ptr_psi_term  term)

make_feature_private

Parameters
term- ptr_psi_term term

MAKE_FEATURE_PRIVATE(feature) Make a feature private.

Definition at line 1256 of file modules.c.

References wl_keyword::combined_name, wl_keyword::definition, deref_ptr, hash_lookup(), wl_definition::keyword, wl_keyword::private_feature, wl_keyword::public, wl_keyword::symbol, wl_module::symbol_table, TRUE, wl_psi_term::type, update_symbol(), and warningline().

1257 {
1258  int ok=TRUE;
1259  ptr_keyword key;
1260  ptr_definition def;
1261 
1262  deref_ptr(term);
1263 
1265 
1266  if(key) {
1267  /*
1268  if(key->definition->keyword->module!=current_module) {
1269  warningline("local definition of '%s' overrides '%s'\n",
1270  key->definition->keyword->symbol,
1271  key->definition->keyword->combined_name);
1272 
1273  new_definition(key);
1274  }
1275  */
1276 
1277  key->private_feature=TRUE;
1278  def=key->definition;
1279  }
1280  else {
1283  }
1284 
1285 
1286  if(ok && def->keyword->public) {
1287  warningline("feature '%s' is now private, but was also declared public\n",
1288  def->keyword->combined_name);
1289  }
1290 
1291  return ok;
1292 }
ptr_keyword hash_lookup(ptr_hash_table table, char *symbol)
HASH_LOOKUP.
Definition: hash_table.c:131
char * combined_name
Definition: def_struct.h:119
ptr_definition definition
Definition: def_struct.h:122
ptr_hash_table symbol_table
Definition: def_struct.h:110
ptr_keyword keyword
Definition: def_struct.h:147
ptr_module current_module
Definition: modules.c:15
char * symbol
Definition: def_struct.h:118
ptr_definition update_symbol(ptr_module module, char *symbol)
update_symbol
Definition: modules.c:270
#define deref_ptr(P)
Definition: def_macro.h:100
#define TRUE
Standard boolean.
Definition: def_const.h:268
int private_feature
Definition: def_struct.h:121
void warningline(char *format,...)
warningline
Definition: error.c:371
ptr_definition type
Definition: def_struct.h:181
char* make_module_token ( ptr_module  module,
char *  str 
)

make_module_token

Parameters
module- ptr_module module
str- char *str

MAKE_MODULE_TOKEN(module,string) Write 'module::string' in module_buffer. If string is a qualified reference to a given module, then modify the calling module variable to reflect this.

The result must be immediately stored in a newly allocated string.

Definition at line 191 of file modules.c.

References extract_module_from_name(), module_buffer, and wl_module::module_name.

192 {
193  ptr_module explicit;
194 
195 
196  /* Check if the string already contains a module */
197  explicit=extract_module_from_name(str);
198  if(explicit)
199  strcpy(module_buffer,str);
200  else
201  if(module!=no_module) {
202  strcpy(module_buffer,module->module_name);
203  strcat(module_buffer,"#");
204  strcat(module_buffer,str);
205  }
206  else
207  strcpy(module_buffer,str);
208 
209  return module_buffer;
210 }
string module_buffer
Definition: def_glob.h:953
char * module_name
Definition: def_struct.h:106
ptr_module no_module
Definition: modules.c:16
ptr_module extract_module_from_name(char *str)
extract_module_from_name
Definition: modules.c:116
long make_public ( ptr_psi_term  term,
long  bool 
)

make_public

Parameters
term- ptr_psi_term term
bool- long bool

MAKE_PUBLIC(term,bool) Make a term public.

Definition at line 613 of file modules.c.

References wl_keyword::combined_name, wl_keyword::definition, deref_ptr, hash_lookup(), wl_definition::keyword, wl_keyword::module, new_definition(), wl_keyword::public, wl_keyword::symbol, wl_module::symbol_table, TRUE, wl_psi_term::type, update_symbol(), and warningline().

614 {
615  int ok=TRUE;
616  ptr_keyword key;
617  ptr_definition def;
618 
619  deref_ptr(term);
620 
622  if(key) {
623 
624  if(key->definition->keyword->module!=current_module && !bool) {
625  warningline("local definition of '%s' overrides '%s'\n",
626  key->definition->keyword->symbol,
628 
629  (void)new_definition(key);
630  }
631 
632  key->public=bool;
633  }
634  else {
636  def->keyword->public=bool;
637  }
638 
639  return ok;
640 }
ptr_keyword hash_lookup(ptr_hash_table table, char *symbol)
HASH_LOOKUP.
Definition: hash_table.c:131
char * combined_name
Definition: def_struct.h:119
ptr_definition new_definition(ptr_keyword key)
new_definition
Definition: modules.c:220
ptr_definition definition
Definition: def_struct.h:122
ptr_hash_table symbol_table
Definition: def_struct.h:110
ptr_keyword keyword
Definition: def_struct.h:147
ptr_module current_module
Definition: modules.c:15
char * symbol
Definition: def_struct.h:118
ptr_definition update_symbol(ptr_module module, char *symbol)
update_symbol
Definition: modules.c:270
#define deref_ptr(P)
Definition: def_macro.h:100
#define TRUE
Standard boolean.
Definition: def_const.h:268
ptr_module module
Definition: def_struct.h:117
void warningline(char *format,...)
warningline
Definition: error.c:371
ptr_definition type
Definition: def_struct.h:181
ptr_definition new_definition ( ptr_keyword  key)

new_definition

Parameters
key- ptr_keyword key

NEW_DEFINITION(key) Create a definition for a key.

Definition at line 220 of file modules.c.

References wl_definition::already_loaded, wl_definition::always_check, wl_definition::children, wl_definition::code, wl_definition::date, wl_keyword::definition, wl_definition::evaluate_args, FALSE, first_definition, wl_definition::global_value, HEAP_ALLOC, wl_definition::init_value, wl_definition::keyword, wl_definition::next, NOT_CODED, NULL, wl_definition::op_data, wl_definition::parents, wl_definition::properties, wl_definition::protected, wl_definition::rule, TRUE, wl_definition::type_def, and undef_it.

221 {
222  ptr_definition result;
223 
224 
225  /* printf("*** New definition: %s\n",key->combined_name); */
226 
227  /* Create a new definition */
228  result=HEAP_ALLOC(struct wl_definition);
229 
230  /* RM: Feb 3 1993 */
231  result->next=first_definition; /* Linked list of all definitions */
232  first_definition=result;
233 
234  result->keyword=key;
235  result->rule=NULL;
236  result->properties=NULL;
237  result->date=0;
238  result->type_def=(def_type)undef_it;
239  result->always_check=TRUE;
240  result->protected=TRUE;
241  result->evaluate_args=TRUE;
242  result->already_loaded=FALSE;
243  result->children=NULL;
244  result->parents=NULL;
245  result->code=NOT_CODED;
246  result->op_data=NULL;
247  result->global_value=NULL; /* RM: Feb 8 1993 */
248  result->init_value=NULL; /* RM: Mar 23 1993 */
249  key->definition=result;
250 
251  return result;
252 }
char already_loaded
Definition: def_struct.h:157
#define undef_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1394
ptr_psi_term init_value
Definition: def_struct.h:160
struct wl_definition * def_type
Definition: def_struct.h:60
char evaluate_args
Definition: def_struct.h:156
ptr_definition first_definition
All definition are stores in a linked list starting at first_definition.
Definition: def_glob.h:13
#define NOT_CODED
For LIFE boolean calculation built-in.
Definition: def_const.h:294
ptr_definition definition
Definition: def_struct.h:122
def_type type_def
Definition: def_struct.h:153
ptr_keyword keyword
Definition: def_struct.h:147
#define NULL
Definition: def_const.h:533
char always_check
Definition: def_struct.h:154
ptr_definition next
Definition: def_struct.h:164
#define TRUE
Standard boolean.
Definition: def_const.h:268
ptr_pair_list rule
Definition: def_struct.h:148
ptr_psi_term global_value
Definition: def_struct.h:159
#define FALSE
Standard boolean.
Definition: def_const.h:275
ptr_int_list code
Definition: def_struct.h:150
ptr_triple_list properties
Definition: def_struct.h:149
ptr_int_list children
Definition: def_struct.h:152
#define HEAP_ALLOC(A)
Definition: def_macro.h:20
ptr_operator_data op_data
Definition: def_struct.h:158
ptr_int_list parents
Definition: def_struct.h:151
void open_module_one ( ptr_psi_term  t,
int *  onefailed 
)

open_module_one

Parameters
t= ptr_psi_term t
onefailed- int *onefailed

Definition at line 562 of file modules.c.

References wl_keyword::combined_name, wl_keyword::definition, Errorline(), FALSE, find_module(), hash_lookup(), HEAP_ALLOC, wl_int_list::next, wl_module::open_modules, wl_keyword::public, string_val(), wl_keyword::symbol, wl_module::symbol_table, TRUE, and wl_int_list::value_1.

563 {
564  ptr_module open_module;
565  ptr_int_list opens;
566  ptr_keyword key1,key2;
567  int i;
568  int found=FALSE;
569 
570  open_module=find_module(string_val(t));
571  if (open_module) {
572 
573  for (opens=current_module->open_modules;opens;opens=opens->next)
574  if (opens->value_1 == (GENERIC)open_module) {
575  /* warningline("module \"%s\" is already open\n",
576  open_module->module_name); */ /* RM: Jan 27 1993 */
577  found=TRUE;
578  }
579 
580  if (!found) {
581  opens=HEAP_ALLOC(struct wl_int_list);
582  opens->value_1=(GENERIC)open_module;
585 
586  /* Check for name conflicts */
587  /* RM: Feb 23 1993 */
588  for (i=0;i<open_module->symbol_table->size;i++)
589  if ((key1=open_module->symbol_table->data[i]) && key1->public) {
591  if (key2 && key1->definition!=key2->definition)
592  Errorline("symbol clash '%s' and '%s'\n",
593  key1->combined_name,
594  key2->combined_name);
595  }
596  }
597  }
598  else {
599  Errorline("module \"%s\" not found\n",string_val(t));
600  *onefailed=TRUE;
601  }
602 }
ptr_keyword hash_lookup(ptr_hash_table table, char *symbol)
HASH_LOOKUP.
Definition: hash_table.c:131
char * combined_name
Definition: def_struct.h:119
ptr_definition definition
Definition: def_struct.h:122
ptr_hash_table symbol_table
Definition: def_struct.h:110
ptr_module current_module
Definition: modules.c:15
char * symbol
Definition: def_struct.h:118
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
#define TRUE
Standard boolean.
Definition: def_const.h:268
#define FALSE
Standard boolean.
Definition: def_const.h:275
ptr_int_list open_modules
Definition: def_struct.h:108
char * string_val(ptr_psi_term term)
string_val
Definition: modules.c:169
ptr_module find_module(char *module)
find_module
Definition: modules.c:54
GENERIC value_1
Definition: def_struct.h:85
#define HEAP_ALLOC(A)
Definition: def_macro.h:20
ptr_int_list next
Definition: def_struct.h:86
void open_module_tree ( ptr_node  n,
int *  onefailed 
)

open_module_tree

Parameters
n- ptr_node n
onefailed- int *onefailed

Definition at line 542 of file modules.c.

References wl_node::data, wl_node::left, open_module_one(), and wl_node::right.

543 {
544  if (n) {
545  ptr_psi_term t;
546  open_module_tree(n->left,onefailed);
547 
548  t=(ptr_psi_term)n->data;
549  open_module_one(t,onefailed);
550 
551  open_module_tree(n->right,onefailed);
552  }
553 }
void open_module_tree(ptr_node n, int *onefailed)
open_module_tree
Definition: modules.c:542
struct wl_psi_term * ptr_psi_term
quotedStackCopy
Definition: def_struct.h:62
GENERIC data
Definition: def_struct.h:201
void open_module_one(ptr_psi_term t, int *onefailed)
open_module_one
Definition: modules.c:562
ptr_node left
Definition: def_struct.h:199
ptr_node right
Definition: def_struct.h:200
void pretty_quote_symbol ( ptr_keyword  k)

pretty_quote_symbol

Parameters
k- ptr_keyword k

PRETTY_QUOTE_SYMBOL(k) Prints the string to be used to display keyword K, with quotes if required.

Definition at line 470 of file modules.c.

References wl_keyword::definition, display_modules, wl_definition::keyword, wl_keyword::module, wl_module::module_name, prettyf(), prettyf_quote(), and wl_keyword::symbol.

471 {
472  k=k->definition->keyword;
473  if(display_modules) {
475  prettyf("#");
476  }
477  prettyf_quote(k->symbol);
478 }
long display_modules
Definition: modules.c:25
ptr_definition definition
Definition: def_struct.h:122
ptr_keyword keyword
Definition: def_struct.h:147
char * symbol
Definition: def_struct.h:118
char * module_name
Definition: def_struct.h:106
ptr_module module
Definition: def_struct.h:117
void prettyf(char *s)
prettyf
Definition: print.c:496
void prettyf_quote(char *s)
prettyf_quote
Definition: print.c:529
void pretty_symbol ( ptr_keyword  k)

pretty_symbol

Parameters
k- ptr_keyword k

PRETTY_SYMBOL(k) Prints the string to be used to display keyword K.

Definition at line 452 of file modules.c.

References wl_keyword::definition, display_modules, wl_definition::keyword, wl_keyword::module, wl_module::module_name, prettyf(), and wl_keyword::symbol.

453 {
454  k=k->definition->keyword;
455  if(display_modules) {
457  prettyf("#");
458  }
459  prettyf(k->symbol);
460 }
long display_modules
Definition: modules.c:25
ptr_definition definition
Definition: def_struct.h:122
ptr_keyword keyword
Definition: def_struct.h:147
char * symbol
Definition: def_struct.h:118
char * module_name
Definition: def_struct.h:106
ptr_module module
Definition: def_struct.h:117
void prettyf(char *s)
prettyf
Definition: print.c:496
char* print_symbol ( ptr_keyword  k)

print_symbol

OBSOLETE ptr_psi_term get_function_value(module,symbol)

ptr_module module; char *symbol;

{ ptr_node n; ptr_definition def; ptr_psi_term result=NULL; ptr_pair_list rule;

n=find(STRCMP,make_module_token(module,symbol),symbol_table); if(n) def=(ptr_definition)n->data; if(def && def->type==function) { rule=def->rule; while (rule && (!rule->aaaa_1 || !rule->bbbb_1)) rule=rule->next; if(rule) { result=(ptr_psi_term)rule->bbbb_1; deref_ptr(result); } } }

if(!result) Errorline("error in definition of '%s'\n",module_buffer);

return result; }

Parameters
k- ptr_keyword k

PRINT_SYMBOL(k) Returns the string to be used to display keyword K.

Definition at line 435 of file modules.c.

References wl_keyword::combined_name, wl_keyword::definition, display_modules, wl_definition::keyword, and wl_keyword::symbol.

436 {
437  k=k->definition->keyword;
438  if(display_modules)
439  return k->combined_name;
440  else
441  return k->symbol;
442 }
long display_modules
Definition: modules.c:25
char * combined_name
Definition: def_struct.h:119
ptr_definition definition
Definition: def_struct.h:122
ptr_keyword keyword
Definition: def_struct.h:147
char * symbol
Definition: def_struct.h:118
void rec_replace ( ptr_definition  old,
ptr_definition  new,
ptr_psi_term  term 
)

rec_replace

Parameters
old- ptr_definition old
new- ptr_definition new
term- ptr_psi_term term

Definition at line 865 of file modules.c.

References wl_psi_term::attr_list, def_ptr, deref_ptr, insert_translation(), int_ptr, NULL, push_ptr_value(), replace_attr(), translate(), wl_psi_term::type, and wl_psi_term::value_3.

866 {
867  ptr_psi_term done;
868  long *info; // some trouble w this - don't see
869  ptr_node old_attr;
870 
871  deref_ptr(term);
872  done=translate(term,&info);
873  if(!done) {
874  insert_translation(term,term,0);
875 
876  if(term->type==old && !term->value_3) {
877  push_ptr_value(def_ptr,(GENERIC *)&(term->type));
878  term->type=new;
879  }
880  old_attr=term->attr_list;
881  if(old_attr) {
883  term->attr_list=NULL;
884  replace_attr(old_attr,term,old,new);
885  }
886  }
887 }
void push_ptr_value(type_ptr t, GENERIC *p)
push_ptr_value
Definition: login.c:383
ptr_psi_term translate(ptr_psi_term a, long **infoptr)
translate
Definition: copy.c:108
#define def_ptr
values of type_ptr
Definition: def_const.h:404
void replace_attr(ptr_node, ptr_psi_term, ptr_definition, ptr_definition)
replace_attr
Definition: modules.c:898
void insert_translation(ptr_psi_term a, ptr_psi_term b, long info)
insert_translation
Definition: copy.c:67
#define NULL
Definition: def_const.h:533
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
#define deref_ptr(P)
Definition: def_macro.h:100
GENERIC value_3
Definition: def_struct.h:186
ptr_definition type
Definition: def_struct.h:181
ptr_node attr_list
Definition: def_struct.h:187
#define int_ptr
values of type_ptr
Definition: def_const.h:397
void replace ( ptr_definition  old,
ptr_definition  new,
ptr_psi_term  term 
)

replace

Parameters
old- ptr_definition old
new- ptr_definition new
term- ptr_psi_term term)

REPLACE(old,new,term) Replace all occurrences of type OLD with NEW in TERM.

Definition at line 851 of file modules.c.

References clear_copy(), and rec_replace().

852 {
853  clear_copy();
854  rec_replace(old,new,term);
855 }
void clear_copy()
clear_copy
Definition: copy.c:53
void rec_replace(ptr_definition, ptr_definition, ptr_psi_term)
rec_replace
Definition: modules.c:865
void replace_attr ( ptr_node  old_attr,
ptr_psi_term  term,
ptr_definition  old,
ptr_definition  new 
)

replace_attr

Parameters
old_attr- ptr_node old_attr
term- ptr_psi_term term
old- ptr_definition old
new- ptr_definition new

Definition at line 898 of file modules.c.

References wl_psi_term::attr_list, wl_keyword::combined_name, wl_node::data, FEATCMP, wl_node::key, wl_definition::keyword, wl_node::left, wl_keyword::private_feature, rec_replace(), wl_node::right, stack_insert(), and wl_keyword::symbol.

899 {
900  ptr_psi_term value;
901  char *oldlabel; /* RM: Mar 12 1993 */
902  char *newlabel;
903 
904  if(old_attr->left)
905  replace_attr(old_attr->left,term,old,new);
906 
907  value=(ptr_psi_term)old_attr->data;
908  rec_replace(old,new,value);
909 
910  if(old->keyword->private_feature) /* RM: Mar 12 1993 */
911  oldlabel=old->keyword->combined_name;
912  else
913  oldlabel=old->keyword->symbol;
914 
915  if(new->keyword->private_feature) /* RM: Mar 12 1993 */
916  newlabel=new->keyword->combined_name;
917  else
918  newlabel=new->keyword->symbol;
919 
920  if(!strcmp(old_attr->key,oldlabel))
921  (void)stack_insert(FEATCMP,newlabel,&(term->attr_list),(GENERIC)value);
922  else
923  (void)stack_insert(FEATCMP,old_attr->key,&(term->attr_list),(GENERIC)value);
924 
925  if(old_attr->right)
926  replace_attr(old_attr->right,term,old,new);
927 }
#define FEATCMP
indicates to use featcmp for comparison (in trees.c)
Definition: def_const.h:979
char * combined_name
Definition: def_struct.h:119
void replace_attr(ptr_node, ptr_psi_term, ptr_definition, ptr_definition)
replace_attr
Definition: modules.c:898
ptr_keyword keyword
Definition: def_struct.h:147
struct wl_psi_term * ptr_psi_term
quotedStackCopy
Definition: def_struct.h:62
GENERIC data
Definition: def_struct.h:201
char * symbol
Definition: def_struct.h:118
ptr_node left
Definition: def_struct.h:199
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
ptr_node stack_insert(long comp, char *keystr, ptr_node *tree, GENERIC info)
stack_insert
Definition: trees.c:337
char * key
Definition: def_struct.h:198
void rec_replace(ptr_definition, ptr_definition, ptr_psi_term)
rec_replace
Definition: modules.c:865
int private_feature
Definition: def_struct.h:121
ptr_node attr_list
Definition: def_struct.h:187
ptr_node right
Definition: def_struct.h:200
ptr_module set_current_module ( ptr_module  module)

set_current_module

Parameters
module- ptr_module module

SET_CURRENT_MODULE(module) Set the current module to a given string.

Definition at line 100 of file modules.c.

References current_module.

101 {
102  current_module=module;
103  /* printf("*** Current module: '%s'\n",current_module->module_name); */
104  return current_module;
105 }
ptr_module current_module
Definition: modules.c:15
char* string_val ( ptr_psi_term  term)

string_val

Parameters
term- ptr_psi_term term

STRING_VAL(term) Return a string defined by a term, that is: if term is a string, return the value, otherwise return the symbol for that term.

Definition at line 169 of file modules.c.

References deref_ptr, wl_definition::keyword, quoted_string, wl_keyword::symbol, wl_psi_term::type, and wl_psi_term::value_3.

170 {
171  deref_ptr(term);
172  if(term->value_3 && term->type==quoted_string)
173  return (char *)term->value_3;
174  else
175  return term->type->keyword->symbol;
176 }
ptr_keyword keyword
Definition: def_struct.h:147
char * symbol
Definition: def_struct.h:118
#define deref_ptr(P)
Definition: def_macro.h:100
GENERIC value_3
Definition: def_struct.h:186
ptr_definition type
Definition: def_struct.h:181
ptr_definition quoted_string
symbol in bi module
Definition: def_glob.h:368
char* strip_module_name ( char *  str)

strip_module_name

Parameters
str- char *str

STRIP_MODULE_NAME(symbol) Return the sub-string of symbol without the module prefix.

Definition at line 144 of file modules.c.

References legal_in_name().

145 {
146  char *s=str;
147 
148  while(legal_in_name(*s))
149  s++;
150  if(s!=str && *s=='#' /* && *(s+1)!=0 */) {
151  s++;
152  /* printf("Stripped module from '%s' yielding '%s'\n",str,s); */
153  return s;
154  }
155  else
156  return str;
157 }
long legal_in_name(long c)
legal_in_name
Definition: token.c:980
void traverse_tree ( ptr_node  n,
int  flag 
)

traverse_tree

Parameters
n- ptr_node n
flag- int flag

Do for all arguments, for the built-ins c_public, c_private, and c_private_feature.

Definition at line 656 of file modules.c.

References wl_node::data, deref_ptr, FALSE, wl_node::left, MAKE_FEATURE_PRIVATE, make_feature_private(), MAKE_PRIVATE, make_public(), MAKE_PUBLIC, wl_node::right, and TRUE.

657 {
658  if (n) {
659  ptr_psi_term t;
660  traverse_tree(n->left,flag);
661 
662  t=(ptr_psi_term)n->data;
663  deref_ptr(t);
664  switch (flag) {
665  case MAKE_PUBLIC:
666  (void)make_public(t,TRUE);
667  break;
668  case MAKE_PRIVATE:
669  (void)make_public(t,FALSE);
670  break;
672  (void)make_feature_private(t);
673  break;
674  }
675  traverse_tree(n->right,flag);
676  }
677 }
void traverse_tree(ptr_node n, int flag)
traverse_tree
Definition: modules.c:656
struct wl_psi_term * ptr_psi_term
quotedStackCopy
Definition: def_struct.h:62
GENERIC data
Definition: def_struct.h:201
ptr_node left
Definition: def_struct.h:199
#define MAKE_PRIVATE
Definition: modules.c:644
#define deref_ptr(P)
Definition: def_macro.h:100
#define TRUE
Standard boolean.
Definition: def_const.h:268
#define FALSE
Standard boolean.
Definition: def_const.h:275
int make_feature_private(ptr_psi_term term)
make_feature_private
Definition: modules.c:1256
long make_public(ptr_psi_term term, long bool)
make_public
Definition: modules.c:613
#define MAKE_FEATURE_PRIVATE
Definition: modules.c:645
#define MAKE_PUBLIC
Definition: modules.c:643
ptr_node right
Definition: def_struct.h:200
ptr_definition update_feature ( ptr_module  module,
char *  feature 
)

update_feature

Parameters
module- ptr_module module
feature- char *feature

UPDATE_FEATURE(module,feature) Look up a FEATURE. May return NULL if the FEATURE is not visible from MODULE.

Definition at line 1331 of file modules.c.

References current_module, wl_keyword::definition, extract_module_from_name(), hash_lookup(), NULL, wl_keyword::private_feature, wl_module::symbol_table, and update_symbol().

1332 {
1333  ptr_keyword key;
1334  ptr_module explicit;
1335 
1336  /* Check if the feature already contains a module name */
1337 
1338  if(!module)
1339  module=current_module;
1340 
1341  explicit=extract_module_from_name(feature);
1342  if(explicit)
1343  if(explicit!=module)
1344  return NULL; /* Feature isn't visible */
1345  else
1346  return update_symbol(NULL,feature);
1347 
1348  /* Now we have a simple feature to look up */
1349  key=hash_lookup(module->symbol_table,feature);
1350  if(key && key->private_feature)
1351  return key->definition;
1352  else
1353  return update_symbol(module,feature);
1354 }
ptr_keyword hash_lookup(ptr_hash_table table, char *symbol)
HASH_LOOKUP.
Definition: hash_table.c:131
ptr_definition definition
Definition: def_struct.h:122
ptr_hash_table symbol_table
Definition: def_struct.h:110
#define NULL
Definition: def_const.h:533
ptr_module current_module
Definition: modules.c:15
ptr_definition update_symbol(ptr_module module, char *symbol)
update_symbol
Definition: modules.c:270
int private_feature
Definition: def_struct.h:121
ptr_module extract_module_from_name(char *str)
extract_module_from_name
Definition: modules.c:116
ptr_definition update_symbol ( ptr_module  module,
char *  symbol 
)

update_symbol

Parameters
module- ptr_module module
symbol- char *symbol

UPDATE_SYMBOL(m,s) S is a string of characters encountered during parsing, M is the module it belongs too.

if M is NULL then extract the module name from S. If that fails then use the current module.

Then, retrieve the keyword for 'module::symbol'. Then find the correct definition by scanning the opened modules.

Definition at line 270 of file modules.c.

References wl_keyword::combined_name, current_module, wl_keyword::definition, error_psi_term, Errorline(), extract_module_from_name(), FALSE, hash_insert(), hash_lookup(), HEAP_ALLOC, heap_copy_string(), make_module_token(), wl_keyword::module, wl_module::module_name, new_definition(), wl_int_list::next, NULL, wl_module::open_modules, wl_keyword::private_feature, wl_keyword::public, strip_module_name(), wl_keyword::symbol, wl_module::symbol_table, wl_psi_term::type, wl_int_list::value_1, and warningline().

271 {
272  ptr_keyword key;
273  ptr_definition result=NULL;
274  ptr_int_list opens;
275  ptr_module opened;
276  ptr_keyword openkey;
277  ptr_keyword tempkey;
278 
279  /* First clean up the arguments and find out which module to use */
280 
281  if(!module) {
282  module=extract_module_from_name(symbol);
283  if(!module)
284  module=current_module;
285  symbol=strip_module_name(symbol);
286  }
287 
288  /* printf("looking up %s#%s\n",module->module_name,symbol); */
289 
290  /* Now look up 'module#symbol' in the symbol table */
291  key=hash_lookup(module->symbol_table,symbol);
292 
293  if(key)
294  if(key->public || module==current_module)
295  result=key->definition;
296  else {
297  Errorline("qualified call to private symbol '%s'\n",
298  key->combined_name);
299 
300  result=error_psi_term->type;
301  }
302  else
303  if(module!=current_module) {
304  Errorline("qualified call to undefined symbol '%s#%s'\n",
305  module->module_name,symbol);
306  result=error_psi_term->type;
307  }
308  else
309  {
310  /* Add 'module#symbol' to the symbol table */
311  key=HEAP_ALLOC(struct wl_keyword);
312  key->module=module;
313  key->symbol=(char *)heap_copy_string(symbol);
314  key->combined_name=heap_copy_string(make_module_token(module,symbol));
315  key->public=FALSE;
316  key->private_feature=FALSE; /* RM: Mar 11 1993 */
317  key->definition=NULL;
318 
319  hash_insert(module->symbol_table,key->symbol,key);
320 
321 
322  /* Search the open modules of 'module' for 'symbol' */
323  opens=module->open_modules;
324  openkey=NULL;
325  while(opens) {
326  opened=(ptr_module)(opens->value_1);
327  if(opened!=module) {
328 
329  tempkey=hash_lookup(opened->symbol_table,symbol);
330 
331  if(tempkey)
332  if(openkey && openkey->public && tempkey->public) {
333  if(openkey->definition==tempkey->definition) {
334  warningline("benign module name clash: %s and %s\n",
335  openkey->combined_name,
336  tempkey->combined_name);
337  }
338  else {
339  Errorline("serious module name clash: \"%s\" and \"%s\"\n",
340  openkey->combined_name,
341  tempkey->combined_name);
342 
343  result=error_psi_term->type;
344  }
345  }
346  else
347  if(!openkey || !openkey->public)
348  openkey=tempkey;
349  }
350 
351  opens=opens->next;
352  }
353 
354  if(!result) { /* RM: Feb 1 1993 */
355 
356  if(openkey && openkey->public) {
357  /* Found the symbol in an open module */
358 
359  if(!openkey->public)
360  warningline("implicit reference to non-public symbol: %s\n",
361  openkey->combined_name);
362 
363  result=openkey->definition;
364  key->definition=result;
365 
366  /*
367  printf("*** Aliasing %s#%s to %s#%s\n",
368  key->module->module_name,
369  key->symbol,
370  openkey->module->module_name,
371  openkey->symbol);
372  */
373 
374  }
375  else { /* Didn't find it */
376  result=new_definition(key);
377  }
378  }
379  }
380 
381  return result;
382 }
ptr_keyword hash_lookup(ptr_hash_table table, char *symbol)
HASH_LOOKUP.
Definition: hash_table.c:131
char * combined_name
Definition: def_struct.h:119
ptr_definition new_definition(ptr_keyword key)
new_definition
Definition: modules.c:220
ptr_definition definition
Definition: def_struct.h:122
ptr_hash_table symbol_table
Definition: def_struct.h:110
#define NULL
Definition: def_const.h:533
ptr_module current_module
Definition: modules.c:15
char * symbol
Definition: def_struct.h:118
char * strip_module_name(char *str)
strip_module_name
Definition: modules.c:144
struct wl_module * ptr_module
Definition: def_struct.h:114
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
char * heap_copy_string(char *s)
heap_copy_string
Definition: trees.c:172
void hash_insert(ptr_hash_table table, char *symbol, ptr_keyword keyword)
HASH_INSERT.
Definition: hash_table.c:151
#define FALSE
Standard boolean.
Definition: def_const.h:275
char * module_name
Definition: def_struct.h:106
ptr_int_list open_modules
Definition: def_struct.h:108
ptr_module module
Definition: def_struct.h:117
ptr_psi_term error_psi_term
symbol in bi module
Definition: def_glob.h:118
int private_feature
Definition: def_struct.h:121
ptr_module extract_module_from_name(char *str)
extract_module_from_name
Definition: modules.c:116
void warningline(char *format,...)
warningline
Definition: error.c:371
ptr_definition type
Definition: def_struct.h:181
GENERIC value_1
Definition: def_struct.h:85
#define HEAP_ALLOC(A)
Definition: def_macro.h:20
char * make_module_token(ptr_module module, char *str)
make_module_token
Definition: modules.c:191
ptr_int_list next
Definition: def_struct.h:86

Variable Documentation

ptr_module bi_module =NULL

Definition at line 17 of file modules.c.

ptr_module current_module =NULL

Definition at line 15 of file modules.c.

long display_modules =TRUE

Definition at line 25 of file modules.c.

ptr_node module_table =NULL

Definition at line 14 of file modules.c.

ptr_module no_module =NULL

Definition at line 16 of file modules.c.

ptr_module syntax_module =NULL

Definition at line 18 of file modules.c.

ptr_module sys_module =NULL

Definition at line 19 of file modules.c.

ptr_module user_module =NULL

Definition at line 22 of file modules.c.

ptr_module x_module = NULL

Definition at line 23 of file modules.c.