Debian Codegraph @

src/ikarus-exec.c

raw
1 /*
2 * Ikarus Scheme -- A compiler for R6RS Scheme.
3 * Copyright (C) 2006,2007,2008 Abdulaziz Ghuloum
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18
19 #include "ikarus-data.h"
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <assert.h>
23 #include <string.h>
24
25
26 #undef DEBUG_EXEC
27
28 ikptr ik_exec_code(ikpcb* pcb, ikptr code_ptr, ikptr argcount, ikptr cp){
29 ikptr argc = ik_asm_enter(pcb, code_ptr+off_code_data, argcount, cp);
30 ikptr next_k = pcb->next_k;
31 while(next_k){
32 cont* k = (cont*)(long)(next_k - vector_tag);
33 if (k->tag == system_continuation_tag) {
34 break;
35 }
36 ikptr top = k->top;
37 ikptr rp = ref(top, 0);
38 long int framesize = (long int) ref(rp, disp_frame_size);
39 #ifdef DEBUG_EXEC
40 fprintf(stderr, "exec framesize=0x%016lx ksize=%ld rp=0x%016lx\n",
41 framesize, k->size, rp);
42 #endif
43 if(framesize == 0){
44 framesize = ref(top, wordsize);
45 }
46 if(framesize <= 0){
47 fprintf(stderr, "invalid framesize %ld\n", framesize);
48 exit(-10);
49 }
50 if(framesize < k->size){
51 cont* nk = (cont*)(long)ik_unsafe_alloc(pcb, sizeof(cont));
52 nk->tag = k->tag;
53 nk->next = k->next;
54 nk->top = top + framesize;
55 nk->size = k->size - framesize;
56 k->size = framesize;
57 k->next = vector_tag + (ikptr)(long)nk;
58 /* record side effect */
59 unsigned long int idx = ((unsigned long int)(&k->next)) >> pageshift;
60 ((unsigned int*)(long)(pcb->dirty_vector))[idx] = -1;
61 } else if (framesize > k->size) {
62 fprintf(stderr,
63 "ikarus internal error: invalid framesize %ld, expected %ld or less\n",
64 framesize, k->size);
65 long int offset = ref(rp, disp_frame_offset);
66 fprintf(stderr, "rp = 0x%016lx\n", rp);
67 fprintf(stderr, "rp offset = %ld\n", offset);
68 exit(-10);
69 }
70 pcb->next_k = k->next;
71 ikptr fbase = pcb->frame_base - wordsize;
72 ikptr new_fbase = fbase - framesize;
73 memmove((char*)(long)new_fbase + argc,
74 (char*)(long)fbase + argc,
75 -argc);
76 memcpy((char*)(long)new_fbase, (char*)(long)top, framesize);
77 argc = ik_asm_reenter(pcb, new_fbase, argc);
78 next_k = pcb->next_k;
79 }
80 ikptr rv = ref(pcb->frame_base, -2*wordsize);
81 return rv;
82 }
83
84