genie-misc.c
1 //! @file genie-misc.c
2 //! @author J. Marcel van der Veer
3 //!
4 //! @section Copyright
5 //!
6 //! This file is part of Algol68G - an Algol 68 compiler-interpreter.
7 //! Copyright 2001-2023 J. Marcel van der Veer [algol68g@xs4all.nl].
8 //!
9 //! @section License
10 //!
11 //! This program is free software; you can redistribute it and/or modify it
12 //! under the terms of the GNU General Public License as published by the
13 //! Free Software Foundation; either version 3 of the License, or
14 //! (at your option) any later version.
15 //!
16 //! This program is distributed in the hope that it will be useful, but
17 //! WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 //! or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 //! more details. You should have received a copy of the GNU General Public
20 //! License along with this program. If not, see [http://www.gnu.org/licenses/].
21
22 //! @section Synopsis
23 //!
24 //! Miscellaneous interpreter routines.
25
26 #include "a68g.h"
27 #include "a68g-genie.h"
28 #include "a68g-prelude.h"
29 #include "a68g-mp.h"
30 #include "a68g-physics.h"
31 #include "a68g-numbers.h"
32 #include "a68g-optimiser.h"
33 #include "a68g-double.h"
34 #include "a68g-transput.h"
35
36 #define VECTOR_SIZE 512
37 #define FD_READ 0
38 #define FD_WRITE 1
39
40 //! @brief PROC (PROC VOID) VOID on gc event
41
42 void genie_on_gc_event (NODE_T * p)
43 {
44 POP_PROCEDURE (p, &A68 (on_gc_event));
45 }
46
47 //! @brief Generic procedure for OP AND BECOMES (+:=, -:=, ...).
48
49 void genie_f_and_becomes (NODE_T * p, MOID_T * ref, GPROC * f)
50 {
51 MOID_T *mode = SUB (ref);
52 int size = SIZE (mode);
53 BYTE_T *src = STACK_OFFSET (-size), *addr;
54 A68_REF *dst = (A68_REF *) STACK_OFFSET (-size - A68_REF_SIZE);
55 CHECK_REF (p, *dst, ref);
56 addr = ADDRESS (dst);
57 PUSH (p, addr, size);
58 genie_check_initialisation (p, STACK_OFFSET (-size), mode);
59 PUSH (p, src, size);
60 (*f) (p);
61 POP (p, addr, size);
62 DECREMENT_STACK_POINTER (p, size);
63 }
64
65 //! @brief INT system heap pointer
66
67 void genie_system_heap_pointer (NODE_T * p)
68 {
69 PUSH_VALUE (p, (int) (A68_HP), A68_INT);
70 }
71
72 //! @brief INT system stack pointer
73
74 void genie_system_stack_pointer (NODE_T * p)
75 {
76 BYTE_T stack_offset;
77 PUSH_VALUE (p, (int) (A68 (system_stack_offset) - &stack_offset), A68_INT);
78 }