Download Compiling functional languages by Leroy X. PDF

pushl $i popl %eax addl 0(%esp), %eax • By efficient interpretation. The interpreter is typically written in C as shown on the next slide, and is about one order of magnitude faster than term-level interpretation. 35 A typical abstract machine interpreter value interpret(int * start_code) { register int * c = start_code; register value * s = bottom_of_stack; register environment e; while(1) switch case case case case case { (*c++) { CONST: ADD: ACCESS: CLOSURE: APPLY: case RETURN: case STOP: *s++ = *c++; break; s[-2] = s[-2] + s[-1]; s--; break; *s++ = Lookup(e, *c++); break; *s++ = MakeClosure(*c++, e); break; arg = *--sp; clos = *--sp; *sp++ = (value) c; *sp++ = (value) e; c = Code(clos); e = AddEnv(arg, Environment(clos)); break; res = *--sp; e = (environment) *--sp; c = (int *) *--sp; *sp++ = res; break; return *--sp; } } } 36 An abstract machine for call-by-name: Krivine’s machine As before, three components in this machine: code c, environment e, stack s.

Vn) where v1, . . a. Note: the function code_fn above has no free variables. The occurrence of code_fn in makeblock(code_fn, \ldots) denotes a pointer to its (fixed) code. 53 From intermediate language to machine code Standard compiler technology applies largely unchanged. g. Modern Compiler Implementation in ML, Andrew W. Appel, Cambridge Univ. Press, 1998. ) Calls to a computed address are expensive on modern processors: • the destination address is usually not predicted in advance; • this stalls the pipeline (cannot fetch and start executing instructions from the called function while earlier instructions complete).

Download PDF sample

Rated 4.67 of 5 – based on 14 votes