1 /* File: "setup.c", Time-stamp: <2009-06-07 19:04:22 feeley> */
3 /* Copyright (c) 1994-2008 by Marc Feeley, All Rights Reserved. */
6 * This module contains the routines that setup the Scheme program for
10 #define ___INCLUDED_FROM_SETUP
11 #define ___VERSION 404003
21 /*---------------------------------------------------------------------------*/
24 * Global state structure.
27 ___EXP_DATA(___global_state_struct
,___gstate
);
31 * Global variables needed by this module.
34 ___NEED_GLO(___G__23__23_kernel_2d_handlers
) /* from "_kernel.scm" */
35 ___NEED_GLO(___G__23__23_dynamic_2d_env_2d_bind
)
39 * Parameters passed to ___setup.
42 ___HIDDEN ___UCS_2 reset_argv0
[] = { 0 };
43 ___HIDDEN ___UCS_2STRING reset_argv
[] = { reset_argv0
, 0 };
45 ___setup_params_struct ___setup_params
=
46 { 0, reset_argv
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
50 * Initial length of symbol table and keyword table.
53 #define INIT_SYMKEY_TBL_LENGTH 128
56 /*---------------------------------------------------------------------------*/
63 * '___raise_interrupt (code)' is called when an interrupt has
64 * occured. At some later point in time, the Gambit kernel will cause
65 * the Scheme procedure ##interrupt-handler to be called with a single
66 * integer argument indicating which interrupt has been received.
67 * Interrupt codes are defined in "gambit.h". Currently, the
68 * following codes are defined:
70 * ___INTR_USER user has interrupted the program (e.g. ctrl-C)
71 * ___INTR_HEARTBEAT heartbeat time interval has elapsed
72 * ___INTR_GC a garbage collection has finished
75 ___EXP_FUNC(void,___raise_interrupt
)
80 ___processor_state ___ps
= ___PSTATE
;
83 * Note: ___raise_interrupt may be called before the processor state
84 * is initialized. As a consequence, the interrupt(s) received
85 * before the initialization of the processor state will be ignored.
88 #ifdef CALL_GC_FREQUENTLY
89 if (code
!= ___INTR_USER
)
93 ___ps
->intr_flag
[code
] = 1;
94 if (___ps
->intr_enabled
)
95 ___ps
->stack_trip
= ___ps
->stack_start
;
99 ___EXP_FUNC(void,___begin_interrupt_service
) ___PVOID
101 ___processor_state ___ps
= ___PSTATE
;
103 ___ps
->stack_trip
= ___ps
->stack_limit
;
107 ___EXP_FUNC(___BOOL
,___check_interrupt
)
112 ___processor_state ___ps
= ___PSTATE
;
114 if (___ps
->intr_flag
[code
])
116 ___ps
->intr_flag
[code
] = 0;
124 ___EXP_FUNC(void,___end_interrupt_service
)
129 ___processor_state ___ps
= ___PSTATE
;
131 if (___ps
->intr_enabled
)
133 #ifdef CALL_HANDLER_AT_EVERY_POLL
134 ___ps
->stack_trip
= ___ps
->stack_start
;
136 while (code
< ___NB_INTRS
)
138 if (___ps
->intr_flag
[code
]) /* don't ignore other interrupts */
140 ___ps
->stack_trip
= ___ps
->stack_start
;
150 ___EXP_FUNC(void,___disable_interrupts
) ___PVOID
152 ___processor_state ___ps
= ___PSTATE
;
154 ___ps
->intr_enabled
= 0;
156 ___begin_interrupt_service ();
157 ___end_interrupt_service (0);
161 ___EXP_FUNC(void,___enable_interrupts
) ___PVOID
163 ___processor_state ___ps
= ___PSTATE
;
165 ___ps
->intr_enabled
= 1;
167 ___begin_interrupt_service ();
168 ___end_interrupt_service (0);
172 /*---------------------------------------------------------------------------*/
175 * Routines to setup symbol table, keyword table and global variable
180 * The hashing functions 'hash_UTF_8_string (str)' and
181 * 'hash_scheme_string (str)' must compute the same value as the
182 * function 'targ-hash' in the file "gsc/_t-c-3.scm".
183 * A fixnum error code is returned when there is an error.
186 #define HASH_STEP(h,c) ((((h)>>8) + (c)) * 331804471) & ___MAX_FIX32
188 ___HIDDEN ___SCMOBJ hash_UTF_8_string
189 ___P((___UTF_8STRING str
),
194 ___UTF_8STRING p
= str
;
199 ___UTF_8STRING start
= p
;
200 c
= ___UTF_8_get (&p
);
201 if (p
== start
|| c
> ___MAX_CHR
)
202 return ___FIX(___CTOS_UTF_8STRING_ERR
);
212 ___HIDDEN ___SCMOBJ hash_scheme_string
213 ___P((___SCMOBJ str
),
217 unsigned long i
, n
= ___INT(___STRINGLENGTH(str
));
221 h
= HASH_STEP(h
,___INT(___STRINGREF(str
,___FIX(i
))));
227 ___HIDDEN ___SCMOBJ symkey_table
228 ___P((unsigned int subtype
),
230 unsigned int subtype
;)
235 return ___GSTATE
->keyword_table
;
236 default: /* assume ___sSYMBOL */
237 return ___GSTATE
->symbol_table
;
242 ___HIDDEN
void symkey_table_set
243 ___P((unsigned int subtype
,
244 ___SCMOBJ new_table
),
247 unsigned int subtype
;
248 ___SCMOBJ new_table
;)
253 ___GSTATE
->keyword_table
= new_table
;
255 default: /* assume ___sSYMBOL */
256 ___GSTATE
->symbol_table
= new_table
;
262 ___HIDDEN ___SCMOBJ symkey_table_alloc
263 ___P((unsigned int subtype
,
267 unsigned int subtype
;
270 ___SCMOBJ tbl
= ___make_vector (length
+1, ___NUL
, ___STILL
);
272 if (!___FIXNUMP(tbl
))
273 ___FIELD(tbl
,0) = ___FIX(0);
279 ___HIDDEN
void symkey_add
280 ___P((___SCMOBJ symkey
),
284 unsigned int subtype
= ___INT(___SUBTYPE(symkey
));
285 ___SCMOBJ tbl
= symkey_table (subtype
);
286 int i
= ___INT(___FIELD(symkey
,___SYMKEY_HASH
))
287 % (___INT(___VECTORLENGTH(tbl
)) - 1)
290 ___FIELD(symkey
,___SYMKEY_NEXT
) = ___FIELD(tbl
,i
);
291 ___FIELD(tbl
,i
) = symkey
;
293 ___FIELD(tbl
,0) = ___FIXADD(___FIELD(tbl
,0),___FIX(1));
295 if (___INT(___FIELD(tbl
,0)) > ___INT(___VECTORLENGTH(tbl
)) * 4)
297 int new_len
= (___INT(___VECTORLENGTH(tbl
))-1) * 2;
298 ___SCMOBJ new_tbl
= symkey_table_alloc (subtype
, new_len
);
300 if (!___FIXNUMP(new_tbl
))
302 for (i
=___INT(___VECTORLENGTH(tbl
))-1; i
>0; i
--)
304 ___SCMOBJ probe
= ___FIELD(tbl
,i
);
306 while (probe
!= ___NUL
)
308 ___SCMOBJ symkey
= probe
;
309 int j
= ___INT(___FIELD(symkey
,___SYMKEY_HASH
))%new_len
+ 1;
311 probe
= ___FIELD(symkey
,___SYMKEY_NEXT
);
312 ___FIELD(symkey
,___SYMKEY_NEXT
) = ___FIELD(new_tbl
,j
);
313 ___FIELD(new_tbl
,j
) = symkey
;
317 ___FIELD(new_tbl
,0) = ___FIELD(tbl
,0);
319 symkey_table_set (subtype
, new_tbl
);
325 ___HIDDEN ___SCMOBJ find_symkey_from_UTF_8_string
327 unsigned int subtype
),
331 unsigned int subtype
;)
335 ___SCMOBJ h
= hash_UTF_8_string (str
);
340 tbl
= symkey_table (subtype
);
341 probe
= ___FIELD(tbl
, ___INT(h
) % (___INT(___VECTORLENGTH(tbl
))-1) + 1);
343 while (probe
!= ___NUL
)
345 ___SCMOBJ name
= ___FIELD(probe
,___SYMKEY_NAME
);
347 unsigned long n
= ___INT(___STRINGLENGTH(name
));
348 ___UTF_8STRING p
= str
;
350 if (___UTF_8_get (&p
) !=
351 ___CAST(___UCS_4
,___INT(___STRINGREF(name
,___FIX(i
)))))
353 if (___UTF_8_get (&p
) == 0)
356 probe
= ___FIELD(probe
,___SYMKEY_NEXT
);
363 ___SCMOBJ ___find_symkey_from_scheme_string
365 unsigned int subtype
),
369 unsigned int subtype
;)
373 ___SCMOBJ h
= hash_scheme_string (str
);
375 tbl
= symkey_table (subtype
);
376 probe
= ___FIELD(tbl
, ___INT(h
) % (___INT(___VECTORLENGTH(tbl
))-1) + 1);
378 while (probe
!= ___NUL
)
380 ___SCMOBJ name
= ___FIELD(probe
,___SYMKEY_NAME
);
382 long n
= ___INT(___STRINGLENGTH(name
));
383 if (___INT(___STRINGLENGTH(str
)) == n
)
386 if (___STRINGREF(str
,___FIX(i
)) != ___STRINGREF(name
,___FIX(i
)))
391 probe
= ___FIELD(probe
,___SYMKEY_NEXT
);
398 ___SCMOBJ ___new_symkey
399 ___P((___SCMOBJ name
, /* name must be a permanent object */
400 unsigned int subtype
),
404 unsigned int subtype
;)
412 obj
= ___alloc_scmobj (___sKEYWORD
, ___KEYWORD_SIZE
<<___LWS
, ___PERM
);
414 default: /* assume ___sSYMBOL */
415 obj
= ___alloc_scmobj (___sSYMBOL
, ___SYMBOL_SIZE
<<___LWS
, ___PERM
);
422 tbl
= symkey_table (subtype
);
424 /* object layout is same for ___sSYMBOL and ___sKEYWORD */
426 ___FIELD(obj
,___SYMKEY_NAME
) = name
;
427 ___FIELD(obj
,___SYMKEY_HASH
) = hash_scheme_string (name
);
429 if (subtype
== ___sSYMBOL
)
430 ___FIELD(obj
,___SYMBOL_GLOBAL
) = 0;
438 ___HIDDEN ___SCMOBJ make_symkey
439 ___P((___UTF_8STRING str
,
440 unsigned int subtype
),
444 unsigned int subtype
;)
446 ___SCMOBJ obj
= find_symkey_from_UTF_8_string (str
, subtype
);
456 if ((err
= ___NONNULLUTF_8STRING_to_SCMOBJ (str
, &name
, 0))
457 != ___FIX(___NO_ERR
))
460 obj
= ___new_symkey (name
, subtype
);
467 ___HIDDEN ___SCMOBJ make_global
468 ___P((___UTF_8STRING str
,
470 ___glo_struct
**glo
),
476 ___glo_struct
**glo
;)
482 sym
= make_symkey (str
, ___sSYMBOL
);
487 g
= ___FIELD(sym
,___SYMBOL_GLOBAL
);
491 ___processor_state ___ps
= ___PSTATE
;
493 if ((e
= ___alloc_global_var (&p
)) != ___FIX(___NO_ERR
))
495 p
->val
= supply
?___UNB2
:___UNB1
;
498 if (___ps
->glo_list_head
== 0)
499 ___ps
->glo_list_head
= ___CAST(___SCMOBJ
,p
);
501 ___CAST(___glo_struct
*,___ps
->glo_list_tail
)->next
=
502 ___CAST(___SCMOBJ
,p
);
503 ___ps
->glo_list_tail
= ___CAST(___SCMOBJ
,p
);
504 ___FIELD(sym
,___SYMBOL_GLOBAL
) = ___CAST(___SCMOBJ
,p
);
508 p
= ___CAST(___glo_struct
*,g
);
509 if (supply
&& p
->val
== ___UNB1
)
515 return ___FIX(___NO_ERR
);
519 void ___for_each_symkey
520 ___P((unsigned int subtype
,
521 void (*visit
) (___SCMOBJ symkey
, void *data
),
526 unsigned int subtype
;
530 ___SCMOBJ tbl
= symkey_table (subtype
);
533 for (i
=___INT(___VECTORLENGTH(tbl
))-1; i
>0; i
--)
535 ___SCMOBJ probe
= ___FIELD(tbl
, i
);
537 while (probe
!= ___NUL
)
540 probe
= ___FIELD(probe
,___SYMKEY_NEXT
);
546 /*---------------------------------------------------------------------------*/
549 * Alignment of objects.
552 ___HIDDEN ___SCMOBJ
*align
553 ___P((___SCMOBJ
*from
,
555 int need_64bit_alignment
),
558 need_64bit_alignment
)
561 int need_64bit_alignment
;)
566 if (need_64bit_alignment
)
567 to
= ___ALIGNUP((from
+1), 8) - 1;
570 to
= ___ALIGNUP(from
, ___WS
);
576 for (i
=words
-1; i
>=0; i
--)
584 ___HIDDEN ___SCMOBJ align_subtyped
585 ___P((___SCMOBJ
*ptr
),
589 ___SCMOBJ head
= ptr
[0];
590 int subtype
= ___HD_SUBTYPE(head
);
591 int words
= ___HD_WORDS(head
);
592 return ___TAG(align (ptr
, words
+1, subtype
>=___sS64VECTOR
), ___tSUBTYPED
);
596 /*---------------------------------------------------------------------------*/
599 * Routines to setup a module for execution.
602 ___HIDDEN ___mod_or_lnk linker_to_mod_or_lnk
603 ___P((___mod_or_lnk (*linker
) (___global_state_struct
*)),
605 ___mod_or_lnk (*linker
) ();)
607 ___mod_or_lnk mol
= linker (&___gstate
);
608 if (mol
->module
.kind
== ___LINKFILE_KIND
)
610 void **p
= mol
->linkfile
.linker_tbl
;
613 *p
= linker_to_mod_or_lnk
614 (*___CAST(___mod_or_lnk (**) ___P((___global_state_struct
*),()),p
));
622 ___HIDDEN ___SCMOBJ for_each_module
623 ___P((___mod_or_lnk mol
,
624 ___SCMOBJ (*proc
) (___module_struct
*)),
628 ___SCMOBJ (*proc
) ();)
630 if (mol
->module
.kind
== ___LINKFILE_KIND
)
632 void **p
= mol
->linkfile
.linker_tbl
;
635 ___SCMOBJ e
= for_each_module (___CAST(___mod_or_lnk
,*p
++), proc
);
636 if (e
!= ___FIX(___NO_ERR
))
639 return ___FIX(___NO_ERR
);
642 return proc (___CAST(___module_struct
*,mol
));
646 ___HIDDEN
void fixref
668 *p
= sym_tbl
[-1-___INT(v
)];
670 *p
= ___TAG(___ALIGNUP(&cns_tbl
[(___PAIR_SIZE
+1)*___INT(v
)],___WS
),
676 *p
= key_tbl
[-1-___INT(v
)];
678 *p
= sub_tbl
[___INT(v
)];
684 ___HIDDEN
int module_count
;
685 ___HIDDEN ___SCMOBJ module_descr
;
688 ___HIDDEN ___SCMOBJ setup_module_phase1
689 ___P((___module_struct
*module
),
691 ___module_struct
*module
;)
696 int flags
= module
->flags
;
697 ___FAKEWORD
*glo_tbl
= module
->glo_tbl
;
698 int sup_count
= module
->sup_count
;
699 ___UTF_8STRING
*glo_names
= module
->glo_names
;
700 ___SCMOBJ
*sym_tbl
= ___CAST(___SCMOBJ
*,module
->sym_tbl
);
701 int sym_count
= module
->sym_count
;
702 ___UTF_8STRING
*sym_names
= module
->sym_names
;
703 ___SCMOBJ
*key_tbl
= ___CAST(___SCMOBJ
*,module
->key_tbl
);
704 int key_count
= module
->key_count
;
705 ___UTF_8STRING
*key_names
= module
->key_names
;
706 ___SCMOBJ
*lp
= module
->lp
;
707 ___SCMOBJ
*lbl_tbl
= ___CAST(___SCMOBJ
*,module
->lbl_tbl
);
708 int lbl_count
= module
->lbl_count
;
709 ___SCMOBJ
*ofd_tbl
= module
->ofd_tbl
;
710 int ofd_length
= module
->ofd_length
;
711 ___SCMOBJ
*cns_tbl
= module
->cns_tbl
;
712 int cns_count
= module
->cns_count
;
713 ___SCMOBJ
*sub_tbl
= ___CAST(___SCMOBJ
*,module
->sub_tbl
);
714 int sub_count
= module
->sub_count
;
717 * Check that the version of the compiler used to compile the module
718 * is compatible with the compiler used to compile the runtime
722 if (module
->version
/ 10000 < ___VERSION
/ 10000)
723 return ___FIX(___MODULE_VERSION_TOO_OLD_ERR
);
725 if (module
->version
/ 10000 > ___VERSION
/ 10000)
726 return ___FIX(___MODULE_VERSION_TOO_NEW_ERR
);
728 /* Align module's pair table */
731 cns
= align (cns_tbl
, (___PAIR_SIZE
+1)*cns_count
, 0);
733 /* Setup module's global variable table */
738 * Create global variables in reverse order so that global
739 * variables bound to c-lambdas are created last.
742 while (glo_names
[i
] != 0)
746 ___glo_struct
*glo
= 0;
747 ___SCMOBJ e
= make_global (glo_names
[i
], i
<sup_count
, &glo
);
748 if (e
!= ___FIX(___NO_ERR
))
750 glo_tbl
[i
] = ___CAST(___FAKEWORD
,glo
);
754 /* Setup module's symbol table */
759 while (sym_names
[i
] != 0)
761 ___SCMOBJ sym
= make_symkey (sym_names
[i
], ___sSYMBOL
);
769 for (i
=sym_count
-1; i
>=0; i
--)
770 sym_tbl
[i
] = ___TAG(___ALIGNUP(sym_tbl
[i
], ___WS
), ___tSUBTYPED
);
772 /* Setup module's keyword table */
777 while (key_names
[i
] != 0)
779 ___SCMOBJ key
= make_symkey (key_names
[i
], ___sKEYWORD
);
787 for (i
=key_count
-1; i
>=0; i
--)
788 key_tbl
[i
] = ___TAG(___ALIGNUP(key_tbl
[i
], ___WS
), ___tSUBTYPED
);
790 /* Setup module's subtyped object table */
792 for (i
=sub_count
-1; i
>=0; i
--)
793 sub_tbl
[i
] = align_subtyped (___CAST(___SCMOBJ
*,sub_tbl
[i
]));
795 /* Fix references in module's pair table */
797 for (i
=cns_count
-1; i
>=0; i
--)
799 fixref (cns
+i
*(___PAIR_SIZE
+1)+1, sym_tbl
, key_tbl
, cns_tbl
, sub_tbl
);
800 fixref (cns
+i
*(___PAIR_SIZE
+1)+2, sym_tbl
, key_tbl
, cns_tbl
, sub_tbl
);
803 /* Fix references in module's subtyped object table */
805 for (j
=sub_count
-1; j
>=0; j
--)
807 ___SCMOBJ
*p
= ___UNTAG_AS(sub_tbl
[j
],___tSUBTYPED
);
808 ___SCMOBJ head
= p
[0];
809 int subtype
= ___HD_SUBTYPE(head
);
810 int words
= ___HD_WORDS(head
);
819 for (i
=1; i
<=words
; i
++)
820 fixref (p
+i
, sym_tbl
, key_tbl
, cns_tbl
, sub_tbl
);
824 /* Align module's out-of-line frame descriptor table */
827 ofd_tbl
= ___CAST(___SCMOBJ
*,align (ofd_tbl
, ofd_length
, 0));
829 /* Align module's label table */
833 ___host current_host
= 0;
835 ___label_struct
*new_lt
;
836 ___SCMOBJ
*ofd_alloc
;
840 new_lt
= ___CAST(___label_struct
*,align (lbl_tbl
, lbl_count
*___LS
, 0));
843 for (i
=0; i
<lbl_count
; i
++)
845 ___label_struct
*lbl
= &new_lt
[i
];
846 ___SCMOBJ head
= lbl
->header
;
848 if (___TESTHEADERTAG(head
,___sVECTOR
))
850 ___UTF_8STRING name
=
851 ___CAST(___UTF_8STRING
,
852 ___CAST_FAKEVOIDSTAR_TO_VOIDSTAR(lbl
->host_label
));
855 lbl
->host_label
= ___CAST(___FAKEVOIDSTAR
,___FAL
);
859 find_symkey_from_UTF_8_string (name
, ___sSYMBOL
);
865 return ___FIX(___UNKNOWN_ERR
);
867 lbl
->host_label
= ___CAST(___FAKEVOIDSTAR
,sym
);
870 fixref (&lbl
->entry_or_descr
, sym_tbl
, key_tbl
, cns_tbl
, sub_tbl
);
873 hlbl_ptr
++; /* skip INTRO label */
877 if (flags
& 1) /* module uses gcc's computed goto? */
879 if (___CAST_FAKEHOST_TO_HOST(lbl
->host
) != current_host
)
881 current_host
= ___CAST_FAKEHOST_TO_HOST(lbl
->host
);
882 hlbl_ptr
= ___CAST(void**,current_host (0));
883 hlbl_ptr
++; /* skip INTRO label */
885 lbl
->host_label
= ___CAST_VOIDSTAR_TO_FAKEVOIDSTAR(*hlbl_ptr
++);
887 if (head
== ___MAKE_HD((3<<___LWS
),___sRETURN
,___PERM
))
890 descr
= lbl
->entry_or_descr
;
891 if (___IFD_GCMAP(descr
) == 0) /* out-of-line descriptor? */
894 lbl
->entry_or_descr
= ___CAST(___SCMOBJ
,ofd_alloc
);
895 fs
= ___OFD_FS(*ofd_alloc
);
896 if (___IFD_KIND(descr
) == ___RETI
)
897 fs
= ___RETI_CFS_TO_FS(fs
);
898 ofd_alloc
+= 1 + ___CEILING_DIV(fs
,___WORD_WIDTH
);
902 lbl
->entry_or_descr
= ___TAG(&lbl
->header
,___tSUBTYPED
);
905 *lp
= ___TAG(new_lt
,___tSUBTYPED
);
908 return ___FIX(___NO_ERR
);
912 ___HIDDEN
char module_prefix
[] = ___MODULE_PREFIX
;
914 #define module_prefix_length (sizeof(module_prefix)-1)
917 ___HIDDEN ___SCMOBJ setup_module_phase2
918 ___P((___module_struct
*module
),
920 ___module_struct
*module
;)
922 ___UTF_8STRING
*glo_names
= module
->glo_names
;
926 ___UTF_8STRING name
= module
->name
;
927 ___FAKEWORD
*glo_tbl
= module
->glo_tbl
;
928 int glo_count
= module
->glo_count
;
929 int sup_count
= module
->sup_count
;
931 for (i
=sup_count
; i
<glo_count
; i
++)
934 * If the global variable is undefined, add it to the list
935 * of undefined variables in the module descriptor.
938 ___glo_struct
*glo
= ___CAST(___glo_struct
*,glo_tbl
[i
]);
940 if (glo
->val
== ___UNB1
)
944 ___SCMOBJ module_name
;
948 if ((err
= ___NONNULLUTF_8STRING_to_SCMOBJ
952 != ___FIX(___NO_ERR
))
955 if ((err
= ___NONNULLUTF_8STRING_to_SCMOBJ
956 (name
+module_prefix_length
,
959 != ___FIX(___NO_ERR
))
961 ___release_scmobj (glo_name
);
965 pair1
= ___make_pair (glo_name
, module_name
, ___STILL
);
967 ___release_scmobj (glo_name
);
968 ___release_scmobj (module_name
);
970 if (___FIXNUMP(pair1
))
973 pair2
= ___make_pair (pair1
, ___FIELD(module_descr
,1), ___STILL
);
975 ___release_scmobj (pair1
);
977 if (___FIXNUMP(pair2
))
980 ___FIELD(module_descr
,1) = pair2
;
982 ___release_scmobj (pair2
);
987 return ___FIX(___NO_ERR
);
991 ___HIDDEN ___SCMOBJ setup_module_phase3
992 ___P((___module_struct
*module
),
994 ___module_struct
*module
;)
996 if (module
->lbl_count
> 0)
998 ___FIELD(___FIELD(module_descr
,0),module_count
) =
999 *module
->lp
+___LS
*___WS
;
1002 return module
->init_proc ();
1006 ___HIDDEN ___UTF_8STRING module_script_line
;
1009 ___HIDDEN ___SCMOBJ get_script_line_proc
1010 ___P((___module_struct
*module
),
1012 ___module_struct
*module
;)
1014 if (module
->script_line
!= 0)
1015 module_script_line
= module
->script_line
;
1016 return ___FIX(___NO_ERR
);
1020 ___HIDDEN ___UTF_8STRING get_script_line
1021 ___P((___mod_or_lnk mol
),
1025 module_script_line
= 0;
1027 if (for_each_module (mol
, get_script_line_proc
) == ___FIX(___NO_ERR
))
1028 return module_script_line
;
1034 ___HIDDEN ___SCMOBJ setup_modules
1035 ___P((___mod_or_lnk mol
),
1041 result
= ___make_vector (3, ___NUL
, ___STILL
);
1043 if (!___FIXNUMP(result
))
1046 module_descr
= result
;
1048 if ((result
= for_each_module (mol
, setup_module_phase1
))
1049 == ___FIX(___NO_ERR
))
1051 if ((result
= for_each_module (mol
, setup_module_phase2
))
1052 == ___FIX(___NO_ERR
))
1054 result
= ___make_vector (module_count
, ___FAL
, ___STILL
);
1056 if (!___FIXNUMP(result
))
1058 ___FIELD(module_descr
,0) = result
;
1059 ___release_scmobj (result
);
1063 if ((result
= for_each_module (mol
, setup_module_phase3
))
1064 == ___FIX(___NO_ERR
))
1066 ___SCMOBJ script_line
;
1068 if ((result
= ___UTF_8STRING_to_SCMOBJ
1069 (get_script_line (mol
),
1072 == ___FIX(___NO_ERR
))
1074 ___FIELD(module_descr
,2) = script_line
;
1075 ___release_scmobj (script_line
);
1076 result
= module_descr
;
1083 if (___FIXNUMP(result
))
1084 ___release_scmobj (module_descr
);
1091 ___SCMOBJ ___os_load_object_file
1092 ___P((___SCMOBJ path
,
1103 if ((result
= ___dynamic_load (path
, modname
, &linker
)) == ___FIX(___NO_ERR
))
1105 mol
= linker_to_mod_or_lnk
1106 (___CAST(___mod_or_lnk (*) ___P((___global_state_struct
*),()),
1109 if (mol
->linkfile
.version
< 0) /* was it already setup? */
1110 result
= ___FIX(___MODULE_ALREADY_LOADED_ERR
);
1113 result
= setup_modules (mol
);
1114 mol
->linkfile
.version
= -1; /* mark link file as 'setup' */
1118 ___release_scmobj (result
);
1124 /*---------------------------------------------------------------------------*/
1127 * Character operations.
1131 ___EXP_FUNC(___BOOL
,___iswalpha
)
1138 return iswalpha (x
);
1142 return (x
>= 97 && x
<= 122) || (x
>= 65 && x
<= 90);
1148 ___EXP_FUNC(___BOOL
,___iswdigit
)
1155 return iswdigit (x
);
1159 return x
>= 48 && x
<= 57;
1165 ___EXP_FUNC(___BOOL
,___iswspace
)
1172 return iswspace (x
);
1176 return (x
>= 9 && x
<= 13) || (x
== 32);
1182 ___EXP_FUNC(___BOOL
,___iswupper
)
1189 return iswupper (x
);
1193 return x
>= 65 && x
<= 90;
1199 ___EXP_FUNC(___BOOL
,___iswlower
)
1206 return iswlower (x
);
1210 return x
>= 97 && x
<= 122;
1216 ___EXP_FUNC(___UCS_4
,___towupper
)
1223 return towupper (x
);
1227 return (x
>= 97 && x
<= 122) ? x
-32 : x
;
1233 ___EXP_FUNC(___UCS_4
,___towlower
)
1240 return towlower (x
);
1244 return (x
>= 65 && x
<= 90) ? x
+32 : x
;
1250 #define STRING_COLLATE_BUF_LENGTH 1000
1253 ___EXP_FUNC(___SCMOBJ
,___string_collate
)
1254 ___P((___SCMOBJ str1
,
1261 int len1
= ___INT(___STRINGLENGTH(str1
));
1262 int len2
= ___INT(___STRINGLENGTH(str2
));
1266 wchar_t buf
[STRING_COLLATE_BUF_LENGTH
];
1275 if (len1
+ len2
+ 2 > STRING_COLLATE_BUF_LENGTH
)
1277 b1
= ___CAST(wchar_t*,___alloc_mem (len1
+ 1));
1280 return ___FIX(___HEAP_OVERFLOW_ERR
);
1284 for (i
=0; i
<len1
; i
++)
1285 *p
++ = ___INT(___STRINGREF(str1
,___FIX(i
)));
1289 b2
= ___CAST(wchar_t*,___alloc_mem (len1
+ 1));
1294 return ___FIX(___HEAP_OVERFLOW_ERR
);
1299 for (i
=0; i
<len2
; i
++)
1300 *p
++ = ___INT(___STRINGREF(str2
,___FIX(i
)));
1310 for (i
=0; i
<len1
; i
++)
1311 *p
++ = ___INT(___STRINGREF(str1
,___FIX(i
)));
1317 for (i
=0; i
<len2
; i
++)
1318 *p
++ = ___INT(___STRINGREF(str2
,___FIX(i
)));
1327 while (len1
> 0 && len2
> 0 && result
== 0)
1332 result
= wcscoll (s1
, s2
);
1334 l1
= wcslen (s1
) + 1;
1335 l2
= wcslen (s2
) + 1;
1344 if (len1
+ len2
+ 2 > STRING_COLLATE_BUF_LENGTH
)
1375 ___SCMOBJ c1
= ___STRINGREF(str1
,___FIX(i
));
1376 ___SCMOBJ c2
= ___STRINGREF(str2
,___FIX(i
));
1378 if (___CHARLTP(c1
,c2
))
1381 if (___CHARGTP(c1
,c2
))
1397 ___EXP_FUNC(___SCMOBJ
,___string_collate_ci
)
1398 ___P((___SCMOBJ str1
,
1405 int len1
= ___INT(___STRINGLENGTH(str1
));
1406 int len2
= ___INT(___STRINGLENGTH(str2
));
1423 ___UCS_4 c1
= ___INT(___STRINGREF(str1
,___FIX(i
)));
1424 ___UCS_4 c2
= ___INT(___STRINGREF(str2
,___FIX(i
)));
1426 if (c1
>= 65 && c1
<= 90)
1429 if (c2
>= 65 && c2
<= 90)
1451 /*---------------------------------------------------------------------------*/
1454 * Numerical library routines.
1457 #ifdef ___BIG_ENDIAN
1470 ___EXP_FUNC(double,___copysign
)
1480 (___FETCH_U8(&x
,F64_HI8
)&0x7f)|(___FETCH_U8(&y
,F64_HI8
)&0x80));
1486 ___EXP_FUNC(___BOOL
,___isfinite
)
1491 #ifdef ___CRAY_FP_FORMAT
1505 return ((y
.u16
[F64_HI16
] ^ 0x7ff0) & 0x7fff) >= 0x10;
1511 ___EXP_FUNC(___BOOL
,___isnan
)
1516 #ifdef ___CRAY_FP_FORMAT
1530 ___UM32 tmp
= (y
.u32
[F64_HI32
] ^ 0x7ff00000) & 0x7fffffff;
1532 return tmp
< 0x100000 && (tmp
| y
.u32
[F64_LO32
]) != 0;
1538 ___EXP_FUNC(double,___trunc
)
1543 double f
= floor (x
);
1544 if (x
< 0.0 && x
!= f
)
1551 ___EXP_FUNC(double,___round
)
1560 if (f
> 0.5 || (f
== 0.5 && modf (i
*0.5, &t
) != 0.0))
1565 else if (x
== 0.0) /* so that round (-0.0) = -0.0 */
1570 if (f
> 0.5 || (f
== 0.5 && modf (i
*0.5, &t
) != 0.0))
1578 #ifndef ___GOOD_ATAN2
1580 ___EXP_FUNC(double,___atan2
)
1590 else if (___isnan (y
))
1594 if (___copysign (1.0, y
) > 0.0)
1596 if (___copysign (1.0, x
) > 0.0)
1599 return 3.141592653589793; /* from "header.scm" */
1603 if (___copysign (1.0, x
) > 0.0)
1606 return -3.141592653589793; /* from "header.scm" */
1609 else if (___isfinite (x
) || ___isfinite (y
))
1610 return atan2 (y
, x
);
1612 return ___copysign (x
/y
, x
*y
); /* returns NAN with appropriate sign */
1620 ___EXP_FUNC(double,___pow
)
1630 else if (___isnan (x
))
1632 else if (___isnan (y
))
1641 /*---------------------------------------------------------------------------*/
1644 * Initialization of symbol and keyword tables, and global variables.
1647 ___HIDDEN
void init_symkey_glo1
1648 ___P((___mod_or_lnk mol
),
1652 if (mol
->module
.kind
== ___LINKFILE_KIND
)
1654 void **p1
= mol
->linkfile
.linker_tbl
;
1655 ___FAKEWORD
*p2
= mol
->linkfile
.sym_list
;
1658 init_symkey_glo1 (___CAST(___mod_or_lnk
,*p1
++));
1665 sym_ptr
= ___CAST(___SCMOBJ
*,p2
);
1667 p2
= ___CAST(___FAKEWORD
*,sym_ptr
[0]);
1668 glo
= ___CAST(___glo_struct
*,sym_ptr
[1+___SYMBOL_GLOBAL
]);
1670 sym_ptr
[1+___SYMKEY_HASH
] = glo
->prm
; /* move symbol's hash value */
1676 ___HIDDEN
void init_symkey_glo2
1677 ___P((___mod_or_lnk mol
),
1681 if (mol
->module
.kind
== ___LINKFILE_KIND
)
1683 void **p1
= mol
->linkfile
.linker_tbl
;
1684 ___FAKEWORD
*p2
= mol
->linkfile
.sym_list
;
1685 ___FAKEWORD
*p3
= mol
->linkfile
.key_list
;
1686 ___processor_state ___ps
= ___PSTATE
;
1689 init_symkey_glo2 (___CAST(___mod_or_lnk
,*p1
++));
1698 sym_ptr
= ___CAST(___SCMOBJ
*,p2
);
1700 p2
= ___CAST(___FAKEWORD
*,sym_ptr
[0]);
1701 str
= align_subtyped (___CAST(___SCMOBJ
*,sym_ptr
[1+___SYMKEY_NAME
]));
1702 glo
= ___CAST(___glo_struct
*,sym_ptr
[1+___SYMBOL_GLOBAL
]);
1705 if (___ps
->glo_list_head
== 0)
1706 ___ps
->glo_list_head
= ___CAST(___SCMOBJ
,glo
);
1708 ___CAST(___glo_struct
*,___ps
->glo_list_tail
)->next
=
1709 ___CAST(___SCMOBJ
,glo
);
1710 ___ps
->glo_list_tail
= ___CAST(___SCMOBJ
,glo
);
1712 *sym_ptr
= ___MAKE_HD((___SYMBOL_SIZE
<<___LWS
),___sSYMBOL
,___PERM
);
1714 sym
= align_subtyped (sym_ptr
);
1716 ___FIELD(sym
,___SYMKEY_NAME
) = str
;
1717 ___FIELD(sym
,___SYMBOL_GLOBAL
) = ___CAST(___SCMOBJ
,glo
);
1727 key_ptr
= ___CAST(___SCMOBJ
*,p3
);
1729 p3
= ___CAST(___FAKEWORD
*,key_ptr
[0]);
1730 str
= align_subtyped (___CAST(___SCMOBJ
*,key_ptr
[1+___SYMKEY_NAME
]));
1732 *key_ptr
= ___MAKE_HD((___KEYWORD_SIZE
<<___LWS
),___sKEYWORD
,___PERM
);
1734 key
= align_subtyped (key_ptr
);
1736 ___FIELD(key
,___SYMKEY_NAME
) = str
;
1737 ___FIELD(key
,___SYMKEY_HASH
) = hash_scheme_string (str
);
1745 /*---------------------------------------------------------------------------*/
1748 * C to Scheme call handler.
1751 ___EXP_FUNC(___SCMOBJ
,___call
)
1754 ___SCMOBJ stack_marker
),
1760 ___SCMOBJ stack_marker
;)
1763 ___processor_state ___ps
= ___PSTATE
;
1764 ___SCMOBJ
*___fp
= ___ps
->fp
;
1767 * The C function which has called ___call() has put the arguments
1768 * of the Scheme procedure on the stack above ___fp as shown in the
1769 * 'on entry' picture below. The free space under arg1 is for a
1770 * continuation frame that performs the return of control from
1771 * Scheme to C. This frame is set up by ___call() before the
1772 * destination Scheme procedure is invoked. The frame is accessed
1773 * by the return_to_c handler (in "_kernel.scm") which is invoked
1774 * when the called procedure returns. The frame contains a heap
1775 * allocated 'stack marker', allocated by the caller, which
1776 * indicates the destination Scheme procedure and if it is still possible
1777 * to return to the caller (i.e. its activation frame is still on
1778 * the C stack). The caller will store #f in the stack marker so
1779 * that any subsequent attempt to return to that invocation of the
1780 * caller will be detected and trigger an error.
1783 * ON ENTRY: JUST BEFORE JUMPING TO THE SCHEME PROCEDURE:
1790 * | arg N | | arg N |
1791 * | ... | ___fp -->| ... |
1792 * | arg 1 | | arg 1 |
1793 * +------------+ +------------+
1794 * | RESERVED | | RESERVED | stack marker
1795 * | <PADDING> | | <PADDING> | +------------+
1796 * | undefined | | ---------->| HEAD |
1797 * | undefined | | return adr | | procedure |
1798 * +------------+ +------------+ +------------+
1799 * ___fp -->| RESERVED | | RESERVED |
1801 * +------------+ +------------+
1805 ___LD_ARG_REGS
/* declare and load GVM argument registers from ___ps */
1807 ___fp
[-1] = ___PSR0
; /* create a frame with the same format as the */
1808 ___fp
[-2] = stack_marker
; /* one created for the return to C handler */
1809 /* in "_kernel.scm" */
1811 ___fp
-= ___FRAME_SPACE(2) + nargs
; /* move ___fp to point to last arg */
1813 ___POP_ARGS_IN_REGS(nargs
) /* load arguments into appropriate registers */
1815 ___ST_ARG_REGS
/* write back GVM argument registers to ___ps */
1817 ___PSR0
= ___GSTATE
->handler_return_to_c
;
1821 ___ps
->pc
= ___CAST(___label_struct
*,proc
-___tSUBTYPED
)->entry_or_descr
;
1826 ___SCMOBJ ___pc
= ___ps
->pc
;
1831 ___pc = ___CAST_FAKEHOST_TO_HOST(___CAST(___label_struct*,___pc-___tSUBTYPED) \
1845 if (___err
!= ___FIX(___UNWIND_C_STACK
) ||
1846 stack_marker
!= ___ps
->fp
[___FRAME_SPACE(2)-2]) /*need more unwinding?*/
1849 ___ps
->fp
+= ___FRAME_SPACE(2);
1850 ___PSR0
= ___ps
->fp
[-1];
1852 return ___FIX(___NO_ERR
);
1856 ___EXP_FUNC(void,___propagate_error
)
1857 ___P((___SCMOBJ err
),
1861 if (err
!= ___FIX(___NO_ERR
))
1863 ___processor_state ___ps
= ___PSTATE
;
1871 ___SCMOBJ find_global_var_bound_to
1872 ___P((___SCMOBJ val
),
1876 ___SCMOBJ sym
= ___NUL
;
1879 for (i
= ___INT(___VECTORLENGTH(___GSTATE
->symbol_table
)) - 1; i
>0; i
--)
1881 sym
= ___FIELD(___GSTATE
->symbol_table
,i
);
1883 while (sym
!= ___NUL
)
1885 ___SCMOBJ g
= ___FIELD(sym
,___SYMBOL_GLOBAL
);
1889 ___glo_struct
*p
= ___CAST(___glo_struct
*,g
);
1891 if (p
->prm
== val
|| p
->val
== val
)
1898 sym
= ___FIELD(sym
,___SYMKEY_NEXT
);
1908 #ifdef ___DEBUG_HOST_CHANGES
1910 ___EXP_FUNC(void,___register_host_entry
)
1911 ___P((___WORD start
,
1920 ___processor_state ___ps
= ___PSTATE
;
1923 ___printf ("*** Entering ");
1925 if ((sym
= find_global_var_bound_to (___ps
->pc
)) != ___NUL
||
1926 (sym
= find_global_var_bound_to (start
)) != ___NUL
)
1928 ___SCMOBJ name
= ___FIELD(sym
,___SYMKEY_NAME
);
1930 for (i
=0; i
<___INT(___STRINGLENGTH(name
)); i
++)
1931 ___printf ("%c", ___INT(___STRINGREF(name
,___FIX(i
))));
1935 ___printf ("|%s| host=0x%08x", module_name
, start
);
1938 if (start
== ___ps
->pc
)
1941 ___printf (" (subprocedure %d)\n",
1942 ___CAST(___label_struct
*,___ps
->pc
) -
1943 ___CAST(___label_struct
*,start
));
1951 /*---------------------------------------------------------------------------*/
1954 * Setup program and execute it.
1957 ___HIDDEN
int setup_state
= 0; /* 0=pre-setup, 1=post-setup, 2=post-cleanup */
1960 ___EXP_FUNC(void,___cleanup
) ___PVOID
1963 * Only do cleanup once after successful setup.
1966 if (setup_state
!= 1)
1976 ___EXP_FUNC(void,___cleanup_and_exit_process
)
1982 ___exit_process (status
);
1986 ___EXP_FUNC(void,___setup_params_reset
)
1987 ___P((___setup_params_struct
*setup_params
),
1989 ___setup_params_struct
*setup_params
;)
1991 setup_params
->version
= 0;
1992 setup_params
->argv
= reset_argv
;
1993 setup_params
->min_heap
= 0;
1994 setup_params
->max_heap
= 0;
1995 setup_params
->live_percent
= 0;
1996 setup_params
->gc_hook
= 0;
1997 setup_params
->display_error
= 0;
1998 setup_params
->fatal_error
= 0;
1999 setup_params
->standard_level
= 0;
2000 setup_params
->debug_settings
= 0;
2001 setup_params
->file_settings
= 0;
2002 setup_params
->terminal_settings
= 0;
2003 setup_params
->stdio_settings
= 0;
2004 setup_params
->gambcdir
= 0;
2005 setup_params
->gambcdir_map
= 0;
2006 setup_params
->remote_dbg_addr
= 0;
2007 setup_params
->rpc_server_addr
= 0;
2008 setup_params
->linker
= 0;
2009 setup_params
->dummy8
= 0;
2010 setup_params
->dummy7
= 0;
2011 setup_params
->dummy6
= 0;
2012 setup_params
->dummy5
= 0;
2013 setup_params
->dummy4
= 0;
2014 setup_params
->dummy3
= 0;
2015 setup_params
->dummy2
= 0;
2016 setup_params
->dummy1
= 0;
2020 ___EXP_FUNC(unsigned long,___get_min_heap
) ___PVOID
2022 return ___setup_params
.min_heap
;
2026 ___EXP_FUNC(void,___set_min_heap
)
2027 ___P((unsigned long bytes
),
2029 unsigned long bytes
;)
2031 ___setup_params
.min_heap
= bytes
;
2035 ___EXP_FUNC(unsigned long,___get_max_heap
) ___PVOID
2037 return ___setup_params
.max_heap
;
2041 ___EXP_FUNC(void,___set_max_heap
)
2042 ___P((unsigned long bytes
),
2044 unsigned long bytes
;)
2046 ___setup_params
.max_heap
= bytes
;
2050 ___EXP_FUNC(int,___get_live_percent
) ___PVOID
2052 return ___setup_params
.live_percent
;
2056 ___EXP_FUNC(void,___set_live_percent
)
2061 ___setup_params
.live_percent
= percent
;
2065 ___EXP_FUNC(int,___get_standard_level
) ___PVOID
2067 return ___setup_params
.standard_level
;
2071 ___EXP_FUNC(void,___set_standard_level
)
2076 ___setup_params
.standard_level
= level
;
2080 ___EXP_FUNC(int,___set_debug_settings
)
2088 int old_settings
= ___setup_params
.debug_settings
;
2090 ___setup_params
.debug_settings
=
2091 (old_settings
& ~mask
) | (new_settings
& mask
);
2093 return old_settings
;
2097 ___EXP_FUNC(___program_startup_info_struct
*,___get_program_startup_info
)
2100 return &___program_startup_info
;
2104 ___EXP_FUNC(___SCMOBJ
,___setup
)
2105 ___P((___setup_params_struct
*setup_params
),
2107 ___setup_params_struct
*setup_params
;)
2110 ___processor_state ___ps
;
2117 * Check for valid setup_params structure.
2120 if (setup_params
== 0 ||
2121 setup_params
->version
!= ___VERSION
)
2122 return ___FIX(___UNKNOWN_ERR
);
2125 * Only do setup once.
2128 if (setup_state
!= 0)
2129 return ___FIX(___UNKNOWN_ERR
);
2131 setup_state
= 2; /* disallow cleanup, in case setup fails */
2134 * Remember setup parameters.
2137 ___setup_params
= *setup_params
;
2140 * Setup the operating system module.
2143 if ((___err
= ___setup_os ()) != ___FIX(___NO_ERR
))
2147 * Setup stack and heap.
2150 if ((___err
= ___setup_mem ()) != ___FIX(___NO_ERR
))
2156 setup_state
= 1; /* allow cleanup */
2159 * Setup global state to avoid problems on systems that don't
2160 * support the dynamic loading of files that import functions.
2163 ___gstate
.dummy8
= 0;
2164 ___gstate
.dummy7
= 0;
2165 ___gstate
.dummy6
= 0;
2166 ___gstate
.dummy5
= 0;
2167 ___gstate
.dummy4
= 0;
2168 ___gstate
.dummy3
= 0;
2169 ___gstate
.dummy2
= 0;
2170 ___gstate
.dummy1
= 0;
2172 #ifndef ___CAN_IMPORT_CLIB_DYNAMICALLY
2174 ___gstate
.fabs
= fabs
;
2175 ___gstate
.floor
= floor
;
2176 ___gstate
.ceil
= ceil
;
2177 ___gstate
.exp
= exp
;
2178 ___gstate
.log
= log
;
2179 ___gstate
.sin
= sin
;
2180 ___gstate
.cos
= cos
;
2181 ___gstate
.tan
= tan
;
2182 ___gstate
.asin
= asin
;
2183 ___gstate
.acos
= acos
;
2184 ___gstate
.atan
= atan
;
2185 #ifdef ___GOOD_ATAN2
2186 ___gstate
.atan2
= atan2
;
2189 ___gstate
.pow
= pow
;
2191 ___gstate
.sqrt
= sqrt
;
2195 #ifdef ___USE_SETJMP
2196 #ifndef ___CAN_IMPORT_SETJMP_DYNAMICALLY
2198 ___gstate
.setjmp
= setjmp
;
2203 #ifndef ___CAN_IMPORT_DYNAMICALLY
2205 ___gstate
.___iswalpha
2208 ___gstate
.___iswdigit
2211 ___gstate
.___iswspace
2214 ___gstate
.___iswupper
2217 ___gstate
.___iswlower
2220 ___gstate
.___towupper
2223 ___gstate
.___towlower
2226 ___gstate
.___string_collate
2227 = ___string_collate
;
2229 ___gstate
.___string_collate_ci
2230 = ___string_collate_ci
;
2232 ___gstate
.___copysign
2235 ___gstate
.___isfinite
2247 #ifndef ___GOOD_ATAN2
2257 ___gstate
.___S64_from_SM32_fn
2258 = ___S64_from_SM32_fn
;
2260 ___gstate
.___S64_from_SM32_UM32_fn
2261 = ___S64_from_SM32_UM32_fn
;
2263 ___gstate
.___S64_from_LONGLONG_fn
2264 = ___S64_from_LONGLONG_fn
;
2266 ___gstate
.___S64_to_LONGLONG_fn
2267 = ___S64_to_LONGLONG_fn
;
2269 ___gstate
.___S64_fits_in_width_fn
2270 = ___S64_fits_in_width_fn
;
2272 ___gstate
.___U64_from_UM32_fn
2273 = ___U64_from_UM32_fn
;
2275 ___gstate
.___U64_from_UM32_UM32_fn
2276 = ___U64_from_UM32_UM32_fn
;
2278 ___gstate
.___U64_from_ULONGLONG_fn
2279 = ___U64_from_ULONGLONG_fn
;
2281 ___gstate
.___U64_to_ULONGLONG_fn
2282 = ___U64_to_ULONGLONG_fn
;
2284 ___gstate
.___U64_fits_in_width_fn
2285 = ___U64_fits_in_width_fn
;
2287 ___gstate
.___U64_mul_UM32_UM32_fn
2288 = ___U64_mul_UM32_UM32_fn
;
2290 ___gstate
.___U64_add_U64_U64_fn
2291 = ___U64_add_U64_U64_fn
;
2293 ___gstate
.___SCMOBJ_to_S8
2296 ___gstate
.___SCMOBJ_to_U8
2299 ___gstate
.___SCMOBJ_to_S16
2302 ___gstate
.___SCMOBJ_to_U16
2305 ___gstate
.___SCMOBJ_to_S32
2308 ___gstate
.___SCMOBJ_to_U32
2311 ___gstate
.___SCMOBJ_to_S64
2314 ___gstate
.___SCMOBJ_to_U64
2317 ___gstate
.___SCMOBJ_to_F32
2320 ___gstate
.___SCMOBJ_to_F64
2323 ___gstate
.___SCMOBJ_to_CHAR
2324 = ___SCMOBJ_to_CHAR
;
2326 ___gstate
.___SCMOBJ_to_SCHAR
2327 = ___SCMOBJ_to_SCHAR
;
2329 ___gstate
.___SCMOBJ_to_UCHAR
2330 = ___SCMOBJ_to_UCHAR
;
2332 ___gstate
.___SCMOBJ_to_ISO_8859_1
2333 = ___SCMOBJ_to_ISO_8859_1
;
2335 ___gstate
.___SCMOBJ_to_UCS_2
2336 = ___SCMOBJ_to_UCS_2
;
2338 ___gstate
.___SCMOBJ_to_UCS_4
2339 = ___SCMOBJ_to_UCS_4
;
2341 ___gstate
.___SCMOBJ_to_WCHAR
2342 = ___SCMOBJ_to_WCHAR
;
2344 ___gstate
.___SCMOBJ_to_SHORT
2345 = ___SCMOBJ_to_SHORT
;
2347 ___gstate
.___SCMOBJ_to_USHORT
2348 = ___SCMOBJ_to_USHORT
;
2350 ___gstate
.___SCMOBJ_to_INT
2353 ___gstate
.___SCMOBJ_to_UINT
2354 = ___SCMOBJ_to_UINT
;
2356 ___gstate
.___SCMOBJ_to_LONG
2357 = ___SCMOBJ_to_LONG
;
2359 ___gstate
.___SCMOBJ_to_ULONG
2360 = ___SCMOBJ_to_ULONG
;
2362 ___gstate
.___SCMOBJ_to_LONGLONG
2363 = ___SCMOBJ_to_LONGLONG
;
2365 ___gstate
.___SCMOBJ_to_ULONGLONG
2366 = ___SCMOBJ_to_ULONGLONG
;
2368 ___gstate
.___SCMOBJ_to_FLOAT
2369 = ___SCMOBJ_to_FLOAT
;
2371 ___gstate
.___SCMOBJ_to_DOUBLE
2372 = ___SCMOBJ_to_DOUBLE
;
2374 ___gstate
.___SCMOBJ_to_STRUCT
2375 = ___SCMOBJ_to_STRUCT
;
2377 ___gstate
.___SCMOBJ_to_UNION
2378 = ___SCMOBJ_to_UNION
;
2380 ___gstate
.___SCMOBJ_to_TYPE
2381 = ___SCMOBJ_to_TYPE
;
2383 ___gstate
.___SCMOBJ_to_POINTER
2384 = ___SCMOBJ_to_POINTER
;
2386 ___gstate
.___SCMOBJ_to_NONNULLPOINTER
2387 = ___SCMOBJ_to_NONNULLPOINTER
;
2389 ___gstate
.___SCMOBJ_to_FUNCTION
2390 = ___SCMOBJ_to_FUNCTION
;
2392 ___gstate
.___SCMOBJ_to_NONNULLFUNCTION
2393 = ___SCMOBJ_to_NONNULLFUNCTION
;
2395 ___gstate
.___SCMOBJ_to_BOOL
2396 = ___SCMOBJ_to_BOOL
;
2398 ___gstate
.___SCMOBJ_to_STRING
2399 = ___SCMOBJ_to_STRING
;
2401 ___gstate
.___SCMOBJ_to_NONNULLSTRING
2402 = ___SCMOBJ_to_NONNULLSTRING
;
2404 ___gstate
.___SCMOBJ_to_NONNULLSTRINGLIST
2405 = ___SCMOBJ_to_NONNULLSTRINGLIST
;
2407 ___gstate
.___SCMOBJ_to_CHARSTRING
2408 = ___SCMOBJ_to_CHARSTRING
;
2410 ___gstate
.___SCMOBJ_to_NONNULLCHARSTRING
2411 = ___SCMOBJ_to_NONNULLCHARSTRING
;
2413 ___gstate
.___SCMOBJ_to_NONNULLCHARSTRINGLIST
2414 = ___SCMOBJ_to_NONNULLCHARSTRINGLIST
;
2416 ___gstate
.___SCMOBJ_to_ISO_8859_1STRING
2417 = ___SCMOBJ_to_ISO_8859_1STRING
;
2419 ___gstate
.___SCMOBJ_to_NONNULLISO_8859_1STRING
2420 = ___SCMOBJ_to_NONNULLISO_8859_1STRING
;
2422 ___gstate
.___SCMOBJ_to_NONNULLISO_8859_1STRINGLIST
2423 = ___SCMOBJ_to_NONNULLISO_8859_1STRINGLIST
;
2425 ___gstate
.___SCMOBJ_to_UTF_8STRING
2426 = ___SCMOBJ_to_UTF_8STRING
;
2428 ___gstate
.___SCMOBJ_to_NONNULLUTF_8STRING
2429 = ___SCMOBJ_to_NONNULLUTF_8STRING
;
2431 ___gstate
.___SCMOBJ_to_NONNULLUTF_8STRINGLIST
2432 = ___SCMOBJ_to_NONNULLUTF_8STRINGLIST
;
2434 ___gstate
.___SCMOBJ_to_UTF_16STRING
2435 = ___SCMOBJ_to_UTF_16STRING
;
2437 ___gstate
.___SCMOBJ_to_NONNULLUTF_16STRING
2438 = ___SCMOBJ_to_NONNULLUTF_16STRING
;
2440 ___gstate
.___SCMOBJ_to_NONNULLUTF_16STRINGLIST
2441 = ___SCMOBJ_to_NONNULLUTF_16STRINGLIST
;
2443 ___gstate
.___SCMOBJ_to_UCS_2STRING
2444 = ___SCMOBJ_to_UCS_2STRING
;
2446 ___gstate
.___SCMOBJ_to_NONNULLUCS_2STRING
2447 = ___SCMOBJ_to_NONNULLUCS_2STRING
;
2449 ___gstate
.___SCMOBJ_to_NONNULLUCS_2STRINGLIST
2450 = ___SCMOBJ_to_NONNULLUCS_2STRINGLIST
;
2452 ___gstate
.___SCMOBJ_to_UCS_4STRING
2453 = ___SCMOBJ_to_UCS_4STRING
;
2455 ___gstate
.___SCMOBJ_to_NONNULLUCS_4STRING
2456 = ___SCMOBJ_to_NONNULLUCS_4STRING
;
2458 ___gstate
.___SCMOBJ_to_NONNULLUCS_4STRINGLIST
2459 = ___SCMOBJ_to_NONNULLUCS_4STRINGLIST
;
2461 ___gstate
.___SCMOBJ_to_WCHARSTRING
2462 = ___SCMOBJ_to_WCHARSTRING
;
2464 ___gstate
.___SCMOBJ_to_NONNULLWCHARSTRING
2465 = ___SCMOBJ_to_NONNULLWCHARSTRING
;
2467 ___gstate
.___SCMOBJ_to_NONNULLWCHARSTRINGLIST
2468 = ___SCMOBJ_to_NONNULLWCHARSTRINGLIST
;
2470 ___gstate
.___SCMOBJ_to_VARIANT
2471 = ___SCMOBJ_to_VARIANT
;
2473 ___gstate
.___release_foreign
2474 = ___release_foreign
;
2476 ___gstate
.___release_pointer
2477 = ___release_pointer
;
2479 ___gstate
.___release_function
2480 = ___release_function
;
2482 ___gstate
.___addref_function
2483 = ___addref_function
;
2485 ___gstate
.___release_string
2486 = ___release_string
;
2488 ___gstate
.___addref_string
2491 ___gstate
.___release_string_list
2492 = ___release_string_list
;
2494 ___gstate
.___addref_string_list
2495 = ___addref_string_list
;
2497 ___gstate
.___release_variant
2498 = ___release_variant
;
2500 ___gstate
.___addref_variant
2501 = ___addref_variant
;
2503 ___gstate
.___S8_to_SCMOBJ
2506 ___gstate
.___U8_to_SCMOBJ
2509 ___gstate
.___S16_to_SCMOBJ
2512 ___gstate
.___U16_to_SCMOBJ
2515 ___gstate
.___S32_to_SCMOBJ
2518 ___gstate
.___U32_to_SCMOBJ
2521 ___gstate
.___S64_to_SCMOBJ
2524 ___gstate
.___U64_to_SCMOBJ
2527 ___gstate
.___F32_to_SCMOBJ
2530 ___gstate
.___F64_to_SCMOBJ
2533 ___gstate
.___CHAR_to_SCMOBJ
2534 = ___CHAR_to_SCMOBJ
;
2536 ___gstate
.___SCHAR_to_SCMOBJ
2537 = ___SCHAR_to_SCMOBJ
;
2539 ___gstate
.___UCHAR_to_SCMOBJ
2540 = ___UCHAR_to_SCMOBJ
;
2542 ___gstate
.___ISO_8859_1_to_SCMOBJ
2543 = ___ISO_8859_1_to_SCMOBJ
;
2545 ___gstate
.___UCS_2_to_SCMOBJ
2546 = ___UCS_2_to_SCMOBJ
;
2548 ___gstate
.___UCS_4_to_SCMOBJ
2549 = ___UCS_4_to_SCMOBJ
;
2551 ___gstate
.___WCHAR_to_SCMOBJ
2552 = ___WCHAR_to_SCMOBJ
;
2554 ___gstate
.___SHORT_to_SCMOBJ
2555 = ___SHORT_to_SCMOBJ
;
2557 ___gstate
.___USHORT_to_SCMOBJ
2558 = ___USHORT_to_SCMOBJ
;
2560 ___gstate
.___INT_to_SCMOBJ
2563 ___gstate
.___UINT_to_SCMOBJ
2564 = ___UINT_to_SCMOBJ
;
2566 ___gstate
.___LONG_to_SCMOBJ
2567 = ___LONG_to_SCMOBJ
;
2569 ___gstate
.___ULONG_to_SCMOBJ
2570 = ___ULONG_to_SCMOBJ
;
2572 ___gstate
.___LONGLONG_to_SCMOBJ
2573 = ___LONGLONG_to_SCMOBJ
;
2575 ___gstate
.___ULONGLONG_to_SCMOBJ
2576 = ___ULONGLONG_to_SCMOBJ
;
2578 ___gstate
.___FLOAT_to_SCMOBJ
2579 = ___FLOAT_to_SCMOBJ
;
2581 ___gstate
.___DOUBLE_to_SCMOBJ
2582 = ___DOUBLE_to_SCMOBJ
;
2584 ___gstate
.___STRUCT_to_SCMOBJ
2585 = ___STRUCT_to_SCMOBJ
;
2587 ___gstate
.___UNION_to_SCMOBJ
2588 = ___UNION_to_SCMOBJ
;
2590 ___gstate
.___TYPE_to_SCMOBJ
2591 = ___TYPE_to_SCMOBJ
;
2593 ___gstate
.___POINTER_to_SCMOBJ
2594 = ___POINTER_to_SCMOBJ
;
2596 ___gstate
.___NONNULLPOINTER_to_SCMOBJ
2597 = ___NONNULLPOINTER_to_SCMOBJ
;
2599 ___gstate
.___FUNCTION_to_SCMOBJ
2600 = ___FUNCTION_to_SCMOBJ
;
2602 ___gstate
.___NONNULLFUNCTION_to_SCMOBJ
2603 = ___NONNULLFUNCTION_to_SCMOBJ
;
2605 ___gstate
.___BOOL_to_SCMOBJ
2606 = ___BOOL_to_SCMOBJ
;
2608 ___gstate
.___STRING_to_SCMOBJ
2609 = ___STRING_to_SCMOBJ
;
2611 ___gstate
.___NONNULLSTRING_to_SCMOBJ
2612 = ___NONNULLSTRING_to_SCMOBJ
;
2614 ___gstate
.___NONNULLSTRINGLIST_to_SCMOBJ
2615 = ___NONNULLSTRINGLIST_to_SCMOBJ
;
2617 ___gstate
.___CHARSTRING_to_SCMOBJ
2618 = ___CHARSTRING_to_SCMOBJ
;
2620 ___gstate
.___NONNULLCHARSTRING_to_SCMOBJ
2621 = ___NONNULLCHARSTRING_to_SCMOBJ
;
2623 ___gstate
.___NONNULLCHARSTRINGLIST_to_SCMOBJ
2624 = ___NONNULLCHARSTRINGLIST_to_SCMOBJ
;
2626 ___gstate
.___ISO_8859_1STRING_to_SCMOBJ
2627 = ___ISO_8859_1STRING_to_SCMOBJ
;
2629 ___gstate
.___NONNULLISO_8859_1STRING_to_SCMOBJ
2630 = ___NONNULLISO_8859_1STRING_to_SCMOBJ
;
2632 ___gstate
.___NONNULLISO_8859_1STRINGLIST_to_SCMOBJ
2633 = ___NONNULLISO_8859_1STRINGLIST_to_SCMOBJ
;
2635 ___gstate
.___UTF_8STRING_to_SCMOBJ
2636 = ___UTF_8STRING_to_SCMOBJ
;
2638 ___gstate
.___NONNULLUTF_8STRING_to_SCMOBJ
2639 = ___NONNULLUTF_8STRING_to_SCMOBJ
;
2641 ___gstate
.___NONNULLUTF_8STRINGLIST_to_SCMOBJ
2642 = ___NONNULLUTF_8STRINGLIST_to_SCMOBJ
;
2644 ___gstate
.___UTF_16STRING_to_SCMOBJ
2645 = ___UTF_16STRING_to_SCMOBJ
;
2647 ___gstate
.___NONNULLUTF_16STRING_to_SCMOBJ
2648 = ___NONNULLUTF_16STRING_to_SCMOBJ
;
2650 ___gstate
.___NONNULLUTF_16STRINGLIST_to_SCMOBJ
2651 = ___NONNULLUTF_16STRINGLIST_to_SCMOBJ
;
2653 ___gstate
.___UCS_2STRING_to_SCMOBJ
2654 = ___UCS_2STRING_to_SCMOBJ
;
2656 ___gstate
.___NONNULLUCS_2STRING_to_SCMOBJ
2657 = ___NONNULLUCS_2STRING_to_SCMOBJ
;
2659 ___gstate
.___NONNULLUCS_2STRINGLIST_to_SCMOBJ
2660 = ___NONNULLUCS_2STRINGLIST_to_SCMOBJ
;
2662 ___gstate
.___UCS_4STRING_to_SCMOBJ
2663 = ___UCS_4STRING_to_SCMOBJ
;
2665 ___gstate
.___NONNULLUCS_4STRING_to_SCMOBJ
2666 = ___NONNULLUCS_4STRING_to_SCMOBJ
;
2668 ___gstate
.___NONNULLUCS_4STRINGLIST_to_SCMOBJ
2669 = ___NONNULLUCS_4STRINGLIST_to_SCMOBJ
;
2671 ___gstate
.___WCHARSTRING_to_SCMOBJ
2672 = ___WCHARSTRING_to_SCMOBJ
;
2674 ___gstate
.___NONNULLWCHARSTRING_to_SCMOBJ
2675 = ___NONNULLWCHARSTRING_to_SCMOBJ
;
2677 ___gstate
.___NONNULLWCHARSTRINGLIST_to_SCMOBJ
2678 = ___NONNULLWCHARSTRINGLIST_to_SCMOBJ
;
2680 ___gstate
.___VARIANT_to_SCMOBJ
2681 = ___VARIANT_to_SCMOBJ
;
2683 ___gstate
.___CHARSTRING_to_UCS_2STRING
2684 = ___CHARSTRING_to_UCS_2STRING
;
2686 ___gstate
.___free_UCS_2STRING
2687 = ___free_UCS_2STRING
;
2689 ___gstate
.___NONNULLCHARSTRINGLIST_to_NONNULLUCS_2STRINGLIST
2690 = ___NONNULLCHARSTRINGLIST_to_NONNULLUCS_2STRINGLIST
;
2692 ___gstate
.___free_NONNULLUCS_2STRINGLIST
2693 = ___free_NONNULLUCS_2STRINGLIST
;
2695 ___gstate
.___make_sfun_stack_marker
2696 = ___make_sfun_stack_marker
;
2698 ___gstate
.___kill_sfun_stack_marker
2699 = ___kill_sfun_stack_marker
;
2701 ___gstate
.___alloc_rc
2704 ___gstate
.___release_rc
2707 ___gstate
.___addref_rc
2710 ___gstate
.___data_rc
2713 ___gstate
.___set_data_rc
2716 ___gstate
.___alloc_scmobj
2719 ___gstate
.___release_scmobj
2720 = ___release_scmobj
;
2722 ___gstate
.___make_pair
2725 ___gstate
.___make_vector
2728 ___gstate
.___still_obj_refcount_inc
2729 = ___still_obj_refcount_inc
;
2731 ___gstate
.___still_obj_refcount_dec
2732 = ___still_obj_refcount_dec
;
2734 ___gstate
.___gc_hash_table_ref
2735 = ___gc_hash_table_ref
;
2737 ___gstate
.___gc_hash_table_set
2738 = ___gc_hash_table_set
;
2740 ___gstate
.___gc_hash_table_rehash
2741 = ___gc_hash_table_rehash
;
2743 ___gstate
.___get_min_heap
2746 ___gstate
.___set_min_heap
2749 ___gstate
.___get_max_heap
2752 ___gstate
.___set_max_heap
2755 ___gstate
.___get_live_percent
2756 = ___get_live_percent
;
2758 ___gstate
.___set_live_percent
2759 = ___set_live_percent
;
2761 ___gstate
.___get_standard_level
2762 = ___get_standard_level
;
2764 ___gstate
.___set_standard_level
2765 = ___set_standard_level
;
2767 ___gstate
.___set_debug_settings
2768 = ___set_debug_settings
;
2770 ___gstate
.___get_program_startup_info
2771 = ___get_program_startup_info
;
2773 ___gstate
.___cleanup
2776 ___gstate
.___cleanup_and_exit_process
2777 = ___cleanup_and_exit_process
;
2782 ___gstate
.___propagate_error
2783 = ___propagate_error
;
2785 #ifdef ___DEBUG_HOST_CHANGES
2786 ___gstate
.___register_host_entry
2787 = ___register_host_entry
;
2790 ___gstate
.___raise_interrupt
2791 = ___raise_interrupt
;
2793 ___gstate
.___begin_interrupt_service
2794 = ___begin_interrupt_service
;
2796 ___gstate
.___check_interrupt
2797 = ___check_interrupt
;
2799 ___gstate
.___end_interrupt_service
2800 = ___end_interrupt_service
;
2802 ___gstate
.___disable_interrupts
2803 = ___disable_interrupts
;
2805 ___gstate
.___enable_interrupts
2806 = ___enable_interrupts
;
2808 ___gstate
.___alloc_mem
2811 ___gstate
.___free_mem
2817 * Get processor state.
2823 * Setup multithreading structures.
2826 ___ps
->current_thread
= ___FAL
;
2827 ___ps
->run_queue
= ___FAL
;
2833 for (i
=0; i
<___NB_GVM_REGS
; i
++)
2834 ___ps
->r
[i
] = ___VOID
;
2837 * Setup exception handling.
2840 #ifdef ___USE_SETJMP
2847 * Setup interrupt system.
2850 ___disable_interrupts ();
2852 for (i
=0; i
<___NB_INTRS
; i
++)
2853 ___ps
->intr_flag
[i
] = 0;
2855 ___begin_interrupt_service ();
2856 ___end_interrupt_service (0);
2859 * Create empty global variable list, symbol table and keyword
2863 ___ps
->glo_list_head
= 0;
2864 ___ps
->glo_list_tail
= 0;
2866 ___GSTATE
->symbol_table
=
2867 symkey_table_alloc (___sSYMBOL
, INIT_SYMKEY_TBL_LENGTH
);
2869 if (___FIXNUMP(___GSTATE
->symbol_table
))
2872 return ___GSTATE
->symbol_table
;
2875 ___GSTATE
->keyword_table
=
2876 symkey_table_alloc (___sKEYWORD
, INIT_SYMKEY_TBL_LENGTH
);
2878 if (___FIXNUMP(___GSTATE
->keyword_table
))
2881 return ___GSTATE
->keyword_table
;
2885 * Setup program's linker structure.
2888 mol
= linker_to_mod_or_lnk (___setup_params
.linker
);
2891 * Initialize symbol table, keyword table, global variables
2895 init_symkey_glo1 (mol
);
2896 init_symkey_glo2 (mol
);
2899 * Setup each module.
2902 ___GSTATE
->program_descr
= setup_modules (mol
);
2904 if (___FIXNUMP(___GSTATE
->program_descr
))
2907 return ___GSTATE
->program_descr
;
2911 * Create list of command line arguments (accessible through ##command-line).
2915 ___UCS_2STRING
*argv
= ___setup_params
.argv
;
2917 if (argv
[0] == 0) /* use dummy program name if none supplied */
2920 #define ___COMMAND_LINE_CE_SELECT(ISO_8859_1,UTF_8,UCS_2,UCS_4,wchar,native) UCS_2
2922 if ((___err
= ___NONNULLSTRINGLIST_to_SCMOBJ
2924 &___GSTATE
->command_line
,
2926 ___CE(___COMMAND_LINE_CE_SELECT
)))
2927 != ___FIX(___NO_ERR
))
2935 * Setup kernel handlers.
2938 #define ___PH_LBL0 1
2941 * The label numbers must match those in the procedure
2942 * "##kernel-handlers" in the file "_kernel.scm".
2945 ___start
= ___G__23__23_kernel_2d_handlers
.prm
;
2947 ___gstate
.handler_sfun_conv_error
= ___LBL(0);
2948 ___gstate
.handler_cfun_conv_error
= ___LBL(1);
2949 ___gstate
.handler_stack_limit
= ___LBL(2);
2950 ___gstate
.handler_heap_limit
= ___LBL(3);
2951 ___gstate
.handler_not_proc
= ___LBL(4);
2952 ___gstate
.handler_not_proc_glo
= ___LBL(5);
2953 ___gstate
.handler_wrong_nargs
= ___LBL(6);
2954 ___gstate
.handler_get_rest
= ___LBL(7);
2955 ___gstate
.handler_get_key
= ___LBL(8);
2956 ___gstate
.handler_get_key_rest
= ___LBL(9);
2957 ___gstate
.handler_force
= ___LBL(10);
2958 ___gstate
.handler_return_to_c
= ___LBL(11);
2959 ___gstate
.handler_break
= ___LBL(12);
2960 ___gstate
.internal_return
= ___LBL(13);
2963 * The label numbers must match those in the procedure
2964 * "##dynamic-env-bind" in the file "_kernel.scm".
2967 ___start
= ___G__23__23_dynamic_2d_env_2d_bind
.prm
;
2969 ___gstate
.dynamic_env_bind_return
= ___LBL(1);
2974 * Call kernel to start executing program.
2977 ___ps
->r
[0] = ___gstate
.handler_break
;
2981 if ((___err
= ___make_sfun_stack_marker
2983 ___FIELD(___FIELD(___GSTATE
->program_descr
,0),0)))
2984 == ___FIX(___NO_ERR
))
2986 ___err
= ___call (0, ___FIELD(marker
,0), marker
);
2987 ___kill_sfun_stack_marker (marker
);
2992 if (___err
!= ___FIX(___NO_ERR
))
2999 /*---------------------------------------------------------------------------*/