PIPS
genLisp.c File Reference
#include <stdio.h>
#include "newgen_include.h"
+ Include dependency graph for genLisp.c:

Go to the source code of this file.

Macros

#define TYPE(bp)   (bp-Domains-Number_imports-Current_start)
 
#define NEWGEN_IMPL   "#+akcl lisp:vector #-akcl (lisp:vector lisp:t)"
 
#define OR_VALUE_INDEX   3
 Unused in Lisp. More...
 

Functions

char * init_member (dp)
 INIT_MEMBER returns the initialization code for a value in the domain DP. More...
 
void gen_external (bp)
 GEN_EXTERNAL generates the type code for external type BP. More...
 
int gen_external_member (dp, offset)
 GEN_EXTERNAL_MEMBER generates the manipulation functions for a possible external member (either and or or) in domain DP and OFFSET. More...
 
static void gen_prelude (bp)
 GEN_PRELUDE generates prelude declarations for potentially tabulated domain BP. More...
 
static void gen_postlude (bp)
 GEN_POSTLUDE generates tabulation table updates. More...
 
static generate_type_member (bp)
 GEN_TYPE generates the type member for potentially tabulated BP domain. More...
 
void gen_and (bp)
 GEN_AND generates the manipulation functions for an AND type BP. More...
 
void gen_or (bp)
 GEN_OR generates the manipulation function for an OR_OP type BP. More...
 
void gen_list (bp)
 GEN_LIST defines the manipulation functions for a list type BP. More...
 
void gen_array (bp)
 GEN_ARRAY defines the manipulation functions for an array type BP. More...
 
void gen_set (bp)
 GEN_SET defines the manipulation functions for a set type BP. More...
 
void gen_domain (bp)
 GEN_DOMAIN generates the manipulation functions for a type BP. More...
 
void gencode (file)
 GENCODE generates the code necessary to manipulate every non-inlinable type in the Domains table. More...
 

Variables

static char start [1024]
 The name of the variable from which to start counting domain numbers. More...
 
static char * package
 The package name in which functions will be defined. More...
 
struct gen_bindingTabulated_bp
 
int Read_spec_mode
 extern int Current_first ; More...
 
static int or_counter
 

Macro Definition Documentation

◆ NEWGEN_IMPL

#define NEWGEN_IMPL   "#+akcl lisp:vector #-akcl (lisp:vector lisp:t)"

Definition at line 51 of file genLisp.c.

◆ OR_VALUE_INDEX

#define OR_VALUE_INDEX   3

Unused in Lisp.

Definition at line 65 of file genLisp.c.

◆ TYPE

#define TYPE (   bp)    (bp-Domains-Number_imports-Current_start)

Definition at line 50 of file genLisp.c.

Function Documentation

◆ gen_and()

void gen_and ( bp  )

GEN_AND generates the manipulation functions for an AND type BP.

Definition at line 211 of file genLisp.c.

