1 /* yForth? - Written by Luca Padovani (C) 1996/97
2 * ------------------------------------------------------------------------
3 * This software is FreeWare as long as it comes with this header in each
4 * source file, anyway you can use it or any part of it whatever
5 * you want. It comes without any warranty, so use it at your own risk.
6 * ------------------------------------------------------------------------
7 * Module name: yfinit.c
8 * Abstract: Allocate memory for the main structures of the
9 * environment and initialize the environment itself.
20 /* init_stacks: allocate memory for the stacks */
21 void init_stacks(int dstack_size, int rstack_size, int fstack_size) {
22 sp_base = (Cell *) malloc(dstack_size * sizeof(Cell));
23 rp_base = (Cell *) malloc(rstack_size * sizeof(Cell));
24 fp_base = (Real *) malloc(fstack_size * sizeof(Real));
25 if (sp_base && rp_base && (fp_base || !fstack_size)) {
26 sp = sp_top = sp_base + dstack_size;
27 rp = rp_top = rp_base + rstack_size;
28 fp = fp_top = fp_base + fstack_size;
30 fprintf(stderr, "Stack sizes: %d %d %d. Not enough memory.\n", dstack_size,
31 rstack_size, fstack_size);
36 /* init_data_space: allocate memory for the data-space dictionary */
37 void init_data_space(int dspace_size) {
38 dp0 = _dp = (Char *) malloc(dspace_size * sizeof(Cell));
40 printf("Data Space size: %d. Not enough memory.\n", dspace_size);
45 /* init_tib: allocate memory for the TIB */
46 void init_tib(int size) {
47 _tib = (Char *) malloc(size * sizeof(Char));
49 fprintf(stderr, "Tib size: %d. Not enough memory.\n", size);
54 /* init_pad: allocate memory for the PAD */
55 void init_pad(int size) {
56 _pad = (Char *) malloc(size * sizeof(Char));
58 fprintf(stderr, "PAD size: %d. Not enough memory.\n", size);
63 /* init_pnos: allocate memory for PNOS, note that the size of PNOS is
64 * determined by the actual size of a double cell.
67 pnos_size = sizeof(DCell) * 8 + 2; /* plus a space and eventually a '-' */
68 pnos = (Char *) malloc(pnos_size * sizeof(Char));
70 fprintf(stderr, "Can't allocate PNOS.\n");
75 /* init_forth_environment: perform actual inizialization of the dictionary
76 * only if "reload" is true, then initialize the value of variables
77 * of the forth environment. This variable must be initialized even in
78 * the case of an image file since they're not inside the dictionary,
79 * but are simply C variables.
81 void init_forth_environment(int reload) {
85 list[0] = forth_wid = voc = (struct vocabulary *) *sp++;
87 init_vocabulary(&_dp);
90 _env_slash_counted_string = (1 << (8 * sizeof(Char))) - 1;
91 _env_slash_hold = pnos_size;
92 _env_slash_pad = pad_size;
93 _env_address_unit_bits = 8 * sizeof(Char);
95 _env_core_ext = FFLAG(COREE_DEF);
96 _env_floored = FFLAG(FLOORED_DIVISION);
97 _env_max_char = _env_slash_counted_string;
101 _env_max_ud = MAX_UD;
102 _env_return_stack_cells = rstack_size;
103 _env_stack_cells = dstack_size;
104 _env_double = FFLAG(DOUBLE_DEF);
105 _env_double_ext = FFLAG(DOUBLEE_DEF);
106 _env_floating = FFLAG(FLOAT_DEF);
107 _env_floating_stack = fstack_size;
108 _env_max_float = MAX_F;
109 _env_floating_ext = FFLAG(FLOATE_DEF);
110 _env_memory_alloc = FFLAG(MEMALL_DEF);
111 _env_memory_alloc_ext = FFLAG(MEMALLE_DEF);
112 _env_search_order = FFLAG(SEARCH_DEF);
113 _env_search_order_ext = FFLAG(SEARCHE_DEF);
114 _env_wordlists = WORD_LISTS;
115 _env_tools = FFLAG(TOOLS_DEF);
116 _env_tools_ext = FFLAG(TOOLSE_DEF);
117 _env_number_locals = MAX_LOCALS;
118 _env_locals = FFLAG(LOCALS_DEF);
119 _env_locals_ext = FFLAG(LOCALSE_DEF);
120 _env_facility = FFLAG(FACILITY_DEF);
121 _env_facility_ext = FFLAG(FACILITYE_DEF);
122 _env_block = FFLAG(BLOCK_DEF);
123 _env_block_ext = FFLAG(BLOCKE_DEF);
124 _env_exception = FFLAG(EXCEPTION_DEF);
125 _env_exception_ext = FFLAG(EXCEPTIONE_DEF);
126 _env_file = FFLAG(FILE_DEF);
127 _env_file_ext = FFLAG(FILEE_DEF);
128 _env_string = FFLAG(STRING_DEF);
129 _env_string_ext = FFLAG(STRINGE_DEF);