builtin.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* $Header$ */
  2. /*
  3. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  4. * See the copyright notice in the ACK home directory, in the file "Copyright".
  5. */
  6. #include "symtab.h"
  7. #include "expr.h"
  8. #include "sizes.h"
  9. void init_builtins()
  10. /* Insert all builtin names into the outermost symbol table (first statement
  11. * is sym_down() ). Note that this table is never destroy()ed, so static
  12. * initializers may be used.
  13. */
  14. {
  15. union type_info info;
  16. static char file[]="file";
  17. static struct par_list
  18. open_list[] = {
  19. { &open_list[1], nil, T_VAR }, /* File descriptor */
  20. { &open_list[2], nil, T_VALUE|T_ARR }, /* File name */
  21. { nil, nil, T_VALUE|T_ARR } /* "r", "w", "a" */
  22. },
  23. close_list[]= {
  24. { nil, nil, T_VALUE } /* File descriptor */
  25. },
  26. exit_list[]= {
  27. { nil, nil, T_VALUE } /* Exit code */
  28. };
  29. sym_down(); /* Add level of symbols above all others */
  30. /* CHAN file[20], input=file[0], output=file[1], error=file[2]: */
  31. info.vc.st.builtin=file;
  32. info.vc.offset=0;
  33. insert(file, T_CHAN|T_ARR|T_BUILTIN, 20, &info);
  34. info.vc.st.builtin=file;
  35. info.vc.offset=0;
  36. insert("input", T_CHAN|T_BUILTIN, 1, &info);
  37. info.vc.st.builtin=file;
  38. info.vc.offset=wz+pz;
  39. insert("output", T_CHAN|T_BUILTIN, 1, &info);
  40. info.vc.st.builtin=file;
  41. info.vc.offset=2*(wz+pz);
  42. insert("error", T_CHAN|T_BUILTIN, 1, &info);
  43. /* DEF EOF= -1, TEXT= -2, RAW= -3: */
  44. info.const=new_const(-1L);
  45. insert("EOF", T_CONST|T_BUILTIN, 0, &info);
  46. info.const=new_const(-2L);
  47. insert("TEXT", T_CONST|T_BUILTIN, 0, &info);
  48. info.const=new_const(-3L);
  49. insert("RAW", T_CONST|T_BUILTIN, 0, &info);
  50. /* PROC open(VAR fd, VALUE name[], mode[])= .... : */
  51. info.proc.st.builtin="b_open";
  52. info.proc.pars=open_list;
  53. insert("open", T_PROC|T_BUILTIN, 0, &info);
  54. /* PROC close(VALUE fd)= .... : */
  55. info.proc.st.builtin="b_close";
  56. info.proc.pars=close_list;
  57. insert("close", T_PROC|T_BUILTIN, 0, &info);
  58. /* PROC exit(VALUE code)= .... : */
  59. info.proc.st.builtin="b_exit";
  60. info.proc.pars=exit_list;
  61. insert("exit", T_PROC|T_BUILTIN, 0, &info);
  62. }