213 {
214  union domain *dom = bp->domain ;
215  struct domainlist *dlp = dom->co.components ;
216  int size ;
217 
218  gen_prelude( bp ) ;
219  printf( "(lisp:defstruct (%s (:type %s))\n", bp->name, NEWGEN_IMPL ) ;
220  generate_type_member( bp ) ;
221 
222  for( ; dlp != NULL ; dlp=dlp->cdr ) {
223  union domain *dp = dlp->domain ;
224 
225  printf( " (%s %s)\n", dp->ba.constructor, init_member( dp )) ;
226  }
227  printf( ")\n" ) ;
228 
229  for( size=2, dlp=dom->co.components; dlp != NULL ; dlp=dlp->cdr, size++ ) {
230  gen_external_member( dlp->domain, size ) ;
231  }
232  gen_postlude( bp ) ;
233 }
int gen_external_member(dp, offset)
GEN_EXTERNAL_MEMBER generates the manipulation functions for a possible external member (either and o...
Definition: genLisp.c:130
static void gen_prelude(bp)
GEN_PRELUDE generates prelude declarations for potentially tabulated domain BP.
Definition: genLisp.c:155
static generate_type_member(bp)
GEN_TYPE generates the type member for potentially tabulated BP domain.
Definition: genLisp.c:197
static void gen_postlude(bp)
GEN_POSTLUDE generates tabulation table updates.
Definition: genLisp.c:173
char * init_member(dp)
INIT_MEMBER returns the initialization code for a value in the domain DP.
Definition: genLisp.c:72
#define NEWGEN_IMPL
Definition: genLisp.c:51
int printf()
A DOMAIN union describes the structure of a user type.
char * constructor
struct domainlist * components
struct domain::@7 co
struct domain::@3 ba

References domain::ba, domain::co, domain::components, domain::constructor, gen_binding::domain, gen_external_member(), gen_postlude(), gen_prelude(), generate_type_member(), init_member(), gen_binding::name, NEWGEN_IMPL, and printf().

Referenced by gen_domain().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gen_array()

void gen_array ( bp  )

GEN_ARRAY defines the manipulation functions for an array type BP.

Definition at line 305 of file genLisp.c.

307 {
308  union domain *dom = bp->domain ;
309 
310  gen_prelude( bp ) ;
311  printf( "(lisp:defstruct (%s (:type %s))\n", bp->name, NEWGEN_IMPL ) ;
312  generate_type_member( bp ) ;
313  printf( " (%s %))\n",
314  dom->ar.constructor, init_member( dom->ar.element->domain )) ;
315  gen_postlude( bp ) ;
316 }
union domain * domain
struct gen_binding * element
struct domain::@6 ar

References domain::ar, domain::constructor, gen_binding::domain, domain::element, gen_postlude(), gen_prelude(), generate_type_member(), init_member(), gen_binding::name, NEWGEN_IMPL, and printf().

Referenced by gen_domain().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gen_domain()

void gen_domain ( bp  )

GEN_DOMAIN generates the manipulation functions for a type BP.

This is manily a dispatching function.

Definition at line 338 of file genLisp.c.

340 {
341  union domain *dp = bp->domain ;
342 
343  if( !IS_INLINABLE( bp ) && !IS_EXTERNAL( bp )) {
344  printf( "(lisp:defmacro write-%s (fd obj) `(gen-write ,fd ,obj))\n",
345  bp->name, bp->name ) ;
346  printf("(lisp:defmacro read-%s (lisp:&optional (fd *standard-input*))\n",
347  bp->name ) ;
348  printf(" `(gen-read ,fd))\n");
349  }
350  switch( dp->ba.type ) {
351  case CONSTRUCTED_DT:
352  if( dp->co.op == AND_OP ) gen_and( bp ) ;
353  else if( dp->co.op == OR_OP ) gen_or( bp ) ;
354  else fatal( "gen_domain: Unknown constructed %s\n", i2a( dp->co.op )) ;
355  break ;
356  case LIST_DT:
357  gen_list( bp ) ;
358  break ;
359  case ARRAY_DT:
360  gen_array( bp ) ;
361  break ;
362  case SET_DT:
363  gen_set( bp ) ;
364  break ;
365  case EXTERNAL_DT:
366  gen_external( bp ) ;
367  break ;
368  default:
369  fatal( "gen_domain: Unknown type %s\n", i2a( dp->ba.type )) ;
370  }
371 }
void gen_external(bp)
GEN_EXTERNAL generates the type code for external type BP.
Definition: genLisp.c:117
void gen_list(bp)
GEN_LIST defines the manipulation functions for a list type BP.
Definition: genLisp.c:292
void gen_or(bp)
GEN_OR generates the manipulation function for an OR_OP type BP.
Definition: genLisp.c:240
void gen_and(bp)
GEN_AND generates the manipulation functions for an AND type BP.
Definition: genLisp.c:211
void gen_array(bp)
GEN_ARRAY defines the manipulation functions for an array type BP.
Definition: genLisp.c:305
void gen_set(bp)
GEN_SET defines the manipulation functions for a set type BP.
Definition: genLisp.c:321
char * i2a(int)
I2A (Integer TO Ascii) yields a string for a given Integer.
Definition: string.c:121
@ OR_OP
@ AND_OP
#define IS_EXTERNAL(bp)
#define IS_INLINABLE(bp)
Different kinds of BINDING structure pointers.
@ EXTERNAL_DT
@ SET_DT
@ ARRAY_DT
@ LIST_DT
@ CONSTRUCTED_DT
void fatal(char *,...)
enum domain_operator op
int type
EXTERNAL.

References AND_OP, ARRAY_DT, domain::ba, domain::co, CONSTRUCTED_DT, gen_binding::domain, EXTERNAL_DT, fatal(), gen_and(), gen_array(), gen_external(), gen_list(), gen_or(), gen_set(), i2a(), IS_EXTERNAL, IS_INLINABLE, LIST_DT, gen_binding::name, domain::op, OR_OP, printf(), SET_DT, and domain::type.

Referenced by gencode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gen_external()

void gen_external ( bp  )

GEN_EXTERNAL generates the type code for external type BP.

Definition at line 117 of file genLisp.c.

119 {
120  printf( "(lisp:defvar %s (lisp:+ %s %d))\n", bp->name, start, TYPE( bp )) ;
121 }
static char start[1024]
The name of the variable from which to start counting domain numbers.
Definition: genLisp.c:55
#define TYPE(bp)
Definition: genLisp.c:50

References gen_binding::name, printf(), start, and TYPE.

Referenced by gen_domain().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gen_external_member()

int gen_external_member ( dp  ,
offset   
)

GEN_EXTERNAL_MEMBER generates the manipulation functions for a possible external member (either and or or) in domain DP and OFFSET.

It returns whether some code has been generated or not.

See INIT_MEMBER to understand mutation code.

Definition at line 130 of file genLisp.c.

133 {
134  if( dp->ba.type == BASIS_DT ) {
135  struct gen_binding *bp = dp->ba.constructand ;
136 
137  if( !IS_INLINABLE( bp ) && IS_EXTERNAL( bp )) {
138  printf( "(lisp:defun %s-%s (and)\n", bp->name, dp->ba.constructor ) ;
139  printf( " (lisp:caddr (lisp:svref and %d)))\n", offset ) ;
140 
141  printf( "(lisp:defsetf %s-%s (and) (new-and)\n",
142  bp->name, dp->ba.constructor ) ;
143  printf( " `(lisp:setf (lisp:caddr (lisp:svref ,and %d)) ", offset ) ;
144  printf( ",new-and))\n" ) ;
145  return( 1 ) ;
146  }
147  }
148  return( 0 ) ;
149 }
static Value offset
Definition: translation.c:283
@ BASIS_DT

References domain::ba, BASIS_DT, domain::constructand, domain::constructor, IS_EXTERNAL, IS_INLINABLE, gen_binding::name, offset, printf(), and domain::type.

Referenced by gen_and(), and gen_or().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gen_list()

void gen_list ( bp  )

GEN_LIST defines the manipulation functions for a list type BP.

Definition at line 292 of file genLisp.c.

294 {
295  gen_prelude( bp ) ;
296  printf( "(lisp:defstruct (%s (:type %s))\n", bp->name, NEWGEN_IMPL ) ;
297  generate_type_member( bp ) ;
298  printf( " (%s '()))\n", bp->domain->li.constructor ) ;
299  gen_postlude( bp ) ;
300 }

References domain::constructor, gen_binding::domain, gen_postlude(), gen_prelude(), generate_type_member(), domain::li, gen_binding::name, NEWGEN_IMPL, and printf().

Referenced by gen_domain().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gen_or()

void gen_or ( bp  )

GEN_OR generates the manipulation function for an OR_OP type BP.

Note that for a UNIT_TYPE_NAME, no access function is defined since the value is meaningless.

Definition at line 240 of file genLisp.c.

242 {
243  char *name = bp->name ;
244  union domain *dom = bp->domain ;
245  struct domainlist *dlp ;
246  char *or_impl = (IS_TABULATED( bp )) ? "tabular-or" : "or" ;
247 
248  gen_prelude( bp ) ;
249  printf( "(lisp:defun make-%s ", name ) ;
250  printf( "(tag lisp:&optional (val :unit))\n" );
251  printf( " (lisp:let ((node (newgen::make-%s)))\n", or_impl) ;
252  printf( " (lisp:setf (newgen::%s-type node) `(:newgen ,(lisp:+ %s %d)))\n",
253  or_impl, start, TYPE( bp ) ) ;
254 
255  if( IS_TABULATED( bp )) {
256  printf( " (lisp:setf (newgen::%s-tabular node) ", or_impl ) ;
257  printf( "(newgen::find-free-tabulated (lisp:+ %s %d)))\n",
258  start, TYPE( bp )) ;
259  }
260  printf( " (lisp:setf (newgen::%s-tag node) tag)\n", or_impl ) ;
261  printf( " (lisp:setf (newgen::%s-val node) val)\n", or_impl ) ;
262  printf( " node))\n" ) ;
263  printf( "(lisp:defmacro %s-tag(node) `(newgen::%s-tag ,node))\n",
264  name, or_impl ) ;
265 
266  for( dlp=dom->co.components ; dlp != NULL ; dlp=dlp->cdr, or_counter++ ){
267  union domain *dp = dlp->domain ;
268 
269  printf( "(lisp:defconstant is-%s-%s %d)\n",
270  name, dp->ba.constructor, or_counter ) ;
271  printf( "(lisp:setf newgen::*tag-names* " ) ;
272  printf( "(lisp:acons %d 'is-%s-%s newgen::*tag-names*))\n",
273  or_counter, name, dp->ba.constructor ) ;
274  printf( "(lisp:defmacro %s-%s-p (or) ", name, dp->ba.constructor ) ;
275  printf( "`(lisp:= (%s-tag ,or) is-%s-%s))\n",
276  name, name, dp->ba.constructor ) ;
277 
278  if( dp->ba.type == BASIS &&
279  strcmp( dp->ba.constructand->name, UNIT_TYPE_NAME ) == 0 ||
281  continue ;
282 
283  printf( "(lisp:defmacro %s-%s (or) `(newgen::%s-val ,or))\n",
284  name, dp->ba.constructor, or_impl ) ;
285  }
286  gen_postlude( bp ) ;
287 }
#define OR_VALUE_INDEX
Unused in Lisp.
Definition: genLisp.c:65
static int or_counter
Definition: genLisp.c:67
#define IS_TABULATED(bp)
#define UNIT_TYPE_NAME
The UNIT_TYPE_NAME is the used to type expressions which only perform side-effects.
struct gen_binding * constructand

References domain::ba, domain::co, domain::components, domain::constructand, domain::constructor, gen_binding::domain, gen_external_member(), gen_postlude(), gen_prelude(), IS_TABULATED, gen_binding::name, or_counter, OR_VALUE_INDEX, printf(), start, TYPE, domain::type, and UNIT_TYPE_NAME.

Referenced by gen_domain().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gen_postlude()

static void gen_postlude ( bp  )
static

GEN_POSTLUDE generates tabulation table updates.

Definition at line 173 of file genLisp.c.

175 {
176  if( IS_TABULATED( bp )) {
177  printf( "(lisp:defvar old-make-%s)\n", bp->name ) ;
178  printf( "(lisp:setf old-make-%s (lisp:symbol-function 'make-%s))\n",
179  bp->name, bp->name ) ;
180  printf( "(lisp:fmakunbound 'make-%s)\n", bp->name) ;
181  printf( "(lisp:setf (lisp:symbol-function 'make-%s)\n", bp->name ) ;
182  printf( " #'(lisp:lambda (lisp:&rest args)\n", bp->name ) ;
183  printf( " (lisp:let ((node (lisp:apply old-make-%s args)))\n", bp->name ) ;
184  printf( " (newgen::enter-tabulated-def\n" ) ;
185  printf( " (lisp:aref newgen::*gen-tabulated-index* %s-domain)\n",
186  bp->name ) ;
187  printf( " %s-domain\n", bp->name ) ;
188  printf( " (lisp:aref node %d)\n", HASH_OFFSET ) ;
189  printf( " node\n" ) ;
190  printf( " :allow-ref-p lisp:nil)\n" ) ;
191  printf( " node)))\n" ) ;
192  }
193 }
#define HASH_OFFSET
For tabulated objects, the offset HASH_OFFSET of the hashed subdomain.

References HASH_OFFSET, IS_TABULATED, gen_binding::name, and printf().

Referenced by gen_and(), gen_array(), gen_list(), gen_or(), and gen_set().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gen_prelude()

static void gen_prelude ( bp  )
static

GEN_PRELUDE generates prelude declarations for potentially tabulated domain BP.

Definition at line 155 of file genLisp.c.

157 {
158  printf( "(lisp:setf (lisp:aref newgen::*gen-tabulated-alloc*" ) ;
159  printf( " (lisp:+ %s %d)) %d)\n",
160  start, TYPE( bp ), (IS_TABULATED( bp )) ? 0 : -1 ) ;
161  printf( "(lisp:defvar %s::%s-domain (lisp:+ %s %d))\n",
162  package, bp->name, start, TYPE( bp )) ;
163 
164  if( IS_TABULATED( bp )) {
165  printf( "(lisp:setf (lisp:aref newgen::*gen-tabulated-index* " ) ;
166  printf( "%s::%s-domain) %d)\n", package, bp->name, bp->index ) ;
167  }
168 }
static char * package
The package name in which functions will be defined.
Definition: genLisp.c:59

References IS_TABULATED, gen_binding::name, package, printf(), start, and TYPE.

Referenced by gen_and(), gen_array(), gen_list(), gen_or(), and gen_set().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gen_set()

void gen_set ( bp  )

GEN_SET defines the manipulation functions for a set type BP.

Definition at line 321 of file genLisp.c.

323 {
324  union domain *dom = bp->domain ;
325 
326  gen_prelude( bp ) ;
327  printf( "(lisp:defstruct (%s (:type %s))\n", bp->name, NEWGEN_IMPL ) ;
328  generate_type_member( bp ) ;
329  printf( " (%s %))\n",
330  dom->se.constructor, init_member( dom->se.element->domain )) ;
331  gen_postlude( bp ) ;
332 }
struct domain::@5 se

References domain::constructor, gen_binding::domain, domain::element, gen_postlude(), gen_prelude(), generate_type_member(), init_member(), gen_binding::name, NEWGEN_IMPL, printf(), and domain::se.

Referenced by gen_domain().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gencode()

void gencode ( file  )

GENCODE generates the code necessary to manipulate every non-inlinable type in the Domains table.

Definition at line 377 of file genLisp.c.

379 {
380  struct gen_binding *bp ;
381  int domain_count = 0 ;
382 
383  or_counter = 0 ;
384  package = file ;
385  sprintf( start, "newgen::*gen-%s-start*", file ) ;
386 
387  for( bp = Domains ; bp < &Domains[ MAX_DOMAIN ] ; bp++ ) {
388  if( bp->name == NULL ||
389  IS_INLINABLE( bp ) || IS_IMPORT( bp ) || bp == Tabulated_bp )
390  continue ;
391 
392  gen_domain( bp ) ;
393  }
394 }
struct gen_binding * Tabulated_bp
Definition: genLisp.c:61
void gen_domain(bp)
GEN_DOMAIN generates the manipulation functions for a type BP.
Definition: genLisp.c:338
struct gen_binding Domains[MAX_DOMAIN]
in build.c
Definition: genspec_yacc.c:114
#define MAX_DOMAIN
MAX_DOMAIN is the maximum number of entries in the DOMAINS table.
#define IS_IMPORT(bp)

References Domains, gen_domain(), IS_IMPORT, IS_INLINABLE, MAX_DOMAIN, gen_binding::name, or_counter, start, and Tabulated_bp.

+ Here is the call graph for this function:

◆ generate_type_member()

static generate_type_member ( bp  )
static

GEN_TYPE generates the type member for potentially tabulated BP domain.

Definition at line 197 of file genLisp.c.

199 {
200  printf( " (-type- `(:newgen ,(lisp:+ %s %d)))\n", start, TYPE( bp ) ) ;
201 
202  if( IS_TABULATED( bp )) {
203  printf( " (-tabular- (newgen::find-free-tabulated %d))\n",
204  TYPE( bp )) ;
205  }
206 }

References IS_TABULATED, printf(), start, and TYPE.

Referenced by gen_and(), gen_array(), gen_list(), and gen_set().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init_member()

char* init_member ( dp  )

INIT_MEMBER returns the initialization code for a value in the domain DP.

OTREACHED

Definition at line 72 of file genLisp.c.

74 {
75  static char buffer[ 1024 ] ;
76 
77  switch( dp->ba.type ) {
78  case BASIS_DT: {
79  struct gen_binding *bp = dp->ba.constructand ;
80 
81  if( IS_INLINABLE( bp ))
82  sprintf( buffer, "%s", bp->inlined->Lisp_value ) ;
83  else if( IS_EXTERNAL( bp ))
84  sprintf( buffer, "`(:external ,(lisp:+ %s %d) %s)",
85  start, TYPE( bp ), ":external-undefined" ) ;
86  else sprintf( buffer, ":undefined", bp->name ) ;
87  break ;
88  }
89  case LIST_DT:
90  sprintf( buffer, ":list-undefined" ) ;
91  break ;
92  case ARRAY_DT: {
93  struct intlist *ilp ;
94 
95  sprintf( buffer, "(lisp:make-array '(" ) ;
96 
97  for( ilp = dp->ar.dimensions ; ilp != NULL ; ilp = ilp->cdr ) {
98  strcat( buffer, i2a( ilp->val )) ;
99  strcat( buffer, " " ) ;
100  }
101  strcat( buffer, ") :initial-element '--no-value--)" ) ;
102  break ;
103  }
104  case SET_DT:
105  sprintf( buffer, "(set:set-make)" ) ;
106  break ;
107  default:
108  fatal( "init_member: Unknown type %s\n", i2a( dp->ba.type )) ;
109  /*NOTREACHED*/
110  }
111  return( buffer ) ;
112 }
static string buffer
Definition: string.c:113
struct inlinable * inlined
string Lisp_value
Definition: build.c:49

References domain::ar, ARRAY_DT, domain::ba, BASIS_DT, buffer, domain::constructand, domain::dimensions, fatal(), i2a(), gen_binding::inlined, IS_EXTERNAL, IS_INLINABLE, inlinable::Lisp_value, LIST_DT, gen_binding::name, SET_DT, start, TYPE, and domain::type.

Referenced by gen_and(), gen_array(), and gen_set().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ or_counter

int or_counter
static

Definition at line 67 of file genLisp.c.

Referenced by gen_or(), and gencode().

◆ package

char* package
static

◆ Read_spec_mode

int Read_spec_mode

extern int Current_first ;

Definition at line 63 of file genLisp.c.

◆ start

◆ Tabulated_bp

struct gen_binding* Tabulated_bp

Definition at line 61 of file genLisp.c.

Referenced by gencode().