Expressions Components - SICP Comparison Edition" /> 5.5.2   Compiling <span style="color:green">Expressions</span> <span style="color:blue">Components</span> - SICP Comparison Edition
Original JavaScript
Original JavaScript
Original JavaScript
Original JavaScript

[1] This procedure uses a feature of Lisp called backquote (or quasiquote) that is handy for constructing lists. Preceding a list with a backquote symbol is much like quoting it, except that anything in the list that is flagged with a comma is evaluated.

For example, if the value of linkage is the symbol branch25, then the expression `((goto (label ,linkage))) evaluates to the list ((goto (label branch25))). Similarly, if the value of x is the list (a b c), then `(1 2 ,x) evaluates to the list (1 2 a).
[2] We can't just use the labels true-branch, true_branch, false-branch, false_branch, and after-if after_cond as shown above, because there might be more than one ifconditional in the program. The compiler uses the procedure function make-label make_label to generate labels. Make-label The function make_label takes a symbolstring as argument and returns a new symbolstring that begins with the given symbolstring. For example, successive calls to (make-label 'a) make_label("a") would return a1"a1", a2"a2", and so on. Make-label The function make_label can be implemented similarly to the generation of unique variable names in the query language, as follows:
Original JavaScript
(define label-counter 0) (define (new-label-number) (set! label-counter (+ 1 label-counter)) label-counter) (define (make-label name) (string->symbol (string-append (symbol->string name) (number->string (new-label-number))))) let label_counter = 0; function new_label_number() { label_counter = label_counter + 1; return label_counter; } function make_label(string) { return string + stringify(new_label_number()); }
[3] The continue register would be needed for a "return" linkage, which can result from a compilation by compile_and_go (section 5.5.7).
[4] Our compiler does not detect all dead code. For example, a conditional statement whose consequent and alternative branches both end in a return statement will not stop subsequent statements from being compiled. See exercises 5.36 and 5.37.
[5] We need machine operations to implement a data structure for representing compiled procedures, functions, analogous to the structure for compound procedures functions described in section 4.1.3:
Original JavaScript
(define (make-compiled-procedure entry env) (list 'compiled-procedure entry env)) (define (compiled-procedure? proc) (tagged-list? proc 'compiled-procedure)) (define (compiled-procedure-entry c-proc) (cadr c-proc)) (define (compiled-procedure-env c-proc) (caddr c-proc)) function make_compiled_function(entry, env) { return list("compiled_function", entry, env); } function is_compiled_function(fun) { return is_tagged_list(fun, "compiled_function"); } function compiled_function_entry(c_fun) { return head(tail(c_fun)); } function compiled_function_env(c_fun) { return head(tail(tail(c_fun))); }
[6] The augmented function body is a sequence ending with a return statement. Compilation of a sequence of statements uses the linkage "next" for all its component statements except the last, for which it uses the given linkage. In this case, the last statement is a return statement, and as we will see in section 5.5.3, a return statement always uses the "return" linkage descriptor for its return expression. Thus all function bodies will end with a "return" linkage, not the "next" we pass as the linkage argument to compile in compile_lambda_body.
5.5.2   Compiling Expressions Components