1 ;;;; File: "context.scm", Time-stamp: <2006-05-08 16:04:37 feeley>
3 ;;;; Copyright (C) 2004-2009 by Marc Feeley and Vincent St-Amour
4 ;;;; All Rights Reserved.
6 ;; Compilation context representation.
14 (define context-change-code
20 (define context-change-env
22 (make-context (context-code ctx)
26 (define context-change-env2
28 (make-context (context-code ctx)
32 (define make-init-context
34 (make-context (make-init-code)
38 (define context-make-label
40 (context-change-code ctx (code-make-label (context-code ctx)))))
42 (define context-last-label
44 (code-last-label (context-code ctx))))
46 (define context-add-bb
48 (context-change-code ctx (code-add-bb (context-code ctx) label))))
50 (define context-add-instr
52 (context-change-code ctx (code-add-instr (context-code ctx) instr))))
54 ;; Representation of code.
66 (define make-init-code
69 (list (make-bb 0 (list))))))
71 (define code-make-label
73 (let ((label (+ (code-last-label code) 1)))
75 (code-rev-bbs code)))))
80 (code-last-label code)
81 (cons (make-bb label '())
82 (code-rev-bbs code)))))
84 (define code-add-instr
86 (let* ((rev-bbs (code-rev-bbs code))
88 (rev-instrs (bb-rev-instrs bb)))
90 (code-last-label code)
91 (cons (make-bb (bb-label bb)
92 (cons instr rev-instrs))
95 ;; Representation of compile-time stack.
98 size ; number of slots
99 slots ; for each slot, the variable (or #f) contained in the slot
102 (define make-init-stack
107 (lambda (x nb-slots stk)
108 (let ((size (stack-size stk)))
111 (append (repeat nb-slots x) (stack-slots stk))))))
113 (define stack-discard
114 (lambda (nb-slots stk)
115 (let ((size (stack-size stk)))
118 (list-tail (stack-slots stk) nb-slots)))))
120 ;; Representation of compile-time environment.
127 (define make-init-env
129 (make-env (make-init-stack)
132 (define env-change-local
137 (define env-change-closed
139 (make-env (env-local env)
142 (define find-local-var
144 (let ((i (pos-in-list var (stack-slots (env-local env)))))
146 (- (+ (pos-in-list var (env-closed env)) 1))))))
151 (let ((params (prc-params prc)))
152 (make-stack (length params)
153 (append (map var-id params) '())))
154 (let ((vars (varset->list (non-global-fv prc))))
155 ; (pp (map var-id vars))
156 (map var-id vars)))))