├── 10 ├── String.d ├── Cmd.d ├── Sort.d ├── Wc.d ├── depend ├── makefile ├── Cmd.dc ├── String.dc ├── List.d ├── Sort.dc ├── Wc.dc ├── Filter.d └── Object.d ├── 11 ├── parse.h ├── Symtab.d ├── depend ├── binary.h ├── makefile ├── binary.c ├── Symbol.d ├── Symtab.dc ├── Object.d ├── Symbol.dc └── Node.d ├── 12 ├── parse.h ├── depend ├── Symtab.d ├── binary.h ├── binary.c ├── makefile ├── Symbol.d ├── Object.d └── Node.d ├── 13 ├── parse.h ├── Exception.d ├── Symtab.d ├── binary.h ├── except.c ├── List.d ├── depend ├── Exception.dc ├── binary.c ├── Symbol.d ├── makefile ├── Node.d ├── Object.d └── List.dc ├── 14 ├── .gdb_history ├── makefile.etc ├── xhello.c ├── cbutton.c ├── hello.c ├── button.c ├── List.d ├── run.c ├── Crt.d ├── xbutton.c ├── xrun.c ├── crun.c ├── Ic.d ├── Xt.d ├── makefile ├── Object.d ├── Xapp └── depend ├── depend ├── 07 ├── Queue.d ├── Stack.d ├── Queue.dc ├── Stack.dc ├── Circle.d ├── Circle.dc ├── Point.dc ├── points.c ├── Point.d ├── circles.c ├── queues.c ├── stacks.c ├── List.d ├── depend ├── makefile ├── Object.d ├── Object.dc └── List.dc ├── 08 ├── .gdb_history ├── Circle.d ├── Circle.dc ├── Point.dc ├── Point.d ├── circles.c ├── depend ├── makefile ├── List.d ├── lists.c ├── Object.d └── List.dc ├── 02 ├── String.h ├── depend ├── new.h ├── new.r ├── strings.c ├── makefile ├── new.c ├── String.c └── Atom.c ├── 01 ├── depend ├── new.h ├── Object.h ├── Set.h ├── makefile ├── main.c ├── Set.c └── Bag.c ├── ooc ├── rep │ ├── m.rep │ ├── header.rep │ ├── va.rep │ ├── dc.rep │ ├── h.rep │ ├── h-R.rep │ ├── r.rep │ ├── r-R.rep │ ├── c.rep │ └── c-R.rep ├── rep-10 │ ├── m.rep │ ├── header.rep │ ├── va.rep │ ├── dc.rep │ ├── h.rep │ ├── h-R.rep │ ├── r.rep │ ├── r-R.rep │ ├── c.rep │ └── c-R.rep ├── rep-11 │ ├── m.rep │ ├── header.rep │ ├── va.rep │ ├── dc.rep │ ├── h.rep │ ├── h-R.rep │ ├── r.rep │ ├── r-R.rep │ ├── c.rep │ └── c-R.rep ├── rep-7 │ ├── m.rep │ ├── header.rep │ ├── dc.rep │ ├── va.rep │ ├── h.rep │ ├── h-R.rep │ ├── r.rep │ ├── r-R.rep │ ├── c-R.rep │ └── c.rep ├── rep-8 │ ├── m.rep │ ├── header.rep │ ├── dc.rep │ ├── va.rep │ ├── h.rep │ ├── h-R.rep │ ├── r.rep │ ├── r-R.rep │ ├── c-R.rep │ └── c.rep ├── rep-9 │ ├── m.rep │ ├── header.rep │ ├── dc.rep │ ├── va.rep │ ├── h.rep │ ├── h-R.rep │ ├── r.rep │ ├── r-R.rep │ ├── c.rep │ └── c-R.rep ├── Test.d ├── T.dc ├── T.d ├── Test.dc ├── TBase.dc ├── TBase.d ├── awk │ └── report.dbg └── regress ├── 04 ├── Circle.r ├── Circle.h ├── new.h ├── Point.h ├── depend ├── Point.r ├── new.r ├── points.c ├── circles.c ├── makefile ├── Circle.c ├── Point.c └── new.c ├── 06 ├── Circle.r ├── Circle.h ├── depend ├── Point.h ├── points.c ├── circles.c ├── Point.r ├── makefile ├── any.c ├── Object.h ├── Circle.c ├── Object.r └── Point.c ├── 03 ├── depend ├── parse.h ├── value.h └── makefile ├── 09 ├── Circle.d ├── Circle.dc ├── Point.dc ├── circles.c ├── Point.d ├── depend ├── makefile ├── List.d ├── lists.c ├── Object.d ├── munch └── List.dc ├── 05 ├── mathlib.h ├── Var.h ├── Name.r ├── depend ├── makefile ├── value.h ├── Name.h ├── parse.h ├── value.r ├── binary.h ├── binary.c ├── Name.c ├── mathlib.c └── Var.c ├── makefile ├── man ├── man3 │ ├── intro.3 │ └── Exception.3 ├── man2 │ └── retrieve.2 ├── whatis.db ├── man4 │ ├── Event.4 │ ├── Crt.4 │ └── intro.4 ├── cat3 │ ├── intro.0 │ └── Exception.0 ├── cat4 │ ├── Event.0 │ ├── Crt.0 │ └── intro.0 ├── cat2 │ └── retrieve.0 ├── man1 │ └── munch.1 └── cat1 │ └── munch.0 └── make └── Makefile.solaris /depend: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /14/.gdb_history: -------------------------------------------------------------------------------- 1 | run x) 10 | #define y(p) (((const struct Point *)(p)) -> y) 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /04/new.r: -------------------------------------------------------------------------------- 1 | #ifndef CLASS_R 2 | #define CLASS_R 3 | 4 | #include 5 | 6 | struct Class { 7 | size_t size; 8 | void * (* ctor) (void * self, va_list * app); 9 | void * (* dtor) (void * self); 10 | void (* draw) (const void * self); 11 | }; 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /06/depend: -------------------------------------------------------------------------------- 1 | Object.o: Object.c Object.h Object.r 2 | Point.o: Point.c Point.h Object.h Point.r Object.r 3 | Circle.o: Circle.c Circle.h Point.h Object.h Circle.r Point.r Object.r 4 | any.o: any.c Object.h 5 | points.o: points.c Point.h Object.h 6 | circles.o: circles.c Circle.h Point.h Object.h 7 | -------------------------------------------------------------------------------- /07/Circle.dc: -------------------------------------------------------------------------------- 1 | % Circle ctor { 2 | struct Circle * self = super_ctor(Circle, _self, app); 3 | 4 | self -> rad = va_arg(* app, int); 5 | return self; 6 | } 7 | 8 | % Circle draw { 9 | %casts 10 | printf("circle at %d,%d rad %d\n", 11 | x(self), y(self), self -> rad); 12 | } 13 | 14 | %init 15 | -------------------------------------------------------------------------------- /08/Circle.dc: -------------------------------------------------------------------------------- 1 | % Circle ctor { 2 | struct Circle * self = super_ctor(Circle, _self, app); 3 | 4 | self -> rad = va_arg(* app, int); 5 | return self; 6 | } 7 | 8 | % Circle draw { 9 | %casts 10 | printf("circle at %d,%d rad %d\n", 11 | x(self), y(self), self -> rad); 12 | } 13 | 14 | %init 15 | -------------------------------------------------------------------------------- /09/Circle.dc: -------------------------------------------------------------------------------- 1 | % Circle ctor { 2 | struct Circle * self = super_ctor(Circle(), _self, app); 3 | 4 | self -> rad = va_arg(* app, int); 5 | return self; 6 | } 7 | 8 | % Circle draw { 9 | %casts 10 | printf("circle at %d,%d rad %d\n", 11 | x(self), y(self), self -> rad); 12 | } 13 | 14 | %init 15 | -------------------------------------------------------------------------------- /14/xhello.c: -------------------------------------------------------------------------------- 1 | #include "Xt.h" 2 | 3 | int main (int argc, char * argv []) 4 | { void * shell = new(XtApplicationShell(), & argc, argv); 5 | void * lineOut = new(XLineOut(), shell, 0, "hello, world"); 6 | 7 | puto(lineOut, stdout); 8 | mainLoop(shell); 9 | return 0; /* dummy */ 10 | } 11 | -------------------------------------------------------------------------------- /02/new.h: -------------------------------------------------------------------------------- 1 | #ifndef NEW_H 2 | #define NEW_H 3 | 4 | #include 5 | 6 | void * new (const void * class, ...); 7 | void delete (void * item); 8 | 9 | void * clone (const void * self); 10 | int differ (const void * self, const void * b); 11 | 12 | size_t sizeOf (const void * self); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /03/parse.h: -------------------------------------------------------------------------------- 1 | #ifndef PARSE_H 2 | #define PARSE_H 3 | 4 | /* 5 | * symbols 6 | */ 7 | 8 | enum tokens { /* must not clash with operators */ 9 | NUMBER = 'n' /* literal constant */ 10 | }; 11 | 12 | /* 13 | * error recovery 14 | */ 15 | 16 | void error (const char * fmt, ...); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /05/Name.r: -------------------------------------------------------------------------------- 1 | #ifndef NAME_R 2 | #define NAME_R 3 | 4 | /* 5 | * Name 6 | * maintain a table of Name structures 7 | */ 8 | 9 | struct Name { /* base structure */ 10 | const void * type; /* for dynamic linkage */ 11 | const char * name; /* may be malloc-ed */ 12 | int token; 13 | }; 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /12/parse.h: -------------------------------------------------------------------------------- 1 | #ifndef PARSE_H 2 | #define PARSE_H 3 | 4 | /* 5 | * error recovery 6 | */ 7 | 8 | void error (const char * fmt, ...); 9 | 10 | /* 11 | * symbol transput 12 | */ 13 | 14 | int putsymbol (const void * sym, FILE * fp); 15 | void * getsymbol (const void * class, FILE * fp); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /13/parse.h: -------------------------------------------------------------------------------- 1 | #ifndef PARSE_H 2 | #define PARSE_H 3 | 4 | /* 5 | * error recovery 6 | */ 7 | 8 | void error (const char * fmt, ...); 9 | 10 | /* 11 | * symbol transput 12 | */ 13 | 14 | int putsymbol (const void * sym, FILE * fp); 15 | void * getsymbol (const void * class, FILE * fp); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /10/Sort.d: -------------------------------------------------------------------------------- 1 | // new(Sort(), minimal-dimension) 2 | 3 | % SortClass: ListClass Sort: List { 4 | char rflag; 5 | %- 6 | void flags (_self, Object @ filter, char flag); 7 | int line (_self, const Object @ filter, const char * fnm, \ 8 | char * buf); 9 | int quit (_self, const Object @ filter); 10 | %} 11 | -------------------------------------------------------------------------------- /makefile: -------------------------------------------------------------------------------- 1 | p = 01 02 03 04 05 06 07 08 09 10 11 12 13 14 2 | 3 | all clean test:: 4 | @ for p in $p; do \ 5 | if [ -d $$p -a -r $$p/makefile ]; then \ 6 | echo; echo make $@ in $$p; echo; \ 7 | (cd $$p && $(MAKE) $(MFLAGS) $@) \ 8 | fi; \ 9 | done 10 | 11 | include make/Makefile.$(OSTYPE) 12 | -------------------------------------------------------------------------------- /05/depend: -------------------------------------------------------------------------------- 1 | binary.o: binary.c binary.h 2 | Name.o: Name.c binary.h parse.h value.h Name.h Name.r Var.h 3 | value.o: value.c parse.h value.h value.r 4 | Var.o: Var.c Name.h Name.r parse.h Var.h value.h value.r 5 | mathlib.o: mathlib.c Name.h Name.r mathlib.h parse.h value.h value.r 6 | parse.o: parse.c parse.h value.h mathlib.h Var.h Name.h Name.r 7 | -------------------------------------------------------------------------------- /06/Point.h: -------------------------------------------------------------------------------- 1 | #ifndef POINT_H 2 | #define POINT_H 3 | 4 | #include "Object.h" 5 | 6 | extern const void * Point; /* new(Point, x, y); */ 7 | 8 | void draw (const void * self); 9 | void move (void * point, int dx, int dy); 10 | 11 | extern const void * PointClass; /* adds draw */ 12 | 13 | void initPoint (void); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /02/new.r: -------------------------------------------------------------------------------- 1 | #ifndef CLASS_R 2 | #define CLASS_R 3 | 4 | #include 5 | #include 6 | 7 | struct Class { 8 | size_t size; 9 | void * (* ctor) (void * self, va_list * app); 10 | void * (* dtor) (void * self); 11 | void * (* clone) (const void * self); 12 | int (* differ) (const void * self, const void * b); 13 | }; 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /01/Set.h: -------------------------------------------------------------------------------- 1 | #ifndef SET_H 2 | #define SET_H 3 | 4 | extern const void * Set; 5 | 6 | void * add (void * set, const void * element); 7 | void * find (const void * set, const void * element); 8 | void * drop (void * set, const void * element); 9 | int contains (const void * set, const void * element); 10 | unsigned count (const void * set); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /13/Exception.d: -------------------------------------------------------------------------------- 1 | // new(Exception()) 2 | 3 | #include 4 | 5 | #define catch(e) setjmp(catchException(e)) 6 | 7 | void cause (int number); // if set up, goto catch() 8 | 9 | % Class Exception: Object { 10 | int armed; // set by a catch() 11 | jmp_buf label; // used by a catch() 12 | % 13 | void * catchException (_self); 14 | %} 15 | -------------------------------------------------------------------------------- /ooc/Test.d: -------------------------------------------------------------------------------- 1 | // Test.d -- 5.2 Jun 9 08:59:52 1993 2 | // Copyright (c) 1993 Axel T. Schreiner 3 | // 4 | line 1 class without new meta class 5 | line 2 // comment 6 | % TBaseClass Test:TBase { 7 | int line4; 8 | int line5; 9 | % 10 | int tInt (int i, _self, _v, const Object @ o, ...); 11 | const Test @ tTest (const _self); 12 | %} 13 | line -2 14 | line -1 15 | -------------------------------------------------------------------------------- /ooc/rep/va.rep: -------------------------------------------------------------------------------- 1 | % va // variable argument list parameter, if any 2 | 3 | `{ifnot `,... ` , va_list * app `} 4 | 5 | % link // component of metaclass structure 6 | 7 | struct Method `method ; 8 | 9 | % super-header // header for super selector 10 | 11 | `result super_ `method (const void * _class, ` \ 12 | `{() `const `type `_ `name `}, `%va ) 13 | -------------------------------------------------------------------------------- /04/points.c: -------------------------------------------------------------------------------- 1 | #include "Point.h" 2 | #include "new.h" 3 | 4 | int main (int argc, char ** argv) 5 | { void * p; 6 | 7 | while (* ++ argv) 8 | { switch (** argv) { 9 | case 'p': 10 | p = new(Point, 1, 2); 11 | break; 12 | default: 13 | continue; 14 | } 15 | draw(p); 16 | move(p, 10, 20); 17 | draw(p); 18 | delete(p); 19 | } 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /05/makefile: -------------------------------------------------------------------------------- 1 | c = binary.c Name.c value.c Var.c mathlib.c parse.c 2 | h = $(c:.c=.h) 3 | r = Name.r value.r 4 | t = value 5 | 6 | value = $(c:.c=.o) 7 | 8 | all: $t 9 | clean: ; rm -f $t *.o 10 | 11 | test:: value ; echo 'let a = sin(1) + PI' | value 12 | 13 | value: $(value) ; $(CC) $(CFLAGS) -o $@ $(value) $(Lm) 14 | 15 | include ../make/Makefile.$(OSTYPE) 16 | -------------------------------------------------------------------------------- /ooc/rep-10/va.rep: -------------------------------------------------------------------------------- 1 | % va // variable argument list parameter, if any 2 | 3 | `{ifnot `,... ` , va_list * app `} 4 | 5 | % link // component of metaclass structure 6 | 7 | struct Method `method ; 8 | 9 | % super-header // header for super selector 10 | 11 | `result super_ `method (const void * _class, ` \ 12 | `{() `const `type `_ `name `}, `%va ) 13 | -------------------------------------------------------------------------------- /ooc/rep-11/va.rep: -------------------------------------------------------------------------------- 1 | % va // variable argument list parameter, if any 2 | 3 | `{ifnot `,... ` , va_list * app `} 4 | 5 | % link // component of metaclass structure 6 | 7 | struct Method `method ; 8 | 9 | % super-header // header for super selector 10 | 11 | `result super_ `method (const void * _class, ` \ 12 | `{() `const `type `_ `name `}, `%va ) 13 | -------------------------------------------------------------------------------- /ooc/rep-7/dc.rep: -------------------------------------------------------------------------------- 1 | % -dc // implement -dc option 2 | 3 | / ` / `n 4 | / ` / `n `n 5 | 6 | `{% `%thunk `} 7 | 8 | `{super 9 | `{%- `%thunk `} 10 | `}super 11 | 12 | ` %init `n 13 | 14 | % thunk // suggest one method 15 | 16 | ` % `desc `method { / ` / `%header `n 17 | ` %casts `n `n 18 | 19 | `{ifnot `result void `t return ( `result ) 0; `}n 20 | } `n `n 21 | -------------------------------------------------------------------------------- /ooc/rep-8/dc.rep: -------------------------------------------------------------------------------- 1 | % -dc // implement -dc option 2 | 3 | / ` / `n 4 | / ` / `n `n 5 | 6 | `{% `%thunk `} 7 | 8 | `{super 9 | `{%- `%thunk `} 10 | `}super 11 | 12 | ` %init `n 13 | 14 | % thunk // suggest one method 15 | 16 | ` % `desc `method { / ` / `%header `n 17 | ` %casts `n `n 18 | 19 | `{ifnot `result void `t return ( `result ) 0; `}n 20 | } `n `n 21 | -------------------------------------------------------------------------------- /ooc/rep-9/dc.rep: -------------------------------------------------------------------------------- 1 | % -dc // implement -dc option 2 | 3 | / ` / `n 4 | / ` / `n `n 5 | 6 | `{% `%thunk `} 7 | 8 | `{super 9 | `{%- `%thunk `} 10 | `}super 11 | 12 | ` %init `n 13 | 14 | % thunk // suggest one method 15 | 16 | ` % `desc `method { / ` / `%header `n 17 | ` %casts `n `n 18 | 19 | `{ifnot `result void `t return ( `result ) 0; `}n 20 | } `n `n 21 | -------------------------------------------------------------------------------- /06/points.c: -------------------------------------------------------------------------------- 1 | #include "Point.h" 2 | 3 | int main (int argc, char ** argv) 4 | { void * p; 5 | 6 | initPoint(); 7 | 8 | while (* ++ argv) 9 | { switch (** argv) { 10 | case 'p': 11 | p = new(Point, 1, 2); 12 | break; 13 | default: 14 | continue; 15 | } 16 | draw(p); 17 | move(p, 10, 20); 18 | draw(p); 19 | delete(p); 20 | } 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /07/Point.dc: -------------------------------------------------------------------------------- 1 | % move { 2 | %casts 3 | self -> x += dx, self -> y += dy; 4 | } 5 | 6 | % Point ctor { 7 | struct Point * self = super_ctor(Point, _self, app); 8 | 9 | self -> x = va_arg(* app, int); 10 | self -> y = va_arg(* app, int); 11 | return self; 12 | } 13 | 14 | % Point draw { 15 | %casts 16 | printf("\".\" at %d,%d\n", x(self), y(self)); 17 | } 18 | 19 | %init 20 | -------------------------------------------------------------------------------- /07/points.c: -------------------------------------------------------------------------------- 1 | #include "Point.h" 2 | 3 | int main (int argc, char ** argv) 4 | { void * p; 5 | 6 | initPoint(); 7 | 8 | while (* ++ argv) 9 | { switch (** argv) { 10 | case 'p': 11 | p = new(Point, 1, 2); 12 | break; 13 | default: 14 | continue; 15 | } 16 | draw(p); 17 | move(p, 10, 20); 18 | draw(p); 19 | delete(p); 20 | } 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /08/Point.dc: -------------------------------------------------------------------------------- 1 | % move { 2 | %casts 3 | self -> x += dx, self -> y += dy; 4 | } 5 | 6 | % Point ctor { 7 | struct Point * self = super_ctor(Point, _self, app); 8 | 9 | self -> x = va_arg(* app, int); 10 | self -> y = va_arg(* app, int); 11 | return self; 12 | } 13 | 14 | % Point draw { 15 | %casts 16 | printf("\".\" at %d,%d\n", x(self), y(self)); 17 | } 18 | 19 | %init 20 | -------------------------------------------------------------------------------- /ooc/rep-10/dc.rep: -------------------------------------------------------------------------------- 1 | % -dc // implement -dc option 2 | 3 | / ` / `n 4 | / ` / `n `n 5 | 6 | `{% `%thunk `} 7 | 8 | `{super 9 | `{%- `%thunk `} 10 | `}super 11 | 12 | ` %init `n 13 | 14 | % thunk // suggest one method 15 | 16 | ` % `desc `method { / ` / `%header `n 17 | ` %casts `n `n 18 | 19 | `{ifnot `result void `t return ( `result ) 0; `}n 20 | } `n `n 21 | -------------------------------------------------------------------------------- /09/Point.dc: -------------------------------------------------------------------------------- 1 | % move { 2 | %casts 3 | self -> x += dx, self -> y += dy; 4 | } 5 | 6 | % Point ctor { 7 | struct Point * self = super_ctor(Point(), _self, app); 8 | 9 | self -> x = va_arg(* app, int); 10 | self -> y = va_arg(* app, int); 11 | return self; 12 | } 13 | 14 | % Point draw { 15 | %casts 16 | printf("\".\" at %d,%d\n", x(self), y(self)); 17 | } 18 | 19 | %init 20 | -------------------------------------------------------------------------------- /11/Symtab.d: -------------------------------------------------------------------------------- 1 | // new(Symtab(), minimal-dimension) 2 | 3 | #include 4 | 5 | % Class Symtab: Object { 6 | const void ** buf; // const void * buf [dim] 7 | size_t dim; // current buffer dimension 8 | size_t count; // # elements in buffer 9 | % 10 | void install (_self, const Symbol @ entry); 11 | Symbol @ screen (_self, const char * name, int lex); 12 | %} 13 | -------------------------------------------------------------------------------- /14/cbutton.c: -------------------------------------------------------------------------------- 1 | #include "Crt.h" 2 | 3 | int main () 4 | { void * crt = new(Crt()); 5 | void * lineOut = new(CLineOut(), 5, 10, 40); 6 | void * button = new(CButton(), "a", 10, 40); 7 | 8 | makeWindow(crt, 0, 0, 0, 0); /* total screen */ 9 | gate(lineOut, "hello, world"); 10 | 11 | wire(lineOut, button), wire(button, crt); 12 | gate(crt, 0); /* main loop */ 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /ooc/rep-11/dc.rep: -------------------------------------------------------------------------------- 1 | % -dc // implement -dc option 2 | 3 | / ` / `n 4 | / ` / `n `n 5 | 6 | `{% `%thunk `} 7 | 8 | `{super 9 | `{%- `%thunk `} 10 | `{%+ `%thunk `} 11 | `}super 12 | 13 | ` %init `n 14 | 15 | % thunk // suggest one method 16 | 17 | ` % `desc `method { / ` / `%header `n 18 | ` %casts `n `n 19 | 20 | `{ifnot `result void `t return ( `result ) 0; `}n 21 | } `n `n 22 | -------------------------------------------------------------------------------- /ooc/rep/dc.rep: -------------------------------------------------------------------------------- 1 | % -dc // implement -dc option 2 | 3 | / ` / `n 4 | / ` / `n `n 5 | 6 | `{% `%thunk `} 7 | 8 | `{super 9 | `{%- `%thunk `} 10 | `{%+ `%thunk `} 11 | `}super 12 | 13 | ` %init `n 14 | 15 | % thunk // suggest one method 16 | 17 | ` % `desc `method { / ` / `%header `n 18 | ` %casts `n `n 19 | 20 | `{ifnot `result void `t return ( `result ) 0; `}n 21 | } `n `n 22 | -------------------------------------------------------------------------------- /01/makefile: -------------------------------------------------------------------------------- 1 | c = Set.c Bag.c 2 | h = new.h Set.h Object.h 3 | m = main.c 4 | t = sets bags 5 | 6 | sets = main.o Set.o 7 | bags = main.o Bag.o 8 | 9 | all: $t 10 | clean: ; rm -f $t *.o 11 | 12 | test:: sets ; sets 13 | test:: bags ; bags 14 | 15 | sets: $(sets) ; $(CC) $(CFLAGS) -o $@ $(sets) 16 | bags: $(bags) ; $(CC) $(CFLAGS) -o $@ $(bags) 17 | 18 | include ../make/Makefile.$(OSTYPE) 19 | -------------------------------------------------------------------------------- /03/value.h: -------------------------------------------------------------------------------- 1 | #ifndef VALUE_H 2 | #define VALUE_H 3 | 4 | /* 5 | * node types 6 | */ 7 | 8 | const void * Minus; 9 | const void * Value; 10 | const void * Mult; 11 | const void * Div; 12 | const void * Add; 13 | const void * Sub; 14 | 15 | /* 16 | * tree management 17 | */ 18 | 19 | void * new (const void * type, ...); 20 | void process (const void * tree); 21 | void delete (void * tree); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /05/value.h: -------------------------------------------------------------------------------- 1 | #ifndef VALUE_H 2 | #define VALUE_H 3 | 4 | /* 5 | * node types 6 | */ 7 | 8 | const void * Minus; 9 | const void * Value; 10 | const void * Mult; 11 | const void * Div; 12 | const void * Add; 13 | const void * Sub; 14 | 15 | /* 16 | * tree management 17 | */ 18 | 19 | void * new (const void * type, ...); 20 | void process (const void * tree); 21 | void delete (void * tree); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /ooc/rep-7/va.rep: -------------------------------------------------------------------------------- 1 | % va // variable argument list parameter, if any 2 | 3 | `{ifnot `,... ` , va_list * app `} 4 | 5 | % link // component of metaclass structure 6 | 7 | `result (* `method ) ( `{() `const `type `_ `name `}, `%va ); 8 | 9 | % super-header // header for super selector 10 | 11 | `result super_ `method (const void * _class, ` \ 12 | `{() `const `type `_ `name `}, `%va ) 13 | -------------------------------------------------------------------------------- /ooc/rep-8/va.rep: -------------------------------------------------------------------------------- 1 | % va // variable argument list parameter, if any 2 | 3 | `{ifnot `,... ` , va_list * app `} 4 | 5 | % link // component of metaclass structure 6 | 7 | `result (* `method ) ( `{() `const `type `_ `name `}, `%va ); 8 | 9 | % super-header // header for super selector 10 | 11 | `result super_ `method (const void * _class, ` \ 12 | `{() `const `type `_ `name `}, `%va ) 13 | -------------------------------------------------------------------------------- /ooc/rep-9/va.rep: -------------------------------------------------------------------------------- 1 | % va // variable argument list parameter, if any 2 | 3 | `{ifnot `,... ` , va_list * app `} 4 | 5 | % link // component of metaclass structure 6 | 7 | `result (* `method ) ( `{() `const `type `_ `name `}, `%va ); 8 | 9 | % super-header // header for super selector 10 | 11 | `result super_ `method (const void * _class, ` \ 12 | `{() `const `type `_ `name `}, `%va ) 13 | -------------------------------------------------------------------------------- /ooc/T.dc: -------------------------------------------------------------------------------- 1 | // T.dc -- 5.1 Jun 8 17:55:47 1993 2 | // Copyright (c) 1993 Axel T. Schreiner 3 | 4 | // T 5 | 6 | % s { 7 | %casts 8 | } 9 | 10 | % S { 11 | %casts 12 | } 13 | 14 | %+ T c { 15 | } 16 | 17 | %+ T C { 18 | } 19 | 20 | %- T ctor { 21 | 22 | return _self; 23 | } 24 | 25 | %- T D { 26 | } 27 | 28 | // Class 29 | 30 | % cc { 31 | %casts 32 | } 33 | 34 | % CC { 35 | %casts 36 | } 37 | 38 | %init 39 | -------------------------------------------------------------------------------- /09/circles.c: -------------------------------------------------------------------------------- 1 | #include "Circle.h" 2 | 3 | int main (int argc, char ** argv) 4 | { void * p; 5 | 6 | while (* ++ argv) 7 | { switch (** argv) { 8 | case 'c': 9 | p = new(Circle(), 1, 2, 3); 10 | break; 11 | case 'p': 12 | p = new(Point(), 1, 2); 13 | break; 14 | default: 15 | continue; 16 | } 17 | draw(p); 18 | move(p, 10, 20); 19 | draw(p); 20 | delete(p); 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /07/Point.d: -------------------------------------------------------------------------------- 1 | // new(Point, x, y) 2 | 3 | % PointClass: Class Point: Object { // header 4 | int x; // object components 5 | int y; 6 | % // statically linked 7 | void move (_self, int dx, int dy); 8 | %- // dynamically linked 9 | void draw (const _self); 10 | %} 11 | 12 | %prot 13 | 14 | #define x(p) (((const struct Point *)(p)) -> x) 15 | #define y(p) (((const struct Point *)(p)) -> y) 16 | -------------------------------------------------------------------------------- /08/Point.d: -------------------------------------------------------------------------------- 1 | // new(Point, x, y) 2 | 3 | % PointClass: Class Point: Object { // header 4 | int x; // object components 5 | int y; 6 | % // statically linked 7 | void move (_self, int dx, int dy); 8 | %- // dynamically linked 9 | void draw (const _self); 10 | %} 11 | 12 | %prot 13 | 14 | #define x(p) (((const struct Point *)(p)) -> x) 15 | #define y(p) (((const struct Point *)(p)) -> y) 16 | -------------------------------------------------------------------------------- /09/Point.d: -------------------------------------------------------------------------------- 1 | // new(Point(), x, y) 2 | 3 | % PointClass: Class Point: Object { // header 4 | int x; // object components 5 | int y; 6 | % // statically linked 7 | void move (_self, int dx, int dy); 8 | %- // dynamically linked 9 | void draw (const _self); 10 | %} 11 | 12 | %prot 13 | 14 | #define x(p) (((const struct Point *)(p)) -> x) 15 | #define y(p) (((const struct Point *)(p)) -> y) 16 | -------------------------------------------------------------------------------- /14/hello.c: -------------------------------------------------------------------------------- 1 | #include "Ic.h" 2 | 3 | int main () 4 | { void * ic = new(Ic()); 5 | void * mux = new(Mux()); 6 | int i; 7 | void * lineOut = new(LineOut()); 8 | 9 | for (i = 0; i < 2; ++ i) 10 | wire(new(Ic()), mux); 11 | wire(lineOut, mux); 12 | wire(lineOut, mux); 13 | wire(mux, ic); 14 | puto(ic, stdout); 15 | gate(ic, "hello, world"); 16 | delete(ic); 17 | delete(mux); 18 | delete(lineOut); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /04/circles.c: -------------------------------------------------------------------------------- 1 | #include "Circle.h" 2 | #include "new.h" 3 | 4 | int main (int argc, char ** argv) 5 | { void * p; 6 | 7 | while (* ++ argv) 8 | { switch (** argv) { 9 | case 'c': 10 | p = new(Circle, 1, 2, 3); 11 | break; 12 | case 'p': 13 | p = new(Point, 1, 2); 14 | break; 15 | default: 16 | continue; 17 | } 18 | draw(p); 19 | move(p, 10, 20); 20 | draw(p); 21 | delete(p); 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /06/circles.c: -------------------------------------------------------------------------------- 1 | #include "Circle.h" 2 | 3 | int main (int argc, char ** argv) 4 | { void * p; 5 | 6 | initCircle(); 7 | 8 | while (* ++ argv) 9 | { switch (** argv) { 10 | case 'c': 11 | p = new(Circle, 1, 2, 3); 12 | break; 13 | case 'p': 14 | p = new(Point, 1, 2); 15 | break; 16 | default: 17 | continue; 18 | } 19 | draw(p); 20 | move(p, 10, 20); 21 | draw(p); 22 | delete(p); 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /07/circles.c: -------------------------------------------------------------------------------- 1 | #include "Circle.h" 2 | 3 | int main (int argc, char ** argv) 4 | { void * p; 5 | 6 | initCircle(); 7 | 8 | while (* ++ argv) 9 | { switch (** argv) { 10 | case 'c': 11 | p = new(Circle, 1, 2, 3); 12 | break; 13 | case 'p': 14 | p = new(Point, 1, 2); 15 | break; 16 | default: 17 | continue; 18 | } 19 | draw(p); 20 | move(p, 10, 20); 21 | draw(p); 22 | delete(p); 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /08/circles.c: -------------------------------------------------------------------------------- 1 | #include "Circle.h" 2 | 3 | int main (int argc, char ** argv) 4 | { void * p; 5 | 6 | initCircle(); 7 | 8 | while (* ++ argv) 9 | { switch (** argv) { 10 | case 'c': 11 | p = new(Circle, 1, 2, 3); 12 | break; 13 | case 'p': 14 | p = new(Point, 1, 2); 15 | break; 16 | default: 17 | continue; 18 | } 19 | draw(p); 20 | move(p, 10, 20); 21 | draw(p); 22 | delete(p); 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /02/strings.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "String.h" 3 | #include "new.h" 4 | 5 | int main () 6 | { void * a = new(String, "a"), * aa = clone(a); 7 | void * b = new(String, "b"); 8 | 9 | printf("sizeOf(a) == %lu\n", (unsigned long)sizeOf(a)); 10 | if (differ(a, b)) 11 | puts("ok"); 12 | 13 | if (differ(a, aa)) 14 | puts("differ?"); 15 | 16 | if (a == aa) 17 | puts("clone?"); 18 | 19 | delete(a), delete(aa), delete(b); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /02/makefile: -------------------------------------------------------------------------------- 1 | c = new.c String.c Atom.c 2 | h = new.h String.h 3 | m = strings.c 4 | r = new.r 5 | t = strings atoms 6 | 7 | strings = strings.o new.o String.o 8 | atoms = strings.o new.o Atom.o 9 | 10 | all: $t 11 | clean: ; rm -f $t *.o 12 | 13 | test:: strings ; strings 14 | test:: atoms ; atoms 15 | 16 | strings: $(strings) ; $(CC) $(CFLAGS) -o $@ $(strings) 17 | atoms: $(atoms) ; $(CC) $(CFLAGS) -o $@ $(atoms) 18 | 19 | include ../make/Makefile.$(OSTYPE) 20 | -------------------------------------------------------------------------------- /05/Name.h: -------------------------------------------------------------------------------- 1 | #ifndef NAME_H 2 | #define NAME_H 3 | 4 | /* 5 | * install(& struct Name) arrange for object to be found later 6 | * 7 | * screen(name) 8 | * find a name in a table 9 | * if nothing found, enter new(Var, name) into table 10 | * return associated token and pointer to structure 11 | */ 12 | 13 | extern void * symbol; /* -> last Name found by screen() */ 14 | 15 | void install (const void * symbol); 16 | int screen (const char * name); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /05/parse.h: -------------------------------------------------------------------------------- 1 | #ifndef PARSE_H 2 | #define PARSE_H 3 | 4 | /* 5 | * symbols 6 | */ 7 | 8 | enum tokens { /* must not clash with operators */ 9 | NUMBER = 'n', /* literal constant */ 10 | CONST = 'c', /* constant name */ 11 | MATH = 'm', /* library function name */ 12 | VAR = 'v', /* variable name */ 13 | 14 | LET = 'l' /* LET VAR = sum */ 15 | }; 16 | 17 | /* 18 | * error recovery 19 | */ 20 | 21 | void error (const char * fmt, ...); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /14/button.c: -------------------------------------------------------------------------------- 1 | #include "Ic.h" 2 | 3 | int main () 4 | { void * button, * lineOut; 5 | char buf [100]; 6 | 7 | lineOut = new(LineOut()); 8 | button = new(Button(), "a"); 9 | wire(lineOut, button); 10 | puto(button, stdout); 11 | 12 | while (fgets(buf, sizeof buf, stdin)) 13 | { void * event = new(Event(), 0, buf); 14 | 15 | if (gate(button, event) == accept) 16 | break; 17 | delete(event); 18 | } 19 | 20 | delete(lineOut), delete(button); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /08/depend: -------------------------------------------------------------------------------- 1 | Object.o: Object.c Object.h Object.r 2 | Point.o: Point.c Point.h Object.h Point.r Object.r 3 | Circle.o: Circle.c Circle.h Point.h Object.h Circle.r Point.r Object.r 4 | List.o: List.c List.h Object.h List.r Object.r 5 | circles.o: circles.c Circle.h Point.h Object.h 6 | lists.o: lists.c Circle.h Point.h Object.h List.h 7 | Point.d: Object.d 8 | Circle.d: Point.d 9 | List.d: Object.d 10 | Object.c: Object.d 11 | Point.c: Point.d 12 | Circle.c: Circle.d 13 | List.c: List.d 14 | -------------------------------------------------------------------------------- /09/depend: -------------------------------------------------------------------------------- 1 | Object.o: Object.c Object.h Object.r 2 | Point.o: Point.c Point.h Object.h Point.r Object.r 3 | Circle.o: Circle.c Circle.h Point.h Object.h Circle.r Point.r Object.r 4 | List.o: List.c List.h Object.h List.r Object.r 5 | circles.o: circles.c Circle.h Point.h Object.h 6 | lists.o: lists.c Circle.h Point.h Object.h List.h 7 | Point.d: Object.d 8 | Circle.d: Point.d 9 | List.d: Object.d 10 | Object.c: Object.d 11 | Point.c: Point.d 12 | Circle.c: Circle.d 13 | List.c: List.d 14 | -------------------------------------------------------------------------------- /04/makefile: -------------------------------------------------------------------------------- 1 | c = new.c Point.c Circle.c 2 | h = $(c:.c=.h) 3 | m = points.c circles.c 4 | r = $(c:.c=.r) 5 | t = $(m:.c=) 6 | 7 | points = points.o new.o Point.o 8 | circles = circles.o new.o Point.o Circle.o 9 | 10 | all: $t 11 | clean: ; rm -f $t *.o 12 | 13 | test:: points ; points p 14 | test:: circles ; circles p c 15 | 16 | points: $(points) ; $(CC) $(CFLAGS) -o $@ $(points) 17 | circles: $(circles) ; $(CC) $(CFLAGS) -o $@ $(circles) 18 | 19 | include ../make/Makefile.$(OSTYPE) 20 | -------------------------------------------------------------------------------- /07/queues.c: -------------------------------------------------------------------------------- 1 | #include "Queue.h" 2 | 3 | int main (int argc, char ** argv) 4 | { void * q; 5 | unsigned n; 6 | 7 | initQueue(); 8 | q = new(Queue, 1); 9 | 10 | while (* ++ argv) 11 | switch (** argv) { 12 | case '+': 13 | add(q, *argv + 1); 14 | break; 15 | case '-': 16 | puts((char *) take(q)); 17 | break; 18 | default: 19 | n = count(q); 20 | while (n -- > 0) 21 | { const void * p = take(q); 22 | 23 | puts(p), add(q, p); 24 | } 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /ooc/rep-10/h.rep: -------------------------------------------------------------------------------- 1 | % -h // implement -h option 2 | 3 | # ifndef `class _h `n 4 | # define `class _h `n `n 5 | 6 | # include " `super .h" `n `n 7 | 8 | `{pub 9 | `{if `class ` 10 | `line `n 11 | `} `{else `n 12 | extern const void * `%const `class (void); `n `n 13 | 14 | `{% `%header ; `n `}n 15 | 16 | `{if `newmeta 1 17 | `{%- `%header ; `n `}n 18 | extern const void * `%const `meta (void); `n `n 19 | `} 20 | 21 | `}fi 22 | `}n 23 | 24 | # endif `n 25 | -------------------------------------------------------------------------------- /ooc/rep-9/h.rep: -------------------------------------------------------------------------------- 1 | % -h // implement -h option 2 | 3 | # ifndef `class _h `n 4 | # define `class _h `n `n 5 | 6 | # include " `super .h" `n `n 7 | 8 | `{pub 9 | `{if `class ` 10 | `line `n 11 | `} `{else `n 12 | extern const void * `%const `class (void); `n `n 13 | 14 | `{% `%header ; `n `}n 15 | 16 | `{if `newmeta 1 17 | `{%- `%header ; `n `}n 18 | extern const void * `%const `meta (void); `n `n 19 | `} 20 | 21 | `}fi 22 | `}n 23 | 24 | # endif `n 25 | -------------------------------------------------------------------------------- /06/Point.r: -------------------------------------------------------------------------------- 1 | #ifndef POINT_R 2 | #define POINT_R 3 | 4 | #include "Object.r" 5 | 6 | struct Point { const struct Object _; /* Point : Object */ 7 | int x, y; /* coordinates */ 8 | }; 9 | 10 | #define x(p) (((const struct Point *)(p)) -> x) 11 | #define y(p) (((const struct Point *)(p)) -> y) 12 | 13 | void super_draw (const void * class, const void * self); 14 | 15 | struct PointClass { 16 | const struct Class _; /* PointClass : Class */ 17 | void (* draw) (const void * self); 18 | }; 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /07/stacks.c: -------------------------------------------------------------------------------- 1 | #include "Stack.h" 2 | 3 | int main (int argc, char ** argv) 4 | { void * q; 5 | unsigned n; 6 | 7 | initStack(); 8 | q = new(Stack, 1); 9 | 10 | while (* ++ argv) 11 | switch (** argv) { 12 | case '+': 13 | add(q, *argv + 1); 14 | break; 15 | case '-': 16 | puts((char *) take(q)); 17 | break; 18 | default: 19 | n = count(q); 20 | while (n -- > 0) 21 | { const void * p = takeFirst(q); 22 | 23 | puts(p), addLast(q, p); 24 | } 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /11/depend: -------------------------------------------------------------------------------- 1 | Object.o: Object.c Object.h Object.r 2 | Node.o: Node.c Node.h Object.h Node.r Object.r parse.h Symbol.h 3 | Symbol.o: Symbol.c Symbol.h Object.h Symbol.r Object.r parse.h Node.h 4 | Symtab.o: Symtab.c Symtab.h Object.h Symtab.r Object.r binary.h Symbol.h 5 | binary.o: binary.c binary.h 6 | parse.o: parse.c parse.h Node.h Object.h Symbol.h Symtab.h 7 | Node.d: Object.d 8 | Symbol.d: Object.d 9 | Symtab.d: Object.d 10 | Object.c: Object.d 11 | Node.c: Node.d 12 | Symbol.c: Symbol.d 13 | Symtab.c: Symtab.d 14 | -------------------------------------------------------------------------------- /12/depend: -------------------------------------------------------------------------------- 1 | Object.o: Object.c Object.h Object.r 2 | Node.o: Node.c Node.h Object.h Node.r Object.r parse.h Symbol.h 3 | Symbol.o: Symbol.c Symbol.h Object.h Symbol.r Object.r parse.h Node.h 4 | Symtab.o: Symtab.c Symtab.h Object.h Symtab.r Object.r binary.h Symbol.h 5 | binary.o: binary.c binary.h 6 | parse.o: parse.c parse.h Node.h Object.h Symbol.h Symtab.h 7 | Node.d: Object.d 8 | Symbol.d: Object.d 9 | Symtab.d: Object.d 10 | Object.c: Object.d 11 | Node.c: Node.d 12 | Symbol.c: Symbol.d 13 | Symtab.c: Symtab.d 14 | -------------------------------------------------------------------------------- /ooc/rep-7/h.rep: -------------------------------------------------------------------------------- 1 | % -h // implement -h option 2 | 3 | # ifndef `class _h `n 4 | # define `class _h `n `n 5 | 6 | # include " `super .h" `n `n 7 | 8 | `{pub 9 | `{if `class ` 10 | `line `n 11 | `} `{else `n 12 | extern const void * `class ; `n `n 13 | 14 | `{% `%header ; `n `}n 15 | 16 | `{if `newmeta 1 17 | `{%- `%header ; `n `}n 18 | extern const void * `meta ; `n `n 19 | `} 20 | 21 | void init `class (void); `n `n 22 | 23 | `}fi 24 | `}n 25 | 26 | # endif `n 27 | -------------------------------------------------------------------------------- /ooc/rep-8/h.rep: -------------------------------------------------------------------------------- 1 | % -h // implement -h option 2 | 3 | # ifndef `class _h `n 4 | # define `class _h `n `n 5 | 6 | # include " `super .h" `n `n 7 | 8 | `{pub 9 | `{if `class ` 10 | `line `n 11 | `} `{else `n 12 | extern const void * `class ; `n `n 13 | 14 | `{% `%header ; `n `}n 15 | 16 | `{if `newmeta 1 17 | `{%- `%header ; `n `}n 18 | extern const void * `meta ; `n `n 19 | `} 20 | 21 | void init `class (void); `n `n 22 | 23 | `}fi 24 | `}n 25 | 26 | # endif `n 27 | -------------------------------------------------------------------------------- /ooc/rep-11/h.rep: -------------------------------------------------------------------------------- 1 | % -h // implement -h option 2 | 3 | # ifndef `class _h `n 4 | # define `class _h `n `n 5 | 6 | # include " `super .h" `n `n 7 | 8 | `{pub 9 | `{if `class ` 10 | `line `n 11 | `} `{else `n 12 | extern const void * `%const `class (void); `n `n 13 | 14 | `{% `%header ; `n `}n 15 | 16 | `{if `newmeta 1 17 | `{%- `%header ; `n `}n 18 | extern const void * `%const `meta (void); `n `n 19 | `{%+ `%header ; `n `}n 20 | `} 21 | 22 | `}fi 23 | `}n 24 | 25 | # endif `n 26 | -------------------------------------------------------------------------------- /ooc/rep/h.rep: -------------------------------------------------------------------------------- 1 | % -h // implement -h option 2 | 3 | # ifndef `class _h `n 4 | # define `class _h `n `n 5 | 6 | # include " `super .h" `n `n 7 | 8 | `{pub 9 | `{if `class ` 10 | `line `n 11 | `} `{else `n 12 | extern const void * `%const `class (void); `n `n 13 | 14 | `{% `%header ; `n `}n 15 | 16 | `{if `newmeta 1 17 | `{%- `%header ; `n `}n 18 | extern const void * `%const `meta (void); `n `n 19 | `{%+ `%header ; `n `}n 20 | `} 21 | 22 | `}fi 23 | `}n 24 | 25 | # endif `n 26 | -------------------------------------------------------------------------------- /10/Wc.d: -------------------------------------------------------------------------------- 1 | // new(Wc()) 2 | 3 | % WcClass: Class Wc: Object { 4 | unsigned lines; // lines in current file 5 | unsigned allLines; // lines in previous files 6 | unsigned chars; // bytes in current file 7 | unsigned allChars; // bytes in previous files 8 | unsigned files; // files completed 9 | %- 10 | line: int wc (_self, const Object @ filter, \ 11 | const char * fnm, char * buf); 12 | wrap: int printFile (_self, const Object @ filter, \ 13 | const char * fnm); 14 | quit: int printTotal (_self, const Object @ filter); 15 | %} 16 | -------------------------------------------------------------------------------- /05/value.r: -------------------------------------------------------------------------------- 1 | #ifndef VALUE_R 2 | #define VALUE_R 3 | 4 | #include 5 | 6 | struct Type { 7 | void * (* new) (va_list ap); 8 | double (* exec) (const void * tree); 9 | void (* delete) (void * tree); 10 | }; 11 | 12 | double exec (const void * tree); 13 | 14 | struct Bin { 15 | const void * type; 16 | void * left, * right; 17 | }; 18 | 19 | #define left(tree) (((struct Bin *) tree) -> left) 20 | #define right(tree) (((struct Bin *) tree) -> right) 21 | 22 | void * mkBin (va_list ap); 23 | void freeBin (void * tree); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /12/Symtab.d: -------------------------------------------------------------------------------- 1 | // new(Symtab(), minimal-dimension) 2 | 3 | #include 4 | 5 | % Class Symtab: Object { 6 | const void ** buf; // const void * buf [dim] 7 | size_t dim; // current buffer dimension 8 | size_t count; // # elements in buffer 9 | % 10 | void install (_self, const Symbol @ entry); 11 | Symbol @ screen (_self, const char * name, int lex); 12 | // i/o functions return EOF on error 13 | int save (const _self, const Var @ entry, const char * fnm); 14 | int load (_self, Symbol @ entry, const char * fnm); 15 | %} 16 | -------------------------------------------------------------------------------- /13/Symtab.d: -------------------------------------------------------------------------------- 1 | // new(Symtab(), minimal-dimension) 2 | 3 | #include 4 | 5 | % Class Symtab: Object { 6 | const void ** buf; // const void * buf [dim] 7 | size_t dim; // current buffer dimension 8 | size_t count; // # elements in buffer 9 | % 10 | void install (_self, const Symbol @ entry); 11 | Symbol @ screen (_self, const char * name, int lex); 12 | // i/o functions return EOF on error 13 | int save (const _self, const Var @ entry, const char * fnm); 14 | int load (_self, Symbol @ entry, const char * fnm); 15 | %} 16 | -------------------------------------------------------------------------------- /ooc/T.d: -------------------------------------------------------------------------------- 1 | // T.d -- 5.3 Thu Jan 3 18:42:58 EST 2002 2 | // Copyright (c) 1993 Axel T. Schreiner 3 | // 4 | line 1 root and meta root class 5 | line 2 // comment 6 | % Class T { 7 | const Class @ class; 8 | % 9 | void s (_self); 10 | void S (_self); 11 | %- 12 | void * ctor (_self, va_list * app); 13 | void D (_self); 14 | %+ 15 | void c (_self); 16 | void C (_self); 17 | %} 18 | 19 | % Class Class:T { 20 | const char * name; 21 | const Class @ super; 22 | size_t size; 23 | % 24 | void cc (_self); 25 | void CC (_self); 26 | %} 27 | line -2 28 | line -1 29 | -------------------------------------------------------------------------------- /ooc/Test.dc: -------------------------------------------------------------------------------- 1 | // Test.dc -- 5.1 Jun 6 18:18:16 1993 2 | // Copyright (c) 1993 Axel T. Schreiner 3 | // 4 | line 1 implementation of class without new meta class 5 | line 2 // comment 6 | 7 | % tInt { 8 | %casts 9 | return 1; 10 | } 11 | 12 | % tTest { 13 | %casts 14 | return self; 15 | } 16 | 17 | %+ Test cInt { 18 | %casts 19 | return 2; 20 | } 21 | 22 | %+ Test C { 23 | %casts 24 | } 25 | 26 | %- Test dTBase { 27 | %casts 28 | return _self; 29 | } 30 | 31 | %- Test D { 32 | %casts 33 | } 34 | 35 | line -5 36 | line -4 37 | %init 38 | line -2 39 | line -1 40 | -------------------------------------------------------------------------------- /ooc/TBase.dc: -------------------------------------------------------------------------------- 1 | // TBase.dc -- 5.1 Jun 6 18:17:54 1993 2 | // Copyright (c) 1993 Axel T. Schreiner 3 | // 4 | line 1 implementation of class with new meta class 5 | line 2 // comment 6 | 7 | % sInt { 8 | %casts 9 | return 1; 10 | } 11 | 12 | % sTBase { 13 | %casts 14 | return self; 15 | } 16 | 17 | %+ TBase cInt { 18 | %casts 19 | return 2; 20 | } 21 | 22 | %+ TBase cVoid { 23 | %casts 24 | } 25 | 26 | %- TBase dVoid { 27 | %casts 28 | } 29 | 30 | %- TBase dTBase { 31 | %casts 32 | return _self; 33 | } 34 | 35 | line -5 36 | line -4 37 | %init 38 | line -2 39 | line -1 40 | -------------------------------------------------------------------------------- /01/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "new.h" 4 | #include "Object.h" 5 | #include "Set.h" 6 | 7 | int main () 8 | { void * s = new(Set); 9 | void * a = add(s, new(Object)); 10 | void * b = add(s, new(Object)); 11 | void * c = new(Object); 12 | 13 | if (contains(s, a) && contains(s, b)) 14 | puts("ok"); 15 | 16 | if (contains(s, c)) 17 | puts("contains?"); 18 | 19 | if (differ(a, add(s, a))) 20 | puts("differ?"); 21 | 22 | if (contains(s, drop(s, a))) 23 | puts("drop?"); 24 | 25 | delete(drop(s, b)); 26 | delete(drop(s, c)); 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /ooc/rep-7/h-R.rep: -------------------------------------------------------------------------------- 1 | // differences from h.rep: 2 | // there is no superclass header to be included 3 | // `root and `metaroot are produced separately; both can have methods 4 | // 5 | // it does not hurt to produce `{%- for `metaroot -- empty 6 | // 7 | % -h // implement -h option for root class 8 | 9 | # ifndef `class _h `n 10 | # define `class _h `n `n 11 | 12 | `{pub 13 | `{if `class ` 14 | `line `n 15 | `} `{else `n 16 | extern const void * `class ; `n `n 17 | 18 | `{% `%header ; `n `}n 19 | `{%- `%header ; `n `}n 20 | 21 | `}fi 22 | `}n 23 | 24 | # endif `n 25 | -------------------------------------------------------------------------------- /ooc/rep-8/h-R.rep: -------------------------------------------------------------------------------- 1 | // differences from h.rep: 2 | // there is no superclass header to be included 3 | // `root and `metaroot are produced separately; both can have methods 4 | // 5 | // it does not hurt to produce `{%- for `metaroot -- empty 6 | // 7 | % -h // implement -h option for root class 8 | 9 | # ifndef `class _h `n 10 | # define `class _h `n `n 11 | 12 | `{pub 13 | `{if `class ` 14 | `line `n 15 | `} `{else `n 16 | extern const void * `class ; `n `n 17 | 18 | `{% `%header ; `n `}n 19 | `{%- `%header ; `n `}n 20 | 21 | `}fi 22 | `}n 23 | 24 | # endif `n 25 | -------------------------------------------------------------------------------- /ooc/rep-9/h-R.rep: -------------------------------------------------------------------------------- 1 | // differences from h.rep: 2 | // there is no superclass header to be included 3 | // `root and `metaroot are produced separately; both can have methods 4 | // 5 | // it does not hurt to produce `{%- for `metaroot -- empty 6 | // 7 | % -h // implement -h option for root class 8 | 9 | # ifndef `class _h `n 10 | # define `class _h `n `n 11 | 12 | `{pub 13 | `{if `class ` 14 | `line `n 15 | `} `{else `n 16 | extern const void * `%const `class (void); `n `n 17 | 18 | `{% `%header ; `n `}n 19 | `{%- `%header ; `n `}n 20 | 21 | `}fi 22 | `}n 23 | 24 | # endif `n 25 | -------------------------------------------------------------------------------- /ooc/rep-10/h-R.rep: -------------------------------------------------------------------------------- 1 | // differences from h.rep: 2 | // there is no superclass header to be included 3 | // `root and `metaroot are produced separately; both can have methods 4 | // 5 | // it does not hurt to produce `{%- for `metaroot -- empty 6 | // 7 | % -h // implement -h option for root class 8 | 9 | # ifndef `class _h `n 10 | # define `class _h `n `n 11 | 12 | `{pub 13 | `{if `class ` 14 | `line `n 15 | `} `{else `n 16 | extern const void * `%const `class (void); `n `n 17 | 18 | `{% `%header ; `n `}n 19 | `{%- `%header ; `n `}n 20 | 21 | `}fi 22 | `}n 23 | 24 | # endif `n 25 | -------------------------------------------------------------------------------- /06/makefile: -------------------------------------------------------------------------------- 1 | c = Object.c Point.c Circle.c 2 | h = $(c:.c=.h) 3 | m = any.c points.c circles.c 4 | r = $(c:.c=.r) 5 | t = $(m:.c=) 6 | 7 | any = any.o Object.o 8 | points = points.o Object.o Point.o 9 | circles = circles.o Object.o Point.o Circle.o 10 | 11 | all: $h $r $c $m $t 12 | clean: ; rm -f $t *.o 13 | 14 | test:: any ; any 15 | test:: points ; points p 16 | test:: circles ; circles p c 17 | 18 | any: $(any) ; $(CC) $(CFLAGS) -o $@ $(any) 19 | points: $(points) ; $(CC) $(CFLAGS) -o $@ $(points) 20 | circles: $(circles) ; $(CC) $(CFLAGS) -o $@ $(circles) 21 | 22 | include ../make/Makefile.$(OSTYPE) 23 | -------------------------------------------------------------------------------- /08/makefile: -------------------------------------------------------------------------------- 1 | chapter = -8 2 | 3 | c = Object.c Point.c Circle.c List.c 4 | d = $(c:.c=) 5 | h = $(c:.c=.h) 6 | m = circles.c lists.c 7 | r = $(c:.c=.r) 8 | t = $(m:.c=) 9 | 10 | circles = circles.o Object.o Point.o Circle.o 11 | lists = lists.o Object.o List.o Point.o Circle.o 12 | 13 | all: $t 14 | clean: ; rm -f $c $h $r $t *.o 15 | 16 | test:: circles ; circles p c 17 | test:: lists ;- lists + +c +p . - 1234 18 | test:: lists ;- lists axel 19 | 20 | circles: $(circles) ; $(CC) $(CFLAGS) -o $@ $(circles) 21 | lists: $(lists) ; $(CC) $(CFLAGS) -o $@ $(lists) 22 | 23 | include ../make/Makefile.$(OSTYPE) 24 | -------------------------------------------------------------------------------- /09/makefile: -------------------------------------------------------------------------------- 1 | chapter = -9 2 | 3 | c = Object.c Point.c Circle.c List.c 4 | d = $(c:.c=) 5 | h = $(c:.c=.h) 6 | m = circles.c lists.c 7 | r = $(c:.c=.r) 8 | t = $(m:.c=) 9 | 10 | circles = circles.o Object.o Point.o Circle.o 11 | lists = lists.o Object.o List.o Point.o Circle.o 12 | 13 | all: $t 14 | clean: ; rm -f $c $h $r $t *.o 15 | 16 | test:: circles ; circles p c 17 | test:: lists ;- lists + +c +p . - 1234 18 | test:: lists ;- lists axel 19 | 20 | circles: $(circles) ; $(CC) $(CFLAGS) -o $@ $(circles) 21 | lists: $(lists) ; $(CC) $(CFLAGS) -o $@ $(lists) 22 | 23 | include ../make/Makefile.$(OSTYPE) 24 | -------------------------------------------------------------------------------- /ooc/TBase.d: -------------------------------------------------------------------------------- 1 | // TBase.d -- 5.2 Thu Jan 3 18:47:44 EST 2002 2 | // Copyright (c) 1993 Axel T. Schreiner 3 | // 4 | line 1 class with new meta class 5 | line 2 // comment 6 | % TBaseClass:Class TBase:T { 7 | TBase @ line4; 8 | int line5; 9 | % 10 | int sInt (int i, _self, _v, TBase @ t, const Object @ o, ...); 11 | const TBase @ sTBase (const _self); 12 | %- 13 | void dVoid (int i, _self, _v, TBase @ t, const Object @ o, ...); 14 | const TBase @ dTBase (const _self); 15 | %+ 16 | const int cInt (int i, _self, _v, TBase @ t, const Object @ o, ...); 17 | void cVoid (const _self); 18 | %} 19 | line -2 20 | line -1 21 | -------------------------------------------------------------------------------- /03/makefile: -------------------------------------------------------------------------------- 1 | c = postfix.c value.c infix.c 2 | h = value.h parse.h 3 | m = parse.c 4 | t = postfix value infix 5 | 6 | postfix = parse.o postfix.o 7 | value = parse.o value.o 8 | infix = parse.o infix.o 9 | 10 | all: $t 11 | clean: ; rm -f $t *.o 12 | 13 | test:: postfix ; echo '2 * (3 + 4)' | postfix 14 | test:: value ; echo '2 * (3 + 4)' | value 15 | test:: infix ; echo '2 * (3 + 4)' | infix 16 | 17 | postfix:: $(postfix) ; $(CC) $(CFLAGS) -o $@ $(postfix) 18 | value:: $(value) ; $(CC) $(CFLAGS) -o $@ $(value) 19 | infix:: $(infix) ; $(CC) $(CFLAGS) -o $@ $(infix) 20 | 21 | include ../make/Makefile.$(OSTYPE) 22 | -------------------------------------------------------------------------------- /05/binary.h: -------------------------------------------------------------------------------- 1 | #ifndef BINARY_H 2 | #define BINARY_H 3 | 4 | /* 5 | * binary() 6 | * search and maintain a sorted array 7 | * 8 | * key search argument, passed as first argument to cmp 9 | * if not found, entered as width bytes into table 10 | * base begin of table with *nelp elements of width bytes 11 | * cmp() comparison, must return < == > 0 12 | * 13 | * returns pointer to table entry containing key, e.g., base, base+1... 14 | */ 15 | 16 | #include 17 | 18 | void * binary (const void * key, void * base, size_t * nelp, 19 | size_t width, int (* cmp) (const void * key, const void * elt)); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /11/binary.h: -------------------------------------------------------------------------------- 1 | #ifndef BINARY_H 2 | #define BINARY_H 3 | 4 | /* 5 | * binary() 6 | * search and maintain a sorted array 7 | * 8 | * key search argument, passed as first argument to cmp 9 | * if not found, entered as width bytes into table 10 | * base begin of table with *nelp elements of width bytes 11 | * cmp() comparison, must return < == > 0 12 | * 13 | * returns pointer to table entry containing key, e.g., base, base+1... 14 | */ 15 | 16 | #include 17 | 18 | void * binary (const void * key, void * base, size_t * nelp, 19 | size_t width, int (* cmp) (const void * key, const void * elt)); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /12/binary.h: -------------------------------------------------------------------------------- 1 | #ifndef BINARY_H 2 | #define BINARY_H 3 | 4 | /* 5 | * binary() 6 | * search and maintain a sorted array 7 | * 8 | * key search argument, passed as first argument to cmp 9 | * if not found, entered as width bytes into table 10 | * base begin of table with *nelp elements of width bytes 11 | * cmp() comparison, must return < == > 0 12 | * 13 | * returns pointer to table entry containing key, e.g., base, base+1... 14 | */ 15 | 16 | #include 17 | 18 | void * binary (const void * key, void * base, size_t * nelp, 19 | size_t width, int (* cmp) (const void * key, const void * elt)); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /13/binary.h: -------------------------------------------------------------------------------- 1 | #ifndef BINARY_H 2 | #define BINARY_H 3 | 4 | /* 5 | * binary() 6 | * search and maintain a sorted array 7 | * 8 | * key search argument, passed as first argument to cmp 9 | * if not found, entered as width bytes into table 10 | * base begin of table with *nelp elements of width bytes 11 | * cmp() comparison, must return < == > 0 12 | * 13 | * returns pointer to table entry containing key, e.g., base, base+1... 14 | */ 15 | 16 | #include 17 | 18 | void * binary (const void * key, void * base, size_t * nelp, 19 | size_t width, int (* cmp) (const void * key, const void * elt)); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /ooc/rep-10/r.rep: -------------------------------------------------------------------------------- 1 | % -r // implement -r option 2 | 3 | # ifndef `class _r `n 4 | # define `class _r `n `n 5 | 6 | # include " `super .r" `n `n 7 | 8 | `{prot 9 | `{if `class ` 10 | `line `n 11 | `} `{else `n 12 | struct `class { const struct `super _; `n 13 | `{struct `class 14 | `t `const `type `name ; `n 15 | `} 16 | }; `n `n 17 | 18 | `{if `newmeta 1 19 | 20 | struct `meta { const struct `supermeta _; `n 21 | `{%- `t `%link `n `} 22 | }; `n `n 23 | 24 | `{%- `%super-header ; `n `}n 25 | 26 | `}fi 27 | `}fi 28 | `}n 29 | 30 | # endif `n 31 | -------------------------------------------------------------------------------- /ooc/rep-7/r.rep: -------------------------------------------------------------------------------- 1 | % -r // implement -r option 2 | 3 | # ifndef `class _r `n 4 | # define `class _r `n `n 5 | 6 | # include " `super .r" `n `n 7 | 8 | `{prot 9 | `{if `class ` 10 | `line `n 11 | `} `{else `n 12 | struct `class { const struct `super _; `n 13 | `{struct `class 14 | `t `const `type `name ; `n 15 | `} 16 | }; `n `n 17 | 18 | `{if `newmeta 1 19 | 20 | struct `meta { const struct `supermeta _; `n 21 | `{%- `t `%link `n `} 22 | }; `n `n 23 | 24 | `{%- `%super-header ; `n `}n 25 | 26 | `}fi 27 | `}fi 28 | `}n 29 | 30 | # endif `n 31 | -------------------------------------------------------------------------------- /ooc/rep-8/r.rep: -------------------------------------------------------------------------------- 1 | % -r // implement -r option 2 | 3 | # ifndef `class _r `n 4 | # define `class _r `n `n 5 | 6 | # include " `super .r" `n `n 7 | 8 | `{prot 9 | `{if `class ` 10 | `line `n 11 | `} `{else `n 12 | struct `class { const struct `super _; `n 13 | `{struct `class 14 | `t `const `type `name ; `n 15 | `} 16 | }; `n `n 17 | 18 | `{if `newmeta 1 19 | 20 | struct `meta { const struct `supermeta _; `n 21 | `{%- `t `%link `n `} 22 | }; `n `n 23 | 24 | `{%- `%super-header ; `n `}n 25 | 26 | `}fi 27 | `}fi 28 | `}n 29 | 30 | # endif `n 31 | -------------------------------------------------------------------------------- /ooc/rep-9/r.rep: -------------------------------------------------------------------------------- 1 | % -r // implement -r option 2 | 3 | # ifndef `class _r `n 4 | # define `class _r `n `n 5 | 6 | # include " `super .r" `n `n 7 | 8 | `{prot 9 | `{if `class ` 10 | `line `n 11 | `} `{else `n 12 | struct `class { const struct `super _; `n 13 | `{struct `class 14 | `t `const `type `name ; `n 15 | `} 16 | }; `n `n 17 | 18 | `{if `newmeta 1 19 | 20 | struct `meta { const struct `supermeta _; `n 21 | `{%- `t `%link `n `} 22 | }; `n `n 23 | 24 | `{%- `%super-header ; `n `}n 25 | 26 | `}fi 27 | `}fi 28 | `}n 29 | 30 | # endif `n 31 | -------------------------------------------------------------------------------- /11/makefile: -------------------------------------------------------------------------------- 1 | chapter = -11 2 | 3 | c = Object.c Node.c Symbol.c Symtab.c 4 | d = $(c:.c=) 5 | h = $(c:.c=.h) binary.h parse.h 6 | m = binary.c parse.c 7 | r = $(c:.c=.r) 8 | t = value 9 | 10 | value = parse.o Object.o Node.o Symbol.o Symtab.o binary.o 11 | 12 | all: $t 13 | clean: ; rm -f $c $(c:.c=.h) $r $t *.o 14 | 15 | test:: value ; echo 'let a = sin(1) + PI' | value 16 | test:: value ; { echo 'def sqr = $$ * $$'; \ 17 | echo 'def one = sqr(sin($$)) + sqr(cos($$))'; \ 18 | echo 'one(10)'; } | value reclaim 19 | 20 | value: $(value); $(CC) $(CFLAGS) -o $@ $(value) $(Lm) $(debug) 21 | 22 | include ../make/Makefile.$(OSTYPE) 23 | -------------------------------------------------------------------------------- /06/any.c: -------------------------------------------------------------------------------- 1 | #include "Object.h" 2 | 3 | static int Any_differ (const void * _self, const void * b) 4 | { 5 | return 0; /* Any equals anything... */ 6 | } 7 | 8 | int main () 9 | { void * o = new(Object); 10 | const void * Any = 11 | new(Class, "Any", Object, sizeOf(o), 12 | differ, Any_differ, 13 | 0); 14 | void * a = new(Any); 15 | 16 | puto(Any, stdout); 17 | puto(o, stdout); 18 | puto(a, stdout); 19 | 20 | if (differ(o, o) == differ(a, a)) 21 | puts("ok"); 22 | 23 | if (differ(o, a) != differ(a, o)) 24 | puts("not commutative"); 25 | 26 | delete(o), delete(a); 27 | delete((void*)Any); 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /ooc/rep/h-R.rep: -------------------------------------------------------------------------------- 1 | // differences from h.rep: 2 | // there is no superclass header to be included 3 | // `root and `metaroot are produced separately; both can have methods 4 | // 5 | // it does not hurt to produce `{%- `{%+ for `metaroot -- they are empty 6 | // 7 | % -h // implement -h option for root class 8 | 9 | # ifndef `class _h `n 10 | # define `class _h `n `n 11 | 12 | `{pub 13 | `{if `class ` 14 | `line `n 15 | `} `{else `n 16 | extern const void * `%const `class (void); `n `n 17 | 18 | `{% `%header ; `n `}n 19 | `{%- `%header ; `n `}n 20 | `{%+ `%header ; `n `}n 21 | 22 | `}fi 23 | `}n 24 | 25 | # endif `n 26 | -------------------------------------------------------------------------------- /ooc/rep-11/h-R.rep: -------------------------------------------------------------------------------- 1 | // differences from h.rep: 2 | // there is no superclass header to be included 3 | // `root and `metaroot are produced separately; both can have methods 4 | // 5 | // it does not hurt to produce `{%- `{%+ for `metaroot -- they are empty 6 | // 7 | % -h // implement -h option for root class 8 | 9 | # ifndef `class _h `n 10 | # define `class _h `n `n 11 | 12 | `{pub 13 | `{if `class ` 14 | `line `n 15 | `} `{else `n 16 | extern const void * `%const `class (void); `n `n 17 | 18 | `{% `%header ; `n `}n 19 | `{%- `%header ; `n `}n 20 | `{%+ `%header ; `n `}n 21 | 22 | `}fi 23 | `}n 24 | 25 | # endif `n 26 | -------------------------------------------------------------------------------- /13/except.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "Exception.h" 4 | 5 | int main () 6 | { void * a = new(Exception()), * b = new(Exception()); 7 | 8 | cause(-1); puts("caused -1"); 9 | 10 | switch (catch(a)) { 11 | case 0: 12 | switch (catch(b)) { 13 | case 0: 14 | cause(1); assert(0); 15 | case 1: 16 | puts("caused 1"); 17 | cause(2); assert(0); 18 | case 2: 19 | puts("caused 2"); 20 | delete(b); 21 | cause(3); assert(0); 22 | default: 23 | assert(0); 24 | } 25 | case 3: 26 | puts("caused 3"); 27 | delete(a); 28 | cause(4); 29 | break; 30 | default: 31 | assert(0); 32 | } 33 | puts("caused 4"); 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /10/depend: -------------------------------------------------------------------------------- 1 | Object.o: Object.c Object.h Object.r 2 | Filter.o: Filter.c Filter.h Object.h Filter.r Object.r 3 | Cmd.o: Cmd.c Cmd.h Object.h Filter.h Cmd.r Object.r 4 | Wc.o: Wc.c Wc.h Object.h Wc.r Object.r Filter.h 5 | String.o: String.c String.h Object.h String.r Object.r 6 | List.o: List.c List.h Object.h List.r Object.r 7 | Sort.o: Sort.c Sort.h List.h Object.h Sort.r List.r Object.r Filter.h \ 8 | String.h 9 | Filter.d: Object.d 10 | Cmd.d: Object.d 11 | Wc.d: Object.d 12 | String.d: Object.d 13 | List.d: Object.d 14 | Sort.d: List.d 15 | Object.c: Object.d 16 | Filter.c: Filter.d 17 | Cmd.c: Cmd.d 18 | Wc.c: Wc.d 19 | String.c: String.d 20 | List.c: List.d 21 | Sort.c: Sort.d 22 | -------------------------------------------------------------------------------- /04/Circle.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "Circle.h" 4 | #include "Circle.r" 5 | #include "new.h" 6 | #include "new.r" 7 | 8 | static void * Circle_ctor (void * _self, va_list * app) 9 | { struct Circle * self = 10 | ((const struct Class *) Point) -> ctor(_self, app); 11 | 12 | self -> rad = va_arg(* app, int); 13 | return self; 14 | } 15 | 16 | static void Circle_draw (const void * _self) 17 | { const struct Circle * self = _self; 18 | 19 | printf("circle at %d,%d rad %d\n", 20 | x(self), y(self), self -> rad); 21 | } 22 | 23 | static const struct Class _Circle = { 24 | sizeof(struct Circle), Circle_ctor, 0, Circle_draw 25 | }; 26 | 27 | const void * Circle = & _Circle; 28 | -------------------------------------------------------------------------------- /man/man3/intro.3: -------------------------------------------------------------------------------- 1 | .\" intro.3 -- 1.4 Sep 26 17:49:41 1993 2 | .\" Copyright (c) 1993 Axel T. Schreiner 3 | .TH intro 3 "local: ats" 4 | .SH NAME 5 | intro \(em introduction to the root classes 6 | .SH SYNOPSIS 7 | .nf 8 | .ta 30n 9 | Object Class 10 | Exception 11 | .fi 12 | .SH DESCRIPTION 13 | .BR Object (3) 14 | is the root class; 15 | .BR Class (3) 16 | is the root metaclass. 17 | Most of the methods defined for 18 | .B Object 19 | are used in the standard reports for 20 | .IR ooc (1), 21 | i.e., 22 | they cannot be changed without changing the reports. 23 | .PP 24 | .BR Exception (3) 25 | manages a stack of exception handlers. 26 | This class is not mandatory for working with 27 | .IR ooc . 28 | -------------------------------------------------------------------------------- /ooc/rep/r.rep: -------------------------------------------------------------------------------- 1 | % -r // implement -r option 2 | 3 | # ifndef `class _r `n 4 | # define `class _r `n `n 5 | 6 | # include " `super .r" `n `n 7 | 8 | `{prot 9 | `{if `class ` 10 | `line `n 11 | `} `{else `n 12 | struct `class { const struct `super _; `n 13 | `{struct `class 14 | `t `const `type `name ; `n 15 | `} 16 | }; `n `n 17 | 18 | `{if `newmeta 1 19 | 20 | struct `meta { const struct `supermeta _; `n 21 | `{%- `t `%link `n `} 22 | `{%+ `t `%link `n `} 23 | }; `n `n 24 | 25 | `{%- `%super-header ; `n `}n 26 | `{%+ `%super-header ; `n `}n 27 | 28 | `}fi 29 | `}fi 30 | `}n 31 | 32 | # endif `n 33 | -------------------------------------------------------------------------------- /10/makefile: -------------------------------------------------------------------------------- 1 | chapter = -10 2 | 3 | c = Object.c Filter.c Cmd.c Wc.c String.c List.c Sort.c 4 | d = $(c:.c=) 5 | h = $(c:.c=.h) 6 | r = $(c:.c=.r) 7 | t = cmd wc sort 8 | 9 | cmd = Object.o Filter.o Cmd.o 10 | wc = Object.o Filter.o Wc.o 11 | sort = Object.o Filter.o String.o List.o Sort.o 12 | 13 | all: $t 14 | clean: ; rm -f $c $h $r $t *.o 15 | 16 | test:: cmd ; cmd -fffv10 -- -f filename 17 | test:: wc ; cat Wc.dc | wc - Wc.dc none-such 18 | test:: sort ; cat Sort.d | sort -r - Sort.d 19 | 20 | cmd: $(cmd) ; $(CC) $(CFLAGS) -o $@ $(cmd) 21 | wc: $(wc) ; $(CC) $(CFLAGS) -o $@ $(wc) 22 | sort: $(sort) ; $(CC) $(CFLAGS) -o $@ $(sort) 23 | 24 | include ../make/Makefile.$(OSTYPE) 25 | -------------------------------------------------------------------------------- /ooc/rep-11/r.rep: -------------------------------------------------------------------------------- 1 | % -r // implement -r option 2 | 3 | # ifndef `class _r `n 4 | # define `class _r `n `n 5 | 6 | # include " `super .r" `n `n 7 | 8 | `{prot 9 | `{if `class ` 10 | `line `n 11 | `} `{else `n 12 | struct `class { const struct `super _; `n 13 | `{struct `class 14 | `t `const `type `name ; `n 15 | `} 16 | }; `n `n 17 | 18 | `{if `newmeta 1 19 | 20 | struct `meta { const struct `supermeta _; `n 21 | `{%- `t `%link `n `} 22 | `{%+ `t `%link `n `} 23 | }; `n `n 24 | 25 | `{%- `%super-header ; `n `}n 26 | `{%+ `%super-header ; `n `}n 27 | 28 | `}fi 29 | `}fi 30 | `}n 31 | 32 | # endif `n 33 | -------------------------------------------------------------------------------- /06/Object.h: -------------------------------------------------------------------------------- 1 | #ifndef OBJECT_H 2 | #define OBJECT_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | extern const void * Object; /* new(Object); */ 9 | 10 | void * new (const void * class, ...); 11 | void delete (void * self); 12 | 13 | const void * classOf (const void * self); 14 | size_t sizeOf (const void * self); 15 | 16 | void * ctor (void * self, va_list * app); 17 | void * dtor (void * self); 18 | int differ (const void * self, const void * b); 19 | int puto (const void * self, FILE * fp); 20 | 21 | extern const void * Class; /* new(Class, "name", super, size 22 | sel, meth, ... 0); */ 23 | 24 | const void * super (const void * self); /* class' superclass */ 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /10/Cmd.dc: -------------------------------------------------------------------------------- 1 | % Cmd flag { 2 | const char * value; 3 | %casts 4 | assert((flagM) flag == flag); 5 | 6 | switch (flg) { 7 | case 'f': 8 | puts("-f"); 9 | break; 10 | case 'v': 11 | if ((value = argval(filter))) 12 | printf("-v \"%s\"\n", value); 13 | else 14 | puts("-v NULL"); 15 | break; 16 | default: 17 | fprintf(stderr, "%s: unknown flag '%c'\n", 18 | progname(filter), flg); 19 | } 20 | } 21 | 22 | % Cmd name { 23 | %casts 24 | assert((nameM) name == name); 25 | 26 | if (arg) 27 | printf("name \"%s\"\n", arg); 28 | else 29 | puts("name NULL"); 30 | return 0; 31 | } 32 | 33 | %init 34 | 35 | int main (int argc, char * argv []) 36 | { void * filter = new(Filter(), new(Cmd())); 37 | 38 | return mainLoop(filter, argv); 39 | } 40 | -------------------------------------------------------------------------------- /07/List.d: -------------------------------------------------------------------------------- 1 | // new(List, minimal-dimension) 2 | 3 | % ListClass: Class List: Object { 4 | const void ** buf; // const void * buf [dim] 5 | unsigned dim; // current buffer dimension 6 | unsigned count; // # elements in buffer 7 | unsigned begin; // index of takeFirst slot, 0..dim 8 | unsigned end; // index of addLast slot, 0..dim 9 | % 10 | Object @ addFirst (_self, const Object @ element); 11 | Object @ addLast (_self, const Object @ element); 12 | unsigned count (const _self); 13 | Object @ lookAt (const _self, unsigned n); 14 | Object @ takeFirst (_self); 15 | Object @ takeLast (_self); 16 | %- // abstract, for Queue/Stack 17 | Object @ add (_self, const Object @ element); 18 | Object @ take (_self); 19 | %} 20 | -------------------------------------------------------------------------------- /08/List.d: -------------------------------------------------------------------------------- 1 | // new(List, minimal-dimension) 2 | 3 | % ListClass: Class List: Object { 4 | const void ** buf; // const void * buf [dim] 5 | unsigned dim; // current buffer dimension 6 | unsigned count; // # elements in buffer 7 | unsigned begin; // index of takeFirst slot, 0..dim 8 | unsigned end; // index of addLast slot, 0..dim 9 | % 10 | Object @ addFirst (_self, const Object @ element); 11 | Object @ addLast (_self, const Object @ element); 12 | unsigned count (const _self); 13 | Object @ lookAt (const _self, unsigned n); 14 | Object @ takeFirst (_self); 15 | Object @ takeLast (_self); 16 | %- // abstract, for Queue/Stack 17 | Object @ add (_self, const Object @ element); 18 | Object @ take (_self); 19 | %} 20 | -------------------------------------------------------------------------------- /09/List.d: -------------------------------------------------------------------------------- 1 | // new(List(), minimal-dimension) 2 | 3 | % ListClass: Class List: Object { 4 | const void ** buf; // const void * buf [dim] 5 | unsigned dim; // current buffer dimension 6 | unsigned count; // # elements in buffer 7 | unsigned begin; // index of takeFirst slot, 0..dim 8 | unsigned end; // index of addLast slot, 0..dim 9 | % 10 | Object @ addFirst (_self, const Object @ element); 11 | Object @ addLast (_self, const Object @ element); 12 | unsigned count (const _self); 13 | Object @ lookAt (const _self, unsigned n); 14 | Object @ takeFirst (_self); 15 | Object @ takeLast (_self); 16 | %- // abstract, for Queue/Stack 17 | Object @ add (_self, const Object @ element); 18 | Object @ take (_self); 19 | %} 20 | -------------------------------------------------------------------------------- /13/List.d: -------------------------------------------------------------------------------- 1 | // new(List(), minimal-dimension) 2 | 3 | % ListClass: Class List: Object { 4 | const void ** buf; // const void * buf [dim] 5 | unsigned dim; // current buffer dimension 6 | unsigned count; // # elements in buffer 7 | unsigned begin; // index of takeFirst slot, 0..dim 8 | unsigned end; // index of addLast slot, 0..dim 9 | % 10 | Object @ addFirst (_self, const Object @ element); 11 | Object @ addLast (_self, const Object @ element); 12 | unsigned count (const _self); 13 | Object @ lookAt (const _self, unsigned n); 14 | Object @ takeFirst (_self); 15 | Object @ takeLast (_self); 16 | %- // abstract, for Queue/Stack 17 | Object @ add (_self, const Object @ element); 18 | Object @ take (_self); 19 | %} 20 | -------------------------------------------------------------------------------- /14/List.d: -------------------------------------------------------------------------------- 1 | // new(List(), minimal-dimension) 2 | 3 | % ListClass: Class List: Object { 4 | const void ** buf; // const void * buf [dim] 5 | unsigned dim; // current buffer dimension 6 | unsigned count; // # elements in buffer 7 | unsigned begin; // index of takeFirst slot, 0..dim 8 | unsigned end; // index of addLast slot, 0..dim 9 | % 10 | Object @ addFirst (_self, const Object @ element); 11 | Object @ addLast (_self, const Object @ element); 12 | unsigned count (const _self); 13 | Object @ lookAt (const _self, unsigned n); 14 | Object @ takeFirst (_self); 15 | Object @ takeLast (_self); 16 | %- // abstract, for Queue/Stack 17 | Object @ add (_self, const Object @ element); 18 | Object @ take (_self); 19 | %} 20 | -------------------------------------------------------------------------------- /04/Point.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "Point.h" 4 | #include "Point.r" 5 | #include "new.h" 6 | #include "new.r" 7 | 8 | static void * Point_ctor (void * _self, va_list * app) 9 | { struct Point * self = _self; 10 | 11 | self -> x = va_arg(* app, int); 12 | self -> y = va_arg(* app, int); 13 | return self; 14 | } 15 | 16 | static void Point_draw (const void * _self) 17 | { const struct Point * self = _self; 18 | 19 | printf("\".\" at %d,%d\n", self -> x, self -> y); 20 | } 21 | 22 | static const struct Class _Point = { 23 | sizeof(struct Point), Point_ctor, 0, Point_draw 24 | }; 25 | 26 | const void * Point = & _Point; 27 | 28 | void move (void * _self, int dx, int dy) 29 | { struct Point * self = _self; 30 | 31 | self -> x += dx, self -> y += dy; 32 | } 33 | -------------------------------------------------------------------------------- /10/String.dc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | % String ctor { 5 | struct String * self = super_ctor(String(), _self, app); 6 | const char * text = va_arg(* app, const char *); 7 | 8 | self -> text = malloc(strlen(text) + 1); 9 | assert(self -> text); 10 | strcpy((char *) self -> text, text); 11 | return self; 12 | } 13 | 14 | % String dtor { 15 | %casts 16 | free((void *) self -> text), self -> text = 0; 17 | return super_dtor(String(), self); 18 | } 19 | 20 | % String puto { 21 | %casts 22 | return fputs(self -> text, fp); 23 | } 24 | 25 | % String differ { 26 | struct String * self = cast(String(), _self); 27 | struct String * sp = cast(String(), b); 28 | 29 | return self == sp ? 0 : strcmp(self -> text, sp -> text); 30 | } 31 | 32 | %init 33 | -------------------------------------------------------------------------------- /man/man2/retrieve.2: -------------------------------------------------------------------------------- 1 | .\" retrieve.2 -- 1.2 Sep 26 17:45:29 1993 2 | .\" Copyright (c) 1993 Axel T. Schreiner 3 | .TH retrieve 2 "local: ats" 4 | .SH NAME 5 | retrieve \(em get object from file 6 | .SH SYNOPSIS 7 | .BI "void * retrieve (FILE * " fp ) 8 | .SH DESCRIPTION 9 | .B retrieve() 10 | returns an object read in from the input stream represented by 11 | .IR fp . 12 | At end of file or in case of an error, 13 | .B retrieve() 14 | returns a null pointer. 15 | .PP 16 | .B retrieve() 17 | requires a sorted table of class function pointers 18 | that can be produced with 19 | .IR munch (1). 20 | Once the class description has been located, 21 | .B retrieve() 22 | applies the method 23 | .B geto 24 | to an area obtained with 25 | .BR allocate . 26 | .SH SEE ALSO 27 | munch(1), Object(3) 28 | -------------------------------------------------------------------------------- /06/Circle.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "Circle.h" 4 | #include "Circle.r" 5 | 6 | static void * Circle_ctor (void * _self, va_list * app) 7 | { struct Circle * self = super_ctor(Circle, _self, app); 8 | 9 | self -> rad = va_arg(* app, int); 10 | return self; 11 | } 12 | 13 | static void Circle_draw (const void * _self) 14 | { const struct Circle * self = _self; 15 | 16 | printf("circle at %d,%d rad %d\n", 17 | x(self), y(self), self -> rad); 18 | } 19 | 20 | /* 21 | * initialization 22 | */ 23 | 24 | const void * Circle; 25 | 26 | void initCircle (void) 27 | { 28 | if (! Circle) 29 | { initPoint(); 30 | Circle = new(PointClass, "Circle", 31 | Point, sizeof(struct Circle), 32 | ctor, Circle_ctor, 33 | draw, Circle_draw, 34 | 0); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /07/depend: -------------------------------------------------------------------------------- 1 | Object.o: Object.c Object.h Object.r 2 | Point.o: Point.c Point.h Object.h Point.r Object.r 3 | Circle.o: Circle.c Circle.h Point.h Object.h Circle.r Point.r Object.r 4 | List.o: List.c List.h Object.h List.r Object.r 5 | Queue.o: Queue.c Queue.h List.h Object.h Queue.r List.r Object.r 6 | Stack.o: Stack.c Stack.h List.h Object.h Stack.r List.r Object.r 7 | points.o: points.c Point.h Object.h 8 | circles.o: circles.c Circle.h Point.h Object.h 9 | queues.o: queues.c Queue.h List.h Object.h 10 | stacks.o: stacks.c Stack.h List.h Object.h 11 | Point.d: Object.d 12 | Circle.d: Point.d 13 | List.d: Object.d 14 | Queue.d: List.d 15 | Stack.d: List.d 16 | Object.c: Object.d 17 | Point.c: Point.d 18 | Circle.c: Circle.d 19 | List.c: List.d 20 | Queue.c: Queue.d 21 | Stack.c: Stack.d 22 | -------------------------------------------------------------------------------- /14/run.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "Ic.h" 4 | 5 | int main () 6 | { void * calc = new(Calc()); 7 | void * lineOut = new(LineOut()); 8 | void * mux = new(Mux()); 9 | static const char * const cmd [] = { "C", "Q", 10 | "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", 11 | "+", "-", "*", "/", "=", 0 }; 12 | const char * const * cpp; 13 | int ch; 14 | 15 | wire(lineOut, calc); 16 | for (cpp = cmd; * cpp; ++ cpp) 17 | { void * button = new(Button(), * cpp); 18 | 19 | wire(calc, button), wire(button, mux); 20 | } 21 | 22 | while ((ch = getchar()) != EOF) 23 | if (! isspace(ch)) 24 | { static char buf [2]; 25 | void * event; 26 | 27 | buf[0] = ch; 28 | gate(mux, event = new(Event(), 0, buf)); 29 | delete(event); 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /14/Crt.d: -------------------------------------------------------------------------------- 1 | // new(Crt()) 2 | // wraps a curses window, gate(crt, 0) produces events 3 | 4 | // new(CLineOut(), y, x, len) 5 | // LineOut, located at y, x, with line length len 6 | 7 | // new(CButton(), "text", y, x) 8 | // Button, located at y, x, sized for "text" 9 | 10 | % IcClass Crt: Ic { 11 | void * window; // curses WINDOW 12 | int rows; // size 13 | int cols; 14 | % 15 | void makeWindow (_self, int rows, int cols, int y, int x); 16 | void addStr(_self, int y, int x, const char * s); 17 | void crtBox(_self); 18 | %} 19 | 20 | %prot 21 | #define rows(c) (((const struct Crt *) c) -> rows) 22 | #define cols(c) (((const struct Crt *) c) -> cols) 23 | 24 | % IcClass CLineOut: Crt { 25 | %} 26 | 27 | % IcClass CButton: Crt { 28 | void * button; 29 | int y; 30 | int x; 31 | %} 32 | -------------------------------------------------------------------------------- /14/xbutton.c: -------------------------------------------------------------------------------- 1 | #include "Ic.h" 2 | #include "Xt.h" 3 | 4 | int main (int argc, char * argv []) 5 | { void * shell = new(XtApplicationShell(), & argc, argv); 6 | void * box = new(XawBox(), shell, 0); 7 | void * composite = new(XawBox(), box, 0); 8 | void * lineOut = new(XLineOut(), composite, 0, "-long-"); 9 | void * button = new(XButton(), composite, 0, "a"); 10 | 11 | wire(lineOut, button); 12 | puto(button, stdout); /* Box will move its children */ 13 | 14 | composite = new(XawForm(), box, "form"); 15 | lineOut = new(XLineOut(), composite,"lineOut", "-long-"); 16 | button = new(XButton(), composite, "button", "b"); 17 | 18 | wire(lineOut, button); 19 | puto(button, stdout); /* Form won't move its children */ 20 | 21 | mainLoop(shell); 22 | return 0; /* dummy */ 23 | } 24 | -------------------------------------------------------------------------------- /10/List.d: -------------------------------------------------------------------------------- 1 | // new(List(), minimal-dimension) 2 | 3 | % ListClass: Class List: Object { 4 | const void ** buf; // const void * buf [dim] 5 | unsigned dim; // current buffer dimension 6 | unsigned count; // # elements in buffer 7 | unsigned begin; // index of takeFirst slot, 0..dim 8 | unsigned end; // index of addLast slot, 0..dim 9 | % 10 | Object @ addFirst (_self, const Object @ element); 11 | Object @ addLast (_self, const Object @ element); 12 | unsigned count (const _self); 13 | Object @ lookAt (const _self, unsigned n); 14 | Object @ takeFirst (_self); 15 | Object @ takeLast (_self); 16 | void sort (_self); 17 | %- // abstract, for Queue/Stack 18 | Object @ add (_self, const Object @ element); 19 | Object @ take (_self); 20 | %} 21 | -------------------------------------------------------------------------------- /man/whatis.db: -------------------------------------------------------------------------------- 1 | Class(3), f3Class Class: Object(3) - root metaclass 2 | Crt(4), f3IcClass(4) - Crt: Ic input/output objects for curses 3 | Event(4), f3Class(4) - Event: Objct input item 4 | Exception(3), f3Class(3) - Exception: Object manage a stack of exception handlers 5 | Ic(4), f3IcClass:(4) - Class Ic: Objct basic input/output/transput objects 6 | Object(3), f3Class(3) - Object root class 7 | Xt(4), f3Class(4) - Xt: Object input/output objects for X11 8 | intro(3) - introduction to the root classes 9 | intro(4) - introduction to the calculator application 10 | munch(1) - produce class list 11 | ooc(1) - preprocessor for object-oriented coding in *(AC 12 | retrieve(2) - get object from file 13 | -------------------------------------------------------------------------------- /04/new.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "new.h" 5 | #include "new.r" 6 | 7 | void * new (const void * _class, ...) 8 | { const struct Class * class = _class; 9 | void * p = calloc(1, class -> size); 10 | 11 | assert(p); 12 | * (const struct Class **) p = class; 13 | 14 | if (class -> ctor) 15 | { va_list ap; 16 | 17 | va_start(ap, _class); 18 | p = class -> ctor(p, & ap); 19 | va_end(ap); 20 | } 21 | return p; 22 | } 23 | 24 | void delete (void * self) 25 | { const struct Class ** cp = self; 26 | 27 | if (self && * cp && (* cp) -> dtor) 28 | self = (* cp) -> dtor(self); 29 | free(self); 30 | } 31 | 32 | void draw (const void * self) 33 | { const struct Class * const * cp = self; 34 | 35 | assert(self && * cp && (* cp) -> draw); 36 | (* cp) -> draw(self); 37 | } 38 | -------------------------------------------------------------------------------- /13/depend: -------------------------------------------------------------------------------- 1 | Object.o: Object.c Object.h Object.r 2 | List.o: List.c List.h Object.h List.r Object.r 3 | Exception.o: Exception.c Exception.h Object.h Exception.r Object.r List.h 4 | Node.o: Node.c Node.h Object.h Node.r Object.r parse.h Symbol.h 5 | Symbol.o: Symbol.c Symbol.h Object.h Symbol.r Object.r parse.h Node.h 6 | Symtab.o: Symtab.c Symtab.h Object.h Symtab.r Object.r binary.h Symbol.h \ 7 | Exception.h 8 | except.o: except.c Exception.h Object.h 9 | binary.o: binary.c binary.h 10 | parse.o: parse.c parse.h Exception.h Object.h Node.h Symbol.h Symtab.h 11 | List.d: Object.d 12 | Exception.d: Object.d 13 | Node.d: Object.d 14 | Symbol.d: Object.d 15 | Symtab.d: Object.d 16 | Object.c: Object.d 17 | List.c: List.d 18 | Exception.c: Exception.d 19 | Node.c: Node.d 20 | Symbol.c: Symbol.d 21 | Symtab.c: Symtab.d 22 | -------------------------------------------------------------------------------- /man/man4/Event.4: -------------------------------------------------------------------------------- 1 | .\" Event.4 -- 1.2 Sep 30 06:37:40 1993 2 | .\" Copyright (c) 1993 Axel T. Schreiner 3 | .TH Event 4 "local: ats" 4 | .SH NAME 5 | \f3Class Event: Objct\fP \(em input item 6 | .SH SYNOPSIS 7 | .nf 8 | Objct 9 | \f3Event\fP 10 | .sp .5 11 | .BI "new(Event(), " kind ", " data ); 12 | .sp .5 13 | .BI "int kind (" self ) 14 | .BI "void * data (" self ) 15 | .fi 16 | .SH DESCRIPTION 17 | An 18 | .B Event 19 | object represents an input item 20 | such as a piece of text, a mouse click, etc. 21 | .PP 22 | .I kind 23 | is zero if 24 | .I data 25 | is a static string. 26 | .I kind 27 | is not zero if 28 | .I data 29 | is a pointer. 30 | In particular, 31 | a mouse click can be represented with 32 | .I kind 33 | 1 and 34 | .I data 35 | pointing to an array with two integer coordinates. 36 | .SH SEE ALSO 37 | Ic(4) 38 | -------------------------------------------------------------------------------- /13/Exception.dc: -------------------------------------------------------------------------------- 1 | #include "List.h" 2 | 3 | static void * stack; 4 | 5 | % Exception ctor { 6 | void * self = super_ctor(Exception(), _self, app); 7 | 8 | if (! stack) 9 | stack = new(List(), 10); 10 | addLast(stack, self); 11 | return self; 12 | } 13 | 14 | % Exception dtor { 15 | void * top; 16 | %casts 17 | assert(stack); 18 | top = takeLast(stack); 19 | assert(top == self); 20 | return super_dtor(Exception(), self); 21 | } 22 | 23 | % catchException { 24 | %casts 25 | self -> armed = 1; 26 | return self -> label; 27 | } 28 | 29 | void cause (int number) { 30 | unsigned cnt; 31 | 32 | if (number && stack && (cnt = count(stack))) 33 | { void * top = lookAt(stack, cnt-1); 34 | struct Exception * e = cast(Exception(), top); 35 | 36 | if (e -> armed) 37 | longjmp(e -> label, number); 38 | } 39 | } 40 | 41 | %init 42 | -------------------------------------------------------------------------------- /ooc/rep-10/r-R.rep: -------------------------------------------------------------------------------- 1 | // differences from r.rep: 2 | // there is no superclass header to include 3 | // we generate `root and `metaroot at % root in `{dcl, because 4 | // we explicitely insert the `root `{%- into struct `metaroot 5 | // 6 | % -r // implement -r option for root class 7 | 8 | # ifndef `class _r `n 9 | # define `class _r `n `n 10 | 11 | `{prot 12 | `{if `class ` 13 | `line `n 14 | `} `{else `{if `class `root `n 15 | struct `root { `n 16 | `{struct `root 17 | `t `const `type `name ; `n 18 | `} 19 | }; `n `n 20 | 21 | struct `metaroot { struct `root _; `n 22 | `{struct `metaroot 23 | `t `const `type `name ; `n 24 | `}n 25 | 26 | `{%- `t `%link `n `} 27 | }; `n `n 28 | 29 | `{%- `%super-header ; `n `}n 30 | 31 | `}fi `}fi 32 | `}n 33 | 34 | # endif `n 35 | -------------------------------------------------------------------------------- /ooc/rep-7/r-R.rep: -------------------------------------------------------------------------------- 1 | // differences from r.rep: 2 | // there is no superclass header to include 3 | // we generate `root and `metaroot at % root in `{dcl, because 4 | // we explicitely insert the `root `{%- into struct `metaroot 5 | // 6 | % -r // implement -r option for root class 7 | 8 | # ifndef `class _r `n 9 | # define `class _r `n `n 10 | 11 | `{prot 12 | `{if `class ` 13 | `line `n 14 | `} `{else `{if `class `root `n 15 | struct `root { `n 16 | `{struct `root 17 | `t `const `type `name ; `n 18 | `} 19 | }; `n `n 20 | 21 | struct `metaroot { struct `root _; `n 22 | `{struct `metaroot 23 | `t `const `type `name ; `n 24 | `}n 25 | 26 | `{%- `t `%link `n `} 27 | }; `n `n 28 | 29 | `{%- `%super-header ; `n `}n 30 | 31 | `}fi `}fi 32 | `}n 33 | 34 | # endif `n 35 | -------------------------------------------------------------------------------- /ooc/rep-8/r-R.rep: -------------------------------------------------------------------------------- 1 | // differences from r.rep: 2 | // there is no superclass header to include 3 | // we generate `root and `metaroot at % root in `{dcl, because 4 | // we explicitely insert the `root `{%- into struct `metaroot 5 | // 6 | % -r // implement -r option for root class 7 | 8 | # ifndef `class _r `n 9 | # define `class _r `n `n 10 | 11 | `{prot 12 | `{if `class ` 13 | `line `n 14 | `} `{else `{if `class `root `n 15 | struct `root { `n 16 | `{struct `root 17 | `t `const `type `name ; `n 18 | `} 19 | }; `n `n 20 | 21 | struct `metaroot { struct `root _; `n 22 | `{struct `metaroot 23 | `t `const `type `name ; `n 24 | `}n 25 | 26 | `{%- `t `%link `n `} 27 | }; `n `n 28 | 29 | `{%- `%super-header ; `n `}n 30 | 31 | `}fi `}fi 32 | `}n 33 | 34 | # endif `n 35 | -------------------------------------------------------------------------------- /ooc/rep-9/r-R.rep: -------------------------------------------------------------------------------- 1 | // differences from r.rep: 2 | // there is no superclass header to include 3 | // we generate `root and `metaroot at % root in `{dcl, because 4 | // we explicitely insert the `root `{%- into struct `metaroot 5 | // 6 | % -r // implement -r option for root class 7 | 8 | # ifndef `class _r `n 9 | # define `class _r `n `n 10 | 11 | `{prot 12 | `{if `class ` 13 | `line `n 14 | `} `{else `{if `class `root `n 15 | struct `root { `n 16 | `{struct `root 17 | `t `const `type `name ; `n 18 | `} 19 | }; `n `n 20 | 21 | struct `metaroot { struct `root _; `n 22 | `{struct `metaroot 23 | `t `const `type `name ; `n 24 | `}n 25 | 26 | `{%- `t `%link `n `} 27 | }; `n `n 28 | 29 | `{%- `%super-header ; `n `}n 30 | 31 | `}fi `}fi 32 | `}n 33 | 34 | # endif `n 35 | -------------------------------------------------------------------------------- /05/binary.c: -------------------------------------------------------------------------------- 1 | /* 2 | * binary() 3 | * search and maintain a sorted array 4 | */ 5 | 6 | #include 7 | #include "binary.h" 8 | 9 | void * binary (const void * key, 10 | void * _base, size_t * nelp, size_t width, 11 | int (* cmp) (const void * key, const void * elt)) 12 | { size_t nel = * nelp; 13 | #define base (* (char **) & _base) 14 | char * lim = base + nel * width, * high; 15 | 16 | if (nel > 0) 17 | { for (high = lim - width; base <= high; nel >>= 1) 18 | { char * mid = base + (nel >> 1) * width; 19 | int c = cmp(key, mid); 20 | 21 | if (c < 0) 22 | high = mid - width; 23 | else if (c > 0) 24 | base = mid + width, -- nel; 25 | else 26 | return (void *) mid; 27 | } 28 | memmove(base + width, base, lim - base); 29 | } 30 | ++ *nelp; 31 | return memcpy(base, key, width); 32 | #undef base 33 | } 34 | -------------------------------------------------------------------------------- /11/binary.c: -------------------------------------------------------------------------------- 1 | /* 2 | * binary() 3 | * search and maintain a sorted array 4 | */ 5 | 6 | #include 7 | #include "binary.h" 8 | 9 | void * binary (const void * key, 10 | void * _base, size_t * nelp, size_t width, 11 | int (* cmp) (const void * key, const void * elt)) 12 | { size_t nel = * nelp; 13 | #define base (* (char **) & _base) 14 | char * lim = base + nel * width, * high; 15 | 16 | if (nel > 0) 17 | { for (high = lim - width; base <= high; nel >>= 1) 18 | { char * mid = base + (nel >> 1) * width; 19 | int c = cmp(key, mid); 20 | 21 | if (c < 0) 22 | high = mid - width; 23 | else if (c > 0) 24 | base = mid + width, -- nel; 25 | else 26 | return (void *) mid; 27 | } 28 | memmove(base + width, base, lim - base); 29 | } 30 | ++ *nelp; 31 | return memcpy(base, key, width); 32 | #undef base 33 | } 34 | -------------------------------------------------------------------------------- /12/binary.c: -------------------------------------------------------------------------------- 1 | /* 2 | * binary() 3 | * search and maintain a sorted array 4 | */ 5 | 6 | #include 7 | #include "binary.h" 8 | 9 | void * binary (const void * key, 10 | void * _base, size_t * nelp, size_t width, 11 | int (* cmp) (const void * key, const void * elt)) 12 | { size_t nel = * nelp; 13 | #define base (* (char **) & _base) 14 | char * lim = base + nel * width, * high; 15 | 16 | if (nel > 0) 17 | { for (high = lim - width; base <= high; nel >>= 1) 18 | { char * mid = base + (nel >> 1) * width; 19 | int c = cmp(key, mid); 20 | 21 | if (c < 0) 22 | high = mid - width; 23 | else if (c > 0) 24 | base = mid + width, -- nel; 25 | else 26 | return (void *) mid; 27 | } 28 | memmove(base + width, base, lim - base); 29 | } 30 | ++ *nelp; 31 | return memcpy(base, key, width); 32 | #undef base 33 | } 34 | -------------------------------------------------------------------------------- /12/makefile: -------------------------------------------------------------------------------- 1 | chapter = -11 2 | 3 | c = Object.c Node.c Symbol.c Symtab.c 4 | d = $(c:.c=) 5 | h = $(c:.c=.h) binary.h parse.h 6 | m = binary.c parse.c 7 | r = $(c:.c=.r) 8 | t = value 9 | 10 | value = parse.o Object.o Node.o Symbol.o Symtab.o binary.o 11 | 12 | all: $t 13 | clean: ; rm -f $c $(c:.c=.h) $r $t classes.? *.stb *.o 14 | rm -rf *.dSYM 15 | 16 | test:: value ; echo 'let a = sin(1) + PI' | value 17 | test:: value ; { echo 'def sqr = $$ * $$'; \ 18 | echo 'def one = sqr(sin($$)) + sqr(cos($$))'; \ 19 | echo 'let n = one(10)'; \ 20 | echo save; } | value 21 | test:: value ; { echo load; \ 22 | echo 'n + one(20)'; } | value 23 | 24 | value: $(value); nm -p $(value) | $(AWK) -f ../09/munch > classes.c 25 | $(CC) $(CFLAGS) -o $@ $(value) classes.c $(Lm) $(debug) 26 | 27 | include ../make/Makefile.$(OSTYPE) 28 | -------------------------------------------------------------------------------- /13/binary.c: -------------------------------------------------------------------------------- 1 | /* 2 | * binary() 3 | * search and maintain a sorted array 4 | */ 5 | 6 | #include 7 | #include "binary.h" 8 | 9 | void * binary (const void * key, 10 | void * _base, size_t * nelp, size_t width, 11 | int (* cmp) (const void * key, const void * elt)) 12 | { size_t nel = * nelp; 13 | #define base (* (char **) & _base) 14 | char * lim = base + nel * width, * high; 15 | 16 | if (nel > 0) 17 | { for (high = lim - width; base <= high; nel >>= 1) 18 | { char * mid = base + (nel >> 1) * width; 19 | int c = cmp(key, mid); 20 | 21 | if (c < 0) 22 | high = mid - width; 23 | else if (c > 0) 24 | base = mid + width, -- nel; 25 | else 26 | return (void *) mid; 27 | } 28 | memmove(base + width, base, lim - base); 29 | } 30 | ++ *nelp; 31 | return memcpy(base, key, width); 32 | #undef base 33 | } 34 | -------------------------------------------------------------------------------- /14/xrun.c: -------------------------------------------------------------------------------- 1 | #include "Ic.h" 2 | #include "Xt.h" 3 | 4 | int main (int argc, char * argv []) 5 | { void * shell = new(XtApplicationShell(), & argc, argv); 6 | void * form = new(XawForm(), shell, "form"); 7 | void * lineOut = new(XLineOut(), form, "lineOut", 8 | "........"); 9 | void * calc = new(Calc()); 10 | static const char * const cmd [] = { "C", "C", 11 | "1", "1", "2", "2", "3", "3", "a", "+", 12 | "4", "4", "5", "5", "6", "6", "s", "-", 13 | "7", "7", "8", "8", "9", "9", "m", "*", 14 | "Q", "Q", "0", "0", "t", "=", "d", "/", 0 }; 15 | const char * const * cpp; 16 | 17 | wire(lineOut, calc); 18 | for (cpp = cmd; * cpp; cpp += 2) 19 | { void * button = new(XButton(), form, cpp[0], cpp[1]); 20 | 21 | wire(calc, button); 22 | } 23 | addAllAccelerators(form); 24 | mainLoop(shell); 25 | return 0; /* dummy */ 26 | } 27 | -------------------------------------------------------------------------------- /06/Object.r: -------------------------------------------------------------------------------- 1 | #ifndef OBJECT_R 2 | #define OBJECT_R 3 | 4 | struct Object { 5 | const struct Class * class; /* object's description */ 6 | }; 7 | 8 | struct Class { 9 | const struct Object _; /* class' description */ 10 | const char * name; /* class' name */ 11 | const struct Class * super; /* class' super class */ 12 | size_t size; /* class' object's size */ 13 | void * (* ctor) (void * self, va_list * app); 14 | void * (* dtor) (void * self); 15 | int (* differ) (const void * self, const void * b); 16 | int (* puto) (const void * self, FILE * fp); 17 | }; 18 | 19 | void * super_ctor (const void * class, void * self, va_list * app); 20 | void * super_dtor (const void * class, void * self); 21 | int super_differ (const void * class, const void * self, const void * b); 22 | int super_puto (const void * class, const void * self, FILE * fp); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /10/Sort.dc: -------------------------------------------------------------------------------- 1 | #include "Filter.h" 2 | #include "String.h" 3 | #include 4 | 5 | % flag: Sort flags { 6 | %casts 7 | assert((flagM) flags == flags); 8 | 9 | if (flag == 'r') 10 | self -> rflag = 1; 11 | else 12 | fprintf(stderr, "usage: %s [-r] [file...]\n", 13 | progname(filter)), 14 | exit(1); 15 | } 16 | 17 | % Sort line { 18 | %casts 19 | assert((lineM) line == line); 20 | 21 | addLast(self, new(String(), buf)); 22 | return 0; 23 | } 24 | 25 | % Sort quit { 26 | %casts 27 | assert((quitM) quit == quit); 28 | 29 | if (count(self)) 30 | { sort(self); 31 | do 32 | puto(self -> rflag ? takeLast(self) 33 | : takeFirst(self), stdout); 34 | while (count(self)); 35 | } 36 | return 0; 37 | } 38 | 39 | %init 40 | 41 | int main (int argc, char * argv []) 42 | { void * filter = new(Filter(), new(Sort(), 0)); 43 | 44 | return mainLoop(filter, argv); 45 | } 46 | -------------------------------------------------------------------------------- /14/crun.c: -------------------------------------------------------------------------------- 1 | #include "Crt.h" 2 | 3 | int main () 4 | { void * calc = new(Calc()); 5 | void * crt = new(Crt()); 6 | void * lineOut = new(CLineOut(), 1, 1, 12); 7 | void * mux = new(Mux()); 8 | static const struct tbl { const char * nm; int y, x; } 9 | tbl [] = { { "C", 0, 15 }, 10 | { "1", 3, 0 }, { "2", 3, 5 }, { "3", 3, 10 }, { "+", 3, 15 }, 11 | { "4", 6, 0 }, { "5", 6, 5 }, { "6", 6, 10 }, { "-", 6, 15 }, 12 | { "7", 9, 0 }, { "8", 9, 5 }, { "9", 9, 10 }, { "*", 9, 15 }, 13 | { "Q", 12, 0 },{ "0", 12, 5 },{ "=", 12, 10 },{ "/", 12, 15 }, 14 | { 0 }}; 15 | const struct tbl * tp; 16 | 17 | makeWindow(crt, 0, 0, 0, 0); 18 | wire(lineOut, calc); 19 | wire(mux, crt); 20 | 21 | for (tp = tbl; tp -> nm; ++ tp) 22 | { void * o = new(CButton(), tp -> nm, tp -> y, tp -> x); 23 | 24 | wire(calc, o), wire(o, mux); 25 | } 26 | 27 | gate(crt, 0); 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /07/makefile: -------------------------------------------------------------------------------- 1 | chapter = -7 2 | 3 | c = Object.c Point.c Circle.c List.c Queue.c Stack.c 4 | d = $(c:.c=) 5 | h = $(c:.c=.h) 6 | m = points.c circles.c queues.c stacks.c 7 | r = $(c:.c=.r) 8 | t = $(m:.c=) 9 | 10 | points = points.o Object.o Point.o 11 | circles = circles.o Object.o Point.o Circle.o 12 | queues = queues.o Object.o List.o Queue.o 13 | stacks = stacks.o Object.o List.o Stack.o 14 | 15 | all: $t 16 | clean: ; rm -f $c $h $r $t *.o 17 | 18 | test:: points ; points p 19 | test:: circles ; circles p c 20 | test:: queues ; queues +axel - +is +here . - . - . 21 | test:: stacks ; stacks +axel - +is +here . - . - . 22 | 23 | points: $(points) ; $(CC) $(CFLAGS) -o $@ $(points) 24 | circles: $(circles) ; $(CC) $(CFLAGS) -o $@ $(circles) 25 | queues: $(queues) ; $(CC) $(CFLAGS) -o $@ $(queues) 26 | stacks: $(stacks) ; $(CC) $(CFLAGS) -o $@ $(stacks) 27 | 28 | include ../make/Makefile.$(OSTYPE) 29 | -------------------------------------------------------------------------------- /ooc/rep-11/r-R.rep: -------------------------------------------------------------------------------- 1 | // differences from r.rep: 2 | // there is no superclass header to include 3 | // we generate `root and `metaroot at % root in `{dcl, because 4 | // we explicitely insert the `root `{%- `{%+ into struct `metaroot 5 | // 6 | % -r // implement -r option for root class 7 | 8 | # ifndef `class _r `n 9 | # define `class _r `n `n 10 | 11 | `{prot 12 | `{if `class ` 13 | `line `n 14 | `} `{else `{if `class `root `n 15 | struct `root { `n 16 | `{struct `root 17 | `t `const `type `name ; `n 18 | `} 19 | }; `n `n 20 | 21 | struct `metaroot { struct `root _; `n 22 | `{struct `metaroot 23 | `t `const `type `name ; `n 24 | `}n 25 | 26 | `{%- `t `%link `n `} 27 | `{%+ `t `%link `n `} 28 | }; `n `n 29 | 30 | `{%- `%super-header ; `n `}n 31 | `{%+ `%super-header ; `n `}n 32 | 33 | `}fi `}fi 34 | `}n 35 | 36 | # endif `n 37 | -------------------------------------------------------------------------------- /ooc/rep/r-R.rep: -------------------------------------------------------------------------------- 1 | // differences from r.rep: 2 | // there is no superclass header to include 3 | // we generate `root and `metaroot at % root in `{dcl, because 4 | // we explicitely insert the `root `{%- `{%+ into struct `metaroot 5 | // 6 | % -r // implement -r option for root class 7 | 8 | # ifndef `class _r `n 9 | # define `class _r `n `n 10 | 11 | `{prot 12 | `{if `class ` 13 | `line `n 14 | `} `{else `{if `class `root `n 15 | struct `root { `n 16 | `{struct `root 17 | `t `const `type `name ; `n 18 | `} 19 | }; `n `n 20 | 21 | struct `metaroot { struct `root _; `n 22 | `{struct `metaroot 23 | `t `const `type `name ; `n 24 | `}n 25 | 26 | `{%- `t `%link `n `} 27 | `{%+ `t `%link `n `} 28 | }; `n `n 29 | 30 | `{%- `%super-header ; `n `}n 31 | `{%+ `%super-header ; `n `}n 32 | 33 | `}fi `}fi 34 | `}n 35 | 36 | # endif `n 37 | -------------------------------------------------------------------------------- /11/Symbol.d: -------------------------------------------------------------------------------- 1 | // new(Symbol(), "name", lex) "name" must not change 2 | // new(Reserved(), "name", lex) 3 | // new(Var(), "name", VAR) 4 | // new(Const(), "name", CONST, value) 5 | // new(Fun(), "name", FUN) 6 | // new(Math(), "name", MATH, function-name) 7 | 8 | % Class Symbol: Object { 9 | const char * name; 10 | int lex; 11 | % 12 | const char * name (const _self); 13 | int lex (const _self); 14 | %} 15 | 16 | % Class Reserved: Symbol { 17 | %} 18 | 19 | % Class Var: Symbol { 20 | double value; 21 | % 22 | double value (const _self); 23 | double setvalue (_self, double value); 24 | %} 25 | 26 | % Class Const: Var { 27 | %} 28 | 29 | % Class Fun: Var { 30 | void * fun; 31 | % 32 | void setfun (_self, Node @ fun); 33 | double funvalue (_self, double value); 34 | %} 35 | 36 | typedef double (* function) (double); 37 | 38 | % Class Math: Symbol { 39 | function fun; 40 | % 41 | double mathvalue (const _self, double value); 42 | %} 43 | -------------------------------------------------------------------------------- /07/Object.d: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | %prot 5 | #include 6 | 7 | % Class Object { 8 | const Class @ class; // object's description 9 | % 10 | void delete (_self); // reclaim instance 11 | const void * classOf (const _self); // object's class 12 | size_t sizeOf (const _self); // object's size 13 | %- 14 | void * ctor (_self, va_list * app); // constructor 15 | void * dtor (_self); // destructor 16 | int differ (const _self, const Object @ b); // true if != 17 | int puto (const _self, FILE * fp); // display 18 | %} 19 | 20 | // order known in Object.c for static initialization 21 | % Class Class: Object { 22 | const char * name; // class' name 23 | const Class @ super; // class' superclass 24 | size_t size; // object's memory size 25 | % 26 | Object @ new (const _self, ...); // create instance 27 | const void * super (const _self); // class' superclass 28 | %} 29 | -------------------------------------------------------------------------------- /man/cat3/intro.0: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | intro(3) intro(3) 5 | 6 | 7 | NAME 8 | intro -- introduction to the root classes 9 | 10 | SYNOPSIS 11 | Object Class 12 | Exception 13 | 14 | DESCRIPTION 15 | Object(3) is the root class; Class(3) is the root meta- 16 | class. Most of the methods defined for Object are used in 17 | the standard reports for ooc(1), i.e., they cannot be 18 | changed without changing the reports. 19 | 20 | Exception(3) manages a stack of exception handlers. This 21 | class is not mandatory for working with ooc. 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | local: ats 1 65 | 66 | 67 | -------------------------------------------------------------------------------- /12/Symbol.d: -------------------------------------------------------------------------------- 1 | // new(Symbol(), "name", lex) "name" must not change 2 | // new(Reserved(), "name", lex) 3 | // new(Var(), "name", VAR) 4 | // new(Const(), "name", CONST, value) 5 | // new(Fun(), "name", FUN) 6 | // new(Math(), "name", MATH, function-name) 7 | 8 | % Class Symbol: Object { 9 | const char * name; 10 | int lex; 11 | % 12 | const char * name (const _self); 13 | int lex (const _self); 14 | %} 15 | 16 | % Class Reserved: Symbol { 17 | %} 18 | 19 | % VarClass: Class Var: Symbol { 20 | double value; 21 | % 22 | double value (const _self); 23 | double setvalue (_self, double value); 24 | %- 25 | void move (_self, _from); 26 | %} 27 | 28 | % VarClass Const: Var { 29 | %} 30 | 31 | % VarClass Fun: Var { 32 | void * fun; 33 | % 34 | void setfun (_self, Node @ fun); 35 | double funvalue (_self, double value); 36 | %} 37 | 38 | typedef double (* function) (double); 39 | 40 | % Class Math: Symbol { 41 | function fun; 42 | % 43 | double mathvalue (const _self, double value); 44 | %} 45 | -------------------------------------------------------------------------------- /13/Symbol.d: -------------------------------------------------------------------------------- 1 | // new(Symbol(), "name", lex) "name" must not change 2 | // new(Reserved(), "name", lex) 3 | // new(Var(), "name", VAR) 4 | // new(Const(), "name", CONST, value) 5 | // new(Fun(), "name", FUN) 6 | // new(Math(), "name", MATH, function-name) 7 | 8 | % Class Symbol: Object { 9 | const char * name; 10 | int lex; 11 | % 12 | const char * name (const _self); 13 | int lex (const _self); 14 | %} 15 | 16 | % Class Reserved: Symbol { 17 | %} 18 | 19 | % VarClass: Class Var: Symbol { 20 | double value; 21 | % 22 | double value (const _self); 23 | double setvalue (_self, double value); 24 | %- 25 | void move (_self, _from); 26 | %} 27 | 28 | % VarClass Const: Var { 29 | %} 30 | 31 | % VarClass Fun: Var { 32 | void * fun; 33 | % 34 | void setfun (_self, Node @ fun); 35 | double funvalue (_self, double value); 36 | %} 37 | 38 | typedef double (* function) (double); 39 | 40 | % Class Math: Symbol { 41 | function fun; 42 | % 43 | double mathvalue (const _self, double value); 44 | %} 45 | -------------------------------------------------------------------------------- /09/lists.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "Circle.h" 5 | #include "List.h" 6 | 7 | int main (int argc, char ** argv) 8 | { void * q; 9 | unsigned n; 10 | 11 | q = new(List(), 1); 12 | 13 | while (* ++ argv) 14 | switch (** argv) { 15 | case '+': 16 | switch ((* argv)[1]) { 17 | case 'c': 18 | addFirst(q, new(Circle(), 1, 2, 3)); 19 | break; 20 | case 'p': 21 | addFirst(q, new(Point(), 4, 5)); 22 | break; 23 | default: 24 | addFirst(q, new(Object())); 25 | } 26 | break; 27 | case '-': 28 | puto(takeLast(q), stdout); 29 | break; 30 | case '.': 31 | n = count(q); 32 | while (n -- > 0) 33 | { const void * p = takeFirst(q); 34 | 35 | if (isOf(p, Point())) 36 | draw(p); 37 | else 38 | puto(p, stdout); 39 | addLast(q, p); 40 | } 41 | break; 42 | default: 43 | if (isdigit(** argv & 0xff)) 44 | addFirst(q, (void *) atoi(* argv)); 45 | else 46 | addFirst(q, * argv + 1); 47 | } 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /man/cat4/Event.0: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Event(4) Event(4) 5 | 6 | 7 | NAME 8 | Class Event: Objct -- input item 9 | 10 | SYNOPSIS 11 | Objct 12 | Event 13 | new(Event(), kind, data); 14 | int kind (self) 15 | void * data (self) 16 | 17 | DESCRIPTION 18 | An Event object represents an input item such as a piece 19 | of text, a mouse click, etc. 20 | 21 | kind is zero if data is a static string. kind is not zero 22 | if data is a pointer. In particular, a mouse click can be 23 | represented with kind 1 and data pointing to an array with 24 | two integer coordinates. 25 | 26 | SEE ALSO 27 | Ic(4) 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | local: ats 1 65 | 66 | 67 | -------------------------------------------------------------------------------- /ooc/awk/report.dbg: -------------------------------------------------------------------------------- 1 | # report.dbg -- 5.3 Jun 13 14:25:42 1993 2 | # Copyright (c) 1993 Axel T. Schreiner 3 | 4 | # report generator debugging 5 | 6 | # dumpReport(r) dump report by name 7 | 8 | $1 ~ /\.rep$/ { # filename.rep 9 | loadReports($1) 10 | } 11 | 12 | $1 != "" && $1 in Report { # reportname 13 | dumpReport($1); next 14 | } 15 | 16 | $1 == "all" || $1 == "reports" { # all | reports 17 | for (r in Report) 18 | if (r != "") 19 | dumpReport(r) 20 | } 21 | 22 | END { 23 | exit status 24 | } 25 | 26 | function dumpReport (r, i, brace) { 27 | if (! (r in Report)) 28 | fatal(r " ?cannot find report") 29 | print "report " r ":" 30 | brace = 0 31 | for (i = Report[r];; ++ i) 32 | if (Token[i] ~ /^`{/) 33 | { printf "%s >>%d ", Token[i], Token[i+1] 34 | ++ i; ++ brace 35 | } 36 | else if (Token[i] ~ /^`}/) 37 | if (-- brace < 0) 38 | break 39 | else 40 | printf "%s [%d] ", Token[i], i+1 41 | else if (Token[i] == "\n") 42 | printf "\n" 43 | else 44 | printf "%s ", Token[i] 45 | printf "\n" 46 | } 47 | -------------------------------------------------------------------------------- /08/lists.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "Circle.h" 5 | #include "List.h" 6 | 7 | int main (int argc, char ** argv) 8 | { void * q; 9 | unsigned n; 10 | 11 | initList(); 12 | initCircle(); 13 | q = new(List, 1); 14 | 15 | while (* ++ argv) 16 | switch (** argv) { 17 | case '+': 18 | switch ((* argv)[1]) { 19 | case 'c': 20 | addFirst(q, new(Circle, 1, 2, 3)); 21 | break; 22 | case 'p': 23 | addFirst(q, new(Point, 4, 5)); 24 | break; 25 | default: 26 | addFirst(q, new(Object)); 27 | } 28 | break; 29 | case '-': 30 | puto(takeLast(q), stdout); 31 | break; 32 | case '.': 33 | n = count(q); 34 | while (n -- > 0) 35 | { const void * p = takeFirst(q); 36 | 37 | if (isOf(p, Point)) 38 | draw(p); 39 | else 40 | puto(p, stdout); 41 | addLast(q, p); 42 | } 43 | break; 44 | default: 45 | if (isdigit(** argv & 0xff)) 46 | addFirst(q, (void *) atoi(* argv)); 47 | else 48 | addFirst(q, * argv + 1); 49 | } 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /man/cat2/retrieve.0: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | retrieve(2) retrieve(2) 5 | 6 | 7 | NAME 8 | retrieve -- get object from file 9 | 10 | SYNOPSIS 11 | void * retrieve (FILE * fp) 12 | 13 | DESCRIPTION 14 | retrieve() returns an object read in from the input stream 15 | represented by fp. At end of file or in case of an error, 16 | retrieve() returns a null pointer. 17 | 18 | retrieve() requires a sorted table of class function 19 | pointers that can be produced with munch(1). Once the 20 | class description has been located, retrieve() applies the 21 | method geto to an area obtained with allocate. 22 | 23 | SEE ALSO 24 | munch(1), Object(3) 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | local: ats 1 65 | 66 | 67 | -------------------------------------------------------------------------------- /man/man1/munch.1: -------------------------------------------------------------------------------- 1 | .\" munch.1 -- 1.3 Sep 26 16:50:35 1993 2 | .\" Copyright (c) 1993 Axel T. Schreiner 3 | .TH munch 1 "local: ats" 4 | .SH NAME 5 | munch \(em produce class list 6 | .SH SYNOPSIS 7 | .B nm \(mip 8 | object... archive... 9 | .B | munch 10 | .SH DESCRIPTION 11 | .I munch 12 | reads a Berkeley-style 13 | .IR nm (1) 14 | listing from standard input and produces as standard output 15 | a C source file 16 | defining a null-terminated array 17 | .B classes[] 18 | with pointers to the class functions found in each 19 | .I object 20 | and 21 | .IR archive . 22 | The array is sorted by class function names. 23 | .PP 24 | A class function 25 | is any name that appears with type 26 | .B T 27 | and, preceded with an underscore, with type 28 | .BR b , 29 | .BR d , 30 | or 31 | .BR s . 32 | .SH BUGS 33 | This is a hack to simplify retrieval programs. 34 | The compatible effect of option 35 | .B \(mip 36 | in Berkeley and System V 37 | .I nm 38 | is quite a surprise. 39 | .PP 40 | Because \s-1HP/UX\s0 41 | .I nm 42 | does not output static symbols, 43 | .I munch 44 | is not very useful on this system. 45 | -------------------------------------------------------------------------------- /10/Wc.dc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "Filter.h" 4 | 5 | % Wc wc { // (self, filter, fnm, buf) 6 | %casts 7 | assert((lineM) wc == wc); 8 | 9 | ++ self -> lines; 10 | self -> chars += strlen(buf); 11 | return 0; 12 | } 13 | 14 | % Wc printFile { // (self, filter, fnm) 15 | %casts 16 | assert((wrapM) printFile == printFile); 17 | 18 | if (fnm && strcmp(fnm, "-")) 19 | printf("%7u %7u %s\n", 20 | self -> lines, self -> chars, fnm); 21 | else 22 | printf("%7u %7u\n", self -> lines, self -> chars); 23 | 24 | self -> allLines += self -> lines, self -> lines = 0; 25 | self -> allChars += self -> chars, self -> chars = 0; 26 | ++ self -> files; 27 | return 0; 28 | } 29 | 30 | % Wc printTotal { // (self, filter) 31 | %casts 32 | assert((quitM) printTotal == printTotal); 33 | 34 | if (self -> files > 1) 35 | printf("%7u %7u in %u files\n", 36 | self -> allLines, self -> allChars, self -> files); 37 | return 0; 38 | } 39 | 40 | %init 41 | 42 | int main (int argc, char * argv []) 43 | { void * filter = new(Filter(), new(Wc())); 44 | 45 | return mainLoop(filter, argv); 46 | } 47 | -------------------------------------------------------------------------------- /10/Filter.d: -------------------------------------------------------------------------------- 1 | // new(Filter(), delegate) 2 | 3 | typedef void (* flagM) (void *, void *, char); 4 | typedef int (* nameM) (void *, const void *, const char *); 5 | typedef int (* fileM) (void *, const void *, const char *, 6 | FILE *); 7 | typedef int (* lineM) (void *, const void *, const char *, 8 | char *); 9 | typedef int (* wrapM) (void *, const void *, const char *); 10 | typedef int (* quitM) (void *, const void *); 11 | 12 | % Class Filter: Object { 13 | Object @ delegate; 14 | flagM flag; // process a flag 15 | nameM name; // process a filename argument 16 | fileM file; // process an opened file 17 | lineM line; // process a line buffer 18 | wrapM wrap; // done with a file 19 | quitM quit; // done with all files 20 | 21 | const char * progname; // argv[0] 22 | char ** argv; // current argument and byte 23 | 24 | char * buf; // dynamic line buffer 25 | unsigned blen; // current maximum length 26 | % 27 | int mainLoop (_self, char ** argv); 28 | const char * argval (_self); 29 | const char * progname (const _self); 30 | int doit (_self, const char * arg); 31 | %} 32 | -------------------------------------------------------------------------------- /02/new.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "new.h" 5 | #include "new.r" 6 | 7 | void * new (const void * _class, ...) 8 | { const struct Class * class = _class; 9 | void * p = calloc(1, class -> size); 10 | 11 | assert(p); 12 | * (const struct Class **) p = class; 13 | 14 | if (class -> ctor) 15 | { va_list ap; 16 | 17 | va_start(ap, _class); 18 | p = class -> ctor(p, & ap); 19 | va_end(ap); 20 | } 21 | return p; 22 | } 23 | 24 | void delete (void * self) 25 | { const struct Class ** cp = self; 26 | 27 | if (self && * cp && (* cp) -> dtor) 28 | self = (* cp) -> dtor(self); 29 | free(self); 30 | } 31 | 32 | void * clone (const void * self) 33 | { const struct Class * const * cp = self; 34 | 35 | assert(self && * cp && (* cp) -> clone); 36 | return (* cp) -> clone(self); 37 | } 38 | 39 | int differ (const void * self, const void * b) 40 | { const struct Class * const * cp = self; 41 | 42 | assert(self && * cp && (* cp) -> differ); 43 | return (* cp) -> differ(self, b); 44 | } 45 | 46 | size_t sizeOf (const void * self) 47 | { const struct Class * const * cp = self; 48 | 49 | assert(self && * cp); 50 | return (* cp) -> size; 51 | } 52 | -------------------------------------------------------------------------------- /08/Object.d: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | %prot 5 | #include 6 | 7 | % Class Object { 8 | unsigned long magic; // magic number 9 | const Class @ class; // object's description 10 | % 11 | void delete (_self); // reclaim instance 12 | const Class @ classOf (const _self); // object's class 13 | size_t sizeOf (const _self); // object's size 14 | int isA (const _self, const Class @ class); // object belongs to class 15 | int isOf (const _self, const Class @ class);// object derives from class 16 | void * cast (const Class @ class, const _self); // asserts isOf() 17 | %- 18 | void * ctor (_self, va_list * app); // constructor 19 | void * dtor (_self); // destructor 20 | int differ (const _self, const Object @ b); // true if != 21 | int puto (const _self, FILE * fp); // display 22 | %} 23 | 24 | // order known in Object.c for static initialization 25 | % Class Class: Object { 26 | const char * name; // class' name 27 | const Class @ super; // class' superclass 28 | size_t size; // object's memory size 29 | % 30 | Object @ new (const _self, ...); // create instance 31 | const Class @ super (const _self); // class' superclass 32 | %} 33 | -------------------------------------------------------------------------------- /13/makefile: -------------------------------------------------------------------------------- 1 | chapter = -11 2 | 3 | c = Object.c List.c Exception.c Node.c Symbol.c Symtab.c 4 | d = $(c:.c=) 5 | h = $(c:.c=.h) binary.h parse.h 6 | m = except.c binary.c parse.c 7 | r = $(c:.c=.r) 8 | t = except value 9 | 10 | except = except.o Object.o List.o Exception.o 11 | value = parse.o binary.o $(c:.c=.o) 12 | 13 | all: $t 14 | clean: ; rm -f $c $(c:.c=.h) $r $t classes.? *.stb *.sym *.o 15 | rm -rf *.dSYM 16 | 17 | test:: except ; except 18 | test:: value ; echo 'let a = sin(1) + PI' | value 19 | test:: value ; { echo 'def sqr = $$ * $$'; \ 20 | echo 'def one = sqr(sin($$)) + sqr(cos($$))'; \ 21 | echo 'let n = one(10)'; \ 22 | echo save; } | value 23 | test:: value ; { echo load; \ 24 | echo 'n + one(20)'; } | value 25 | test:: value ; { echo let a = 1; \ 26 | echo def f = a + 1; \ 27 | echo save f; } | value 28 | test:: value ;- { echo 'def a = 10 - $$'; \ 29 | echo load f; \ 30 | echo 'a(3)'; } | value 31 | 32 | except: $(except) ; $(AWK) -f ../09/munch < /dev/null > classes.c 33 | $(CC) $(CFLAGS) -o $@ $(except) classes.c 34 | value: $(value) ; nm -p $(value) | $(AWK) -f ../09/munch > classes.c 35 | $(CC) $(CFLAGS) -o $@ $(value) classes.c $(Lm) $(debug) 36 | 37 | include ../make/Makefile.$(OSTYPE) 38 | -------------------------------------------------------------------------------- /man/cat1/munch.0: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | munch(1) munch(1) 5 | 6 | 7 | NAME 8 | munch -- produce class list 9 | 10 | SYNOPSIS 11 | nm -p object... archive... | munch 12 | 13 | DESCRIPTION 14 | munch reads a Berkeley-style nm(1) listing from standard 15 | input and produces as standard output a C source file 16 | defining a null-terminated array classes[] with pointers 17 | to the class functions found in each object and archive. 18 | The array is sorted by class function names. 19 | 20 | A class function is any name that appears with type T and, 21 | preceded with an underscore, with type b, d, or s. 22 | 23 | BUGS 24 | This is a hack to simplify retrieval programs. The com- 25 | patible effect of option -p in Berkeley and System V nm is 26 | quite a surprise. 27 | 28 | Because HP/UX nm does not output static symbols, munch is 29 | not very useful on this system. 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | local: ats 1 65 | 66 | 67 | -------------------------------------------------------------------------------- /09/Object.d: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | %prot 5 | #include 6 | 7 | % Class Object { 8 | unsigned long magic; // magic number 9 | const Class @ class; // object's description 10 | % 11 | void delete (_self); // reclaim instance 12 | const Class @ classOf (const _self); // object's class 13 | size_t sizeOf (const _self); // object's size 14 | int isA (const _self, const Class @ class); // object belongs to class 15 | int isOf (const _self, const Class @ class);// object derives from class 16 | void * cast (const Class @ class, const _self); // asserts isOf() 17 | %- 18 | void * ctor (_self, va_list * app); // constructor 19 | void * dtor (_self); // destructor 20 | int differ (const _self, const Object @ b); // true if != 21 | int puto (const _self, FILE * fp); // display 22 | %} 23 | 24 | // order known in Object.c for static initialization 25 | % Class Class: Object { 26 | const char * name; // class' name 27 | const Class @ super; // class' superclass 28 | size_t size; // object's memory size 29 | % 30 | Object @ new (const _self, ...); // create instance 31 | const Class @ super (const _self); // class' superclass 32 | %} 33 | %prot 34 | #define MAGIC 0x0effaced // magic number for objects 35 | -------------------------------------------------------------------------------- /02/String.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "String.h" 6 | #include "new.h" 7 | #include "new.r" 8 | 9 | struct String { 10 | const void * class; /* must be first */ 11 | char * text; 12 | }; 13 | 14 | static void * String_ctor (void * _self, va_list * app) 15 | { struct String * self = _self; 16 | const char * text = va_arg(* app, const char *); 17 | 18 | self -> text = malloc(strlen(text) + 1); 19 | assert(self -> text); 20 | strcpy(self -> text, text); 21 | return self; 22 | } 23 | 24 | static void * String_dtor (void * _self) 25 | { struct String * self = _self; 26 | 27 | free(self -> text), self -> text = 0; 28 | return self; 29 | } 30 | 31 | static void * String_clone (const void * _self) 32 | { const struct String * self = _self; 33 | 34 | return new(String, self -> text); 35 | } 36 | 37 | static int String_differ (const void * _self, const void * _b) 38 | { const struct String * self = _self; 39 | const struct String * b = _b; 40 | 41 | if (self == b) 42 | return 0; 43 | if (! b || b -> class != String) 44 | return 1; 45 | return strcmp(self -> text, b -> text); 46 | } 47 | 48 | static const struct Class _String = { 49 | sizeof(struct String), 50 | String_ctor, String_dtor, 51 | String_clone, String_differ 52 | }; 53 | 54 | const void * String = & _String; 55 | -------------------------------------------------------------------------------- /man/man3/Exception.3: -------------------------------------------------------------------------------- 1 | .\" Exception.3 -- 1.3 Sep 26 18:06:39 1993 2 | .\" Copyright (c) 1993 Axel T. Schreiner 3 | .TH Exception 3 "local: ats" 4 | .SH NAME 5 | \f3Class Exception: Object\fP \(em manage a stack of exception handlers 6 | .SH SYNOPSIS 7 | .nf 8 | Object 9 | \f3Exception\fP 10 | .sp .5 11 | .B new(Exception()); 12 | .sp .5 13 | .BI "int catch (" self ) 14 | .BI "void cause (int " number ) 15 | .fi 16 | .SH DESCRIPTION 17 | .B Exception 18 | is a class for managing a stack of exception handlers. 19 | After it is armed with 20 | .BR catch , 21 | the newest 22 | .B Exception 23 | object can receive a nonzero exception number sent with 24 | .BR cause() . 25 | .PP 26 | .B ctor 27 | pushes the new 28 | .B Exception 29 | object onto the global exception stack, 30 | .B dtor 31 | removes it. 32 | These calls must be balanced. 33 | .PP 34 | .B catch 35 | arms its object for receiving an exception number. 36 | Once the number is sent, 37 | .B catch 38 | will return it. 39 | This function is implemented as a macro with 40 | .BR setjmp (3) 41 | and is subject to the same restrictions; 42 | in particular, 43 | the function containing the call to 44 | .B catch 45 | must still be active when the exception number is sent. 46 | .PP 47 | Other methods should generally not be applied to an 48 | .B Exception 49 | object. 50 | .SH SEE ALSO 51 | setjmp(3) 52 | -------------------------------------------------------------------------------- /ooc/regress: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # regress -- 5.5 Thu Jan 3 18:54:44 EST 2002 3 | # Copyright (c) 1993 Axel T. Schreiner 4 | 5 | tmp=tmp~ 6 | tests='T TBase Test' 7 | 8 | if [ $# = 0 ] 9 | then set $tests 10 | fi 11 | 12 | usage() 13 | { echo >&2 "usage: regress options... clean clobber retract $tests ..." 14 | exit 1 15 | } 16 | 17 | regress() # options desc 18 | { eval desc=\$$# 19 | 20 | if grep >/dev/null \ 21 | '^%[ ]*[^:]*[ ]*[^:]*[ ]*{$' $desc.d 22 | then R=-R 23 | else R= 24 | fi 25 | 26 | echo >&2 ooc -M $R $* -dc -h -r $desc.dc \> $desc 27 | 28 | if [ -r $desc ] 29 | then if ooc -M $R $* -dc -h -r $desc.dc | tee $tmp | cmp -s - $desc 30 | then rm -f $tmp 31 | else rm -f $desc~; mv $desc $desc~; mv $tmp $desc 32 | echo $desc 'new' 33 | diff $desc~ $desc 34 | echo mv $desc~ $desc >> retract~ 35 | fi 36 | else rm -f $3~ 37 | echo $3 new 38 | ooc -M $R $* -dc -h -r $desc.dc > $desc 39 | fi 40 | } 41 | 42 | new=yes options= 43 | for i 44 | do case $i 45 | in -*) options="$options $i" 46 | ;; clean) rm -f *~ 47 | ;; clobber) rm -f *~ $tests 48 | ;; retract) if [ -r retract~ ] 49 | then sh -x retract~ 50 | rm retract~ 51 | fi 52 | ;; *) if [ -r $i.d ] 53 | then if [ "$new" ] 54 | then rm -f retract~ 55 | new= 56 | fi 57 | regress $options $i 58 | else usage 59 | fi 60 | esac 61 | shift 62 | done 63 | -------------------------------------------------------------------------------- /14/Ic.d: -------------------------------------------------------------------------------- 1 | // new(Ic()) 2 | // wire() connects me to other object 3 | // gate() sends something to my outlet; overwritten to receive 4 | 5 | // new(Mux()) 6 | // wire() connects me to many outputs 7 | // gate() tries to send until it finds willing receiver 8 | 9 | // new(LineOut()) 10 | // gate() displays input as string 11 | 12 | // new(Button(), "text") 13 | // gate() takes event, possibly sends text on 14 | 15 | // new(Event(), kind, data) 16 | // something to send to Button 17 | 18 | // new(Calc()) 19 | // gate() combines input with state, sends result on 20 | 21 | enum react { reject, accept }; 22 | 23 | % IcClass: Class Ic: Object { 24 | void * out; 25 | %- 26 | void wire (Object @ to, _self); 27 | enum react gate (_self, const void * item); 28 | %} 29 | 30 | % IcClass Mux: Ic { 31 | void * list; 32 | %} 33 | 34 | % IcClass LineOut: Ic { 35 | %} 36 | 37 | % IcClass Button: Ic { 38 | const char * text; 39 | %} 40 | 41 | %prot 42 | #define text(b) (((const struct Button *) b) -> text) 43 | 44 | % Class Event: Object { 45 | int kind; // 0 means string-data 46 | void * data; // not implicitly deleted 47 | % 48 | int kind (const _self); 49 | void * data (const _self); 50 | %} 51 | 52 | %prot 53 | typedef int values[2]; // left and right operand stack 54 | 55 | % IcClass Calc: Ic { 56 | values value; // left and right operand 57 | int op; // operator 58 | int state; // FSM state 59 | %} 60 | -------------------------------------------------------------------------------- /ooc/rep-7/c-R.rep: -------------------------------------------------------------------------------- 1 | // differences from c.rep: 2 | // `metaroot_ctor() does not call super_ctor() -- no need to, we hope 3 | // first arguments to ctor are copied to struct in order of declaration 4 | // then argumentlist is shared with other `meta_ctor()s 5 | // memcpy() performs binary inheritance 6 | // there is no way to generate `root and `metaroot descriptions and init() 7 | // 8 | // note that 'ctor' and its calling convention are burnt into this file 9 | // 10 | % init // implement %init request for root class 11 | 12 | `{dcl 13 | `{if `class `root 14 | 15 | `%selectors 16 | 17 | static void * `metaroot _ctor (void * _self, va_list * app) { `n 18 | `t struct `metaroot * self = _self; `n 19 | `t const size_t offset = offsetof(struct `metaroot , ctor); `n 20 | `t typedef void (* voidf) (); `n 21 | `t voidf selector; `n 22 | `t va_list ap; `n `n 23 | 24 | `{struct `metaroot 25 | `t self -> `name = va_arg(* app, `type ); `n 26 | `}n 27 | 28 | `t assert(self -> super); `n `n 29 | 30 | `t memcpy((char *) self + offset, ` \ 31 | (char *) self -> super + offset, `n 32 | `t `t sizeOf(self -> super) - offset); `n `n 33 | 34 | #ifdef va_copy `n 35 | `t va_copy(ap, * app); `n 36 | #else `n 37 | `t ap = * app; `n 38 | #endif `n 39 | `%meta-ctor-loop 40 | #ifdef va_copy `n 41 | `t va_end(ap); `n 42 | #endif `n 43 | `t return self; `n 44 | } `n `n 45 | 46 | `}fi 47 | `}dcl 48 | -------------------------------------------------------------------------------- /11/Symtab.dc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "binary.h" 4 | 5 | #include "Symbol.h" 6 | 7 | % Symtab ctor { 8 | struct Symtab * self = super_ctor(Symtab(), _self, app); 9 | 10 | if (! (self -> dim = va_arg(* app, size_t))) 11 | self -> dim = 1; 12 | 13 | self -> buf = malloc(self -> dim * sizeof(void *)); 14 | assert(self -> buf); 15 | return self; 16 | } 17 | 18 | % : Symtab delete { // don't delete 19 | } 20 | 21 | static int cmp (const void * _key, const void * _elt) 22 | { const char * const * key = _key; 23 | const void * const * elt = _elt; 24 | 25 | return strcmp(* key, name(* elt)); 26 | } 27 | 28 | static void ** search (struct Symtab * self, const char ** np) 29 | { 30 | if (self -> count >= self -> dim) 31 | { self -> buf = realloc(self -> buf, 32 | (self -> dim *= 2) * sizeof(void *)); 33 | assert(self -> buf); 34 | } 35 | return binary(np, self -> buf, & self -> count, 36 | sizeof(void *), cmp); 37 | } 38 | 39 | % Symtab install { 40 | const char * nm; 41 | void ** pp; 42 | %casts 43 | nm = name(entry); 44 | pp = search(self, & nm); 45 | if (* pp != nm) // found entry 46 | delete(* pp); 47 | * pp = (void *) entry; 48 | } 49 | 50 | % Symtab screen { 51 | void ** pp; 52 | %casts 53 | pp = search(self, & name); 54 | if (* pp == name) // entered name 55 | { char * copy = malloc(strlen(name) + 1); 56 | 57 | assert(copy); 58 | * pp = new(Symbol(), strcpy(copy, name), lex); 59 | } 60 | return * pp; 61 | } 62 | 63 | %init 64 | -------------------------------------------------------------------------------- /man/cat3/Exception.0: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exception(3) Exception(3) 5 | 6 | 7 | NAME 8 | Class Exception: Object -- manage a stack of exception 9 | handlers 10 | 11 | SYNOPSIS 12 | Object 13 | Exception 14 | new(Exception()); 15 | int catch (self) 16 | void cause (int number) 17 | 18 | DESCRIPTION 19 | Exception is a class for managing a stack of exception 20 | handlers. After it is armed with catch, the newest Excep- 21 | tion object can receive a nonzero exception number sent 22 | with cause(). 23 | 24 | ctor pushes the new Exception object onto the global 25 | exception stack, dtor removes it. These calls must be 26 | balanced. 27 | 28 | catch arms its object for receiving an exception number. 29 | Once the number is sent, catch will return it. This func- 30 | tion is implemented as a macro with setjmp(3) and is sub- 31 | ject to the same restrictions; in particular, the function 32 | containing the call to catch must still be active when the 33 | exception number is sent. 34 | 35 | Other methods should generally not be applied to an Excep- 36 | tion object. 37 | 38 | SEE ALSO 39 | setjmp(3) 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | local: ats 1 65 | 66 | 67 | -------------------------------------------------------------------------------- /14/Xt.d: -------------------------------------------------------------------------------- 1 | // new(Xt()) 2 | // wrapper for Xt/... widget 3 | // Object is part of Xt, i.e., our 'Object' has to be mangled 4 | 5 | // new(XtApplicationShell(), & argc, argv) 6 | // wrapper for Xt application shell 7 | 8 | // new(XawLabel(), parent-xt, "node-name") 9 | // wrapper for Xaw/Label widget 10 | 11 | // new(XawCommand(), parent-xt, "node-name") 12 | // wrapper for Xaw/Command widget 13 | 14 | // new(XawBox(), parent-xt, "node-name") 15 | // wrapper for Xaw/Box widget 16 | 17 | // new(XawForm(), parent-xt, "node-name") 18 | // wrapper for Xaw/Form widget 19 | 20 | // new(XLineOut(), parent-xt, "node-name", "text") 21 | // implements LineOut with a XawLabel 22 | 23 | // new(XButton(), parent-xt, "node-name", "text") 24 | // implements Button with a XawCommand 25 | 26 | #include 27 | 28 | % Class Xt: Object { 29 | Widget widget; 30 | % 31 | void * makeWidget (_self, WidgetClass wc, va_list * app); 32 | void addAllAccelerators (_self); 33 | void setLabel (_self, const char * text); 34 | void addCallback (_self, XtCallbackProc fun, XtPointer data); 35 | %} 36 | %prot 37 | #define widget(xt) (((struct Xt *) xt) -> widget) 38 | 39 | % Class XtApplicationShell: Xt { 40 | XtAppContext appContext; 41 | % 42 | void mainLoop (_self); 43 | %} 44 | 45 | % Class XawLabel: Xt { 46 | %} 47 | 48 | % Class XawCommand: Xt { 49 | %} 50 | 51 | % Class XawBox: Xt { 52 | %} 53 | 54 | % Class XawForm: Xt { 55 | %} 56 | 57 | % Class XLineOut: XawLabel { 58 | %} 59 | 60 | % Class XButton: XawCommand { 61 | void * button; 62 | %} 63 | -------------------------------------------------------------------------------- /ooc/rep-7/c.rep: -------------------------------------------------------------------------------- 1 | // note that 'ctor' and its calling convention is burnt into this file 2 | // 3 | % init // implement %init request 4 | 5 | `{dcl 6 | `{ifnot `class ` 7 | `{if `newmeta 1 8 | 9 | `%selectors 10 | 11 | static void * `meta _ctor (void * _self, va_list * app) { `n 12 | `t struct `meta * self = super_ctor( `meta , _self, app); `n 13 | `t typedef void (* voidf) (); `n 14 | `t voidf selector; `n 15 | #ifdef va_copy `n 16 | `t va_list ap; va_copy(ap, * app); `n 17 | #else `n 18 | `t va_list ap = * app; `n 19 | #endif `n `n 20 | 21 | `%meta-ctor-loop 22 | #ifdef va_copy `n 23 | `t va_end(ap); `n 24 | #endif `n 25 | `t return self; `n 26 | } `n `n 27 | 28 | const void * `meta ; `n 29 | 30 | `}fi 31 | 32 | const void * `class ; `n `n 33 | 34 | void init `class (void) { `n 35 | `{ifnot `super `root 36 | `t init `super (); `n `n 37 | `}fi 38 | 39 | `{if `newmeta 1 40 | `t if (! `meta ) `n 41 | `t `t `meta = new( `metaroot , `n 42 | `t `t `t " `meta ", `supermeta , sizeof(struct `meta ), `n 43 | `t `t `t ctor, `meta _ctor, `n 44 | `{links `meta 45 | `t `t `t `method , `meta _ `method , `n 46 | `} 47 | `t `t `t (void *) 0); `n `n 48 | `}fi 49 | 50 | `t if (! `class ) `n 51 | `t `t `class = new( `meta , `n 52 | `t `t `t " `class ", `super , sizeof(struct `class ), `n 53 | `{links `class 54 | `t `t `t `method , `class _ `method , `n 55 | `} 56 | `t `t `t (void *) 0); `n 57 | } `n 58 | 59 | `}fi 60 | `}dcl 61 | -------------------------------------------------------------------------------- /ooc/rep-8/c-R.rep: -------------------------------------------------------------------------------- 1 | // differences from c.rep: 2 | // `metaroot_ctor() does not call super_ctor() -- no need to, we hope 3 | // first arguments to ctor are copied to struct in order of declaration 4 | // then argumentlist is shared with other `meta_ctor()s 5 | // memcpy() performs binary inheritance 6 | // there is no way to generate `root and `metaroot descriptions and init() 7 | // 8 | // note that 'ctor' and its calling convention are burnt into this file 9 | // 10 | % init // implement %init request for root class 11 | 12 | `{dcl 13 | `{if `class `root 14 | 15 | `%selectors 16 | 17 | static void * `metaroot _ctor (void * _self, va_list * app) { `n 18 | `t struct `metaroot * self = _self; `n 19 | `t const size_t offset = offsetof(struct `metaroot , ctor); `n 20 | `t typedef void (* voidf) (); `n 21 | `t voidf selector; `n 22 | `t va_list ap; `n `n 23 | 24 | `{struct `metaroot 25 | `{if `name super 26 | `t self -> `name = cast( `metaroot , va_arg(* app, `type )); `n 27 | `} `{else 28 | `t self -> `name = va_arg(* app, `type ); `n 29 | `}fi 30 | `}n 31 | 32 | `t memcpy((char *) self + offset, ` \ 33 | (char *) self -> super + offset, `n 34 | `t `t sizeOf(self -> super) - offset); `n `n 35 | 36 | #ifdef va_copy `n 37 | `t va_copy(ap, * app); `n 38 | #else `n 39 | `t ap = * app; `n 40 | #endif `n 41 | `%meta-ctor-loop 42 | #ifdef va_copy `n 43 | `t va_end(ap); `n 44 | #endif `n 45 | `t return self; `n 46 | } `n `n 47 | 48 | `}fi 49 | `}dcl 50 | -------------------------------------------------------------------------------- /ooc/rep-8/c.rep: -------------------------------------------------------------------------------- 1 | // note that 'ctor' and its calling convention is burnt into this file 2 | // 3 | % init // implement %init request 4 | 5 | `{dcl 6 | `{ifnot `class ` 7 | `{if `newmeta 1 8 | 9 | `%selectors 10 | 11 | static void * `meta _ctor (void * _self, va_list * app) { `n 12 | `t struct `meta * self = super_ctor( `meta , _self, app); `n 13 | `t typedef void (* voidf) (); `n 14 | `t voidf selector; `n 15 | #ifdef va_copy `n 16 | `t va_list ap; va_copy(ap, * app); `n 17 | #else `n 18 | `t va_list ap = * app; `n 19 | #endif `n `n 20 | 21 | `%meta-ctor-loop 22 | #ifdef va_copy `n 23 | `t va_end(ap); `n 24 | #endif `n 25 | `t return self; `n 26 | } `n `n 27 | 28 | const void * `meta ; `n 29 | 30 | `}fi 31 | 32 | const void * `class ; `n `n 33 | 34 | void init `class (void) { `n 35 | `{ifnot `super `root 36 | `t init `super (); `n `n 37 | `}fi 38 | 39 | `{if `newmeta 1 40 | `t if (! `meta ) `n 41 | `t `t `meta = new( `metaroot , `n 42 | `t `t `t " `meta ", `supermeta , sizeof(struct `meta ), `n 43 | `t `t `t ctor, `meta _ctor, `n 44 | `{links `meta 45 | `t `t `t `method , `meta _ `method , `n 46 | `} 47 | `t `t `t (void *) 0); `n `n 48 | `}fi 49 | 50 | `t if (! `class ) `n 51 | `t `t `class = new( `meta , `n 52 | `t `t `t " `class ", `super , sizeof(struct `class ), `n 53 | `{links `class 54 | `t `t `t `method , `class _ `method , `n 55 | `} 56 | `t `t `t (void *) 0); `n 57 | } `n 58 | 59 | `}fi 60 | `}dcl 61 | -------------------------------------------------------------------------------- /ooc/rep/c.rep: -------------------------------------------------------------------------------- 1 | // note that 'ctor' and its calling convention is burnt into this file 2 | // 3 | % init // implement %init request 4 | 5 | `{dcl 6 | `{ifnot `class ` 7 | `{if `newmeta 1 8 | 9 | `%selectors 10 | 11 | static void * `meta _ctor (void * _self, va_list * app) { `n 12 | `t struct `meta * self = super_ctor( `meta (), _self, app); `n 13 | `t Method selector; `n 14 | #ifdef va_copy `n 15 | `t va_list ap; va_copy(ap, * app); `n 16 | #else `n 17 | `t va_list ap = * app; `n 18 | #endif `n `n 19 | 20 | `%meta-ctor-loop 21 | #ifdef va_copy `n 22 | `t va_end(ap); `n 23 | #endif `n 24 | `t return self; `n 25 | } `n `n 26 | 27 | static const void * _ `meta ; `n `n 28 | 29 | const void * `%const `meta (void) { `n 30 | `t return _ `meta ? _ `meta : `n 31 | `t `t (_ `meta = new( `metaroot (), `n 32 | `t `t `t " `meta ", `supermeta (), sizeof(struct `meta ), `n 33 | `t `t `t ctor, "", `meta _ctor, `n 34 | `{links `meta 35 | `t `t `t `method , " `tag ", `meta _ `method , `n 36 | `} 37 | `t `t `t (void *) 0)); `n 38 | } `n `n 39 | 40 | `}fi 41 | 42 | static const void * _ `class ; `n `n 43 | 44 | const void * `%const `class (void) { `n 45 | `t return _ `class ? _ `class : `n 46 | `t `t (_ `class = new( `meta (), `n 47 | `t `t `t " `class ", `super (), sizeof(struct `class ), `n 48 | `{links `class 49 | `t `t `t `method , " `tag ", `class _ `method , `n 50 | `} 51 | `t `t `t (void *) 0)); `n 52 | } `n 53 | 54 | `}fi 55 | `}dcl 56 | -------------------------------------------------------------------------------- /ooc/rep-10/c.rep: -------------------------------------------------------------------------------- 1 | // note that 'ctor' and its calling convention is burnt into this file 2 | // 3 | % init // implement %init request 4 | 5 | `{dcl 6 | `{ifnot `class ` 7 | `{if `newmeta 1 8 | 9 | `%selectors 10 | 11 | static void * `meta _ctor (void * _self, va_list * app) { `n 12 | `t struct `meta * self = super_ctor( `meta (), _self, app); `n 13 | `t Method selector; `n 14 | #ifdef va_copy `n 15 | `t va_list ap; va_copy(ap, * app); `n 16 | #else `n 17 | `t va_list ap = * app; `n 18 | #endif `n `n 19 | 20 | `%meta-ctor-loop 21 | #ifdef va_copy `n 22 | `t va_end(ap); `n 23 | #endif `n 24 | `t return self; `n 25 | } `n `n 26 | 27 | static const void * _ `meta ; `n `n 28 | 29 | const void * `%const `meta (void) { `n 30 | `t return _ `meta ? _ `meta : `n 31 | `t `t (_ `meta = new( `metaroot (), `n 32 | `t `t `t " `meta ", `supermeta (), sizeof(struct `meta ), `n 33 | `t `t `t ctor, "", `meta _ctor, `n 34 | `{links `meta 35 | `t `t `t `method , " `tag ", `meta _ `method , `n 36 | `} 37 | `t `t `t (void *) 0)); `n 38 | } `n `n 39 | 40 | `}fi 41 | 42 | static const void * _ `class ; `n `n 43 | 44 | const void * `%const `class (void) { `n 45 | `t return _ `class ? _ `class : `n 46 | `t `t (_ `class = new( `meta (), `n 47 | `t `t `t " `class ", `super (), sizeof(struct `class ), `n 48 | `{links `class 49 | `t `t `t `method , " `tag ", `class _ `method , `n 50 | `} 51 | `t `t `t (void *) 0)); `n 52 | } `n 53 | 54 | `}fi 55 | `}dcl 56 | -------------------------------------------------------------------------------- /ooc/rep-11/c.rep: -------------------------------------------------------------------------------- 1 | // note that 'ctor' and its calling convention is burnt into this file 2 | // 3 | % init // implement %init request 4 | 5 | `{dcl 6 | `{ifnot `class ` 7 | `{if `newmeta 1 8 | 9 | `%selectors 10 | 11 | static void * `meta _ctor (void * _self, va_list * app) { `n 12 | `t struct `meta * self = super_ctor( `meta (), _self, app); `n 13 | `t Method selector; `n 14 | #ifdef va_copy `n 15 | `t va_list ap; va_copy(ap, * app); `n 16 | #else `n 17 | `t va_list ap = * app; `n 18 | #endif `n `n 19 | 20 | `%meta-ctor-loop 21 | #ifdef va_copy `n 22 | `t va_end(ap); `n 23 | #endif `n 24 | `t return self; `n 25 | } `n `n 26 | 27 | static const void * _ `meta ; `n `n 28 | 29 | const void * `%const `meta (void) { `n 30 | `t return _ `meta ? _ `meta : `n 31 | `t `t (_ `meta = new( `metaroot (), `n 32 | `t `t `t " `meta ", `supermeta (), sizeof(struct `meta ), `n 33 | `t `t `t ctor, "", `meta _ctor, `n 34 | `{links `meta 35 | `t `t `t `method , " `tag ", `meta _ `method , `n 36 | `} 37 | `t `t `t (void *) 0)); `n 38 | } `n `n 39 | 40 | `}fi 41 | 42 | static const void * _ `class ; `n `n 43 | 44 | const void * `%const `class (void) { `n 45 | `t return _ `class ? _ `class : `n 46 | `t `t (_ `class = new( `meta (), `n 47 | `t `t `t " `class ", `super (), sizeof(struct `class ), `n 48 | `{links `class 49 | `t `t `t `method , " `tag ", `class _ `method , `n 50 | `} 51 | `t `t `t (void *) 0)); `n 52 | } `n 53 | 54 | `}fi 55 | `}dcl 56 | -------------------------------------------------------------------------------- /ooc/rep-9/c.rep: -------------------------------------------------------------------------------- 1 | // note that 'ctor' and its calling convention is burnt into this file 2 | // 3 | % init // implement %init request 4 | 5 | `{dcl 6 | `{ifnot `class ` 7 | `{if `newmeta 1 8 | 9 | `%selectors 10 | 11 | static void * `meta _ctor (void * _self, va_list * app) { `n 12 | `t struct `meta * self = super_ctor( `meta (), _self, app); `n 13 | `t typedef void (* voidf) (); `n 14 | `t voidf selector; `n 15 | #ifdef va_copy `n 16 | `t va_list ap; va_copy(ap, * app); `n 17 | #else `n 18 | `t va_list ap = * app; `n 19 | #endif `n `n 20 | 21 | `%meta-ctor-loop 22 | #ifdef va_copy `n 23 | `t va_end(ap); `n 24 | #endif `n 25 | `t return self; `n 26 | } `n `n 27 | 28 | static const void * _ `meta ; `n `n 29 | 30 | const void * `%const `meta (void) { `n 31 | `t return _ `meta ? _ `meta : `n 32 | `t `t (_ `meta = new( `metaroot (), `n 33 | `t `t `t " `meta ", `supermeta (), sizeof(struct `meta ), `n 34 | `t `t `t ctor, `meta _ctor, `n 35 | `{links `meta 36 | `t `t `t `method , `meta _ `method , `n 37 | `} 38 | `t `t `t (void *) 0)); `n 39 | } `n `n 40 | 41 | `}fi 42 | 43 | static const void * _ `class ; `n `n 44 | 45 | const void * `%const `class (void) { `n 46 | `t return _ `class ? _ `class : `n 47 | `t `t (_ `class = new( `meta (), `n 48 | `t `t `t " `class ", `super (), sizeof(struct `class ), `n 49 | `{links `class 50 | `t `t `t `method , `class _ `method , `n 51 | `} 52 | `t `t `t (void *) 0)); `n 53 | } `n 54 | 55 | `}fi 56 | `}dcl 57 | -------------------------------------------------------------------------------- /05/Name.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "binary.h" 7 | #include "parse.h" 8 | #include "value.h" 9 | #include "Name.h" 10 | #include "Name.r" 11 | #include "Var.h" /* to create variables */ 12 | 13 | /* 14 | * Name 15 | * maintain a table of Name structures 16 | */ 17 | 18 | #ifndef NAMES /* tunable: initial size of symbol table */ 19 | #define NAMES 4 20 | #endif 21 | 22 | static int cmp (const void * _key, const void * _elt) 23 | { const char * const * key = _key; 24 | const struct Name * const * elt = _elt; 25 | 26 | return strcmp(* key, (* elt) -> name); 27 | } 28 | 29 | static struct Name ** search (const char ** name) 30 | { static const struct Name ** names; /* dynamic table */ 31 | static size_t used, max; 32 | 33 | if (used >= max) 34 | { names = names 35 | ? realloc(names, (max *= 2) * sizeof * names) 36 | : malloc((max = NAMES) * sizeof * names); 37 | assert(names); 38 | } 39 | return binary(name, names, & used, sizeof * names, cmp); 40 | } 41 | 42 | void install (const void * np) 43 | { const char * name = ((struct Name *) np) -> name; 44 | struct Name ** pp = search(& name); 45 | 46 | if (* pp != (void *) name) 47 | error("cannot install name twice: %s", name); 48 | * pp = (struct Name *) np; 49 | } 50 | 51 | void * symbol; /* -> last struct Name found by screen() */ 52 | 53 | int screen (const char * name) 54 | { struct Name ** pp = search(& name); 55 | 56 | if (* pp == (void *) name) /* entered name */ 57 | * pp = new(Var, name); 58 | symbol = * pp; 59 | return (* pp) -> token; 60 | } 61 | -------------------------------------------------------------------------------- /10/Object.d: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | typedef void (* Method) (); // for respondsTo() 6 | 7 | %prot 8 | #include 9 | 10 | struct Method { 11 | const char * tag; // for respondsTo() 12 | Method selector; // returned by respondsTo() 13 | Method method; // accessed by the selector 14 | }; 15 | 16 | % Class Object { 17 | unsigned long magic; // magic number 18 | const Class @ class; // object's description 19 | % 20 | void delete (_self); // reclaim instance 21 | const Class @ classOf (const _self); // object's class 22 | size_t sizeOf (const _self); // object's size 23 | int isA (const _self, const Class @ class); // object belongs to class 24 | int isOf (const _self, const Class @ class);// object derives from class 25 | void * cast (const Class @ class, const _self); // asserts isOf() 26 | Method respondsTo (const _self, const char * tag); 27 | %- 28 | void * ctor (_self, va_list * app); // constructor 29 | void * dtor (_self); // destructor 30 | int differ (const _self, const Object @ b); // true if != 31 | int puto (const _self, FILE * fp); // display 32 | %} 33 | 34 | // order known in Object.c for static initialization 35 | % Class Class: Object { 36 | const char * name; // class' name 37 | const Class @ super; // class' superclass 38 | size_t size; // object's memory size 39 | % 40 | Object @ new (const _self, ...); // create instance 41 | const Class @ super (const _self); // class' superclass 42 | %} 43 | %prot 44 | #define MAGIC 0x0effaced // magic number for objects 45 | -------------------------------------------------------------------------------- /11/Object.d: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | typedef void (* Method) (); // for respondsTo() 6 | 7 | %prot 8 | #include 9 | 10 | struct Method { 11 | const char * tag; // for respondsTo() 12 | Method selector; // returned by respondsTo() 13 | Method method; // accessed by the selector 14 | }; 15 | 16 | % Class Object { 17 | unsigned long magic; // magic number 18 | const Class @ class; // object's description 19 | % 20 | const Class @ classOf (const _self); // object's class 21 | size_t sizeOf (const _self); // object's size 22 | int isA (const _self, const Class @ class); // object belongs to class 23 | int isOf (const _self, const Class @ class);// object derives from class 24 | void * cast (const Class @ class, const _self); // asserts isOf() 25 | Method respondsTo (const _self, const char * tag); 26 | %- 27 | void * ctor (_self, va_list * app); // constructor 28 | void * dtor (_self); // destructor 29 | int puto (const _self, FILE * fp); // display 30 | void delete (_self); // reclaim instance 31 | %+ 32 | Object @ new (const _self, ...); // create instance 33 | %} 34 | 35 | // order known in Object.c for static initialization 36 | % Class Class: Object { 37 | const char * name; // class' name 38 | const Class @ super; // class' superclass 39 | size_t size; // object's memory size 40 | % 41 | Object @ allocate (const _self); // memory for instance 42 | const Class @ super (const _self); // class' superclass 43 | %} 44 | %prot 45 | #define MAGIC 0x0effaced // magic number for objects 46 | -------------------------------------------------------------------------------- /14/makefile: -------------------------------------------------------------------------------- 1 | chapter = 2 | 3 | 1 = List.c Ic.c Crt.c Xt.c 4 | 5 | c = Objct.c $1 6 | d = Object $(1:.c=) 7 | h = $(c:.c=.h) 8 | l = lib.a 9 | m = hello.c button.c run.c cbutton.c crun.c xhello.c xbutton.c xrun.c 10 | r = $(c:.c=.r) 11 | t = $(m:.c=) 12 | 13 | rename = sed 's/Object/Objct/g' 14 | post = | $(rename) 15 | 16 | all: $t 17 | clean: ; rm -f $c $h $l $r $t *.o 18 | rm -rf *.dSYM 19 | 20 | test:: hello ; hello 21 | test:: button ; echo "a" | button 22 | test:: run ; echo "20 + 30 * 40 = Q" | run 23 | test:: cbutton ; echo a | cbutton 24 | test:: crun ; echo "20 + 30 * 40 = Q" | crun 25 | test:: xhello ;- xhello $(host) 26 | test:: xbutton ;- XENVIRONMENT=Xapp xbutton $(host) 27 | test:: xrun ; XENVIRONMENT=Xapp xrun $(host) 28 | 29 | hello: hello.o ; $(CC) $(CFLAGS) -o $@ hello.o $l 30 | button: button.o ; $(CC) $(CFLAGS) -o $@ button.o $l 31 | run: run.o ; $(CC) $(CFLAGS) -o $@ run.o $l 32 | cbutton: cbutton.o ; $(CC) $(CFLAGS) -o $@ cbutton.o $l $(curses) 33 | crun: crun.o ; $(CC) $(CFLAGS) -o $@ crun.o $l $(curses) 34 | xhello: xhello.o ; $(CC) $(CFLAGS) -o $@ xhello.o $l $(x11) 35 | xbutton: xbutton.o ; $(CC) $(CFLAGS) -o $@ xbutton.o $l $(x11) 36 | xrun: xrun.c ; $(CC) $(CFLAGS) -o $@ xrun.c $l $(x11) 37 | 38 | $t: $l 39 | $l: ; $(MAKE) l=$l o='$?' mklib 40 | 41 | Objct.h: Object.d ; $(OOC) -R $(OOCFLAGS) Object -h $(post) > $@ 42 | Objct.r: Object.d ; $(OOC) -R $(OOCFLAGS) Object -r $(post) > $@ 43 | Objct.c: Object.d 44 | Objct.c: Object.dc ; $(OOC) -R $(OOCFLAGS) Object Object.dc $(post) > $@ 45 | 46 | depend: makefile.etc 47 | 48 | include makefile.etc 49 | include ../make/Makefile.$(OSTYPE) 50 | -------------------------------------------------------------------------------- /11/Symbol.dc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "parse.h" // error() 6 | #include "Node.h" 7 | 8 | % Symbol ctor { 9 | struct Symbol * self = super_ctor(Symbol(), _self, app); 10 | 11 | self -> name = va_arg(* app, const char *); 12 | self -> lex = va_arg(* app, int); 13 | return self; 14 | } 15 | 16 | % Symbol name { 17 | %casts 18 | return self -> name; 19 | } 20 | 21 | % Symbol lex { 22 | %casts 23 | return self -> lex; 24 | } 25 | 26 | % : Reserved delete { // don't respondTo delete 27 | } 28 | 29 | % Var value { 30 | %casts 31 | return self -> value; 32 | } 33 | 34 | % Var setvalue { 35 | %casts 36 | return self -> value = value; 37 | } 38 | 39 | % Const ctor { 40 | struct Const * self = super_ctor(Const(), _self, app); 41 | 42 | setvalue(self, va_arg(* app, double)); 43 | return self; 44 | } 45 | 46 | % : Const delete { // don't respondTo delete 47 | } 48 | 49 | % Fun setfun { 50 | %casts 51 | if (self -> fun) 52 | delete(self -> fun); 53 | self -> fun = fun; 54 | } 55 | 56 | % Fun funvalue { 57 | %casts 58 | if (! self -> fun) 59 | error("undefined function"); 60 | setvalue(self, value); // argument for parameter 61 | return exec(self -> fun); 62 | } 63 | 64 | % Math ctor { 65 | struct Math * self = super_ctor(Math(), _self, app); 66 | 67 | self -> fun = va_arg(* app, function); 68 | return self; 69 | } 70 | 71 | % : Math delete { // don't respondTo delete 72 | } 73 | 74 | % Math mathvalue { 75 | double result; 76 | %casts 77 | errno = 0; 78 | result = self -> fun(value); 79 | if (errno) 80 | error("error in %s: %s", name(self), strerror(errno)); 81 | return result; 82 | } 83 | 84 | %init 85 | -------------------------------------------------------------------------------- /09/munch: -------------------------------------------------------------------------------- 1 | #! /usr/local/gnu/bin/gawk -f 2 | 3 | # nm -p object archive image ... | gawk -f munch 4 | # produces a class list 5 | 6 | # System V 7 | # nm -p produces lines 8 | # 1234567890 d _Class the static pointer 9 | # 1234567890 T Class the function 10 | 11 | # Solaris 12 | # nm -p produces lines 13 | # 1234567890 b _Class the static pointer 14 | # 1234567890 d _Class the statically initialized structure 15 | # 1234567890 T Class the function 16 | 17 | # Berkeley 18 | # nm -p produces symbol table ordered lines 19 | # 1234abcd s __Class the statically initialized structure 20 | # 1234abcd b __Class the static pointer 21 | # 1234abcd T _Class the function 22 | 23 | # MacOS X 64-bit 24 | # like Berkeley but with 16 hex digits 25 | 26 | # old awk appears to fail if a vector has never been stored into 27 | 28 | NF != 3 || $1 !~ /^[0-9a-f]+$/ { next } 29 | length($1) == 10 && $2 ~ /^[bd]$/ { sysv[$3] = 1; next } 30 | $2 ~ /^[bs]$/ { bsd[$3] = 1; next } 31 | $2 == "T" { T[$3] = 1; next } 32 | 33 | END { 34 | for (name in T) 35 | if ("_" name in bsd) # eliminate leading _ 36 | names[n ++] = substr(name, 2) 37 | else if ("_" name in sysv) 38 | names[n ++] = name 39 | # shellsort() 40 | for (gap = int(n/2); gap > 0; gap = int(gap/2)) 41 | for (i = gap; i < n; ++ i) 42 | for (j = i-gap; j >= 0 && \ 43 | names[j] > names[j+gap]; j -= gap) 44 | { name = names[j] 45 | names[j] = names[j+gap] 46 | names[j+gap] = name 47 | } 48 | 49 | for (i = 0; i < n; ++ i) 50 | printf "extern const void * %s (void);\n", names[i] 51 | 52 | print "\nconst void * (* classes [])(void) = {" 53 | for (i = 0; i < n; ++ i) 54 | printf "\t%s,\n", names[i] 55 | print "0 };" 56 | } 57 | -------------------------------------------------------------------------------- /14/Object.d: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | typedef void (* Method) (); // for respondsTo() 6 | 7 | %prot 8 | #include 9 | 10 | struct Method { 11 | const char * tag; // for respondsTo() 12 | Method selector; // returned by respondsTo() 13 | Method method; // accessed by the selector 14 | }; 15 | 16 | % Class Object { 17 | unsigned long magic; // magic number 18 | const Class @ class; // object's description 19 | % 20 | const Class @ classOf (const _self); // object's class 21 | size_t sizeOf (const _self); // object's size 22 | int isA (const _self, const Class @ class); // object belongs to class 23 | int isOf (const _self, const Class @ class);// object derives from class 24 | void * cast (const Class @ class, const _self); // asserts isOf() 25 | Method respondsTo (const _self, const char * tag); 26 | %- 27 | void * ctor (_self, va_list * app); // constructor 28 | void * dtor (_self); // destructor 29 | int puto (const _self, FILE * fp); // display 30 | void delete (_self); // reclaim instance 31 | void forward (const _self, void * result, \ 32 | Method selector, const char * name, ...); 33 | %+ 34 | Object @ new (const _self, ...); // create instance 35 | %} 36 | 37 | // order known in Object.c for static initialization 38 | % Class Class: Object { 39 | const char * name; // class' name 40 | const Class @ super; // class' superclass 41 | size_t size; // object's memory size 42 | % 43 | Object @ allocate (const _self); // memory for instance 44 | const Class @ super (const _self); // class' superclass 45 | const char * nameOf (const _self); // class' name 46 | %} 47 | %prot 48 | #define MAGIC 0x0effaced // magic number for objects 49 | -------------------------------------------------------------------------------- /12/Object.d: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | typedef void (* Method) (); // for respondsTo() 6 | void * retrieve (FILE * fp); // object from file 7 | 8 | %prot 9 | #include 10 | 11 | struct Method { 12 | const char * tag; // for respondsTo() 13 | Method selector; // returned by respondsTo() 14 | Method method; // accessed by the selector 15 | }; 16 | 17 | % Class Object { 18 | unsigned long magic; // magic number 19 | const Class @ class; // object's description 20 | % 21 | const Class @ classOf (const _self); // object's class 22 | size_t sizeOf (const _self); // object's size 23 | int isA (const _self, const Class @ class); // object belongs to class 24 | int isOf (const _self, const Class @ class);// object derives from class 25 | void * cast (const Class @ class, const _self); // asserts isOf() 26 | Method respondsTo (const _self, const char * tag); 27 | %- 28 | void * ctor (_self, va_list * app); // constructor 29 | void * dtor (_self); // destructor 30 | int puto (const _self, FILE * fp); // display 31 | void delete (_self); // reclaim instance 32 | : void * geto (_self, FILE * fp); // construct from file 33 | %+ 34 | Object @ new (const _self, ...); // create instance 35 | %} 36 | 37 | // order known in Object.c for static initialization 38 | % Class Class: Object { 39 | const char * name; // class' name 40 | const Class @ super; // class' superclass 41 | size_t size; // object's memory size 42 | % 43 | Object @ allocate (const _self); // memory for instance 44 | const Class @ super (const _self); // class' superclass 45 | const char * nameOf (const _self); // class' name 46 | %} 47 | %prot 48 | #define MAGIC 0x0effaced // magic number for objects 49 | -------------------------------------------------------------------------------- /ooc/rep/c-R.rep: -------------------------------------------------------------------------------- 1 | // differences from c.rep: 2 | // `metaroot_ctor() does not call super_ctor() -- no need to, we hope 3 | // first arguments to ctor are copied to struct in order of declaration 4 | // then argumentlist is shared with other `meta_ctor()s 5 | // memcpy() performs binary inheritance 6 | // there is no way to generate `root and `metaroot descriptions and init() 7 | // 8 | // note that 'ctor' and its calling convention are burnt into this file 9 | // 10 | % init // implement %init request for root class 11 | 12 | `{dcl 13 | `{if `class `root 14 | 15 | `%selectors 16 | 17 | static void * `metaroot _ctor (void * _self, va_list * app) { `n 18 | `t struct `metaroot * self = _self; `n 19 | `t const size_t offset = offsetof(struct `metaroot , ctor); `n 20 | `t Method selector; `n 21 | `t va_list ap; `n `n 22 | 23 | `{struct `metaroot 24 | `{if `name super 25 | `t self -> `name = cast( `metaroot (), va_arg(* app, `type )); `n 26 | `} `{else 27 | `t self -> `name = va_arg(* app, `type ); `n 28 | `}fi 29 | `}n 30 | 31 | `t memcpy((char *) self + offset, ` \ 32 | (char *) self -> super + offset, `n 33 | `t `t sizeOf(self -> super) - offset); `n `n 34 | 35 | #ifdef va_copy `n 36 | `t va_copy(ap, * app); `n 37 | #else `n 38 | `t ap = * app; `n 39 | #endif `n 40 | `%meta-ctor-loop 41 | #ifdef va_copy `n 42 | `t va_end(ap); `n 43 | #endif `n 44 | `t return self; `n 45 | } `n `n 46 | 47 | // we assume that `root and `metaroot are statically initialized structures 48 | 49 | const void * `%const `root (void) { `n 50 | `t return & _ `root ; `n 51 | } `n `n 52 | 53 | const void * `%const `metaroot (void) { `n 54 | `t return & _ `metaroot ; `n 55 | } `n `n 56 | 57 | `}fi 58 | `}dcl 59 | -------------------------------------------------------------------------------- /ooc/rep-10/c-R.rep: -------------------------------------------------------------------------------- 1 | // differences from c.rep: 2 | // `metaroot_ctor() does not call super_ctor() -- no need to, we hope 3 | // first arguments to ctor are copied to struct in order of declaration 4 | // then argumentlist is shared with other `meta_ctor()s 5 | // memcpy() performs binary inheritance 6 | // there is no way to generate `root and `metaroot descriptions and init() 7 | // 8 | // note that 'ctor' and its calling convention are burnt into this file 9 | // 10 | % init // implement %init request for root class 11 | 12 | `{dcl 13 | `{if `class `root 14 | 15 | `%selectors 16 | 17 | static void * `metaroot _ctor (void * _self, va_list * app) { `n 18 | `t struct `metaroot * self = _self; `n 19 | `t const size_t offset = offsetof(struct `metaroot , ctor); `n 20 | `t Method selector; `n 21 | `t va_list ap; `n `n 22 | 23 | `{struct `metaroot 24 | `{if `name super 25 | `t self -> `name = cast( `metaroot (), va_arg(* app, `type )); `n 26 | `} `{else 27 | `t self -> `name = va_arg(* app, `type ); `n 28 | `}fi 29 | `}n 30 | 31 | `t memcpy((char *) self + offset, ` \ 32 | (char *) self -> super + offset, `n 33 | `t `t sizeOf(self -> super) - offset); `n `n 34 | 35 | #ifdef va_copy `n 36 | `t va_copy(ap, * app); `n 37 | #else `n 38 | `t ap = * app; `n 39 | #endif `n 40 | `%meta-ctor-loop 41 | #ifdef va_copy `n 42 | `t va_end(ap); `n 43 | #endif `n 44 | `t return self; `n 45 | } `n `n 46 | 47 | // we assume that `root and `metaroot are statically initialized structures 48 | 49 | const void * `%const `root (void) { `n 50 | `t return & _ `root ; `n 51 | } `n `n 52 | 53 | const void * `%const `metaroot (void) { `n 54 | `t return & _ `metaroot ; `n 55 | } `n `n 56 | 57 | `}fi 58 | `}dcl 59 | -------------------------------------------------------------------------------- /ooc/rep-11/c-R.rep: -------------------------------------------------------------------------------- 1 | // differences from c.rep: 2 | // `metaroot_ctor() does not call super_ctor() -- no need to, we hope 3 | // first arguments to ctor are copied to struct in order of declaration 4 | // then argumentlist is shared with other `meta_ctor()s 5 | // memcpy() performs binary inheritance 6 | // there is no way to generate `root and `metaroot descriptions and init() 7 | // 8 | // note that 'ctor' and its calling convention are burnt into this file 9 | // 10 | % init // implement %init request for root class 11 | 12 | `{dcl 13 | `{if `class `root 14 | 15 | `%selectors 16 | 17 | static void * `metaroot _ctor (void * _self, va_list * app) { `n 18 | `t struct `metaroot * self = _self; `n 19 | `t const size_t offset = offsetof(struct `metaroot , ctor); `n 20 | `t Method selector; `n 21 | `t va_list ap; `n `n 22 | 23 | `{struct `metaroot 24 | `{if `name super 25 | `t self -> `name = cast( `metaroot (), va_arg(* app, `type )); `n 26 | `} `{else 27 | `t self -> `name = va_arg(* app, `type ); `n 28 | `}fi 29 | `}n 30 | 31 | `t memcpy((char *) self + offset, ` \ 32 | (char *) self -> super + offset, `n 33 | `t `t sizeOf(self -> super) - offset); `n `n 34 | 35 | #ifdef va_copy `n 36 | `t va_copy(ap, * app); `n 37 | #else `n 38 | `t ap = * app; `n 39 | #endif `n 40 | `%meta-ctor-loop 41 | #ifdef va_copy `n 42 | `t va_end(ap); `n 43 | #endif `n 44 | `t return self; `n 45 | } `n `n 46 | 47 | // we assume that `root and `metaroot are statically initialized structures 48 | 49 | const void * `%const `root (void) { `n 50 | `t return & _ `root ; `n 51 | } `n `n 52 | 53 | const void * `%const `metaroot (void) { `n 54 | `t return & _ `metaroot ; `n 55 | } `n `n 56 | 57 | `}fi 58 | `}dcl 59 | -------------------------------------------------------------------------------- /07/Object.dc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // Object 5 | 6 | % Object ctor { 7 | return _self; 8 | } 9 | 10 | % Object dtor { 11 | return _self; 12 | } 13 | 14 | % Object differ { 15 | return _self != b; 16 | } 17 | 18 | % Object puto { 19 | const struct Class * class = classOf(_self); 20 | 21 | return fprintf(fp, "%s at %p\n", class -> name, _self); 22 | } 23 | 24 | % delete { 25 | if (_self) 26 | free(dtor(_self)); 27 | } 28 | 29 | % classOf { 30 | %casts 31 | assert(self -> class); 32 | return self -> class; 33 | } 34 | 35 | % sizeOf { 36 | const struct Class * class = classOf(_self); 37 | 38 | return class -> size; 39 | } 40 | 41 | // Class 42 | 43 | % Class dtor { 44 | %casts 45 | fprintf(stderr, "%s: cannot destroy class\n", self -> name); 46 | return 0; 47 | } 48 | 49 | % new { 50 | struct Object * object; 51 | va_list ap; 52 | %casts 53 | assert(self -> size); 54 | object = calloc(1, self -> size); 55 | assert(object); 56 | object -> class = self; 57 | va_start(ap, _self); 58 | object = ctor(object, & ap); 59 | va_end(ap); 60 | return object; 61 | } 62 | 63 | % super { 64 | %casts 65 | assert(self -> super); 66 | return self -> super; 67 | } 68 | 69 | // initialization 70 | // _Class and _Object are statically initialized structures 71 | 72 | static const struct Class _Object; 73 | static const struct Class _Class; 74 | 75 | %init 76 | 77 | static const struct Class _Object = { 78 | { & _Class }, 79 | "Object", & _Object, sizeof(struct Object), 80 | Object_ctor, Object_dtor, Object_differ, Object_puto 81 | }; 82 | 83 | static const struct Class _Class = { 84 | { & _Class }, 85 | "Class", & _Object, sizeof(struct Class), 86 | Class_ctor, Class_dtor, Object_differ, Object_puto 87 | }; 88 | 89 | const void * Object = & _Object; 90 | const void * Class = & _Class; 91 | -------------------------------------------------------------------------------- /ooc/rep-9/c-R.rep: -------------------------------------------------------------------------------- 1 | // differences from c.rep: 2 | // `metaroot_ctor() does not call super_ctor() -- no need to, we hope 3 | // first arguments to ctor are copied to struct in order of declaration 4 | // then argumentlist is shared with other `meta_ctor()s 5 | // memcpy() performs binary inheritance 6 | // there is no way to generate `root and `metaroot descriptions and init() 7 | // 8 | // note that 'ctor' and its calling convention are burnt into this file 9 | // 10 | % init // implement %init request for root class 11 | 12 | `{dcl 13 | `{if `class `root 14 | 15 | `%selectors 16 | 17 | static void * `metaroot _ctor (void * _self, va_list * app) { `n 18 | `t struct `metaroot * self = _self; `n 19 | `t const size_t offset = offsetof(struct `metaroot , ctor); `n 20 | `t typedef void (* voidf) (); `n 21 | `t voidf selector; `n 22 | `t va_list ap; `n `n 23 | 24 | `{struct `metaroot 25 | `{if `name super 26 | `t self -> `name = cast( `metaroot (), va_arg(* app, `type )); `n 27 | `} `{else 28 | `t self -> `name = va_arg(* app, `type ); `n 29 | `}fi 30 | `}n 31 | 32 | `t memcpy((char *) self + offset, ` \ 33 | (char *) self -> super + offset, `n 34 | `t `t sizeOf(self -> super) - offset); `n `n 35 | 36 | #ifdef va_copy `n 37 | `t va_copy(ap, * app); `n 38 | #else `n 39 | `t ap = * app; `n 40 | #endif `n 41 | `%meta-ctor-loop 42 | #ifdef va_copy `n 43 | `t va_end(ap); `n 44 | #endif `n 45 | `t return self; `n 46 | } `n `n 47 | 48 | // we assume that `root and `metaroot are statically initialized structures 49 | 50 | const void * `%const `root (void) { `n 51 | `t return & _ `root ; `n 52 | } `n `n 53 | 54 | const void * `%const `metaroot (void) { `n 55 | `t return & _ `metaroot ; `n 56 | } `n `n 57 | 58 | `}fi 59 | `}dcl 60 | -------------------------------------------------------------------------------- /01/Set.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "new.h" 5 | #include "Set.h" 6 | #include "Object.h" 7 | 8 | const void * Set; 9 | const void * Object; 10 | 11 | #if ! defined MANY || MANY < 1 12 | #define MANY 10 13 | #endif 14 | 15 | static int heap [MANY]; 16 | 17 | void * new (const void * type, ...) 18 | { int * p; /* & heap[1..] */ 19 | 20 | for (p = heap + 1; p < heap + MANY; ++ p) 21 | if (! * p) 22 | break; 23 | assert(p < heap + MANY); 24 | * p = MANY; 25 | return p; 26 | } 27 | 28 | void delete (void * _item) 29 | { int * item = _item; 30 | 31 | if (item) 32 | { assert(item > heap && item < heap + MANY); 33 | * item = 0; 34 | } 35 | } 36 | 37 | void * add (void * _set, const void * _element) 38 | { int * set = _set; 39 | const int * element = _element; 40 | 41 | assert(set > heap && set < heap + MANY); 42 | assert(* set == MANY); 43 | assert(element > heap && element < heap + MANY); 44 | 45 | if (* element == MANY) 46 | * (int *) element = set - heap; 47 | else 48 | assert(* element == set - heap); 49 | 50 | return (void *) element; 51 | } 52 | 53 | void * find (const void * _set, const void * _element) 54 | { const int * set = _set; 55 | const int * element = _element; 56 | 57 | assert(set > heap && set < heap + MANY); 58 | assert(* set == MANY); 59 | assert(element > heap && element < heap + MANY); 60 | assert(* element); 61 | 62 | return * element == set - heap ? (void *) element : 0; 63 | } 64 | 65 | int contains (const void * _set, const void * _element) 66 | { 67 | return find(_set, _element) != 0; 68 | } 69 | 70 | void * drop (void * _set, const void * _element) 71 | { int * element = find(_set, _element); 72 | 73 | if (element) 74 | * element = MANY; 75 | return element; 76 | } 77 | 78 | int differ (const void * a, const void * b) 79 | { 80 | return a != b; 81 | } 82 | -------------------------------------------------------------------------------- /11/Node.d: -------------------------------------------------------------------------------- 1 | // abstract base classes for expression tree 2 | 3 | % NodeClass: Class Node: Object { 4 | void * next; 5 | % 6 | void sunder (_self); 7 | %- 8 | double exec (const _self); 9 | %+ 10 | void reclaim (const _self, Method how); 11 | %} 12 | 13 | % NodeClass Monad: Node { 14 | void * down; 15 | %} 16 | %prot 17 | #define down(x) (((struct Monad *)(x)) -> down) 18 | 19 | % NodeClass Dyad: Node { 20 | void * left; 21 | void * right; 22 | %} 23 | %prot 24 | #define left(x) (((struct Dyad *)(x)) -> left) 25 | #define right(x) (((struct Dyad *)(x)) -> right) 26 | 27 | // literals 28 | 29 | // new(Number(), value) 30 | 31 | % NodeClass Number: Node { 32 | double value; 33 | %} 34 | 35 | // symbol value references 36 | 37 | // new(Global(), constant-or-variable) 38 | // new(Parm(), function) 39 | 40 | % NodeClass Val: Monad { 41 | %} 42 | 43 | % NodeClass Global: Val { 44 | %} 45 | 46 | % NodeClass Parm: Val { 47 | %} 48 | 49 | // unary operations 50 | 51 | // new(Minus(), subtree) 52 | 53 | % NodeClass Unary: Monad { 54 | %} 55 | 56 | % NodeClass Minus: Unary { 57 | %} 58 | 59 | // symbol access 60 | 61 | // new(Assign(), var, right-subtree) 62 | // new(Builtin(), math, arg-subtree) 63 | // new(User(), fun, arg-subtree) 64 | 65 | % NodeClass Ref: Dyad { 66 | %} 67 | 68 | % NodeClass Assign: Ref { 69 | %} 70 | 71 | % NodeClass Builtin: Ref { 72 | %} 73 | 74 | % NodeClass User: Ref { 75 | %} 76 | 77 | // binary operations 78 | 79 | // new(Add(), left-subtree, right-subtree) 80 | // new(Sub(), left-subtree, right-subtree) 81 | // new(Mult(), left-subtree, right-subtree) 82 | // new(Div(), left-subtree, right-subtree) 83 | 84 | % NodeClass Binary: Dyad { 85 | %} 86 | 87 | % NodeClass Add: Binary { 88 | %} 89 | 90 | % NodeClass Sub: Binary { 91 | %} 92 | 93 | % NodeClass Mult: Binary { 94 | %} 95 | 96 | % NodeClass Div: Binary { 97 | %} 98 | -------------------------------------------------------------------------------- /12/Node.d: -------------------------------------------------------------------------------- 1 | // abstract base classes for expression tree 2 | 3 | % NodeClass: Class Node: Object { 4 | void * next; 5 | % 6 | void sunder (_self); 7 | %- 8 | double exec (const _self); 9 | %+ 10 | void reclaim (const _self, Method how); 11 | %} 12 | 13 | % NodeClass Monad: Node { 14 | void * down; 15 | %} 16 | %prot 17 | #define down(x) (((struct Monad *)(x)) -> down) 18 | 19 | % NodeClass Dyad: Node { 20 | void * left; 21 | void * right; 22 | %} 23 | %prot 24 | #define left(x) (((struct Dyad *)(x)) -> left) 25 | #define right(x) (((struct Dyad *)(x)) -> right) 26 | 27 | // literals 28 | 29 | // new(Number(), value) 30 | 31 | % NodeClass Number: Node { 32 | double value; 33 | %} 34 | 35 | // symbol value references 36 | 37 | // new(Global(), constant-or-variable) 38 | // new(Parm(), function) 39 | 40 | % NodeClass Val: Monad { 41 | %} 42 | 43 | % NodeClass Global: Val { 44 | %} 45 | 46 | % NodeClass Parm: Val { 47 | %} 48 | 49 | // unary operations 50 | 51 | // new(Minus(), subtree) 52 | 53 | % NodeClass Unary: Monad { 54 | %} 55 | 56 | % NodeClass Minus: Unary { 57 | %} 58 | 59 | // symbol access 60 | 61 | // new(Assign(), var, right-subtree) 62 | // new(Builtin(), math, arg-subtree) 63 | // new(User(), fun, arg-subtree) 64 | 65 | % NodeClass Ref: Dyad { 66 | %} 67 | 68 | % NodeClass Assign: Ref { 69 | %} 70 | 71 | % NodeClass Builtin: Ref { 72 | %} 73 | 74 | % NodeClass User: Ref { 75 | %} 76 | 77 | // binary operations 78 | 79 | // new(Add(), left-subtree, right-subtree) 80 | // new(Sub(), left-subtree, right-subtree) 81 | // new(Mult(), left-subtree, right-subtree) 82 | // new(Div(), left-subtree, right-subtree) 83 | 84 | % NodeClass Binary: Dyad { 85 | %} 86 | 87 | % NodeClass Add: Binary { 88 | %} 89 | 90 | % NodeClass Sub: Binary { 91 | %} 92 | 93 | % NodeClass Mult: Binary { 94 | %} 95 | 96 | % NodeClass Div: Binary { 97 | %} 98 | -------------------------------------------------------------------------------- /13/Node.d: -------------------------------------------------------------------------------- 1 | // abstract base classes for expression tree 2 | 3 | % NodeClass: Class Node: Object { 4 | void * next; 5 | % 6 | void sunder (_self); 7 | %- 8 | double exec (const _self); 9 | %+ 10 | void reclaim (const _self, Method how); 11 | %} 12 | 13 | % NodeClass Monad: Node { 14 | void * down; 15 | %} 16 | %prot 17 | #define down(x) (((struct Monad *)(x)) -> down) 18 | 19 | % NodeClass Dyad: Node { 20 | void * left; 21 | void * right; 22 | %} 23 | %prot 24 | #define left(x) (((struct Dyad *)(x)) -> left) 25 | #define right(x) (((struct Dyad *)(x)) -> right) 26 | 27 | // literals 28 | 29 | // new(Number(), value) 30 | 31 | % NodeClass Number: Node { 32 | double value; 33 | %} 34 | 35 | // symbol value references 36 | 37 | // new(Global(), constant-or-variable) 38 | // new(Parm(), function) 39 | 40 | % NodeClass Val: Monad { 41 | %} 42 | 43 | % NodeClass Global: Val { 44 | %} 45 | 46 | % NodeClass Parm: Val { 47 | %} 48 | 49 | // unary operations 50 | 51 | // new(Minus(), subtree) 52 | 53 | % NodeClass Unary: Monad { 54 | %} 55 | 56 | % NodeClass Minus: Unary { 57 | %} 58 | 59 | // symbol access 60 | 61 | // new(Assign(), var, right-subtree) 62 | // new(Builtin(), math, arg-subtree) 63 | // new(User(), fun, arg-subtree) 64 | 65 | % NodeClass Ref: Dyad { 66 | %} 67 | 68 | % NodeClass Assign: Ref { 69 | %} 70 | 71 | % NodeClass Builtin: Ref { 72 | %} 73 | 74 | % NodeClass User: Ref { 75 | %} 76 | 77 | // binary operations 78 | 79 | // new(Add(), left-subtree, right-subtree) 80 | // new(Sub(), left-subtree, right-subtree) 81 | // new(Mult(), left-subtree, right-subtree) 82 | // new(Div(), left-subtree, right-subtree) 83 | 84 | % NodeClass Binary: Dyad { 85 | %} 86 | 87 | % NodeClass Add: Binary { 88 | %} 89 | 90 | % NodeClass Sub: Binary { 91 | %} 92 | 93 | % NodeClass Mult: Binary { 94 | %} 95 | 96 | % NodeClass Div: Binary { 97 | %} 98 | -------------------------------------------------------------------------------- /13/Object.d: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | typedef void (* Method) (); // for respondsTo() 6 | void * retrieve (FILE * fp); // object from file 7 | 8 | %prot 9 | #include 10 | 11 | struct Method { 12 | const char * tag; // for respondsTo() 13 | Method selector; // returned by respondsTo() 14 | Method method; // accessed by the selector 15 | }; 16 | 17 | % Class Object { 18 | unsigned long magic; // magic number 19 | const Class @ class; // object's description 20 | % 21 | const Class @ classOf (const _self); // object's class 22 | size_t sizeOf (const _self); // object's size 23 | int isA (const _self, const Class @ class); // object belongs to class 24 | int isOf (const _self, const Class @ class);// object derives from class 25 | void * cast (const Class @ class, const _self); // asserts isOf() 26 | Method respondsTo (const _self, const char * tag); 27 | %- 28 | void * ctor (_self, va_list * app); // constructor 29 | void * dtor (_self); // destructor 30 | int differ (const _self, const Object @ b); // true if != 31 | int puto (const _self, FILE * fp); // display 32 | void delete (_self); // reclaim instance 33 | : void * geto (_self, FILE * fp); // construct from file 34 | %+ 35 | Object @ new (const _self, ...); // create instance 36 | %} 37 | 38 | // order known in Object.c for static initialization 39 | % Class Class: Object { 40 | const char * name; // class' name 41 | const Class @ super; // class' superclass 42 | size_t size; // object's memory size 43 | % 44 | Object @ allocate (const _self); // memory for instance 45 | const Class @ super (const _self); // class' superclass 46 | const char * nameOf (const _self); // class' name 47 | %} 48 | %prot 49 | #define MAGIC 0x0effaced // magic number for objects 50 | -------------------------------------------------------------------------------- /man/cat4/Crt.0: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Crt(4) Crt(4) 5 | 6 | 7 | NAME 8 | IcClass Crt: Ic -- input/output objects for curses 9 | 10 | SYNOPSIS 11 | Objct 12 | Ic 13 | Crt 14 | CButton 15 | CLineout 16 | new(Crt()); 17 | new(CButton(), "text", y, x); 18 | new(CLineOut(), y, x, len); 19 | void makeWindow (self, int rows, int cols, int x, int y) 20 | void addStr (self, int y, int x, const char * s) 21 | void crtBox (self) 22 | 23 | DESCRIPTION 24 | A Crt object wraps a curses(3) window. curses is initial- 25 | ized when the first Crt object is created. 26 | 27 | Crt_gate() is the event loop: it monitors the keyboard; it 28 | implements a vi-style cursor move for the keys hjkl, and 29 | possibly, for the arrow keys; if return is pressed, it 30 | sends an Event object with kind 1 and an array with column 31 | and row position; if control-D is pressed, gate returns 32 | reject; any other key is sent on as an Event object with a 33 | string containing the key character. 34 | 35 | A CLineOut object implements a LineOut object on a curses 36 | screen. Incoming strings should not exceed len bytes. 37 | 38 | A CButton object implements a Button object on a curses 39 | screen. If it receives a matching text, it sends it. 40 | Additionally, if it receives a position event, e.g., from 41 | a Crt object, and if the coordinates are within its win- 42 | dow, it sends its text on. 43 | 44 | SEE ALSO 45 | Event(4) 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | local: ats 1 65 | 66 | 67 | -------------------------------------------------------------------------------- /01/Bag.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "new.h" 6 | #include "Set.h" 7 | #include "Object.h" 8 | 9 | struct Set { unsigned count; }; 10 | struct Object { unsigned count; struct Set * in; }; 11 | 12 | static const size_t _Set = sizeof(struct Set); 13 | static const size_t _Object = sizeof(struct Object); 14 | 15 | const void * Set = & _Set; 16 | const void * Object = & _Object; 17 | 18 | void * new (const void * type, ...) 19 | { const size_t size = * (const size_t *) type; 20 | void * p = calloc(1, size); 21 | 22 | assert(p); 23 | return p; 24 | } 25 | 26 | void delete (void * item) 27 | { 28 | free(item); 29 | } 30 | 31 | void * add (void * _set, const void * _element) 32 | { struct Set * set = _set; 33 | struct Object * element = (void *) _element; 34 | 35 | assert(set); 36 | assert(element); 37 | 38 | if (! element -> in) 39 | element -> in = set; 40 | else 41 | assert(element -> in == set); 42 | ++ element -> count, ++ set -> count; 43 | 44 | return element; 45 | } 46 | 47 | void * find (const void * _set, const void * _element) 48 | { const struct Object * element = _element; 49 | 50 | assert(_set); 51 | assert(element); 52 | 53 | return element -> in == _set ? (void *) element : 0; 54 | } 55 | 56 | int contains (const void * _set, const void * _element) 57 | { 58 | return find(_set, _element) != 0; 59 | } 60 | 61 | void * drop (void * _set, const void * _element) 62 | { struct Set * set = _set; 63 | struct Object * element = find(set, _element); 64 | 65 | if (element) 66 | { if (-- element -> count == 0) 67 | element -> in = 0; 68 | -- set -> count; 69 | } 70 | return element; 71 | } 72 | 73 | unsigned count (const void * _set) 74 | { const struct Set * set = _set; 75 | 76 | assert(set); 77 | return set -> count; 78 | } 79 | 80 | int differ (const void * a, const void * b) 81 | { 82 | return a != b; 83 | } 84 | -------------------------------------------------------------------------------- /man/man4/Crt.4: -------------------------------------------------------------------------------- 1 | .\" Crt.4 -- 1.2 Sep 30 06:35:24 1993 2 | .\" Copyright (c) 1993 Axel T. Schreiner 3 | .TH Crt 4 "local: ats" 4 | .SH NAME 5 | \f3IcClass Crt: Ic\fP \(em input/output objects for curses 6 | .SH SYNOPSIS 7 | .nf 8 | Objct 9 | Ic 10 | \f3Crt\fP 11 | CButton 12 | CLineout 13 | .sp .5 14 | .B new(Crt()); 15 | \f3new(CButton(), "\f2text\fP", \f2y\f3, \f2x\f3);\f1 16 | \f3new(CLineOut(), \f2\y\f3, \f2x\f3, \f2len\f3);\f1 17 | .sp .5 18 | \f3void makeWindow (\f2self\f3, int \f2rows\f3, int \f2cols\f3, int \f2x\f3, int \f2y\f3)\f1 19 | \f3void addStr (\f2self\f3, int \f2y\f3, int \f2x\f3, const char * \f2s\f3)\f1 20 | .BI "void crtBox (" self ) 21 | .SH DESCRIPTION 22 | A 23 | .B Crt 24 | object wraps a 25 | .IR curses (3) 26 | window. 27 | .I curses 28 | is initialized 29 | when the first 30 | .B Crt 31 | object is created. 32 | .PP 33 | .B Crt_gate() 34 | is the event loop: 35 | it monitors the keyboard; 36 | it implements a 37 | .IR vi -style 38 | cursor move for the keys 39 | .BR hjkl , 40 | and possibly, for the arrow keys; 41 | if 42 | .I return 43 | is pressed, it sends an 44 | .B Event 45 | object with 46 | .I kind 47 | 1 and an array with column and row position; 48 | if 49 | .IR control -D 50 | is pressed, 51 | .B gate 52 | returns 53 | .BR reject ; 54 | any other key is sent on as an 55 | .B Event 56 | object with a string containing the key character. 57 | .PP 58 | A 59 | .B CLineOut 60 | object implements a 61 | .B LineOut 62 | object on a 63 | .I curses 64 | screen. 65 | Incoming strings should not exceed 66 | .I len 67 | bytes. 68 | .PP 69 | A 70 | .B CButton 71 | object implements a 72 | .B Button 73 | object on a 74 | .I curses 75 | screen. 76 | If it receives a matching text, it sends it. 77 | Additionally, if it receives a position event, 78 | e.g., from a 79 | .B Crt 80 | object, 81 | and if the coordinates are within its window, it sends its text on. 82 | .SH SEE ALSO 83 | Event(4) 84 | -------------------------------------------------------------------------------- /02/Atom.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "String.h" 6 | #include "new.h" 7 | #include "new.r" 8 | 9 | struct String { 10 | const void * class; /* must be first */ 11 | char * text; 12 | struct String * next; 13 | unsigned count; 14 | }; 15 | 16 | static struct String * ring; /* of all strings */ 17 | 18 | static void * String_ctor (void * _self, va_list * app) 19 | { struct String * self = _self; 20 | const char * text = va_arg(* app, const char *); 21 | 22 | if (ring) 23 | { struct String * p = ring; 24 | 25 | do 26 | if (strcmp(p -> text, text) == 0) 27 | { ++ p -> count; 28 | free(self); 29 | return p; 30 | } 31 | while ((p = p -> next) != ring); 32 | } 33 | else 34 | ring = self; 35 | 36 | self -> next = ring -> next, ring -> next = self; 37 | self -> count = 1; 38 | 39 | self -> text = malloc(strlen(text) + 1); 40 | assert(self -> text); 41 | strcpy(self -> text, text); 42 | return self; 43 | } 44 | 45 | static void * String_dtor (void * _self) 46 | { struct String * self = _self; 47 | 48 | if (-- self -> count > 0) 49 | return 0; 50 | 51 | assert(ring); 52 | if (ring == self) 53 | ring = self -> next; 54 | if (ring == self) 55 | ring = 0; 56 | else 57 | { struct String * p = ring; 58 | 59 | while (p -> next != self) 60 | { p = p -> next; 61 | assert(p != ring); 62 | } 63 | p -> next = self -> next; 64 | } 65 | 66 | free(self -> text), self -> text = 0; 67 | return self; 68 | } 69 | 70 | static void * String_clone (const void * _self) 71 | { struct String * self = (void *) _self; 72 | 73 | ++ self -> count; 74 | return self; 75 | } 76 | 77 | static int String_differ (const void * self, const void * b) 78 | { 79 | return self != b; 80 | } 81 | 82 | static const struct Class _String = { 83 | sizeof(struct String), 84 | String_ctor, String_dtor, 85 | String_clone, String_differ 86 | }; 87 | 88 | const void * String = & _String; 89 | -------------------------------------------------------------------------------- /05/mathlib.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "Name.h" 8 | #include "Name.r" 9 | #include "mathlib.h" 10 | #include "parse.h" 11 | #include "value.h" 12 | #include "value.r" 13 | 14 | /* 15 | * libm(3) functions 16 | * tree -> struct Bin 17 | * type: Math 18 | * left -> struct Math for sin, etc. 19 | * right -> argument tree 20 | */ 21 | 22 | struct Math { struct Name _; 23 | double (* funct) (double); 24 | }; 25 | 26 | #define funct(tree) (((struct Math *) left(tree)) -> funct) 27 | 28 | static double doMath (const void * tree) 29 | { double result = exec(right(tree)); 30 | 31 | errno = 0; 32 | result = funct(tree)(result); 33 | if (errno) 34 | error("error in %s: %s", 35 | ((struct Math *) left(tree)) -> _.name, 36 | strerror(errno)); 37 | return result; 38 | } 39 | 40 | static void freeMath (void * tree) 41 | { 42 | delete(right(tree)); 43 | free(tree); 44 | } 45 | 46 | static const struct Type _Math = { mkBin, doMath, freeMath }; 47 | const void * Math = & _Math; 48 | 49 | void initMath (void) 50 | { static const struct Math functions [] = { 51 | { { &_Math, "sin", MATH }, sin }, 52 | { { &_Math, "cos", MATH }, cos }, 53 | { { &_Math, "tan", MATH }, tan }, 54 | { { &_Math, "asin", MATH }, asin }, 55 | { { &_Math, "acos", MATH }, acos }, 56 | { { &_Math, "atan", MATH }, atan }, 57 | { { &_Math, "sinh", MATH }, sinh }, 58 | { { &_Math, "cosh", MATH }, cosh }, 59 | { { &_Math, "tanh", MATH }, tanh }, 60 | { { &_Math, "exp", MATH }, exp }, 61 | { { &_Math, "log", MATH }, log }, 62 | { { &_Math, "log10", MATH }, log10 }, 63 | { { &_Math, "sqrt", MATH }, sqrt }, 64 | { { &_Math, "ceil", MATH }, ceil }, 65 | { { &_Math, "floor", MATH }, floor }, 66 | { { &_Math, "abs", MATH }, fabs }, 67 | { { 0 } } }; 68 | 69 | const struct Math * mp; 70 | 71 | for (mp = functions; mp -> _.name; ++ mp) 72 | install(mp); 73 | } 74 | -------------------------------------------------------------------------------- /man/man4/intro.4: -------------------------------------------------------------------------------- 1 | .\" intro.4 -- 1.2 Sep 30 06:26:11 1993 2 | .\" Copyright (c) 1993 Axel T. Schreiner 3 | .TH intro 4 "local: ats" 4 | .SH NAME 5 | intro \(em introduction to the calculator application 6 | .SH SYNOPSIS 7 | .nf 8 | .ta 30n 9 | Objct Class 10 | Event 11 | Ic IcClass 12 | Button 13 | Calc 14 | Crt 15 | CButton 16 | CLineOut 17 | LineOut 18 | Mux 19 | List ListClass 20 | Xt 21 | XawBox 22 | XawCommand 23 | XButton 24 | XawForm 25 | XawLabel 26 | XLineOut 27 | XtApplicationShell 28 | .fi 29 | .SH DESCRIPTION 30 | .BR Object (3) 31 | is the root class. 32 | .B Object 33 | needs to be renamed as 34 | .B Objct 35 | because the original name is used by X11. 36 | .PP 37 | .BR Event (4) 38 | is a class to represent input data such as key presses 39 | or mouse clicks. 40 | .PP 41 | .BR Ic (4) 42 | is the base class to represent objects that can receive, 43 | process, and send events. 44 | .B Button 45 | converts incoming events to events with definite text values. 46 | .B Calc 47 | processes texts and sends a result on. 48 | .B LineOut 49 | displays an incoming text. 50 | .B Mux 51 | tries to send an incoming event to one of several objects. 52 | .PP 53 | .BR Crt (4) 54 | is a class to work with the 55 | .I curses 56 | terminal screen function package. 57 | It sends position events for a cursor 58 | and text events for other key presses. 59 | .B CButton 60 | implements 61 | .B Button 62 | on a 63 | .I curses 64 | screen. 65 | .B CLineOut 66 | implements 67 | .BR LineOut . 68 | .PP 69 | .B List 70 | manages a list of objects and is taken from chapter 7. 71 | .PP 72 | .BR Xt (4) 73 | is a class to work with the X Toolkit. 74 | The subclasses wrap toolkit and Athena widgets. 75 | .B XButton 76 | implements a 77 | .B Button 78 | with a 79 | .B Command 80 | widget. 81 | .B XLineOut 82 | implements a 83 | .B LineOut 84 | with a 85 | .B Label 86 | widget. 87 | .SH SEE ALSO 88 | curses(3), X(1) 89 | -------------------------------------------------------------------------------- /05/Var.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "Name.h" 6 | #include "Name.r" 7 | #include "parse.h" 8 | #include "Var.h" 9 | #include "value.h" 10 | #include "value.r" 11 | 12 | /* 13 | * variables 14 | * tree -> struct Var (also located in symbol table) 15 | */ 16 | 17 | struct Var { struct Name _; double value; }; 18 | 19 | #define value(tree) (((struct Var *) tree) -> value) 20 | 21 | static void * mkVar (va_list ap) 22 | { struct Var * node = calloc(1, sizeof(struct Var)); 23 | const char * name = va_arg(ap, const char *); 24 | size_t len = strlen(name); 25 | 26 | assert(node); 27 | node -> _.name = malloc(len+1); 28 | assert(node -> _.name); 29 | strcpy((void *) node -> _.name, name); 30 | node -> _.token = VAR; 31 | return node; 32 | } 33 | 34 | static double doVar (const void * tree) 35 | { 36 | return value(tree); 37 | } 38 | 39 | static void freeVar (void * tree) 40 | { 41 | } 42 | 43 | /* 44 | * assignment 45 | * reuses struct Bin, mkBin() 46 | */ 47 | 48 | static double doAssign (const void * tree) 49 | { 50 | return value(left(tree)) = exec(right(tree)); 51 | } 52 | 53 | /* 54 | * variable types 55 | */ 56 | 57 | static struct Type _Var = { mkVar, doVar, freeVar }; 58 | static struct Type _Assign = { mkBin, doAssign, freeBin }; 59 | 60 | const void * Var = & _Var; 61 | const void * Assign = & _Assign; 62 | 63 | /* 64 | * constants 65 | * like variables, but with a distinct token 66 | */ 67 | 68 | void initConst (void) 69 | { static const struct Var constants [] = { /* like hoc */ 70 | { { &_Var, "PI", CONST }, 3.14159265358979323846 }, 71 | { { &_Var, "E", CONST }, 2.71828182845904523536 }, 72 | { { &_Var, "GAMMA", CONST }, 0.57721566490153286060 }, /* Euler */ 73 | { { &_Var, "DEG", CONST }, 57.29577951308232087680 }, /* deg/radian */ 74 | { { &_Var, "PHI", CONST }, 1.61803398874989484820 }, /* gold ratio */ 75 | { { 0 } } }; 76 | 77 | const struct Var * vp; 78 | 79 | for (vp = constants; vp -> _.name; ++ vp) 80 | install(vp); 81 | } 82 | -------------------------------------------------------------------------------- /14/Xapp: -------------------------------------------------------------------------------- 1 | ! xbutton: this resource places the button to the left of the display 2 | 3 | *form.button.fromHoriz: lineOut 4 | 5 | ! xrun uses a form -- order must match creation 6 | 7 | *form.C.fromHoriz: lineOut 8 | *form.1.fromVert: lineOut 9 | *form.2.fromVert: lineOut 10 | *form.3.fromVert: lineOut 11 | *form.a.fromVert: C 12 | *form.2.fromHoriz: 1 13 | *form.3.fromHoriz: 2 14 | *form.a.fromHoriz: 3 15 | *form.4.fromVert: 1 16 | *form.5.fromVert: 2 17 | *form.6.fromVert: 3 18 | *form.s.fromVert: a 19 | *form.5.fromHoriz: 4 20 | *form.6.fromHoriz: 5 21 | *form.s.fromHoriz: 6 22 | *form.7.fromVert: 4 23 | *form.8.fromVert: 5 24 | *form.9.fromVert: 6 25 | *form.m.fromVert: s 26 | *form.8.fromHoriz: 7 27 | *form.9.fromHoriz: 8 28 | *form.m.fromHoriz: 9 29 | *form.Q.fromVert: 7 30 | *form.0.fromVert: 8 31 | *form.t.fromVert: 9 32 | *form.d.fromVert: m 33 | *form.0.fromHoriz: Q 34 | *form.t.fromHoriz: 0 35 | *form.d.fromHoriz: t 36 | 37 | ! xrun uses accelerators in the form 38 | 39 | *form.C.accelerators: c: set() notify() unset() 40 | *form.Q.accelerators: q: set() notify() unset() 41 | *form.0.accelerators: :0: set() notify() unset() 42 | *form.1.accelerators: :1: set() notify() unset() 43 | *form.2.accelerators: :2: set() notify() unset() 44 | *form.3.accelerators: :3: set() notify() unset() 45 | *form.4.accelerators: :4: set() notify() unset() 46 | *form.5.accelerators: :5: set() notify() unset() 47 | *form.6.accelerators: :6: set() notify() unset() 48 | *form.7.accelerators: :7: set() notify() unset() 49 | *form.8.accelerators: :8: set() notify() unset() 50 | *form.9.accelerators: :9: set() notify() unset() 51 | *form.a.accelerators: :+: set() notify() unset() 52 | *form.s.accelerators: :-: set() notify() unset() 53 | *form.d.accelerators: :/: set() notify() unset() 54 | *form.t.accelerators: :=: set() notify() unset() 55 | *form.m.accelerators: :*: set() notify() unset() 56 | -------------------------------------------------------------------------------- /06/Point.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "Point.h" 4 | #include "Point.r" 5 | 6 | /* 7 | * Point 8 | */ 9 | 10 | static void * Point_ctor (void * _self, va_list * app) 11 | { struct Point * self = super_ctor(Point, _self, app); 12 | 13 | self -> x = va_arg(* app, int); 14 | self -> y = va_arg(* app, int); 15 | return self; 16 | } 17 | 18 | static void Point_draw (const void * _self) 19 | { const struct Point * self = _self; 20 | 21 | printf("\".\" at %d,%d\n", self -> x, self -> y); 22 | } 23 | 24 | void draw (const void * _self) 25 | { const struct PointClass * class = classOf(_self); 26 | 27 | assert(class -> draw); 28 | class -> draw(_self); 29 | } 30 | 31 | void super_draw (const void * _class, const void * _self) 32 | { const struct PointClass * superclass = super(_class); 33 | 34 | assert(_self && superclass -> draw); 35 | superclass -> draw(_self); 36 | } 37 | 38 | void move (void * _self, int dx, int dy) 39 | { struct Point * self = _self; 40 | 41 | self -> x += dx, self -> y += dy; 42 | } 43 | 44 | /* 45 | * PointClass 46 | */ 47 | 48 | static void * PointClass_ctor (void * _self, va_list * app) 49 | { struct PointClass * self 50 | = super_ctor(PointClass, _self, app); 51 | typedef void (* voidf) (); 52 | voidf selector; 53 | #ifdef va_copy 54 | va_list ap; va_copy(ap, * app); 55 | #else 56 | va_list ap = * app; 57 | #endif 58 | 59 | while ((selector = va_arg(ap, voidf))) 60 | { voidf method = va_arg(ap, voidf); 61 | 62 | if (selector == (voidf) draw) 63 | * (voidf *) & self -> draw = method; 64 | } 65 | #ifdef va_copy 66 | va_end(ap); 67 | #endif 68 | 69 | return self; 70 | } 71 | 72 | /* 73 | * initialization 74 | */ 75 | 76 | const void * PointClass, * Point; 77 | 78 | void initPoint (void) 79 | { 80 | if (! PointClass) 81 | PointClass = new(Class, "PointClass", 82 | Class, sizeof(struct PointClass), 83 | ctor, PointClass_ctor, 84 | 0); 85 | if (! Point) 86 | Point = new(PointClass, "Point", 87 | Object, sizeof(struct Point), 88 | ctor, Point_ctor, 89 | draw, Point_draw, 90 | 0); 91 | } 92 | -------------------------------------------------------------------------------- /man/cat4/intro.0: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | intro(4) intro(4) 5 | 6 | 7 | NAME 8 | intro -- introduction to the calculator application 9 | 10 | SYNOPSIS 11 | Objct Class 12 | Event 13 | Ic IcClass 14 | Button 15 | Calc 16 | Crt 17 | CButton 18 | CLineOut 19 | LineOut 20 | Mux 21 | List ListClass 22 | Xt 23 | XawBox 24 | XawCommand 25 | XButton 26 | XawForm 27 | XawLabel 28 | XLineOut 29 | XtApplicationShell 30 | 31 | DESCRIPTION 32 | Object(3) is the root class. Object needs to be renamed 33 | as Objct because the original name is used by X11. 34 | 35 | Event(4) is a class to represent input data such as key 36 | presses or mouse clicks. 37 | 38 | Ic(4) is the base class to represent objects that can 39 | receive, process, and send events. Button converts incom- 40 | ing events to events with definite text values. Calc pro- 41 | cesses texts and sends a result on. LineOut displays an 42 | incoming text. Mux tries to send an incoming event to one 43 | of several objects. 44 | 45 | Crt(4) is a class to work with the curses terminal screen 46 | function package. It sends position events for a cursor 47 | and text events for other key presses. CButton implements 48 | Button on a curses screen. CLineOut implements LineOut. 49 | 50 | List manages a list of objects and is taken from chapter 51 | 7. 52 | 53 | Xt(4) is a class to work with the X Toolkit. The sub- 54 | classes wrap toolkit and Athena widgets. XButton imple- 55 | ments a Button with a Command widget. XLineOut implements 56 | a LineOut with a Label widget. 57 | 58 | SEE ALSO 59 | curses(3), X(1) 60 | 61 | 62 | 63 | 64 | local: ats 1 65 | 66 | 67 | -------------------------------------------------------------------------------- /07/List.dc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #ifndef MIN 5 | #define MIN 32 // minimal buffer dimension 6 | #endif 7 | 8 | % List ctor { 9 | struct List * self = super_ctor(List, _self, app); 10 | 11 | if (! (self -> dim = va_arg(* app, unsigned))) 12 | self -> dim = MIN; 13 | self -> buf = malloc(self -> dim * sizeof * self -> buf); 14 | assert(self -> buf); 15 | return self; 16 | } 17 | 18 | % List dtor { 19 | %casts 20 | free(self -> buf), self -> buf = 0; 21 | return super_dtor(List, self); 22 | } 23 | 24 | static void * add1 (struct List * self, const void * element) 25 | { 26 | self -> end = self -> count = 1; 27 | return (void *) (self -> buf[self -> begin = 0] = element); 28 | } 29 | 30 | static void extend (struct List * self) // one more element 31 | { 32 | if (self -> count >= self -> dim) 33 | { self -> buf = 34 | realloc(self -> buf, 2 * self -> dim 35 | * sizeof * self -> buf); 36 | assert(self -> buf); 37 | if (self -> begin && self -> begin != self -> dim) 38 | { memcpy(self -> buf + self -> dim + self -> begin, 39 | self -> buf + self -> begin, 40 | (self -> dim - self -> begin) 41 | * sizeof * self -> buf); 42 | self -> begin += self -> dim; 43 | } 44 | else 45 | self -> begin = 0; 46 | self -> dim *= 2; 47 | } 48 | ++ self -> count; 49 | } 50 | 51 | % List addFirst { 52 | %casts 53 | if (! self -> count) 54 | return add1(self, element); 55 | extend(self); 56 | if (self -> begin == 0) 57 | self -> begin = self -> dim; 58 | self -> buf[-- self -> begin] = element; 59 | return (void *) element; 60 | } 61 | 62 | % List addLast { 63 | %casts 64 | if (! self -> count) 65 | return add1(self, element); 66 | extend(self); 67 | if (self -> end >= self -> dim) 68 | self -> end = 0; 69 | self -> buf[self -> end ++] = element; 70 | return (void *) element; 71 | } 72 | 73 | % List count { 74 | %casts 75 | return self -> count; 76 | } 77 | 78 | % List lookAt { 79 | %casts 80 | return (void *) (n >= self -> count ? 0 : 81 | self -> buf[(self -> begin + n) % self -> dim]); 82 | } 83 | 84 | % List takeFirst { 85 | %casts 86 | if (! self -> count) 87 | return 0; 88 | -- self -> count; 89 | if (self -> begin >= self -> dim) 90 | self -> begin = 0; 91 | return (void *) self -> buf[self -> begin ++]; 92 | } 93 | 94 | % List takeLast { 95 | %casts 96 | if (! self -> count) 97 | return 0; 98 | -- self -> count; 99 | if (self -> end == 0) 100 | self -> end = self -> dim; 101 | return (void *) self -> buf[-- self -> end]; 102 | } 103 | 104 | %init 105 | -------------------------------------------------------------------------------- /08/List.dc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #ifndef MIN 5 | #define MIN 32 // minimal buffer dimension 6 | #endif 7 | 8 | % List ctor { 9 | struct List * self = super_ctor(List, _self, app); 10 | 11 | if (! (self -> dim = va_arg(* app, unsigned))) 12 | self -> dim = MIN; 13 | self -> buf = malloc(self -> dim * sizeof * self -> buf); 14 | assert(self -> buf); 15 | return self; 16 | } 17 | 18 | % List dtor { 19 | %casts 20 | free(self -> buf), self -> buf = 0; 21 | return super_dtor(List, self); 22 | } 23 | 24 | static void * add1 (struct List * self, const void * element) 25 | { 26 | self -> end = self -> count = 1; 27 | return (void *) (self -> buf[self -> begin = 0] = element); 28 | } 29 | 30 | static void extend (struct List * self) // one more element 31 | { 32 | if (self -> count >= self -> dim) 33 | { self -> buf = 34 | realloc(self -> buf, 2 * self -> dim 35 | * sizeof * self -> buf); 36 | assert(self -> buf); 37 | if (self -> begin && self -> begin != self -> dim) 38 | { memcpy(self -> buf + self -> dim + self -> begin, 39 | self -> buf + self -> begin, 40 | (self -> dim - self -> begin) 41 | * sizeof * self -> buf); 42 | self -> begin += self -> dim; 43 | } 44 | else 45 | self -> begin = 0; 46 | self -> dim *= 2; 47 | } 48 | ++ self -> count; 49 | } 50 | 51 | % List addFirst { 52 | %casts 53 | if (! self -> count) 54 | return add1(self, element); 55 | extend(self); 56 | if (self -> begin == 0) 57 | self -> begin = self -> dim; 58 | self -> buf[-- self -> begin] = element; 59 | return (void *) element; 60 | } 61 | 62 | % List addLast { 63 | %casts 64 | if (! self -> count) 65 | return add1(self, element); 66 | extend(self); 67 | if (self -> end >= self -> dim) 68 | self -> end = 0; 69 | self -> buf[self -> end ++] = element; 70 | return (void *) element; 71 | } 72 | 73 | % List count { 74 | %casts 75 | return self -> count; 76 | } 77 | 78 | % List lookAt { 79 | %casts 80 | return (void *) (n >= self -> count ? 0 : 81 | self -> buf[(self -> begin + n) % self -> dim]); 82 | } 83 | 84 | % List takeFirst { 85 | %casts 86 | if (! self -> count) 87 | return 0; 88 | -- self -> count; 89 | if (self -> begin >= self -> dim) 90 | self -> begin = 0; 91 | return (void *) self -> buf[self -> begin ++]; 92 | } 93 | 94 | % List takeLast { 95 | %casts 96 | if (! self -> count) 97 | return 0; 98 | -- self -> count; 99 | if (self -> end == 0) 100 | self -> end = self -> dim; 101 | return (void *) self -> buf[-- self -> end]; 102 | } 103 | 104 | %init 105 | -------------------------------------------------------------------------------- /09/List.dc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #ifndef MIN 5 | #define MIN 32 // minimal buffer dimension 6 | #endif 7 | 8 | % List ctor { 9 | struct List * self = super_ctor(List(), _self, app); 10 | 11 | if (! (self -> dim = va_arg(* app, unsigned))) 12 | self -> dim = MIN; 13 | self -> buf = malloc(self -> dim * sizeof * self -> buf); 14 | assert(self -> buf); 15 | return self; 16 | } 17 | 18 | % List dtor { 19 | %casts 20 | free(self -> buf), self -> buf = 0; 21 | return super_dtor(List(), self); 22 | } 23 | 24 | static void * add1 (struct List * self, const void * element) 25 | { 26 | self -> end = self -> count = 1; 27 | return (void *) (self -> buf[self -> begin = 0] = element); 28 | } 29 | 30 | static void extend (struct List * self) // one more element 31 | { 32 | if (self -> count >= self -> dim) 33 | { self -> buf = 34 | realloc(self -> buf, 2 * self -> dim 35 | * sizeof * self -> buf); 36 | assert(self -> buf); 37 | if (self -> begin && self -> begin != self -> dim) 38 | { memcpy(self -> buf + self -> dim + self -> begin, 39 | self -> buf + self -> begin, 40 | (self -> dim - self -> begin) 41 | * sizeof * self -> buf); 42 | self -> begin += self -> dim; 43 | } 44 | else 45 | self -> begin = 0; 46 | self -> dim *= 2; 47 | } 48 | ++ self -> count; 49 | } 50 | 51 | % List addFirst { 52 | %casts 53 | if (! self -> count) 54 | return add1(self, element); 55 | extend(self); 56 | if (self -> begin == 0) 57 | self -> begin = self -> dim; 58 | self -> buf[-- self -> begin] = element; 59 | return (void *) element; 60 | } 61 | 62 | % List addLast { 63 | %casts 64 | if (! self -> count) 65 | return add1(self, element); 66 | extend(self); 67 | if (self -> end >= self -> dim) 68 | self -> end = 0; 69 | self -> buf[self -> end ++] = element; 70 | return (void *) element; 71 | } 72 | 73 | % List count { 74 | %casts 75 | return self -> count; 76 | } 77 | 78 | % List lookAt { 79 | %casts 80 | return (void *) (n >= self -> count ? 0 : 81 | self -> buf[(self -> begin + n) % self -> dim]); 82 | } 83 | 84 | % List takeFirst { 85 | %casts 86 | if (! self -> count) 87 | return 0; 88 | -- self -> count; 89 | if (self -> begin >= self -> dim) 90 | self -> begin = 0; 91 | return (void *) self -> buf[self -> begin ++]; 92 | } 93 | 94 | % List takeLast { 95 | %casts 96 | if (! self -> count) 97 | return 0; 98 | -- self -> count; 99 | if (self -> end == 0) 100 | self -> end = self -> dim; 101 | return (void *) self -> buf[-- self -> end]; 102 | } 103 | 104 | %init 105 | -------------------------------------------------------------------------------- /13/List.dc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #ifndef MIN 5 | #define MIN 32 // minimal buffer dimension 6 | #endif 7 | 8 | % List ctor { 9 | struct List * self = super_ctor(List(), _self, app); 10 | 11 | if (! (self -> dim = va_arg(* app, unsigned))) 12 | self -> dim = MIN; 13 | self -> buf = malloc(self -> dim * sizeof * self -> buf); 14 | assert(self -> buf); 15 | return self; 16 | } 17 | 18 | % List dtor { 19 | %casts 20 | free(self -> buf), self -> buf = 0; 21 | return super_dtor(List(), self); 22 | } 23 | 24 | static void * add1 (struct List * self, const void * element) 25 | { 26 | self -> end = self -> count = 1; 27 | return (void *) (self -> buf[self -> begin = 0] = element); 28 | } 29 | 30 | static void extend (struct List * self) // one more element 31 | { 32 | if (self -> count >= self -> dim) 33 | { self -> buf = 34 | realloc(self -> buf, 2 * self -> dim 35 | * sizeof * self -> buf); 36 | assert(self -> buf); 37 | if (self -> begin && self -> begin != self -> dim) 38 | { memcpy(self -> buf + self -> dim + self -> begin, 39 | self -> buf + self -> begin, 40 | (self -> dim - self -> begin) 41 | * sizeof * self -> buf); 42 | self -> begin += self -> dim; 43 | } 44 | else 45 | self -> begin = 0; 46 | self -> dim *= 2; 47 | } 48 | ++ self -> count; 49 | } 50 | 51 | % List addFirst { 52 | %casts 53 | if (! self -> count) 54 | return add1(self, element); 55 | extend(self); 56 | if (self -> begin == 0) 57 | self -> begin = self -> dim; 58 | self -> buf[-- self -> begin] = element; 59 | return (void *) element; 60 | } 61 | 62 | % List addLast { 63 | %casts 64 | if (! self -> count) 65 | return add1(self, element); 66 | extend(self); 67 | if (self -> end >= self -> dim) 68 | self -> end = 0; 69 | self -> buf[self -> end ++] = element; 70 | return (void *) element; 71 | } 72 | 73 | % List count { 74 | %casts 75 | return self -> count; 76 | } 77 | 78 | % List lookAt { 79 | %casts 80 | return (void *) (n >= self -> count ? 0 : 81 | self -> buf[(self -> begin + n) % self -> dim]); 82 | } 83 | 84 | % List takeFirst { 85 | %casts 86 | if (! self -> count) 87 | return 0; 88 | -- self -> count; 89 | if (self -> begin >= self -> dim) 90 | self -> begin = 0; 91 | return (void *) self -> buf[self -> begin ++]; 92 | } 93 | 94 | % List takeLast { 95 | %casts 96 | if (! self -> count) 97 | return 0; 98 | -- self -> count; 99 | if (self -> end == 0) 100 | self -> end = self -> dim; 101 | return (void *) self -> buf[-- self -> end]; 102 | } 103 | 104 | %init 105 | -------------------------------------------------------------------------------- /make/Makefile.solaris: -------------------------------------------------------------------------------- 1 | # OSTYPE=solaris Solaris 5.8 2 | 3 | # SunOS holly 5.8 Generic_111433-01 sun4u sparc SUNW,Ultra-80 4 | 5 | # 01 sets bags 6 | # 02 strings atoms 7 | # 03 postfix value infix 8 | # 04 points circles 9 | # 05 value 10 | # 06 any points circles 11 | # 07 points circles queues stacks 12 | # 08 circles lists 13 | # 09 circles lists 14 | # 10 cmd wc sort 15 | # 11 value 16 | # 12 value 17 | # 13 except value 18 | # 14 hello button run cbutton crun ## xhello xbutton xrun 19 | 20 | AWK = gawk# 'new' awk 21 | CC = gcc -Wall -Wno-unused -g# how to call the C compiler 22 | curses = -lcurses# how to link curses(3) 23 | debug = # how to track memory leaks 24 | host = -dis unix:0# how to get to the X11 host 25 | Lm = -lm# math functions 26 | # OOC = ../ooc/ooc $(chapter)# how to call the ooc script 27 | OOC = ../ooc/ooc -DGNUC=1 $(chapter)# ... using const functions 28 | Rflag = `if [ $* = Object ]; then echo -R; else :; fi` 29 | x11 = -lXaw -lXmu -lXext -lXt -lX11# how to link X11 30 | 31 | # Rflag is used to hide ooc entirely behind implicit rules. 32 | # otherwise we need explicit rules for Object.[chr] 33 | # which backfire in the early chapters. 34 | 35 | # this rule uses the GNU C compiler and ooc to produce dependencies 36 | # from the C source file lists $c $m and from the class list $d. 37 | # the rule depends on the header file lists $h and $r to simplify 38 | # bootstrapping. the for-loop accounts for the fact that producing 39 | # foo.c from foo.dc depends on foo.d -- but ooc cannot deduce that. 40 | 41 | depend: $h $r $c $m makefile 42 | > $@ 43 | - [ "$c$m" ] && $(CC) -MM $(CFLAGS) $c $m >> $@ 44 | - [ "$d" ] && $(OOC) -M $d >> $@ 45 | - [ "$d" ] && { d="$d"; for i in $$d; do echo $$i.c: $$i.d; done >> $@; } 46 | 47 | # this rule generates the dependencies of a library $l on its objects made 48 | # from the file list $c. this rule could be much smarter but at least 49 | # ESIX/make appears to be quite broken. 50 | 51 | makefile.etc: makefile 52 | for o in $(c:.c=); do \ 53 | echo '$$l: '"$$o.o"; \ 54 | echo "$$o.o: $$o.c"; \ 55 | done > $@ 56 | 57 | # this rule inserts the objects $o into the library $l. 58 | # note that NeXTSTEP 3.1 ranlib apparently backdates the library, i.e., 59 | # this rule may get executed a few times too many... 60 | 61 | mklib: $(mklib) 62 | $(AR) $(ARFLAGS) $l $o 63 | ranlib $l 64 | .c.a: ; 65 | 66 | # these implicit rules produce header files from class description files 67 | # and C sources from class implementation files. in chapter 14 $(post) is 68 | # set to change the base class name from Object to Objct. 69 | 70 | .SUFFIXES: .h .r .dc .d 71 | 72 | .d.h: ; $(OOC) $(Rflag) $(OOCFLAGS) $* -h $(post) > $@ 73 | .d.r: ; $(OOC) $(Rflag) $(OOCFLAGS) $* -r $(post) > $@ 74 | .dc.c: ; $(OOC) $(Rflag) $(OOCFLAGS) $* $*.dc $(post) > $@ 75 | 76 | -include depend 77 | -------------------------------------------------------------------------------- /14/depend: -------------------------------------------------------------------------------- 1 | Objct.o: Objct.c Objct.h Objct.r 2 | List.o: List.c List.h Objct.h List.r Objct.r 3 | Ic.o: Ic.c Ic.h Objct.h Ic.r Objct.r List.h 4 | Crt.o: Crt.c Crt.h Ic.h Objct.h Crt.r Ic.r Objct.r 5 | Xt.o: Xt.c Xt.h Objct.h /usr/X11R6/include/X11/Intrinsic.h \ 6 | /usr/X11R6/include/X11/Xlib.h /usr/X11R6/include/X11/X.h \ 7 | /usr/X11R6/include/X11/Xfuncproto.h /usr/X11R6/include/X11/Xosdefs.h \ 8 | /usr/X11R6/include/X11/Xutil.h /usr/X11R6/include/X11/keysym.h \ 9 | /usr/X11R6/include/X11/keysymdef.h /usr/X11R6/include/X11/Xresource.h \ 10 | /usr/X11R6/include/X11/Core.h /usr/X11R6/include/X11/Composite.h \ 11 | /usr/X11R6/include/X11/Constraint.h /usr/X11R6/include/X11/Object.h \ 12 | /usr/X11R6/include/X11/RectObj.h Xt.r Objct.r \ 13 | /usr/X11R6/include/X11/StringDefs.h /usr/X11R6/include/X11/Xaw/Label.h \ 14 | /usr/X11R6/include/X11/Xaw/Simple.h \ 15 | /usr/X11R6/include/X11/Xmu/Converters.h \ 16 | /usr/X11R6/include/X11/Xaw/Command.h /usr/X11R6/include/X11/Xaw/Box.h \ 17 | /usr/X11R6/include/X11/Xaw/Form.h Ic.h 18 | hello.o: hello.c Ic.h Objct.h 19 | button.o: button.c Ic.h Objct.h 20 | run.o: run.c Ic.h Objct.h 21 | cbutton.o: cbutton.c Crt.h Ic.h Objct.h 22 | crun.o: crun.c Crt.h Ic.h Objct.h 23 | xhello.o: xhello.c Xt.h Objct.h /usr/X11R6/include/X11/Intrinsic.h \ 24 | /usr/X11R6/include/X11/Xlib.h /usr/X11R6/include/X11/X.h \ 25 | /usr/X11R6/include/X11/Xfuncproto.h /usr/X11R6/include/X11/Xosdefs.h \ 26 | /usr/X11R6/include/X11/Xutil.h /usr/X11R6/include/X11/keysym.h \ 27 | /usr/X11R6/include/X11/keysymdef.h /usr/X11R6/include/X11/Xresource.h \ 28 | /usr/X11R6/include/X11/Core.h /usr/X11R6/include/X11/Composite.h \ 29 | /usr/X11R6/include/X11/Constraint.h /usr/X11R6/include/X11/Object.h \ 30 | /usr/X11R6/include/X11/RectObj.h 31 | xbutton.o: xbutton.c Ic.h Objct.h Xt.h /usr/X11R6/include/X11/Intrinsic.h \ 32 | /usr/X11R6/include/X11/Xlib.h /usr/X11R6/include/X11/X.h \ 33 | /usr/X11R6/include/X11/Xfuncproto.h /usr/X11R6/include/X11/Xosdefs.h \ 34 | /usr/X11R6/include/X11/Xutil.h /usr/X11R6/include/X11/keysym.h \ 35 | /usr/X11R6/include/X11/keysymdef.h /usr/X11R6/include/X11/Xresource.h \ 36 | /usr/X11R6/include/X11/Core.h /usr/X11R6/include/X11/Composite.h \ 37 | /usr/X11R6/include/X11/Constraint.h /usr/X11R6/include/X11/Object.h \ 38 | /usr/X11R6/include/X11/RectObj.h 39 | xrun.o: xrun.c Ic.h Objct.h Xt.h /usr/X11R6/include/X11/Intrinsic.h \ 40 | /usr/X11R6/include/X11/Xlib.h /usr/X11R6/include/X11/X.h \ 41 | /usr/X11R6/include/X11/Xfuncproto.h /usr/X11R6/include/X11/Xosdefs.h \ 42 | /usr/X11R6/include/X11/Xutil.h /usr/X11R6/include/X11/keysym.h \ 43 | /usr/X11R6/include/X11/keysymdef.h /usr/X11R6/include/X11/Xresource.h \ 44 | /usr/X11R6/include/X11/Core.h /usr/X11R6/include/X11/Composite.h \ 45 | /usr/X11R6/include/X11/Constraint.h /usr/X11R6/include/X11/Object.h \ 46 | /usr/X11R6/include/X11/RectObj.h 47 | List.d: Object.d 48 | Ic.d: Object.d 49 | Crt.d: Ic.d 50 | Xt.d: Object.d 51 | Object.c: Object.d 52 | List.c: List.d 53 | Ic.c: Ic.d 54 | Crt.c: Crt.d 55 | Xt.c: Xt.d 56 | --------------------------------------------------------------------------------