slip a simple language implementation platform
play

SLIP: a simple language implementation platform Deep into Smalltalk - PowerPoint PPT Presentation

Theo DHondt SLIP: a simple language implementation platform SLIP: a simple language implementation platform Deep into Smalltalk INRIA Lille Nord Europe March 7th - 11th, 2011 Theo DHondt Software Languages Lab Faculty of Sciences -


  1. Theo D’Hondt SLIP: a simple language implementation platform Abstract SLIP is a minimalist platform for the instruction and exploration of language implementations. It is a distillation of two previous platforms - Pico and ˈ sk ē m - but is not intended as a language in its own right. SLIP is of course a language: a very minimal but complete version of LISP - with a distinct Scheme flavour. But SLIP is also a sequence of interpreters, starting with a 100 line fully metacircular version. In the spirit of Friedman's EOPL, this version is rewritten in continuation passing style and translated into C in a straightforward way. Twelve successive versions introduce features such as trampolines, lexical addressing and garbage collection, to end with a fully optimized version that executes a simple benchmark on par with the PLT Scheme interpreter. SLIP is a chain of implementations presented as an instruction tool. It is also an experimentation tool, and this presentation will present a 13th version that introduces simple futures into SLIP in view of experimenting with multi-core systems. SLIP has been used in the Francqui chair (soft.vub.ac.be/francqui) earlier this year, and already twice in the Programming Language Engineering (PLE) course. It will again be used - including version 13 - in this year's issue of PLE. 10 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 10

  2. Theo D’Hondt SLIP: a simple language implementation platform Abstract SLIP is a minimalist platform for the instruction and exploration of language implementations. It is a distillation of two previous platforms - Pico and ˈ sk ē m - but is not intended as a language in its own right. SLIP is of course a language: a very minimal but complete version of LISP - with a distinct Scheme flavour. But SLIP is also a sequence of interpreters, starting with a 100 line fully metacircular version. In the spirit of Friedman's EOPL, this version is rewritten in continuation passing style and translated into C in a straightforward way. Twelve successive versions introduce features such as trampolines, lexical addressing and garbage collection, to end with a fully optimized version that executes a simple benchmark on par with the PLT Scheme interpreter. SLIP is a chain of implementations presented as an instruction tool. It is also an experimentation tool, and this presentation will present a 13th version that introduces simple futures into SLIP in view of experimenting with multi-core systems. SLIP has been used in the Francqui chair (soft.vub.ac.be/francqui) earlier this year, and already twice in the Programming Language Engineering (PLE) course. It will again be used - including version 13 - in this year's issue of PLE. 11 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 11

  3. Theo D’Hondt SLIP: a simple language implementation platform Abstract SLIP is a minimalist platform for the instruction and exploration of language implementations. It is a distillation of two previous platforms - Pico and ˈ sk ē m - but is not intended as a language in its own right. SLIP is of course a language: a very minimal but complete version of LISP - with a distinct Scheme flavour. But SLIP is also a sequence of interpreters, starting with a 100 line fully metacircular version. In the spirit of Friedman's EOPL, this version is rewritten in continuation passing style and translated into C in a straightforward way. Twelve successive versions introduce features such as trampolines, lexical addressing and garbage collection, to end with a fully optimized version that executes a simple benchmark on par with the PLT Scheme interpreter. SLIP is a chain of implementations presented as an instruction tool. It is also an experimentation tool, and this presentation will present a 13th version that introduces simple futures into SLIP in view of experimenting with multi-core systems. SLIP has been used in the Francqui chair (soft.vub.ac.be/francqui) earlier this year, and already twice in the Programming Language Engineering (PLE) course. It will again be used - including version 13 - in this year's issue of PLE. 12 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 12

  4. Theo D’Hondt SLIP: a simple language implementation platform •••update••• (begin ¡ ¡(define ¡(Sort ¡V ¡Low ¡High ¡Recurse) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡... ¡ ¡ ¡ ¡(Recurse ¡Left ¡Right)) ¡ ¡(define ¡(SingleCore-­‑QuickSort ¡V ¡Low ¡High) ¡ ¡ ¡ ¡(define ¡(SingleCore-­‑Recurse ¡Left ¡Right) ¡ ¡ ¡ ¡ ¡ ¡(if ¡(< ¡Low ¡Right) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(SingleCore-­‑QuickSort ¡V ¡Low ¡Right)) ¡ ¡ ¡ ¡ ¡ ¡(if ¡(> ¡High ¡Left) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(SingleCore-­‑QuickSort ¡V ¡Left ¡High))) ¡ ¡ ¡ ¡(Sort ¡V ¡Low ¡High ¡SingleCore-­‑Recurse)) ¡ ¡(define ¡(MultiCore-­‑QuickSort ¡Depth ¡V ¡Low ¡High) ¡ ¡ ¡ ¡(define ¡(MultiCore-­‑Recurse ¡Left ¡Right) ¡ ¡ ¡ ¡ ¡ ¡(if ¡(> ¡Depth ¡0) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(begin ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡promise ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(< ¡Low ¡Right) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(spawn ¡(MultiCore-­‑QuickSort ¡(-­‑ ¡Depth ¡1) ¡V ¡Low ¡Right)))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(> ¡High ¡Left) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(MultiCore-­‑QuickSort ¡(-­‑ ¡Depth ¡1) ¡V ¡Left ¡High)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(sync ¡promise)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(begin ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(SingleCore-­‑QuickSort ¡V ¡Low ¡High) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(collect)))) ¡ ¡ ¡ ¡(Sort ¡V ¡Low ¡High ¡MultiCore-­‑Recurse)) 13 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 13

  5. Theo D’Hondt SLIP: a simple language implementation platform •••update••• (begin ¡ ¡(define ¡(Sort ¡V ¡Low ¡High ¡Recurse) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡... ¡ ¡ ¡ ¡(Recurse ¡Left ¡Right)) ¡ ¡(define ¡(SingleCore-­‑QuickSort ¡V ¡Low ¡High) ¡ ¡ ¡ ¡(define ¡(SingleCore-­‑Recurse ¡Left ¡Right) ¡ ¡ ¡ ¡ ¡ ¡(if ¡(< ¡Low ¡Right) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(SingleCore-­‑QuickSort ¡V ¡Low ¡Right)) ¡ ¡ ¡ ¡ ¡ ¡(if ¡(> ¡High ¡Left) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(SingleCore-­‑QuickSort ¡V ¡Left ¡High))) ¡ ¡ ¡ ¡(Sort ¡V ¡Low ¡High ¡SingleCore-­‑Recurse)) ¡ ¡(define ¡(MultiCore-­‑QuickSort ¡Depth ¡V ¡Low ¡High) ¡ ¡ ¡ ¡(define ¡(MultiCore-­‑Recurse ¡Left ¡Right) ¡ ¡ ¡ ¡ ¡ ¡(if ¡(> ¡Depth ¡0) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(begin ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡promise ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(< ¡Low ¡Right) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(spawn ¡(MultiCore-­‑QuickSort ¡(-­‑ ¡Depth ¡1) ¡V ¡Low ¡Right)))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(> ¡High ¡Left) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(MultiCore-­‑QuickSort ¡(-­‑ ¡Depth ¡1) ¡V ¡Left ¡High)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(sync ¡promise)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(begin ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(SingleCore-­‑QuickSort ¡V ¡Low ¡High) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(collect)))) ¡ ¡ ¡ ¡(Sort ¡V ¡Low ¡High ¡MultiCore-­‑Recurse)) 14 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 14

  6. Theo D’Hondt SLIP: a simple language implementation platform •••update••• (begin ¡ ¡(define ¡(Sort ¡V ¡Low ¡High ¡Recurse) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡... cpSlip/c ¡version ¡13: ¡multithreading >>>(eval ¡(read ¡"quadcoreQuickSort.scm")) ¡ ¡ ¡ ¡(Recurse ¡Left ¡Right)) quadcore ¡quicksort ¡of ¡100000 ¡integers ¡ ¡(define ¡(SingleCore-­‑QuickSort ¡V ¡Low ¡High) ... ¡Collecting ¡109145 ¡cells ¡into ¡103092 ¡cells ¡in ¡0.003919 ¡seconds ¡ ¡ ¡ ¡(define ¡(SingleCore-­‑Recurse ¡Left ¡Right) ¡ ¡ ¡ ¡ ¡ ¡(if ¡(< ¡Low ¡Right) ... ¡Collecting ¡339952 ¡cells ¡into ¡106248 ¡cells ¡in ¡0.006443 ¡seconds ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(SingleCore-­‑QuickSort ¡V ¡Low ¡Right)) ¡ ¡ ¡ ¡ ¡ ¡(if ¡(> ¡High ¡Left) ... ¡Collecting ¡940109 ¡cells ¡into ¡105837 ¡cells ¡in ¡0.01088 ¡seconds ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(SingleCore-­‑QuickSort ¡V ¡Left ¡High))) ¡ ¡ ¡ ¡(Sort ¡V ¡Low ¡High ¡SingleCore-­‑Recurse)) ... ¡Collecting ¡501743 ¡cells ¡into ¡105810 ¡cells ¡in ¡0.003370 ¡seconds ¡ ¡elapsed ¡time ¡= ¡12 ¡secs ¡ ¡(define ¡(MultiCore-­‑QuickSort ¡Depth ¡V ¡Low ¡High) ¡ ¡ ¡ ¡(define ¡(MultiCore-­‑Recurse ¡Left ¡Right) ¡ ¡ ¡ ¡ ¡ ¡(if ¡(> ¡Depth ¡0) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(begin ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡promise ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(< ¡Low ¡Right) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(spawn ¡(MultiCore-­‑QuickSort ¡(-­‑ ¡Depth ¡1) ¡V ¡Low ¡Right)))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(> ¡High ¡Left) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(MultiCore-­‑QuickSort ¡(-­‑ ¡Depth ¡1) ¡V ¡Left ¡High)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(sync ¡promise)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(begin ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(SingleCore-­‑QuickSort ¡V ¡Low ¡High) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(collect)))) ¡ ¡ ¡ ¡(Sort ¡V ¡Low ¡High ¡MultiCore-­‑Recurse)) 15 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 15

  7. Theo D’Hondt SLIP: a simple language implementation platform Agenda motivation history: Pico (1&2), Pic%, ˈ sk ē m SLIP SLIP in cps SLIP in C multicore SLIP 16 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 16

  8. Theo D’Hondt SLIP: a simple language implementation platform Motivation ➜ 17 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 17

  9. Theo D’Hondt SLIP: a simple language implementation platform Motivation ➜ First principles Bare metal 18 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 18

  10. Theo D’Hondt SLIP: a simple language implementation platform Motivation (cont’d) 19 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 19

  11. Theo D’Hondt SLIP: a simple language implementation platform History: Pico 1 /*-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑*/ /* ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡>>>Pico<<< ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡*/ /* ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Theo ¡D'Hondt ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡*/ /* ¡ ¡ ¡VUB ¡Programming ¡Technology ¡Lab ¡ ¡*/ /* ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(c) ¡1997 ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡*/ /*-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑*/ /* ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Main ¡program ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡*/ /*-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑*/ #define ¡NDEBUG #include ¡ <float.h> #include ¡ <limits.h> #include ¡ <setjmp.h> /* ¡private ¡constants ¡*/ #define ¡FUN_NAM_INDEX ¡ 1 #define ¡FUN_ARG_INDEX ¡ 2 #define ¡FUN_EXP_INDEX ¡ 3 #define ¡FUN_DCT_INDEX ¡ 4 #define ¡NAT_NAM_INDEX ¡ 1 #define ¡NAT_NBR_INDEX ¡ 2 #define ¡VAR_NAM_INDEX ¡ 1 #define ¡APL_NAM_INDEX ¡ 1 #define ¡APL_ARG_INDEX ¡ 2 #define ¡TBL_NAM_INDEX ¡ 1 #define ¡TBL_IDX_INDEX ¡ 2 #define ¡DEF_INV_INDEX ¡ 1 #define ¡DEF_EXP_INDEX ¡ 2 #define ¡SET_INV_INDEX ¡ 1 20 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 20

  12. Theo D’Hondt SLIP: a simple language implementation platform History: Pico 1 /*-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑*/ /* ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡>>>Pico<<< ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡*/ /* ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Theo ¡D'Hondt ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡*/ /* ¡ ¡ ¡VUB ¡Programming ¡Technology ¡Lab ¡ ¡*/ /* ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(c) ¡1997 ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡*/ /*-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑*/ /* ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Main ¡program ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡*/ /*-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑*/ #define ¡NDEBUG #include ¡ <float.h> #include ¡ <limits.h> #include ¡ <setjmp.h> /* ¡private ¡constants ¡*/ #define ¡FUN_NAM_INDEX ¡ 1 #define ¡FUN_ARG_INDEX ¡ 2 #define ¡FUN_EXP_INDEX ¡ 3 #define ¡FUN_DCT_INDEX ¡ 4 #define ¡NAT_NAM_INDEX ¡ 1 #define ¡NAT_NBR_INDEX ¡ 2 #define ¡VAR_NAM_INDEX ¡ 1 #define ¡APL_NAM_INDEX ¡ 1 #define ¡APL_ARG_INDEX ¡ 2 #define ¡TBL_NAM_INDEX ¡ 1 #define ¡TBL_IDX_INDEX ¡ 2 #define ¡DEF_INV_INDEX ¡ 1 #define ¡DEF_EXP_INDEX ¡ 2 #define ¡SET_INV_INDEX ¡ 1 21 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 21

  13. Theo D’Hondt SLIP: a simple language implementation platform History: Pico 1 /*-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑*/ /* ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡>>>Pico<<< ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡*/ /* ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Theo ¡D'Hondt ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡*/ /* ¡ ¡ ¡VUB ¡Programming ¡Technology ¡Lab ¡ ¡*/ /* ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(c) ¡1997 ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡*/ /*-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑*/ /* ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Main ¡program ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡*/ /*-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑*/ #define ¡NDEBUG #include ¡ <float.h> #include ¡ <limits.h> #include ¡ <setjmp.h> /* ¡private ¡constants ¡*/ #define ¡FUN_NAM_INDEX ¡ 1 #define ¡FUN_ARG_INDEX ¡ 2 #define ¡FUN_EXP_INDEX ¡ 3 #define ¡FUN_DCT_INDEX ¡ 4 #define ¡NAT_NAM_INDEX ¡ 1 #define ¡NAT_NBR_INDEX ¡ 2 #define ¡VAR_NAM_INDEX ¡ 1 #define ¡APL_NAM_INDEX ¡ 1 #define ¡APL_ARG_INDEX ¡ 2 #define ¡TBL_NAM_INDEX ¡ 1 #define ¡TBL_IDX_INDEX ¡ 2 #define ¡DEF_INV_INDEX ¡ 1 #define ¡DEF_EXP_INDEX ¡ 2 #define ¡SET_INV_INDEX ¡ 1 22 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 22

  14. Theo D’Hondt SLIP: a simple language implementation platform History: Pico 1 /*-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑*/ /* ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡>>>Pico<<< ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡*/ /* ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Theo ¡D'Hondt ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡*/ /* ¡ ¡ ¡VUB ¡Programming ¡Technology ¡Lab ¡ ¡*/ /* ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(c) ¡1997 ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡*/ /*-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑*/ /* ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Main ¡program ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡*/ /*-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑*/ #define ¡NDEBUG #include ¡ <float.h> #include ¡ <limits.h> #include ¡ <setjmp.h> /* ¡private ¡constants ¡*/ #define ¡FUN_NAM_INDEX ¡ 1 #define ¡FUN_ARG_INDEX ¡ 2 #define ¡FUN_EXP_INDEX ¡ 3 #define ¡FUN_DCT_INDEX ¡ 4 #define ¡NAT_NAM_INDEX ¡ 1 #define ¡NAT_NBR_INDEX ¡ 2 #define ¡VAR_NAM_INDEX ¡ 1 #define ¡APL_NAM_INDEX ¡ 1 #define ¡APL_ARG_INDEX ¡ 2 #define ¡TBL_NAM_INDEX ¡ 1 #define ¡TBL_IDX_INDEX ¡ 2 #define ¡DEF_INV_INDEX ¡ 1 #define ¡DEF_EXP_INDEX ¡ 2 #define ¡SET_INV_INDEX ¡ 1 23 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 23

  15. Theo D’Hondt SLIP: a simple language implementation platform History: Pico 1 /*-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑*/ /* ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡>>>Pico<<< ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡*/ /* ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Theo ¡D'Hondt ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡*/ /* ¡ ¡ ¡VUB ¡Programming ¡Technology ¡Lab ¡ ¡*/ /* ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(c) ¡1997 ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡*/ /*-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑*/ /* ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Main ¡program ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡*/ /*-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑*/ #define ¡NDEBUG #include ¡ <float.h> #include ¡ <limits.h> #include ¡ <setjmp.h> /* ¡private ¡constants ¡*/ #define ¡FUN_NAM_INDEX ¡ 1 #define ¡FUN_ARG_INDEX ¡ 2 #define ¡FUN_EXP_INDEX ¡ 3 #define ¡FUN_DCT_INDEX ¡ 4 #define ¡NAT_NAM_INDEX ¡ 1 #define ¡NAT_NBR_INDEX ¡ 2 #define ¡VAR_NAM_INDEX ¡ 1 #define ¡APL_NAM_INDEX ¡ 1 #define ¡APL_ARG_INDEX ¡ 2 #define ¡TBL_NAM_INDEX ¡ 1 #define ¡TBL_IDX_INDEX ¡ 2 #define ¡DEF_INV_INDEX ¡ 1 #define ¡DEF_EXP_INDEX ¡ 2 #define ¡SET_INV_INDEX ¡ 1 24 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 24

  16. Theo D’Hondt SLIP: a simple language implementation platform History: Pic% 25 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 25

  17. Theo D’Hondt SLIP: a simple language implementation platform History: Pic% 26 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 26

  18. Theo D’Hondt SLIP: a simple language implementation platform History: Pic% 27 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 27

  19. Theo D’Hondt SLIP: a simple language implementation platform History: Pic% 28 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 28

  20. Theo D’Hondt SLIP: a simple language implementation platform History: Pico 2 1st class ∀ no compromises abstract grammars uniform memory continuations interpretation 29 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 29

  21. Theo D’Hondt SLIP: a simple language implementation platform History: \ ˈ sk ē m\ 30 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 30

  22. Theo D’Hondt SLIP: a simple language implementation platform SLIP: design performance,performance,performance smallest possible footprint (loc, kb) abstract syntax everywhere no compromises or limitations minimal dynamic language main focus on interpretation clean code incremental implementation 31 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 31

  23. Theo D’Hondt SLIP: a simple language implementation platform SLIP: the language (begin ¡ ¡(define ¡(counter ¡count) ¡ ¡ ¡ ¡(define ¡(self ¡message) ¡ ¡ ¡ ¡ ¡ ¡(if ¡(eq? ¡message ¡'+) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(begin ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡count ¡(+ ¡count ¡1)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡self) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(eq? ¡message ¡'-­‑) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(begin ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡count ¡(-­‑ ¡count ¡1)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡self) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(eq? ¡message ¡'?) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡count ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡'error)))) ¡ ¡ ¡ ¡ ¡ ¡self) ¡ ¡(define ¡c ¡(counter ¡10)) ¡ ¡((((c ¡'+) ¡'+) ¡'-­‑) ¡'?)) 32 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 32

  24. Theo D’Hondt SLIP: a simple language implementation platform SLIP: the language (cont’d) (begin ¡ ¡(define ¡empty ¡ ¡ ¡0) ¡ ¡(define ¡full ¡ ¡ ¡ ¡1) ¡ ¡(define ¡push ¡ ¡ ¡ ¡2) ¡ ¡(define ¡pop ¡ ¡ ¡ ¡ ¡3) ¡ ¡(define ¡S ¡(Stack ¡10)) ¡ ¡(define ¡(Stack ¡n) ¡ ¡(define ¡T ¡(Stack ¡20)) ¡ ¡ ¡ ¡(define ¡stack ¡(make-­‑vector ¡n)) ¡ ¡(if ¡(S ¡full) ¡ ¡ ¡ ¡(define ¡top ¡-­‑1) ¡ ¡ ¡ ¡(display ¡'Overflow) ¡ ¡ ¡ ¡(define ¡(empty) ¡ ¡ ¡ ¡(S ¡push ¡123)) ¡ ¡ ¡ ¡ ¡ ¡(< ¡top ¡0)) ¡ ¡(T ¡push ¡456) ¡ ¡ ¡ ¡(define ¡(full) ¡ ¡(if ¡(S ¡empty) ¡ ¡ ¡ ¡ ¡ ¡(>= ¡top ¡n)) ¡ ¡ ¡ ¡(display ¡'Underflow) ¡ ¡ ¡ ¡(define ¡(push ¡item) ¡ ¡ ¡ ¡(S ¡pop)) ¡ ¡ ¡ ¡ ¡ ¡(set! ¡top ¡(+ ¡top ¡1)) ¡ ¡(display ¡(T ¡pop)) ¡ ¡ ¡ ¡ ¡ ¡(vector-­‑set! ¡stack ¡top ¡item) ¡ ¡(newline) ¡ ¡ ¡ ¡ ¡ ¡()) ¡ ¡(if ¡(S ¡empty) ¡ ¡ ¡ ¡(define ¡(pop) ¡ ¡ ¡ ¡(display ¡'Underflow) ¡ ¡ ¡ ¡ ¡ ¡(define ¡item ¡(vector-­‑ref ¡stack ¡top)) ¡ ¡ ¡ ¡(S ¡pop))) ¡ ¡ ¡ ¡ ¡ ¡(set! ¡top ¡(-­‑ ¡top ¡1)) ¡ ¡ ¡ ¡ ¡ ¡item) ¡ ¡ ¡ ¡(define ¡(self ¡message ¡. ¡arguments) ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡methods ¡(vector ¡empty ¡full ¡push ¡pop)) ¡ ¡ ¡ ¡ ¡ ¡(apply ¡(vector-­‑ref ¡methods ¡message) ¡arguments)) ¡ ¡ ¡ ¡self) 33 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 33

  25. Theo D’Hondt SLIP: a simple language implementation platform SLIP: the language (cont’d) begin , define , if , lambda , set! (, while ) define and set! have a value define used anywhere () instead of '() local variables ≈ parameters no forward references natives inherited from metalevel no top-level sequences 34 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 34

  26. Theo D’Hondt SLIP: a simple language implementation platform A Scheme interpreter for SLIP (begin ¡ ¡ ¡(define ¡environment ¡'()) ¡ ¡ ¡ ¡ ¡ ¡(if ¡(eq? ¡boolean ¡#f) ¡ ¡(define ¡(loop ¡output) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(evaluate ¡alternative) ¡ ¡ ¡ ¡(define ¡rollback ¡environment) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(evaluate ¡consequent))) ¡ ¡ ¡ ¡(define ¡(error ¡message ¡qualifier) ¡ ¡ ¡ ¡(define ¡(evaluate-­‑lambda ¡parameters ¡expression) ¡ ¡ ¡ ¡ ¡ ¡(display ¡message) ¡ ¡ ¡ ¡ ¡ ¡(make-­‑procedure ¡parameters ¡expression)) ¡ ¡ ¡ ¡ ¡ ¡(set! ¡environment ¡rollback) ¡ ¡ ¡ ¡(define ¡(evaluate-­‑set! ¡variable ¡expression) ¡ ¡ ¡ ¡ ¡ ¡(loop ¡qualifier)) ¡ ¡ ¡ ¡ ¡ ¡(define ¡binding ¡(assoc ¡variable ¡environment)) ¡ ¡ ¡ ¡(define ¡(bind-­‑variable ¡variable ¡value) ¡ ¡ ¡ ¡ ¡ ¡(if ¡binding ¡ ¡ ¡ ¡ ¡ ¡(define ¡binding ¡(cons ¡variable ¡value)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(let ¡((value ¡(evaluate ¡expression))) ¡ ¡ ¡ ¡ ¡ ¡(set! ¡environment ¡(cons ¡binding ¡environment))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set-­‑cdr! ¡binding ¡value) ¡ ¡ ¡ ¡(define ¡(bind-­‑parameters ¡parameters ¡arguments) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡value) ¡ ¡ ¡ ¡ ¡ ¡(for-­‑each ¡bind-­‑variable ¡parameters ¡arguments)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(error ¡"inaccessible ¡variable: ¡" ¡variable))) ¡ ¡ ¡ ¡(define ¡(evaluate-­‑sequence ¡expressions) ¡ ¡ ¡ ¡(define ¡(evaluate-­‑variable ¡variable) ¡ ¡ ¡ ¡ ¡ ¡(define ¡head ¡(car ¡expressions)) ¡ ¡ ¡ ¡ ¡ ¡(define ¡binding ¡(assoc ¡variable ¡environment)) ¡ ¡ ¡ ¡ ¡ ¡(define ¡tail ¡(cdr ¡expressions)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡binding ¡ ¡ ¡ ¡ ¡ ¡(if ¡(null? ¡tail) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(cdr ¡binding) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(evaluate ¡head) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(eval ¡variable ¡(interaction-­‑environment)))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(evaluate-­‑sequence ¡tail))) ¡ ¡ ¡ ¡(define ¡(evaluate ¡expression) ¡ ¡ ¡ ¡(define ¡(make-­‑procedure ¡parameters ¡expression) ¡ ¡ ¡ ¡ ¡ ¡(cond ¡ ¡ ¡ ¡ ¡ ¡(define ¡lexical-­‑scope ¡environment) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡((symbol? ¡expression) ¡ ¡ ¡ ¡ ¡ ¡(lambda ¡arguments ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(evaluate-­‑variable ¡expression)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡dynamic-­‑scope ¡environment) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡((pair? ¡expression) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡environment ¡lexical-­‑scope) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(let ¡((operator ¡(car ¡expression)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(bind-­‑parameters ¡parameters ¡arguments) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(operands ¡(cdr ¡expression))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(let ¡((value ¡(evaluate ¡expression))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(apply ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡environment ¡dynamic-­‑scope) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(case ¡operator ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡value))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡((begin) ¡ ¡evaluate-­‑begin ¡) ¡ ¡ ¡ ¡(define ¡(evaluate-­‑application ¡operator) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡((define) ¡evaluate-­‑define) ¡ ¡ ¡ ¡ ¡ ¡(lambda ¡operands ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡((if) ¡ ¡ ¡ ¡ ¡evaluate-­‑if ¡ ¡ ¡ ¡) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(apply ¡(evaluate ¡operator) ¡(map ¡evaluate ¡operands)))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡((lambda) ¡evaluate-­‑lambda) ¡ ¡ ¡ ¡(define ¡(evaluate-­‑begin ¡. ¡expressions) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡((set!) ¡ ¡ ¡evaluate-­‑set! ¡ ¡) ¡ ¡ ¡ ¡ ¡ ¡(evaluate-­‑sequence ¡expressions)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(else ¡ ¡ ¡ ¡ ¡(evaluate-­‑application ¡operator))) ¡operands))) ¡ ¡ ¡ ¡(define ¡(evaluate-­‑define ¡variable ¡expression) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(else ¡ ¡ ¡ ¡ ¡ ¡(define ¡binding ¡(cons ¡variable ¡'())) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡expression))); ¡ ¡ ¡ ¡ ¡ ¡(set! ¡environment ¡(cons ¡binding ¡environment)) ¡ ¡ ¡ ¡(display ¡output) ¡ ¡ ¡ ¡ ¡ ¡(let ¡((value ¡(evaluate ¡expression))) ¡ ¡ ¡ ¡(newline) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set-­‑cdr! ¡binding ¡value) ¡ ¡ ¡ ¡(display ¡">>>") ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡value)) ¡ ¡ ¡ ¡(loop ¡(evaluate ¡(read)))) ¡ ¡ ¡ ¡(define ¡(evaluate-­‑if ¡predicate ¡consequent ¡alternative) ¡ ¡(loop ¡"Slip ¡version ¡0")) ¡ ¡ ¡ ¡ ¡ ¡(define ¡boolean ¡(evaluate ¡predicate)) 35 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 35

  27. Theo D’Hondt SLIP: a simple language implementation platform A Scheme interpreter for SLIP (begin ¡ ¡ ¡(define ¡environment ¡'()) ¡ ¡ ¡ ¡ ¡ ¡(if ¡(eq? ¡boolean ¡#f) ¡ ¡(define ¡(loop ¡output) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(evaluate ¡alternative) ¡ ¡ ¡ ¡(define ¡rollback ¡environment) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(evaluate ¡consequent))) ¡ ¡ ¡ ¡(define ¡(error ¡message ¡qualifier) ¡ ¡ ¡ ¡(define ¡(evaluate-­‑lambda ¡parameters ¡expression) ¡ ¡ ¡ ¡ ¡ ¡(display ¡message) ¡ ¡ ¡ ¡ ¡ ¡(make-­‑procedure ¡parameters ¡expression)) ¡ ¡ ¡ ¡ ¡ ¡(set! ¡environment ¡rollback) ¡ ¡ ¡ ¡(define ¡(evaluate-­‑set! ¡variable ¡expression) ¡ ¡ ¡ ¡ ¡ ¡(loop ¡qualifier)) ¡ ¡ ¡ ¡ ¡ ¡(define ¡binding ¡(assoc ¡variable ¡environment)) ¡ ¡ ¡ ¡(define ¡(bind-­‑variable ¡variable ¡value) ¡ ¡ ¡ ¡ ¡ ¡(if ¡binding ¡ ¡ ¡ ¡ ¡ ¡(define ¡binding ¡(cons ¡variable ¡value)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(let ¡((value ¡(evaluate ¡expression))) ¡ ¡ ¡ ¡ ¡ ¡(set! ¡environment ¡(cons ¡binding ¡environment))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set-­‑cdr! ¡binding ¡value) ¡ ¡ ¡ ¡(define ¡(bind-­‑parameters ¡parameters ¡arguments) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡value) ¡ ¡ ¡ ¡ ¡ ¡(for-­‑each ¡bind-­‑variable ¡parameters ¡arguments)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(error ¡"inaccessible ¡variable: ¡" ¡variable))) ¡ ¡ ¡ ¡(define ¡(evaluate-­‑sequence ¡expressions) ¡ ¡ ¡ ¡(define ¡(evaluate-­‑variable ¡variable) ¡ ¡ ¡ ¡ ¡ ¡(define ¡head ¡(car ¡expressions)) ¡ ¡ ¡ ¡ ¡ ¡(define ¡binding ¡(assoc ¡variable ¡environment)) ¡ ¡ ¡ ¡ ¡ ¡(define ¡tail ¡(cdr ¡expressions)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡binding ¡ ¡ ¡ ¡ ¡ ¡(if ¡(null? ¡tail) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(cdr ¡binding) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(evaluate ¡head) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(eval ¡variable ¡(interaction-­‑environment)))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(evaluate-­‑sequence ¡tail))) ¡ ¡ ¡ ¡(define ¡(evaluate ¡expression) ¡ ¡ ¡ ¡(define ¡(make-­‑procedure ¡parameters ¡expression) ¡ ¡ ¡ ¡ ¡ ¡(cond ¡ ¡ ¡ ¡ ¡ ¡(define ¡lexical-­‑scope ¡environment) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡((symbol? ¡expression) ¡ ¡ ¡ ¡ ¡ ¡(lambda ¡arguments ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(evaluate-­‑variable ¡expression)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡dynamic-­‑scope ¡environment) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡((pair? ¡expression) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡environment ¡lexical-­‑scope) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(let ¡((operator ¡(car ¡expression)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(bind-­‑parameters ¡parameters ¡arguments) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(operands ¡(cdr ¡expression))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(let ¡((value ¡(evaluate ¡expression))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(apply ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡environment ¡dynamic-­‑scope) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(case ¡operator ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡value))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡((begin) ¡ ¡evaluate-­‑begin ¡) ¡ ¡ ¡ ¡(define ¡(evaluate-­‑application ¡operator) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡((define) ¡evaluate-­‑define) ¡ ¡ ¡ ¡ ¡ ¡(lambda ¡operands ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡((if) ¡ ¡ ¡ ¡ ¡evaluate-­‑if ¡ ¡ ¡ ¡) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(apply ¡(evaluate ¡operator) ¡(map ¡evaluate ¡operands)))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡((lambda) ¡evaluate-­‑lambda) ¡ ¡ ¡ ¡(define ¡(evaluate-­‑begin ¡. ¡expressions) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡((set!) ¡ ¡ ¡evaluate-­‑set! ¡ ¡) ¡ ¡ ¡ ¡ ¡ ¡(evaluate-­‑sequence ¡expressions)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(else ¡ ¡ ¡ ¡ ¡(evaluate-­‑application ¡operator))) ¡operands))) ¡ ¡ ¡ ¡(define ¡(evaluate-­‑define ¡variable ¡expression) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(else ¡ ¡ ¡ ¡ ¡ ¡(define ¡binding ¡(cons ¡variable ¡'())) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡expression))); ¡ ¡ ¡ ¡ ¡ ¡(set! ¡environment ¡(cons ¡binding ¡environment)) ¡ ¡ ¡ ¡(display ¡output) ¡ ¡ ¡ ¡ ¡ ¡(let ¡((value ¡(evaluate ¡expression))) ¡ ¡ ¡ ¡(newline) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set-­‑cdr! ¡binding ¡value) ¡ ¡ ¡ ¡(display ¡">>>") ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡value)) ¡ ¡ ¡ ¡(loop ¡(evaluate ¡(read)))) ¡ ¡ ¡ ¡(define ¡(evaluate-­‑if ¡predicate ¡consequent ¡alternative) ¡ ¡(loop ¡"Slip ¡version ¡0")) ¡ ¡ ¡ ¡ ¡ ¡(define ¡boolean ¡(evaluate ¡predicate)) 36 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 36

  28. Theo D’Hondt SLIP: a simple language implementation platform A metacircular SLIP interpreter (begin ¡ ¡(define ¡circularity-­‑level ¡(+ ¡circularity-­‑level ¡1)) ¡ ¡ ¡ ¡ ¡ ¡(define ¡(evaluate-­‑application ¡operator) ¡ ¡(define ¡meta-­‑level-­‑eval ¡eval) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(lambda ¡operands ¡ ¡ ¡ ¡ ¡ ¡(define ¡(evaluate-­‑variable ¡variable) ¡ ¡(define ¡eval ¡()) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(apply ¡(evaluate ¡operator) ¡(map ¡evaluate ¡operands)))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡binding ¡(assoc ¡variable ¡environment)) ¡ ¡(define ¡environment ¡()) ¡ ¡ ¡ ¡ ¡ ¡(define ¡(evaluate-­‑begin ¡. ¡expressions) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(pair? ¡binding) ¡ ¡(define ¡(loop ¡output) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(evaluate-­‑sequence ¡expressions)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(cdr ¡binding) ¡ ¡ ¡ ¡(define ¡rollback ¡environment) ¡ ¡ ¡ ¡ ¡ ¡(define ¡(evaluate-­‑define ¡pattern ¡. ¡expressions) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(meta-­‑level-­‑eval ¡variable))) ¡ ¡ ¡ ¡(define ¡(evaluate ¡expression) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(symbol? ¡pattern) ¡ ¡ ¡ ¡ ¡ ¡(define ¡(evaluate-­‑while ¡predicate ¡. ¡expressions) ¡ ¡ ¡ ¡ ¡ ¡(define ¡(error ¡message ¡qualifier) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(begin ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡(iterate ¡value) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(display ¡message) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡value ¡(evaluate ¡(car ¡expressions))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡boolean ¡(evaluate ¡predicate)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡environment ¡rollback) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡binding ¡(cons ¡pattern ¡value)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(eq? ¡boolean ¡#f) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(loop ¡qualifier)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡environment ¡(cons ¡binding ¡environment)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡value ¡ ¡ ¡ ¡ ¡ ¡(define ¡(bind-­‑variable ¡variable ¡value) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡value) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(iterate ¡(evaluate-­‑sequence ¡expressions)))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡binding ¡(cons ¡variable ¡value)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(begin ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(iterate ¡())) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡environment ¡(cons ¡binding ¡environment))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡binding ¡(cons ¡(car ¡pattern) ¡())) ¡ ¡ ¡ ¡ ¡(if ¡(symbol? ¡expression) ¡ ¡ ¡ ¡ ¡ ¡(define ¡(bind-­‑parameters ¡parameters ¡arguments) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡environment ¡(cons ¡binding ¡environment)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(evaluate-­‑variable ¡expression) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(symbol? ¡parameters) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡procedure ¡(make-­‑procedure ¡(cdr ¡pattern) ¡expressions)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(pair? ¡expression) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(bind-­‑variable ¡parameters ¡arguments) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set-­‑cdr! ¡binding ¡procedure) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(begin ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(pair? ¡parameters) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡procedure))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡operator ¡(car ¡expression)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(begin ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡(evaluate-­‑if ¡predicate ¡consequent ¡. ¡alternative) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡operands ¡(cdr ¡expression)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡variable ¡(car ¡parameters)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡boolean ¡(evaluate ¡predicate)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(apply ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡value ¡(car ¡arguments ¡)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(eq? ¡boolean ¡#f) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(eq? ¡operator ¡'begin) ¡evaluate-­‑begin ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(bind-­‑variable ¡variable ¡value) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(null? ¡alternative) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(eq? ¡operator ¡'define) ¡evaluate-­‑define ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(bind-­‑parameters ¡(cdr ¡parameters) ¡(cdr ¡arguments)))))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡() ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(eq? ¡operator ¡'if) ¡evaluate-­‑if ¡ ¡ ¡ ¡ ¡ ¡(define ¡(evaluate-­‑sequence ¡expressions) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(evaluate ¡(car ¡alternative))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(eq? ¡operator ¡'lambda) ¡evaluate-­‑lambda ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡head ¡(car ¡expressions)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(evaluate ¡consequent))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(eq? ¡operator ¡'quote) ¡evaluate-­‑quote ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡tail ¡(cdr ¡expressions)) ¡ ¡ ¡ ¡ ¡ ¡(define ¡(evaluate-­‑lambda ¡parameters ¡. ¡expressions) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(eq? ¡operator ¡'set!) ¡evaluate-­‑set! ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(null? ¡tail) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(make-­‑procedure ¡parameters ¡expressions)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(eq? ¡operator ¡'while) ¡evaluate-­‑while ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(evaluate ¡head) ¡ ¡ ¡ ¡ ¡ ¡(define ¡(evaluate-­‑quote ¡expression) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(evaluate-­‑application ¡operator)))))))) ¡operands)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(begin ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡expression) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡expression))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(evaluate ¡head) ¡ ¡ ¡ ¡ ¡ ¡(define ¡(evaluate-­‑set! ¡variable ¡expression) ¡ ¡ ¡ ¡(display ¡output) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(evaluate-­‑sequence ¡tail)))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡value ¡(evaluate ¡expression)) ¡ ¡ ¡ ¡(newline) ¡ ¡ ¡ ¡ ¡ ¡(define ¡(make-­‑procedure ¡parameters ¡expressions) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡binding ¡(assoc ¡variable ¡environment)) ¡ ¡ ¡ ¡(display ¡"level ¡") ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡lexical-­‑environment ¡environment) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(pair? ¡binding) ¡ ¡ ¡ ¡(display ¡circularity-­‑level) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(lambda ¡arguments ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(begin ¡ ¡ ¡ ¡ ¡(display ¡">") ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡dynamic-­‑environment ¡environment) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡value ¡(evaluate ¡expression)) ¡ ¡ ¡ ¡(set! ¡eval ¡evaluate) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡environment ¡lexical-­‑environment) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set-­‑cdr! ¡binding ¡value) ¡ ¡ ¡ ¡(loop ¡(evaluate ¡(read)))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(bind-­‑parameters ¡parameters ¡arguments) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡value) ¡ ¡(loop ¡"Meta-­‑Circular ¡Slip")) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡value ¡(evaluate-­‑sequence ¡expressions)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(error ¡"inaccessible ¡variable: ¡" ¡variable))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡environment ¡dynamic-­‑environment) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡value)) 37 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 37

  29. Theo D’Hondt SLIP: a simple language implementation platform A metacircular SLIP interpreter (cont'd) (begin ¡ ¡(define ¡circularity-­‑level ¡0) ¡ ¡(define ¡meta-­‑level-­‑eval ¡eval) ¡ ¡(define ¡eval ¡'()) ¡ ¡ ¡ ¡(loop ¡(evaluate ¡(read)))) ¡ ¡(loop ¡"Root-­‑Level ¡Slip" ¡'())) Slip ¡version ¡3 >>> (begin ¡ ¡(define ¡circularity-­‑level ¡(+ ¡circularity-­‑level ¡1)) ¡ ¡(define ¡meta-­‑level-­‑eval ¡eval) ¡ ¡(define ¡eval ¡()) ¡ ¡(define ¡environment ¡()) ¡ ¡(define ¡(loop ¡output) ¡ ¡ ¡ ¡(define ¡rollback ¡environment) ¡ ¡(loop ¡"Meta-­‑Circular ¡Slip" ¡())) Meta-­‑Circular ¡Slip level ¡1> (begin ¡ ¡(define ¡circularity-­‑level ¡(+ ¡circularity-­‑level ¡1)) ¡ ¡(loop ¡"Meta-­‑Circular ¡Slip" ¡())) Meta-­‑Circular ¡Slip level ¡2> (begin ¡ ¡(define ¡circularity-­‑level ¡(+ ¡circularity-­‑level ¡1)) ¡ ¡(loop ¡"Meta-­‑Circular ¡Slip" ¡())) Meta-­‑Circular ¡Slip level ¡3>(+ ¡1 ¡2) 3 level ¡3> 38 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 38

  30. Theo D’Hondt SLIP: a simple language implementation platform A metacircular SLIP interpreter (cont'd) (define ¡(evaluate-­‑sequence ¡expressions) ¡ ¡(define ¡head ¡(car ¡expressions)) (define ¡environment ¡()) ¡ ¡(define ¡tail ¡(cdr ¡expressions)) ¡ ¡(if ¡(null? ¡tail) ¡ ¡ ¡ ¡(evaluate ¡head) (define ¡(make-­‑procedure ¡parameters ¡expressions) ¡ ¡ ¡ ¡(begin ¡ ¡(define ¡lexical-­‑environment ¡environment) ¡ ¡ ¡ ¡ ¡ ¡(evaluate ¡head) (define ¡(bind-­‑variable ¡variable ¡value) ¡ ¡(lambda ¡arguments ¡ ¡ ¡ ¡ ¡ ¡(evaluate-­‑sequence ¡tail)))) ¡ ¡(define ¡binding ¡(cons ¡variable ¡value)) ¡ ¡ ¡ ¡(define ¡dynamic-­‑environment ¡environment) ¡ ¡(set! ¡environment ¡(cons ¡binding ¡environment))) ¡ ¡ ¡ ¡(set! ¡environment ¡lexical-­‑environment) (define ¡(bind-­‑parameters ¡parameters ¡arguments) ¡ ¡ ¡ ¡(bind-­‑parameters ¡parameters ¡arguments) ¡ ¡(if ¡(symbol? ¡parameters) ¡ ¡ ¡ ¡(define ¡value ¡(evaluate-­‑sequence ¡expressions)) ¡ ¡ ¡ ¡(bind-­‑variable ¡parameters ¡arguments) ¡ ¡ ¡ ¡(set! ¡environment ¡dynamic-­‑environment) ¡ ¡ ¡ ¡(if ¡(pair? ¡parameters) ¡ ¡ ¡ ¡value)) ¡ ¡ ¡ ¡ ¡ ¡(begin ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡variable ¡(car ¡parameters)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡value ¡(car ¡arguments ¡)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(bind-­‑variable ¡variable ¡value) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(bind-­‑parameters ¡(cdr ¡parameters) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(cdr ¡arguments)))))) (define ¡(evaluate-­‑application ¡operator) ¡ ¡(lambda ¡operands ¡ ¡ ¡ ¡(apply ¡(evaluate ¡operator) ¡(map ¡evaluate ¡operands)))) 39 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 39

  31. Theo D’Hondt SLIP: a simple language implementation platform A metacircular SLIP interpreter (cont'd) (define ¡(evaluate-­‑sequence ¡expressions) ¡ ¡(define ¡head ¡(car ¡expressions)) (define ¡environment ¡()) ¡ ¡(define ¡tail ¡(cdr ¡expressions)) ¡ ¡(if ¡(null? ¡tail) ¡ ¡ ¡ ¡(evaluate ¡head) (define ¡(make-­‑procedure ¡parameters ¡expressions) ¡ ¡ ¡ ¡(begin ¡ ¡(define ¡lexical-­‑environment ¡environment) ¡ ¡ ¡ ¡ ¡ ¡(evaluate ¡head) (define ¡(bind-­‑variable ¡variable ¡value) ¡ ¡(lambda ¡arguments ¡ ¡ ¡ ¡ ¡ ¡(evaluate-­‑sequence ¡tail)))) ¡ ¡(define ¡binding ¡(cons ¡variable ¡value)) ¡ ¡ ¡ ¡(define ¡dynamic-­‑environment ¡environment) ¡ ¡(set! ¡environment ¡(cons ¡binding ¡environment))) ¡ ¡ ¡ ¡(set! ¡environment ¡lexical-­‑environment) (define ¡(bind-­‑parameters ¡parameters ¡arguments) ¡ ¡ ¡ ¡(bind-­‑parameters ¡parameters ¡arguments) ¡ ¡(if ¡(symbol? ¡parameters) ¡ ¡ ¡ ¡(define ¡value ¡(evaluate-­‑sequence ¡expressions)) ¡ ¡ ¡ ¡(bind-­‑variable ¡parameters ¡arguments) ¡ ¡ ¡ ¡(set! ¡environment ¡dynamic-­‑environment) ¡ ¡ ¡ ¡(if ¡(pair? ¡parameters) ¡ ¡ ¡ ¡value)) ¡ ¡ ¡ ¡ ¡ ¡(begin ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡variable ¡(car ¡parameters)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡value ¡(car ¡arguments ¡)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(bind-­‑variable ¡variable ¡value) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(bind-­‑parameters ¡(cdr ¡parameters) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(cdr ¡arguments)))))) (define ¡(evaluate-­‑application ¡operator) ¡ ¡(lambda ¡operands ¡ ¡ ¡ ¡(apply ¡(evaluate ¡operator) ¡(map ¡evaluate ¡operands)))) 40 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 40

  32. Theo D’Hondt SLIP: a simple language implementation platform A metacircular SLIP interpreter (cont'd) (define ¡(evaluate-­‑sequence ¡expressions) ¡ ¡(define ¡head ¡(car ¡expressions)) (define ¡environment ¡()) ¡ ¡(define ¡tail ¡(cdr ¡expressions)) ¡ ¡(if ¡(null? ¡tail) ¡ ¡ ¡ ¡(evaluate ¡head) (define ¡(make-­‑procedure ¡parameters ¡expressions) ¡ ¡ ¡ ¡(begin ¡ ¡(define ¡lexical-­‑environment ¡environment) ¡ ¡ ¡ ¡ ¡ ¡(evaluate ¡head) (define ¡(bind-­‑variable ¡variable ¡value) ¡ ¡(lambda ¡arguments ¡ ¡ ¡ ¡ ¡ ¡(evaluate-­‑sequence ¡tail)))) ¡ ¡(define ¡binding ¡(cons ¡variable ¡value)) ¡ ¡ ¡ ¡(define ¡dynamic-­‑environment ¡environment) ¡ ¡(set! ¡environment ¡(cons ¡binding ¡environment))) ¡ ¡ ¡ ¡(set! ¡environment ¡lexical-­‑environment) (define ¡(bind-­‑parameters ¡parameters ¡arguments) ¡ ¡ ¡ ¡(bind-­‑parameters ¡parameters ¡arguments) ¡ ¡(if ¡(symbol? ¡parameters) ¡ ¡ ¡ ¡(define ¡value ¡(evaluate-­‑sequence ¡expressions)) ¡ ¡ ¡ ¡(bind-­‑variable ¡parameters ¡arguments) ¡ ¡ ¡ ¡(set! ¡environment ¡dynamic-­‑environment) ¡ ¡ ¡ ¡(if ¡(pair? ¡parameters) ¡ ¡ ¡ ¡value)) ¡ ¡ ¡ ¡ ¡ ¡(begin ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡variable ¡(car ¡parameters)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡value ¡(car ¡arguments ¡)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(bind-­‑variable ¡variable ¡value) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(bind-­‑parameters ¡(cdr ¡parameters) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(cdr ¡arguments)))))) (define ¡(evaluate-­‑application ¡operator) ¡ ¡(lambda ¡operands ¡ ¡ ¡ ¡(apply ¡(evaluate ¡operator) ¡(map ¡evaluate ¡operands)))) 41 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 41

  33. Theo D’Hondt SLIP: a simple language implementation platform A metacircular SLIP interpreter (cont'd) (define ¡(evaluate-­‑sequence ¡expressions) ¡ ¡(define ¡head ¡(car ¡expressions)) (define ¡environment ¡()) ¡ ¡(define ¡tail ¡(cdr ¡expressions)) ¡ ¡(if ¡(null? ¡tail) ¡ ¡ ¡ ¡(evaluate ¡head) (define ¡(make-­‑procedure ¡parameters ¡expressions) ¡ ¡ ¡ ¡(begin ¡ ¡(define ¡lexical-­‑environment ¡environment) ¡ ¡ ¡ ¡ ¡ ¡(evaluate ¡head) (define ¡(bind-­‑variable ¡variable ¡value) ¡ ¡(lambda ¡arguments ¡ ¡ ¡ ¡ ¡ ¡(evaluate-­‑sequence ¡tail)))) ¡ ¡(define ¡binding ¡(cons ¡variable ¡value)) ¡ ¡ ¡ ¡(define ¡dynamic-­‑environment ¡environment) ¡ ¡(set! ¡environment ¡(cons ¡binding ¡environment))) ¡ ¡ ¡ ¡(set! ¡environment ¡lexical-­‑environment) (define ¡(bind-­‑parameters ¡parameters ¡arguments) ¡ ¡ ¡ ¡(bind-­‑parameters ¡parameters ¡arguments) ¡ ¡(if ¡(symbol? ¡parameters) ¡ ¡ ¡ ¡(define ¡value ¡(evaluate-­‑sequence ¡expressions)) ¡ ¡ ¡ ¡(bind-­‑variable ¡parameters ¡arguments) ¡ ¡ ¡ ¡(set! ¡environment ¡dynamic-­‑environment) ¡ ¡ ¡ ¡(if ¡(pair? ¡parameters) ¡ ¡ ¡ ¡value)) ¡ ¡ ¡ ¡ ¡ ¡(begin ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡variable ¡(car ¡parameters)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡value ¡(car ¡arguments ¡)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(bind-­‑variable ¡variable ¡value) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(bind-­‑parameters ¡(cdr ¡parameters) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(cdr ¡arguments)))))) (define ¡(evaluate-­‑application ¡operator) ¡ ¡(lambda ¡operands ¡ ¡ ¡ ¡(apply ¡(evaluate ¡operator) ¡(map ¡evaluate ¡operands)))) 42 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 42

  34. Theo D’Hondt SLIP: a simple language implementation platform A metacircular SLIP interpreter (cont'd) (define ¡(evaluate-­‑sequence ¡expressions) ¡ ¡(define ¡head ¡(car ¡expressions)) (define ¡environment ¡()) ¡ ¡(define ¡tail ¡(cdr ¡expressions)) ¡ ¡(if ¡(null? ¡tail) ¡ ¡ ¡ ¡(evaluate ¡head) (define ¡(make-­‑procedure ¡parameters ¡expressions) ¡ ¡ ¡ ¡(begin ¡ ¡(define ¡lexical-­‑environment ¡environment) ¡ ¡ ¡ ¡ ¡ ¡(evaluate ¡head) (define ¡(bind-­‑variable ¡variable ¡value) ¡ ¡(lambda ¡arguments ¡ ¡ ¡ ¡ ¡ ¡(evaluate-­‑sequence ¡tail)))) ¡ ¡(define ¡binding ¡(cons ¡variable ¡value)) ¡ ¡ ¡ ¡(define ¡dynamic-­‑environment ¡environment) ¡ ¡(set! ¡environment ¡(cons ¡binding ¡environment))) ¡ ¡ ¡ ¡(set! ¡environment ¡lexical-­‑environment) (define ¡(bind-­‑parameters ¡parameters ¡arguments) ¡ ¡ ¡ ¡(bind-­‑parameters ¡parameters ¡arguments) ¡ ¡(if ¡(symbol? ¡parameters) ¡ ¡ ¡ ¡(define ¡value ¡(evaluate-­‑sequence ¡expressions)) ¡ ¡ ¡ ¡(bind-­‑variable ¡parameters ¡arguments) ¡ ¡ ¡ ¡(set! ¡environment ¡dynamic-­‑environment) ¡ ¡ ¡ ¡(if ¡(pair? ¡parameters) ¡ ¡ ¡ ¡value)) ¡ ¡ ¡ ¡ ¡ ¡(begin ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡variable ¡(car ¡parameters)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡value ¡(car ¡arguments ¡)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(bind-­‑variable ¡variable ¡value) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(bind-­‑parameters ¡(cdr ¡parameters) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(cdr ¡arguments)))))) (define ¡(evaluate-­‑application ¡operator) ¡ ¡(lambda ¡operands ¡ ¡ ¡ ¡(apply ¡(evaluate ¡operator) ¡(map ¡evaluate ¡operands)))) 43 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 43

  35. Theo D’Hondt SLIP: a simple language implementation platform A metacircular SLIP interpreter (cont'd) (define ¡(evaluate-­‑sequence ¡expressions) ¡ ¡(define ¡head ¡(car ¡expressions)) (define ¡environment ¡()) ¡ ¡(define ¡tail ¡(cdr ¡expressions)) ¡ ¡(if ¡(null? ¡tail) ¡ ¡ ¡ ¡(evaluate ¡head) (define ¡(make-­‑procedure ¡parameters ¡expressions) ¡ ¡ ¡ ¡(begin ¡ ¡(define ¡lexical-­‑environment ¡environment) ¡ ¡ ¡ ¡ ¡ ¡(evaluate ¡head) (define ¡(bind-­‑variable ¡variable ¡value) ¡ ¡(lambda ¡arguments ¡ ¡ ¡ ¡ ¡ ¡(evaluate-­‑sequence ¡tail)))) ¡ ¡(define ¡binding ¡(cons ¡variable ¡value)) ¡ ¡ ¡ ¡(define ¡dynamic-­‑environment ¡environment) ¡ ¡(set! ¡environment ¡(cons ¡binding ¡environment))) ¡ ¡ ¡ ¡(set! ¡environment ¡lexical-­‑environment) (define ¡(bind-­‑parameters ¡parameters ¡arguments) ¡ ¡ ¡ ¡(bind-­‑parameters ¡parameters ¡arguments) ¡ ¡(if ¡(symbol? ¡parameters) ¡ ¡ ¡ ¡(define ¡value ¡(evaluate-­‑sequence ¡expressions)) ¡ ¡ ¡ ¡(bind-­‑variable ¡parameters ¡arguments) ¡ ¡ ¡ ¡(set! ¡environment ¡dynamic-­‑environment) ¡ ¡ ¡ ¡(if ¡(pair? ¡parameters) ¡ ¡ ¡ ¡value)) ¡ ¡ ¡ ¡ ¡ ¡(begin ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡variable ¡(car ¡parameters)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡value ¡(car ¡arguments ¡)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(bind-­‑variable ¡variable ¡value) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(bind-­‑parameters ¡(cdr ¡parameters) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(cdr ¡arguments)))))) (define ¡(evaluate-­‑application ¡operator) ¡ ¡(lambda ¡operands ¡ ¡ ¡ ¡(apply ¡(evaluate ¡operator) ¡(map ¡evaluate ¡operands)))) 44 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 44

  36. Theo D’Hondt SLIP: a simple language implementation platform SLIP in cps ¡ ¡ ¡ ¡(define ¡(evaluate ¡expression ¡continue) ¡ ¡ ¡ ¡ ¡ ¡(cond ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡((symbol? ¡expression) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(evaluate-­‑variable ¡expression ¡continue)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡((pair? ¡expression) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(let ¡((operator ¡(car ¡expression)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(operands ¡(cdr ¡expression))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡((apply ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(case ¡operator ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡((begin) ¡ ¡evaluate-­‑begin ¡) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡((define) ¡evaluate-­‑define) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡((if) ¡ ¡ ¡ ¡ ¡evaluate-­‑if ¡ ¡ ¡ ¡) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡((lambda) ¡evaluate-­‑lambda) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡((quote) ¡ ¡evaluate-­‑quote ¡) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡((set!) ¡ ¡ ¡evaluate-­‑set! ¡ ¡) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡((while) ¡ ¡evaluate-­‑while ¡) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(else ¡ ¡ ¡ ¡ ¡(evaluate-­‑application ¡operator))) ¡operands) ¡continue))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(else ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(continue ¡expression)))) 45 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 45

  37. Theo D’Hondt SLIP: a simple language implementation platform SLIP in cps ¡ ¡(define ¡environment ¡'()) ¡ ¡(define ¡(loop ¡output) ¡ ¡ ¡ ¡(define ¡rollback ¡environment) ¡ ¡ ¡ ¡(define ¡(evaluate ¡expression ¡continue) ¡ ¡ ¡ ¡ ¡ ¡(cond ¡ ¡ ¡ ¡(define ¡(error ¡message ¡qualifier) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡((symbol? ¡expression) ¡ ¡ ¡ ¡ ¡ ¡(set! ¡environment ¡rollback) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(evaluate-­‑variable ¡expression ¡continue)) ¡ ¡ ¡ ¡ ¡ ¡(display ¡message) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡((pair? ¡expression) ¡ ¡ ¡ ¡ ¡ ¡(loop ¡qualifier)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(let ¡((operator ¡(car ¡expression)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(operands ¡(cdr ¡expression))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡((apply ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(case ¡operator ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡((begin) ¡ ¡evaluate-­‑begin ¡) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡((define) ¡evaluate-­‑define) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡((if) ¡ ¡ ¡ ¡ ¡evaluate-­‑if ¡ ¡ ¡ ¡) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡((lambda) ¡evaluate-­‑lambda) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡((quote) ¡ ¡evaluate-­‑quote ¡) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡((set!) ¡ ¡ ¡evaluate-­‑set! ¡ ¡) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡((while) ¡ ¡evaluate-­‑while ¡) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(else ¡ ¡ ¡ ¡ ¡(evaluate-­‑application ¡operator))) ¡operands) ¡continue))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(else ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(continue ¡expression)))) ¡ ¡ ¡ ¡(display ¡output) ¡ ¡ ¡ ¡(newline) ¡ ¡ ¡ ¡(display ¡">>>") ¡ ¡ ¡ ¡(evaluate ¡(read) ¡loop)) ¡ ¡(loop ¡"Meta-­‑Circular ¡Slip")) 46 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 46

  38. Theo D’Hondt SLIP: a simple language implementation platform SLIP in cps (cont'd) ¡ ¡(define ¡(evaluate-­‑set! ¡variable ¡expression) ¡ ¡ ¡ ¡(lambda ¡(continue) ¡ ¡ ¡ ¡ ¡ ¡(define ¡(continuation ¡value) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡binding ¡(assoc ¡variable ¡environment)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set-­‑cdr! ¡binding ¡value) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(continue ¡value)) ¡ ¡ ¡ ¡ ¡ ¡(evaluate ¡expression ¡continuation))) ➦ ➦ (let ¡((operator ¡(car ¡expression)) ¡ ¡ ¡ ¡ ¡ ¡(operands ¡(cdr ¡expression))) (define ¡(evaluate ¡expression ¡continue) ¡ ¡ ¡ ¡ ¡... ¡ ¡((apply ¡evaluate-­‑set! ¡operands) ¡continue) ¡ ¡ ¡ ¡ ¡... ¡) 47 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 47

  39. Theo D’Hondt SLIP: a simple language implementation platform SLIP in cps (cont'd) ¡ ¡(define ¡(evaluate-­‑set! ¡variable ¡expression) ¡ ¡ ¡ ¡(lambda ¡(continue) ¡ ¡ ¡ ¡ ¡ ¡(define ¡(continuation ¡value) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡binding ¡(assoc ¡variable ¡environment)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set-­‑cdr! ¡binding ¡value) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(continue ¡value)) ¡ ¡ ¡ ¡ ¡ ¡(evaluate ¡expression ¡continuation))) ➦ ➦ currying (let ¡((operator ¡(car ¡expression)) ¡ ¡ ¡ ¡ ¡ ¡(operands ¡(cdr ¡expression))) (define ¡(evaluate ¡expression ¡continue) ¡ ¡ ¡ ¡ ¡... ¡ ¡((apply ¡evaluate-­‑set! ¡operands) ¡continue) ¡ ¡ ¡ ¡ ¡... ¡) 48 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 48

  40. Theo D’Hondt SLIP: a simple language implementation platform SLIP in cps (cont'd) ¡ ¡(define ¡(evaluate-­‑set! ¡variable ¡expression) ¡ ¡ ¡ ¡(lambda ¡(continue) ¡ ¡ ¡ ¡ ¡ ¡(define ¡(continuation ¡value) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡binding ¡(assoc ¡variable ¡environment)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set-­‑cdr! ¡binding ¡value) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(continue ¡value)) ¡ ¡ ¡ ¡ ¡ ¡(evaluate ¡expression ¡continuation))) ➦ ➦ continuation (let ¡((operator ¡(car ¡expression)) ¡ ¡ ¡ ¡ ¡ ¡(operands ¡(cdr ¡expression))) (define ¡(evaluate ¡expression ¡continue) ¡ ¡ ¡ ¡ ¡... ¡ ¡((apply ¡evaluate-­‑set! ¡operands) ¡continue) ¡ ¡ ¡ ¡ ¡... ¡) 49 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 49

  41. Theo D’Hondt SLIP: a simple language implementation platform SLIP in cps (cont'd) ¡ ¡ ¡ ¡(define ¡(wrap-­‑native-­‑procedure ¡native-­‑procedure) ¡ ¡ ¡ ¡ ¡ ¡(lambda ¡(arguments ¡continue) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡native-­‑value ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(apply ¡native-­‑procedure ¡arguments)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(continue ¡native-­‑value))) price to pay ... 50 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 50

  42. Theo D’Hondt SLIP: a simple language implementation platform SLIP in cps (cont'd) ¡ ¡ ¡ ¡(define ¡(evaluate-­‑set! ¡variable ¡expression) ¡ ¡ ¡ ¡ ¡ ¡(lambda ¡(continue ¡environment) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡(continue-­‑after-­‑expression ¡value ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡environment-­‑after-­‑expression) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡binding ¡(assoc ¡variable ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡environment-­‑after-­‑expression)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡binding ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set-­‑cdr! ¡binding ¡value) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(error ¡"inaccessible ¡variable: ¡" ¡variable)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(continue ¡value ¡environment-­‑after-­‑expression)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(evaluate ¡expression ¡continue-­‑after-­‑expression ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡environment))) 51 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 51

  43. Theo D’Hondt SLIP: a simple language implementation platform SLIP in cps (cont'd) ¡ ¡ ¡ ¡(define ¡(evaluate-­‑set! ¡variable ¡expression) ¡ ¡ ¡ ¡ ¡ ¡(lambda ¡(continue ¡environment) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡(continue-­‑after-­‑expression ¡value ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡environment-­‑after-­‑expression) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡binding ¡(assoc ¡variable ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡environment-­‑after-­‑expression)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡binding ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set-­‑cdr! ¡binding ¡value) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(error ¡"inaccessible ¡variable: ¡" ¡variable)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(continue ¡value ¡environment-­‑after-­‑expression)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(evaluate ¡expression ¡continue-­‑after-­‑expression ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡environment))) 52 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 52

  44. Theo D’Hondt SLIP: a simple language implementation platform SLIP in C: continuations ¡ ¡(define ¡(fibonacci ¡n ¡continue) ¡ ¡ ¡ ¡(define ¡(continuation-­‑1 ¡p) ¡ ¡ ¡ ¡ ¡ ¡(define ¡(continuation-­‑2 ¡q) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(continue ¡(+ ¡p ¡q))) ¡ ¡ ¡ ¡ ¡ ¡(fibonacci ¡(-­‑ ¡n ¡2) ¡continuation-­‑2)) ¡ ¡ ¡ ¡(if ¡(> ¡n ¡1) ¡ ¡ ¡ ¡ ¡ ¡(fibonacci ¡(-­‑ ¡n ¡1) ¡continuation-­‑1) ? ¡ ¡ ¡ ¡ ¡ ¡(continue ¡1))) ➜ C (fibonacci ¡15 ¡display) 53 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 53

  45. Theo D’Hondt SLIP: a simple language implementation platform SLIP in C: continuations (cont'd) No nested functions No garbage collection Static & weak typing No proper tail calls 54 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 54

  46. Theo D’Hondt SLIP: a simple language implementation platform SLIP in C: continuations (cont'd) (begin (begin ¡ ¡(define ¡(factorial ¡n) ¡ ¡(define ¡(factorial ¡n ¡continue) ¡ ¡ ¡ ¡(if ¡(> ¡n ¡1) ¡ ¡ ¡ ¡(define ¡(continuation ¡p) ¡ ¡ ¡ ¡ ¡ ¡(* ¡n ¡(factorial ¡(-­‑ ¡n ¡1))) (begin ¡ ¡ ¡ ¡ ¡ ¡(continue ¡(* ¡n ¡p))) ¡ ¡ ¡ ¡ ¡ ¡1)) ¡ ¡(define ¡(continuation ¡p ¡closure) ¡ ¡ ¡ ¡(if ¡(> ¡n ¡1) ¡ ¡(factorial ¡10)) ¡ ¡ ¡ ¡(let* ¡((n ¡(car ¡closure)) ¡ ¡ ¡ ¡ ¡ ¡(factorial ¡(-­‑ ¡n ¡1) ¡continuation) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(continuation ¡(cadr ¡closure)) ¡ ¡ ¡ ¡ ¡ ¡(continue ¡1))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(nested-­‑closure ¡(caddr ¡closure))) ¡ ¡(factorial ¡10 ¡display)) ¡ ¡ ¡ ¡ ¡ ¡(continuation ¡(* ¡n ¡p) ¡nested-­‑closure))) ¡ ¡(define ¡(factorial ¡. ¡closure) ¡ ¡ ¡ ¡(define ¡n ¡(car ¡closure)) ¡ ¡ ¡ ¡(define ¡nested-­‑continuation ¡(cadr ¡closure)) ¡ ¡ ¡ ¡(define ¡nested-­‑closure ¡(caddr ¡closure)) ¡ ¡ ¡ ¡(if ¡(> ¡n ¡1) ¡ ¡ ¡ ¡ ¡ ¡(factorial ¡(-­‑ ¡n ¡1) ¡continuation ¡closure) ¡ ¡ ¡ ¡ ¡ ¡(nested-­‑continuation ¡1 ¡nested-­‑closure))) ¡ ¡ ¡(define ¡(top-­‑continuation ¡p ¡closure) ¡ ¡ ¡ ¡(display ¡p)) ¡ ¡(factorial ¡10 ¡top-­‑continuation ¡'())) 55 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 55

  47. Theo D’Hondt SLIP: a simple language implementation platform SLIP in C: continuations (cont'd) (begin (begin ¡ ¡(define ¡(factorial ¡n) ¡ ¡(define ¡(factorial ¡n ¡continue) ¡ ¡ ¡ ¡(if ¡(> ¡n ¡1) ¡ ¡ ¡ ¡(define ¡(continuation ¡p) ¡ ¡ ¡ ¡ ¡ ¡(* ¡n ¡(factorial ¡(-­‑ ¡n ¡1))) (begin ¡ ¡ ¡ ¡ ¡ ¡(continue ¡(* ¡n ¡p))) ¡ ¡ ¡ ¡ ¡ ¡1)) ¡ ¡(define ¡(continuation ¡p ¡closure) ¡ ¡ ¡ ¡(if ¡(> ¡n ¡1) ¡ ¡(factorial ¡10)) ¡ ¡ ¡ ¡(let* ¡((n ¡(car ¡closure)) ¡ ¡ ¡ ¡ ¡ ¡(factorial ¡(-­‑ ¡n ¡1) ¡continuation) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(continuation ¡(cadr ¡closure)) ¡ ¡ ¡ ¡ ¡ ¡(continue ¡1))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(nested-­‑closure ¡(caddr ¡closure))) ¡ ¡(factorial ¡10 ¡display)) ¡ ¡ ¡ ¡ ¡ ¡(continuation ¡(* ¡n ¡p) ¡nested-­‑closure))) ¡ ¡(define ¡(factorial ¡. ¡closure) ¡ ¡ ¡ ¡(define ¡n ¡(car ¡closure)) ¡ ¡ ¡ ¡(define ¡nested-­‑continuation ¡(cadr ¡closure)) ¡ ¡ ¡ ¡(define ¡nested-­‑closure ¡(caddr ¡closure)) ¡ ¡ ¡ ¡(if ¡(> ¡n ¡1) ¡ ¡ ¡ ¡ ¡ ¡(factorial ¡(-­‑ ¡n ¡1) ¡continuation ¡closure) ¡ ¡ ¡ ¡ ¡ ¡(nested-­‑continuation ¡1 ¡nested-­‑closure))) ¡ ¡ ¡(define ¡(top-­‑continuation ¡p ¡closure) ¡ ¡ ¡ ¡(display ¡p)) ¡ ¡(factorial ¡10 ¡top-­‑continuation ¡'())) 56 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 56

  48. Theo D’Hondt SLIP: a simple language implementation platform SLIP in C: continuations (cont'd) (begin (begin ¡ ¡(define ¡(factorial ¡n) ¡ ¡(define ¡(factorial ¡n ¡continue) ¡ ¡ ¡ ¡(if ¡(> ¡n ¡1) ¡ ¡ ¡ ¡(define ¡(continuation ¡p) ¡ ¡ ¡ ¡ ¡ ¡(* ¡n ¡(factorial ¡(-­‑ ¡n ¡1))) (begin ¡ ¡ ¡ ¡ ¡ ¡(continue ¡(* ¡n ¡p))) ¡ ¡ ¡ ¡ ¡ ¡1)) ¡ ¡(define ¡(continuation ¡p ¡closure) ¡ ¡ ¡ ¡(if ¡(> ¡n ¡1) ¡ ¡(factorial ¡10)) ¡ ¡ ¡ ¡(let* ¡((n ¡(car ¡closure)) ¡ ¡ ¡ ¡ ¡ ¡(factorial ¡(-­‑ ¡n ¡1) ¡continuation) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(continuation ¡(cadr ¡closure)) ¡ ¡ ¡ ¡ ¡ ¡(continue ¡1))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(nested-­‑closure ¡(caddr ¡closure))) requires ad-hoc ¡ ¡(factorial ¡10 ¡display)) ¡ ¡ ¡ ¡ ¡ ¡(continuation ¡(* ¡n ¡p) ¡nested-­‑closure))) ¡ ¡(define ¡(factorial ¡. ¡closure) closures ¡ ¡ ¡ ¡(define ¡n ¡(car ¡closure)) ¡ ¡ ¡ ¡(define ¡nested-­‑continuation ¡(cadr ¡closure)) ¡ ¡ ¡ ¡(define ¡nested-­‑closure ¡(caddr ¡closure)) ¡ ¡ ¡ ¡(if ¡(> ¡n ¡1) ¡ ¡ ¡ ¡ ¡ ¡(factorial ¡(-­‑ ¡n ¡1) ¡continuation ¡closure) ¡ ¡ ¡ ¡ ¡ ¡(nested-­‑continuation ¡1 ¡nested-­‑closure))) ¡ ¡ ¡(define ¡(top-­‑continuation ¡p ¡closure) ¡ ¡ ¡ ¡(display ¡p)) ¡ ¡(factorial ¡10 ¡top-­‑continuation ¡'())) 57 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 57

  49. Theo D’Hondt SLIP: a simple language implementation platform Ad hoc continuations in C #include ¡<stdio.h> #include ¡<stdlib.h> static ¡int ¡factorial(int ¡n) closure ¡ ¡{ ¡if ¡(n ¡> ¡1) ¡ ¡ ¡ ¡ ¡ ¡return ¡n ¡* ¡factorial(n ¡-­‑ ¡1); number ¡ ¡ ¡ ¡else ¡ ¡ ¡ ¡ ¡ ¡return ¡1; ¡} continuation closure typedef ¡ ¡struct ¡cl ¡* ¡clos; ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ typedef ¡ ¡ ¡void ¡(* ¡cont)(int, ¡clos); ¡ ¡ typedef ¡ ¡struct ¡cl ¡{ ¡int ¡n; ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡cont ¡continuation; ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡clos ¡closure; ¡} ¡cl; static ¡clos ¡make_closure(int ¡n, ¡cont ¡continuation, ¡clos ¡closure) ¡ ¡{ ¡clos ¡new_closure ¡= ¡malloc(sizeof(cl)); ¡ ¡ ¡ ¡new_closure-­‑>n ¡= ¡n; ¡ ¡ ¡ ¡new_closure-­‑>continuation ¡= ¡continuation; ¡ ¡ ¡ ¡new_closure-­‑>closure ¡= ¡closure; ¡ ¡ ¡ ¡return ¡new_closure; ¡} 58 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 58

  50. Theo D’Hondt SLIP: a simple language implementation platform Ad hoc continuations in C (cont'd) static ¡void ¡continuation(int ¡p, ¡clos ¡closure) ¡ ¡{ ¡int ¡n ¡= ¡closure-­‑>n; ¡ ¡ ¡ ¡cont ¡continuation ¡= ¡closure-­‑>continuation; ¡ ¡ ¡ ¡clos ¡nested_closure ¡= ¡closure-­‑>closure; ¡ ¡ ¡ ¡free(closure); ¡ ¡ ¡ ¡continuation(n ¡* ¡p, ¡nested_closure); ¡} ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ static ¡void ¡c_factorial(clos ¡closure) ¡ ¡{ ¡int ¡n ¡= ¡closure-­‑>n; ¡ ¡ ¡ ¡cont ¡nested_continuation ¡= ¡closure-­‑>continuation; ¡ ¡ ¡ ¡clos ¡nested_closure ¡= ¡closure-­‑>closure; ¡ ¡ ¡ ¡if ¡(n ¡> ¡1) ¡ ¡ ¡ ¡ ¡ ¡c_factorial(make_closure(n ¡-­‑ ¡1, ¡continuation, ¡closure)); ¡ ¡ ¡ ¡else ¡ ¡ ¡ ¡ ¡ ¡nested_continuation(1, ¡nested_closure); ¡} static ¡void ¡top_continuation(int ¡p, ¡clos ¡closure) ¡ ¡{ ¡printf("c_factorial(10) ¡= ¡%d\n", ¡p); ¡} int ¡main ¡(int ¡argc, ¡const ¡char ¡* ¡argv[]) ¡ ¡{ ¡printf("factorial(10) ¡ ¡ ¡= ¡%d\n", ¡factorial(10)); ¡ ¡ ¡ ¡c_factorial(make_closure(10, ¡top_continuation, ¡(clos)0)); ¡ ¡ ¡ ¡return ¡0; ¡} 59 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 59

  51. Theo D’Hondt SLIP: a simple language implementation platform Ad hoc continuations in C (cont'd) static ¡void ¡continuation(int ¡p, ¡clos ¡closure) ¡ ¡{ ¡int ¡n ¡= ¡closure-­‑>n; ¡ ¡ ¡ ¡cont ¡continuation ¡= ¡closure-­‑>continuation; ¡ ¡ ¡ ¡clos ¡nested_closure ¡= ¡closure-­‑>closure; ¡ ¡ ¡ ¡free(closure); ¡ ¡ ¡ ¡continuation(n ¡* ¡p, ¡nested_closure); ¡} ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ static ¡void ¡c_factorial(clos ¡closure) ¡ ¡{ ¡int ¡n ¡= ¡closure-­‑>n; ¡ ¡ ¡ ¡cont ¡nested_continuation ¡= ¡closure-­‑>continuation; ¡ ¡ ¡ ¡clos ¡nested_closure ¡= ¡closure-­‑>closure; ¡ ¡ ¡ ¡if ¡(n ¡> ¡1) ¡ ¡ ¡ ¡ ¡ ¡c_factorial(make_closure(n ¡-­‑ ¡1, ¡continuation, ¡closure)); ¡ ¡ ¡ ¡else ¡ ¡ ¡ ¡ ¡ ¡nested_continuation(1, ¡nested_closure); ¡} static ¡void ¡top_continuation(int ¡p, ¡clos ¡closure) ¡ ¡{ ¡printf("c_factorial(10) ¡= ¡%d\n", ¡p); ¡} int ¡main ¡(int ¡argc, ¡const ¡char ¡* ¡argv[]) ¡ ¡{ ¡printf("factorial(10) ¡ ¡ ¡= ¡%d\n", ¡factorial(10)); ¡ ¡ ¡ ¡c_factorial(make_closure(10, ¡top_continuation, ¡(clos)0)); ¡ ¡ ¡ ¡return ¡0; ¡} 60 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 60

  52. Theo D’Hondt SLIP: a simple language implementation platform Ad hoc continuations in C (cont'd) static ¡void ¡continuation(int ¡p, ¡clos ¡closure) ¡ ¡{ ¡int ¡n ¡= ¡closure-­‑>n; ¡ ¡ ¡ ¡cont ¡continuation ¡= ¡closure-­‑>continuation; ¡ ¡ ¡ ¡clos ¡nested_closure ¡= ¡closure-­‑>closure; ¡ ¡ ¡ ¡free(closure); ¡ ¡ ¡ ¡continuation(n ¡* ¡p, ¡nested_closure); ¡} ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ static ¡void ¡c_factorial(clos ¡closure) ¡ ¡{ ¡int ¡n ¡= ¡closure-­‑>n; ¡ ¡ ¡ ¡cont ¡nested_continuation ¡= ¡closure-­‑>continuation; ¡ ¡ ¡ ¡clos ¡nested_closure ¡= ¡closure-­‑>closure; ¡ ¡ ¡ ¡if ¡(n ¡> ¡1) ¡ ¡ ¡ ¡ ¡ ¡c_factorial(make_closure(n ¡-­‑ ¡1, ¡continuation, ¡closure)); ¡ ¡ ¡ ¡else ¡ ¡ ¡ ¡ ¡ ¡nested_continuation(1, ¡nested_closure); ¡} static ¡void ¡top_continuation(int ¡p, ¡clos ¡closure) ¡ ¡{ ¡printf("c_factorial(10) ¡= ¡%d\n", ¡p); ¡} int ¡main ¡(int ¡argc, ¡const ¡char ¡* ¡argv[]) ¡ ¡{ ¡printf("factorial(10) ¡ ¡ ¡= ¡%d\n", ¡factorial(10)); ¡ ¡ ¡ ¡c_factorial(make_closure(10, ¡top_continuation, ¡(clos)0)); ¡ ¡ ¡ ¡return ¡0; ¡} 61 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 61

  53. Theo D’Hondt SLIP: a simple language implementation platform Incremental SLIP implementation in C version 1: straightforward code version 2: using a trampoline version 3: factored out environment version 4: threaded continuations version 5: functional continuations version 6: partial evaluation version 7: iterative constructs version 8: lexical addressing version 9: garbage collection version 10: proper tail recursion version 11: 1st class continuations version 12: smart caching version 13: multicores 62 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 62

  54. Theo D’Hondt SLIP: a simple language implementation platform SLIP/C client interface ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡/*-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑*/ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡/* ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡>>>Slip<<< ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡*/ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡/* ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Theo ¡D'Hondt ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡*/ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡/* ¡ ¡ ¡ ¡ ¡VUB ¡Software ¡Languages ¡Lab ¡ ¡ ¡ ¡*/ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡/* ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(c) ¡2010 ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡*/ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡/*-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑*/ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡/* ¡ ¡version ¡1: ¡straightforward ¡code ¡ ¡*/ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡/*-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑*/ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡/* ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Slip ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡*/ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡/*-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑*/ /*-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑ ¡imported ¡functions ¡-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑*/ void ¡Slip_Load(char ¡ ¡*, ¡char ¡**); void ¡Slip_Print(char ¡ ¡*); void ¡Slip_Read(char ¡**); /*-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑ ¡exported ¡functions ¡-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑-­‑*/ void ¡Slip_REP(char ¡ ¡*, ¡int ¡ ¡ ¡ ¡); 63 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 63

  55. Theo D’Hondt SLIP: a simple language implementation platform SLIP/C example 64 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 64

  56. Theo D’Hondt SLIP: a simple language implementation platform SLIP/C ultimate implementation client ! ! scan pool main print thread stack read grammar evaluate context dictionary compile memory native environment 65 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 65

  57. Theo D’Hondt SLIP: a simple language implementation platform SLIP/C initial implementation client ! ! scan pool main print read grammar evaluate dictionary memory native 66 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 66

  58. Theo D’Hondt SLIP: a simple language implementation platform SLIP/C initial implementation (cont'd) client ! ! scan pool main print read grammar evaluate dictionary memory native 67 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 67

  59. Theo D’Hondt SLIP: a simple language implementation platform SLIP/C initial implementation (cont'd) client ! 347 + 37 loc 58 + 15 loc 179 + 66 loc ! 214 + 17 loc scan pool main print 1435 + 24 loc read grammar evaluate 198 + 15 loc 296 + 171 loc 63 + 26 loc dictionary memory native x + y loc 2071 + 14 loc 5347 loc 68 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 68

  60. Theo D’Hondt SLIP: a simple language implementation platform SLIP/C first stage client ! ! scan pool main print read grammar evaluate dictionary memory native version 1: straightforward cps implementation 69 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 69

  61. Theo D’Hondt SLIP: a simple language implementation platform SLIP/C first stage (cont'd) client ! ! scan pool main print read grammar evaluate dictionary memory native version 2: introducing a trampoline 70 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 70

  62. Theo D’Hondt SLIP: a simple language implementation platform SLIP/C first stage (cont'd) client ! ! scan pool main print read grammar evaluate dictionary memory native version 3: factored out environment 71 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 71

  63. Theo D’Hondt SLIP: a simple language implementation platform SLIP/C second stage client ! ! scan pool main print thread read grammar evaluate dictionary memory native version 4: threaded continuations 72 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 72

  64. Theo D’Hondt SLIP: a simple language implementation platform SLIP/C second stage (cont'd) client ! ! scan pool main print thread read grammar evaluate dictionary memory native version 5: functional continuations 73 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 73

  65. Theo D’Hondt SLIP: a simple language implementation platform SLIP/C third stage client ! ! scan pool main print thread read grammar evaluate dictionary compile memory native version 6: partial evaluation 74 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 74

  66. Theo D’Hondt SLIP: a simple language implementation platform SLIP/C third stage (cont'd) client ! ! scan pool main print thread read grammar evaluate dictionary compile memory native version 7: iterative constructs 75 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 75

  67. Theo D’Hondt SLIP: a simple language implementation platform SLIP/C fourth stage client ! ! scan pool main print thread read grammar evaluate dictionary compile memory native environment version 8: lexical addressing 76 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 76

  68. Theo D’Hondt SLIP: a simple language implementation platform SLIP/C fifth stage client ! ! scan pool main print thread stack read grammar evaluate dictionary compile memory native environment version 9: garbage collection 77 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 77

  69. Theo D’Hondt SLIP: a simple language implementation platform SLIP/C fifth stage (cont'd) client ! ! scan pool main print thread stack read grammar evaluate dictionary compile memory native environment version 10: proper tail recursion 78 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 78

  70. Theo D’Hondt SLIP: a simple language implementation platform SLIP/C fifth stage (cont'd) client ! ! scan pool main print thread stack read grammar evaluate dictionary compile memory native environment version 11: first class continuations 79 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 79

  71. Theo D’Hondt SLIP: a simple language implementation platform SLIP/C fifth stage (cont'd) client ! ! scan pool main print thread stack read grammar evaluate dictionary compile memory native environment version 12: smart caches 80 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 80

  72. Theo D’Hondt SLIP: a simple language implementation platform SLIP/C new stage client ! ! scan pool main print thread stack read grammar evaluate context dictionary compile memory native environment version 13: multicore support 81 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 81

  73. Theo D’Hondt SLIP: a simple language implementation platform SLIP/C implementation size 90,0 67,5 45,0 10000 22,5 7500 0 1 2 3 4 5 6 7 8 9 10 11 12 13 code size (kb) 5000 2500 0 1 2 3 4 5 6 7 8 9 10 11 12 13 source size (loc) 82 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 82

  74. Theo D’Hondt SLIP: a simple language implementation platform Multicore memory management BYT_type ¡Memory_Claim(UNS_type ¡Claim) ¡ ¡{ ¡BYT_type ¡overflow; ¡ ¡ ¡ ¡Slip_Spin_Lock(Memory_lock); ¡ ¡ ¡ ¡Claim_size ¡+= ¡Claim ¡+ ¡1; ¡ ¡ ¡ ¡Claim_counter++; ¡ ¡ ¡ ¡overflow ¡= ¡(Tail_pointer ¡-­‑ ¡Free_pointer ¡<= ¡Claim_size); ¡ ¡ ¡ ¡ if ¡(overflow) ¡ ¡ ¡ ¡ ¡ ¡{ ¡collect(); ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ if ¡(Tail_pointer ¡-­‑ ¡Free_pointer ¡<= ¡Claim_size) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Memory_Fail(); ¡} ¡ ¡ ¡ ¡Slip_Spin_Unlock(Memory_lock); PTR_type ¡Memory_Make_Chunk(BYT_type ¡Tag, ¡ ¡ ¡ ¡ return ¡overflow; ¡} ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡UNS_type ¡Size) ¡ ¡{ ¡PTR_type ¡pointer; ¡ ¡ ¡ ¡UNS_type ¡size; ¡ ¡ ¡ ¡size ¡= ¡Size ¡+ ¡1; ¡ ¡ ¡ ¡Slip_Spin_Lock(Memory_lock); ¡ ¡ ¡ ¡ if ¡(size ¡> ¡Claim_size) ¡ ¡ ¡ ¡ ¡ ¡Memory_Fail(); ¡ ¡ ¡ ¡pointer ¡= ¡Free_pointer; ¡ ¡ ¡ ¡Free_pointer ¡+= ¡size; ¡ ¡ ¡ ¡Slip_Spin_Unlock(Memory_lock); ¡ ¡ ¡ ¡pointer-­‑>cel ¡= ¡make_header(Tag, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Size); NIL_type ¡Memory_Release(UNS_type ¡Claim) ¡ ¡ ¡ ¡ return ¡pointer; ¡} ¡ ¡{ ¡Slip_Spin_Lock(Memory_lock); ¡ ¡ ¡ ¡Claim_size ¡-­‑= ¡Claim ¡+ ¡1; ¡ ¡ ¡ ¡Claim_counter-­‑-­‑; ¡ ¡ ¡ ¡Slip_Spin_Unlock(Memory_lock); ¡} 83 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 83

  75. Theo D’Hondt SLIP: a simple language implementation platform Multicore memory management BYT_type ¡Memory_Claim(UNS_type ¡Claim) ¡ ¡{ ¡BYT_type ¡overflow; ¡ ¡ ¡ ¡Slip_Spin_Lock(Memory_lock); ¡ ¡ ¡ ¡Claim_size ¡+= ¡Claim ¡+ ¡1; ¡ ¡ ¡ ¡Claim_counter++; ¡ ¡ ¡ ¡overflow ¡= ¡(Tail_pointer ¡-­‑ ¡Free_pointer ¡<= ¡Claim_size); ¡ ¡ ¡ ¡ if ¡(overflow) ¡ ¡ ¡ ¡ ¡ ¡{ ¡collect(); ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ if ¡(Tail_pointer ¡-­‑ ¡Free_pointer ¡<= ¡Claim_size) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Memory_Fail(); ¡} ¡ ¡ ¡ ¡Slip_Spin_Unlock(Memory_lock); PTR_type ¡Memory_Make_Chunk(BYT_type ¡Tag, ¡ ¡ ¡ ¡ return ¡overflow; ¡} ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡UNS_type ¡Size) ¡ ¡{ ¡PTR_type ¡pointer; ¡ ¡ ¡ ¡UNS_type ¡size; ¡ ¡ ¡ ¡size ¡= ¡Size ¡+ ¡1; ¡ ¡ ¡ ¡Slip_Spin_Lock(Memory_lock); ¡ ¡ ¡ ¡ if ¡(size ¡> ¡Claim_size) ¡ ¡ ¡ ¡ ¡ ¡Memory_Fail(); ¡ ¡ ¡ ¡pointer ¡= ¡Free_pointer; ¡ ¡ ¡ ¡Free_pointer ¡+= ¡size; ¡ ¡ ¡ ¡Slip_Spin_Unlock(Memory_lock); ¡ ¡ ¡ ¡pointer-­‑>cel ¡= ¡make_header(Tag, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Size); NIL_type ¡Memory_Release(UNS_type ¡Claim) ¡ ¡ ¡ ¡ return ¡pointer; ¡} ¡ ¡{ ¡Slip_Spin_Lock(Memory_lock); ¡ ¡ ¡ ¡Claim_size ¡-­‑= ¡Claim ¡+ ¡1; ¡ ¡ ¡ ¡Claim_counter-­‑-­‑; ¡ ¡ ¡ ¡Slip_Spin_Unlock(Memory_lock); ¡} 84 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 84

  76. Theo D’Hondt SLIP: a simple language implementation platform Multicore memory management BYT_type ¡Memory_Claim(UNS_type ¡Claim) ¡ ¡{ ¡BYT_type ¡overflow; ¡ ¡ ¡ ¡Slip_Spin_Lock(Memory_lock); ¡ ¡ ¡ ¡Claim_size ¡+= ¡Claim ¡+ ¡1; ¡ ¡ ¡ ¡Claim_counter++; ¡ ¡ ¡ ¡overflow ¡= ¡(Tail_pointer ¡-­‑ ¡Free_pointer ¡<= ¡Claim_size); ¡ ¡ ¡ ¡ if ¡(overflow) ¡ ¡ ¡ ¡ ¡ ¡{ ¡collect(); ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ if ¡(Tail_pointer ¡-­‑ ¡Free_pointer ¡<= ¡Claim_size) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Memory_Fail(); ¡} ¡ ¡ ¡ ¡Slip_Spin_Unlock(Memory_lock); PTR_type ¡Memory_Make_Chunk(BYT_type ¡Tag, ¡ ¡ ¡ ¡ return ¡overflow; ¡} ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡UNS_type ¡Size) ¡ ¡{ ¡PTR_type ¡pointer; ¡ ¡ ¡ ¡UNS_type ¡size; ¡ ¡ ¡ ¡size ¡= ¡Size ¡+ ¡1; ¡ ¡ ¡ ¡Slip_Spin_Lock(Memory_lock); ¡ ¡ ¡ ¡ if ¡(size ¡> ¡Claim_size) ¡ ¡ ¡ ¡ ¡ ¡Memory_Fail(); ¡ ¡ ¡ ¡pointer ¡= ¡Free_pointer; ¡ ¡ ¡ ¡Free_pointer ¡+= ¡size; ¡ ¡ ¡ ¡Slip_Spin_Unlock(Memory_lock); ¡ ¡ ¡ ¡pointer-­‑>cel ¡= ¡make_header(Tag, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Size); NIL_type ¡Memory_Release(UNS_type ¡Claim) ¡ ¡ ¡ ¡ return ¡pointer; ¡} ¡ ¡{ ¡Slip_Spin_Lock(Memory_lock); ¡ ¡ ¡ ¡Claim_size ¡-­‑= ¡Claim ¡+ ¡1; ¡ ¡ ¡ ¡Claim_counter-­‑-­‑; ¡ ¡ ¡ ¡Slip_Spin_Unlock(Memory_lock); ¡} 85 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 85

  77. Theo D’Hondt SLIP: a simple language implementation platform Multicore memory management BYT_type ¡Memory_Claim(UNS_type ¡Claim) ¡ ¡{ ¡BYT_type ¡overflow; ¡ ¡ ¡ ¡Slip_Spin_Lock(Memory_lock); ¡ ¡ ¡ ¡Claim_size ¡+= ¡Claim ¡+ ¡1; ¡ ¡ ¡ ¡Claim_counter++; ¡ ¡ ¡ ¡overflow ¡= ¡(Tail_pointer ¡-­‑ ¡Free_pointer ¡<= ¡Claim_size); ¡ ¡ ¡ ¡ if ¡(overflow) ¡ ¡ ¡ ¡ ¡ ¡{ ¡collect(); ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ if ¡(Tail_pointer ¡-­‑ ¡Free_pointer ¡<= ¡Claim_size) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Memory_Fail(); ¡} ¡ ¡ ¡ ¡Slip_Spin_Unlock(Memory_lock); PTR_type ¡Memory_Make_Chunk(BYT_type ¡Tag, ¡ ¡ ¡ ¡ return ¡overflow; ¡} ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡UNS_type ¡Size) ¡ ¡{ ¡PTR_type ¡pointer; ¡ ¡ ¡ ¡UNS_type ¡size; ¡ ¡ ¡ ¡size ¡= ¡Size ¡+ ¡1; ¡ ¡ ¡ ¡Slip_Spin_Lock(Memory_lock); ¡ ¡ ¡ ¡ if ¡(size ¡> ¡Claim_size) ¡ ¡ ¡ ¡ ¡ ¡Memory_Fail(); ¡ ¡ ¡ ¡pointer ¡= ¡Free_pointer; ¡ ¡ ¡ ¡Free_pointer ¡+= ¡size; ¡ ¡ ¡ ¡Slip_Spin_Unlock(Memory_lock); ¡ ¡ ¡ ¡pointer-­‑>cel ¡= ¡make_header(Tag, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Size); NIL_type ¡Memory_Release(UNS_type ¡Claim) ¡ ¡ ¡ ¡ return ¡pointer; ¡} ¡ ¡{ ¡Slip_Spin_Lock(Memory_lock); ¡ ¡ ¡ ¡Claim_size ¡-­‑= ¡Claim ¡+ ¡1; ¡ ¡ ¡ ¡Claim_counter-­‑-­‑; ¡ ¡ ¡ ¡Slip_Spin_Unlock(Memory_lock); ¡} 86 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 86

  78. Theo D’Hondt SLIP: a simple language implementation platform SLIP/C multicore quicksort ¡ ¡(define ¡(Sort ¡V ¡Low ¡High ¡Recurse) ¡ ¡ ¡ ¡(define ¡Left ¡Low) ¡ ¡ ¡ ¡(define ¡Right ¡High) ¡ ¡ ¡ ¡(define ¡Pivot ¡(vector-­‑ref ¡V ¡(quotient ¡(+ ¡Left ¡Right) ¡2))) ¡ ¡ ¡ ¡(define ¡Save ¡0) ¡ ¡(define ¡(SingleCore-­‑QuickSort ¡V ¡Low ¡High) ¡ ¡ ¡ ¡(while ¡(< ¡Left ¡Right) ¡ ¡ ¡ ¡(define ¡(SingleCore-­‑Recurse ¡Left ¡Right) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(while ¡(< ¡(vector-­‑ref ¡V ¡Left) ¡Pivot) ¡ ¡ ¡ ¡ ¡ ¡(if ¡(< ¡Low ¡Right) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡Left ¡(+ ¡Left ¡1))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(SingleCore-­‑QuickSort ¡V ¡Low ¡Right)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(while ¡(> ¡(vector-­‑ref ¡V ¡Right) ¡Pivot) ¡ ¡ ¡ ¡ ¡ ¡(if ¡(> ¡High ¡Left) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡Right ¡(-­‑ ¡Right ¡1))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(SingleCore-­‑QuickSort ¡V ¡Left ¡High))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(<= ¡Left ¡Right) ¡ ¡ ¡ ¡(Sort ¡V ¡Low ¡High ¡SingleCore-­‑Recurse)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(begin ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡Save ¡(vector-­‑ref ¡V ¡Left)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(vector-­‑set! ¡V ¡Left ¡(vector-­‑ref ¡V ¡Right)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(vector-­‑set! ¡V ¡Right ¡Save) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡Left ¡(+ ¡Left ¡1)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡Right ¡(-­‑ ¡Right ¡1))))) ¡ ¡(define ¡(MultiCore-­‑QuickSort ¡Depth ¡V ¡Low ¡High) ¡ ¡ ¡ ¡(Recurse ¡Left ¡Right)) ¡ ¡ ¡ ¡(define ¡(MultiCore-­‑Recurse ¡Left ¡Right) ¡ ¡ ¡ ¡ ¡ ¡(if ¡(> ¡Depth ¡0) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(begin ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡promise ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(< ¡Low ¡Right) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(spawn ¡(MultiCore-­‑QuickSort ¡(-­‑ ¡Depth ¡1) ¡V ¡Low ¡Right)))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(> ¡High ¡Left) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(MultiCore-­‑QuickSort ¡(-­‑ ¡Depth ¡1) ¡V ¡Left ¡High)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(sync ¡promise)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(SingleCore-­‑QuickSort ¡V ¡Low ¡High))) ¡ ¡ ¡ ¡(Sort ¡V ¡Low ¡High ¡MultiCore-­‑Recurse)) 87 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 87

  79. Theo D’Hondt SLIP: a simple language implementation platform SLIP/C multicore quicksort (cont'd) ¡ ¡(define ¡(Sort ¡V ¡Low ¡High ¡Recurse) ¡ ¡ ¡ ¡(define ¡Left ¡Low) ¡ ¡ ¡ ¡(define ¡Right ¡High) ¡ ¡ ¡ ¡(define ¡Pivot ¡(vector-­‑ref ¡V ¡(quotient ¡(+ ¡Left ¡Right) ¡2))) ¡ ¡ ¡ ¡(define ¡Save ¡0) ¡ ¡(define ¡(SingleCore-­‑QuickSort ¡V ¡Low ¡High) ¡ ¡ ¡ ¡(while ¡(< ¡Left ¡Right) ¡ ¡ ¡ ¡(define ¡(SingleCore-­‑Recurse ¡Left ¡Right) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(while ¡(< ¡(vector-­‑ref ¡V ¡Left) ¡Pivot) ¡ ¡ ¡ ¡ ¡ ¡(if ¡(< ¡Low ¡Right) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡Left ¡(+ ¡Left ¡1))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(SingleCore-­‑QuickSort ¡V ¡Low ¡Right)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(while ¡(> ¡(vector-­‑ref ¡V ¡Right) ¡Pivot) ¡ ¡ ¡ ¡ ¡ ¡(if ¡(> ¡High ¡Left) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡Right ¡(-­‑ ¡Right ¡1))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(SingleCore-­‑QuickSort ¡V ¡Left ¡High))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(<= ¡Left ¡Right) ¡ ¡ ¡ ¡(Sort ¡V ¡Low ¡High ¡SingleCore-­‑Recurse)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(begin ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡Save ¡(vector-­‑ref ¡V ¡Left)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(vector-­‑set! ¡V ¡Left ¡(vector-­‑ref ¡V ¡Right)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(vector-­‑set! ¡V ¡Right ¡Save) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡Left ¡(+ ¡Left ¡1)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡Right ¡(-­‑ ¡Right ¡1))))) ¡ ¡(define ¡(MultiCore-­‑QuickSort ¡Depth ¡V ¡Low ¡High) ¡ ¡ ¡ ¡(Recurse ¡Left ¡Right)) ¡ ¡ ¡ ¡(define ¡(MultiCore-­‑Recurse ¡Left ¡Right) ¡ ¡ ¡ ¡ ¡ ¡(if ¡(> ¡Depth ¡0) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(begin ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡promise ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(< ¡Low ¡Right) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(spawn ¡(MultiCore-­‑QuickSort ¡(-­‑ ¡Depth ¡1) ¡V ¡Low ¡Right)))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(> ¡High ¡Left) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(MultiCore-­‑QuickSort ¡(-­‑ ¡Depth ¡1) ¡V ¡Left ¡High)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(sync ¡promise)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(SingleCore-­‑QuickSort ¡V ¡Low ¡High))) ¡ ¡ ¡ ¡(Sort ¡V ¡Low ¡High ¡MultiCore-­‑Recurse)) 88 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 88

  80. Theo D’Hondt SLIP: a simple language implementation platform SLIP/C multicore quicksort (cont'd) ¡ ¡(define ¡(Sort ¡V ¡Low ¡High ¡Recurse) ¡ ¡ ¡ ¡(define ¡Left ¡Low) ¡ ¡ ¡ ¡(define ¡Right ¡High) ¡ ¡ ¡ ¡(define ¡Pivot ¡(vector-­‑ref ¡V ¡(quotient ¡(+ ¡Left ¡Right) ¡2))) ¡ ¡ ¡ ¡(define ¡Save ¡0) ¡ ¡(define ¡(SingleCore-­‑QuickSort ¡V ¡Low ¡High) ¡ ¡ ¡ ¡(while ¡(< ¡Left ¡Right) ¡ ¡ ¡ ¡(define ¡(SingleCore-­‑Recurse ¡Left ¡Right) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(while ¡(< ¡(vector-­‑ref ¡V ¡Left) ¡Pivot) ¡ ¡ ¡ ¡ ¡ ¡(if ¡(< ¡Low ¡Right) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡Left ¡(+ ¡Left ¡1))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(SingleCore-­‑QuickSort ¡V ¡Low ¡Right)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(while ¡(> ¡(vector-­‑ref ¡V ¡Right) ¡Pivot) ¡ ¡ ¡ ¡ ¡ ¡(if ¡(> ¡High ¡Left) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡Right ¡(-­‑ ¡Right ¡1))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(SingleCore-­‑QuickSort ¡V ¡Left ¡High))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(<= ¡Left ¡Right) ¡ ¡ ¡ ¡(Sort ¡V ¡Low ¡High ¡SingleCore-­‑Recurse)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(begin ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡Save ¡(vector-­‑ref ¡V ¡Left)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(vector-­‑set! ¡V ¡Left ¡(vector-­‑ref ¡V ¡Right)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(vector-­‑set! ¡V ¡Right ¡Save) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡Left ¡(+ ¡Left ¡1)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡Right ¡(-­‑ ¡Right ¡1))))) ¡ ¡(define ¡(MultiCore-­‑QuickSort ¡Depth ¡V ¡Low ¡High) ¡ ¡ ¡ ¡(Recurse ¡Left ¡Right)) ¡ ¡ ¡ ¡(define ¡(MultiCore-­‑Recurse ¡Left ¡Right) ¡ ¡ ¡ ¡ ¡ ¡(if ¡(> ¡Depth ¡0) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(begin ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡promise ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(< ¡Low ¡Right) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(spawn ¡(MultiCore-­‑QuickSort ¡(-­‑ ¡Depth ¡1) ¡V ¡Low ¡Right)))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(> ¡High ¡Left) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(MultiCore-­‑QuickSort ¡(-­‑ ¡Depth ¡1) ¡V ¡Left ¡High)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(sync ¡promise)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(SingleCore-­‑QuickSort ¡V ¡Low ¡High))) ¡ ¡ ¡ ¡(Sort ¡V ¡Low ¡High ¡MultiCore-­‑Recurse)) 89 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 89

  81. Theo D’Hondt SLIP: a simple language implementation platform SLIP/C multicore quicksort (cont'd) ¡ ¡(define ¡(Sort ¡V ¡Low ¡High ¡Recurse) ¡ ¡ ¡ ¡(define ¡Left ¡Low) ¡ ¡ ¡ ¡(define ¡Right ¡High) ¡ ¡ ¡ ¡(define ¡Pivot ¡(vector-­‑ref ¡V ¡(quotient ¡(+ ¡Left ¡Right) ¡2))) ¡ ¡ ¡ ¡(define ¡Save ¡0) ¡ ¡(define ¡(SingleCore-­‑QuickSort ¡V ¡Low ¡High) ¡ ¡ ¡ ¡(while ¡(< ¡Left ¡Right) ¡ ¡ ¡ ¡(define ¡(SingleCore-­‑Recurse ¡Left ¡Right) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(while ¡(< ¡(vector-­‑ref ¡V ¡Left) ¡Pivot) ¡ ¡ ¡ ¡ ¡ ¡(if ¡(< ¡Low ¡Right) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡Left ¡(+ ¡Left ¡1))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(SingleCore-­‑QuickSort ¡V ¡Low ¡Right)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(while ¡(> ¡(vector-­‑ref ¡V ¡Right) ¡Pivot) ¡ ¡ ¡ ¡ ¡ ¡(if ¡(> ¡High ¡Left) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡Right ¡(-­‑ ¡Right ¡1))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(SingleCore-­‑QuickSort ¡V ¡Left ¡High))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(<= ¡Left ¡Right) ¡ ¡ ¡ ¡(Sort ¡V ¡Low ¡High ¡SingleCore-­‑Recurse)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(begin ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡Save ¡(vector-­‑ref ¡V ¡Left)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(vector-­‑set! ¡V ¡Left ¡(vector-­‑ref ¡V ¡Right)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(vector-­‑set! ¡V ¡Right ¡Save) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡Left ¡(+ ¡Left ¡1)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡Right ¡(-­‑ ¡Right ¡1))))) ¡ ¡(define ¡(MultiCore-­‑QuickSort ¡Depth ¡V ¡Low ¡High) ¡ ¡ ¡ ¡(Recurse ¡Left ¡Right)) ¡ ¡ ¡ ¡(define ¡(MultiCore-­‑Recurse ¡Left ¡Right) ¡ ¡ ¡ ¡ ¡ ¡(if ¡(> ¡Depth ¡0) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(begin ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡promise ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(< ¡Low ¡Right) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(spawn ¡(MultiCore-­‑QuickSort ¡(-­‑ ¡Depth ¡1) ¡V ¡Low ¡Right)))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(> ¡High ¡Left) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(MultiCore-­‑QuickSort ¡(-­‑ ¡Depth ¡1) ¡V ¡Left ¡High)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(sync ¡promise)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(SingleCore-­‑QuickSort ¡V ¡Low ¡High))) ¡ ¡ ¡ ¡(Sort ¡V ¡Low ¡High ¡MultiCore-­‑Recurse)) 90 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 90

  82. Theo D’Hondt SLIP: a simple language implementation platform SLIP/C multicore quicksort (cont'd) ¡ ¡(define ¡(Sort ¡V ¡Low ¡High ¡Recurse) ¡ ¡ ¡ ¡(define ¡Left ¡Low) ¡ ¡ ¡ ¡(define ¡Right ¡High) ¡ ¡ ¡ ¡(define ¡Pivot ¡(vector-­‑ref ¡V ¡(quotient ¡(+ ¡Left ¡Right) ¡2))) ¡ ¡ ¡ ¡(define ¡Save ¡0) ¡ ¡(define ¡(SingleCore-­‑QuickSort ¡V ¡Low ¡High) ¡ ¡ ¡ ¡(while ¡(< ¡Left ¡Right) ¡ ¡ ¡ ¡(define ¡(SingleCore-­‑Recurse ¡Left ¡Right) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(while ¡(< ¡(vector-­‑ref ¡V ¡Left) ¡Pivot) ¡ ¡ ¡ ¡ ¡ ¡(if ¡(< ¡Low ¡Right) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡Left ¡(+ ¡Left ¡1))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(SingleCore-­‑QuickSort ¡V ¡Low ¡Right)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(while ¡(> ¡(vector-­‑ref ¡V ¡Right) ¡Pivot) ¡ ¡ ¡ ¡ ¡ ¡(if ¡(> ¡High ¡Left) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡Right ¡(-­‑ ¡Right ¡1))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(SingleCore-­‑QuickSort ¡V ¡Left ¡High))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(<= ¡Left ¡Right) ¡ ¡ ¡ ¡(Sort ¡V ¡Low ¡High ¡SingleCore-­‑Recurse)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(begin ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡Save ¡(vector-­‑ref ¡V ¡Left)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(vector-­‑set! ¡V ¡Left ¡(vector-­‑ref ¡V ¡Right)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(vector-­‑set! ¡V ¡Right ¡Save) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡Left ¡(+ ¡Left ¡1)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡Right ¡(-­‑ ¡Right ¡1))))) ¡ ¡(define ¡(MultiCore-­‑QuickSort ¡Depth ¡V ¡Low ¡High) ¡ ¡ ¡ ¡(Recurse ¡Left ¡Right)) ¡ ¡ ¡ ¡(define ¡(MultiCore-­‑Recurse ¡Left ¡Right) ¡ ¡ ¡ ¡ ¡ ¡(if ¡(> ¡Depth ¡0) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(begin ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡promise ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(< ¡Low ¡Right) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(spawn ¡(MultiCore-­‑QuickSort ¡(-­‑ ¡Depth ¡1) ¡V ¡Low ¡Right)))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(> ¡High ¡Left) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(MultiCore-­‑QuickSort ¡(-­‑ ¡Depth ¡1) ¡V ¡Left ¡High)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(sync ¡promise)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(SingleCore-­‑QuickSort ¡V ¡Low ¡High))) ¡ ¡ ¡ ¡(Sort ¡V ¡Low ¡High ¡MultiCore-­‑Recurse)) 91 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 91

  83. Theo D’Hondt SLIP: a simple language implementation platform SLIP/C multicore quicksort (cont'd) ¡ ¡(define ¡(Sort ¡V ¡Low ¡High ¡Recurse) ¡ ¡ ¡ ¡(define ¡Left ¡Low) ¡ ¡ ¡ ¡(define ¡Right ¡High) ¡ ¡ ¡ ¡(define ¡Pivot ¡(vector-­‑ref ¡V ¡(quotient ¡(+ ¡Left ¡Right) ¡2))) ¡ ¡ ¡ ¡(define ¡Save ¡0) ¡ ¡(define ¡(SingleCore-­‑QuickSort ¡V ¡Low ¡High) ¡ ¡ ¡ ¡(while ¡(< ¡Left ¡Right) ¡ ¡ ¡ ¡(define ¡(SingleCore-­‑Recurse ¡Left ¡Right) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(while ¡(< ¡(vector-­‑ref ¡V ¡Left) ¡Pivot) ¡ ¡ ¡ ¡ ¡ ¡(if ¡(< ¡Low ¡Right) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡Left ¡(+ ¡Left ¡1))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(SingleCore-­‑QuickSort ¡V ¡Low ¡Right)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(while ¡(> ¡(vector-­‑ref ¡V ¡Right) ¡Pivot) ¡ ¡ ¡ ¡ ¡ ¡(if ¡(> ¡High ¡Left) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡Right ¡(-­‑ ¡Right ¡1))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(SingleCore-­‑QuickSort ¡V ¡Left ¡High))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(<= ¡Left ¡Right) ¡ ¡ ¡ ¡(Sort ¡V ¡Low ¡High ¡SingleCore-­‑Recurse)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(begin ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡Save ¡(vector-­‑ref ¡V ¡Left)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(vector-­‑set! ¡V ¡Left ¡(vector-­‑ref ¡V ¡Right)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(vector-­‑set! ¡V ¡Right ¡Save) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡Left ¡(+ ¡Left ¡1)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡Right ¡(-­‑ ¡Right ¡1))))) ¡ ¡(define ¡(MultiCore-­‑QuickSort ¡Depth ¡V ¡Low ¡High) ¡ ¡ ¡ ¡(Recurse ¡Left ¡Right)) ¡ ¡ ¡ ¡(define ¡(MultiCore-­‑Recurse ¡Left ¡Right) ¡ ¡ ¡ ¡ ¡ ¡(if ¡(> ¡Depth ¡0) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(begin ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡promise ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(< ¡Low ¡Right) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(spawn ¡(MultiCore-­‑QuickSort ¡(-­‑ ¡Depth ¡1) ¡V ¡Low ¡Right)))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(> ¡High ¡Left) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(MultiCore-­‑QuickSort ¡(-­‑ ¡Depth ¡1) ¡V ¡Left ¡High)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(sync ¡promise)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(SingleCore-­‑QuickSort ¡V ¡Low ¡High))) ¡ ¡ ¡ ¡(Sort ¡V ¡Low ¡High ¡MultiCore-­‑Recurse)) 92 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 92

  84. Theo D’Hondt SLIP: a simple language implementation platform SLIP/C multicore quicksort (cont'd) ¡ ¡(define ¡(Sort ¡V ¡Low ¡High ¡Recurse) ¡ ¡ ¡ ¡(define ¡Left ¡Low) ¡ ¡ ¡ ¡(define ¡Right ¡High) ¡ ¡ ¡ ¡(define ¡Pivot ¡(vector-­‑ref ¡V ¡(quotient ¡(+ ¡Left ¡Right) ¡2))) ¡ ¡ ¡ ¡(define ¡Save ¡0) ¡ ¡(define ¡(SingleCore-­‑QuickSort ¡V ¡Low ¡High) ¡ ¡ ¡ ¡(while ¡(< ¡Left ¡Right) ¡ ¡ ¡ ¡(define ¡(SingleCore-­‑Recurse ¡Left ¡Right) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(while ¡(< ¡(vector-­‑ref ¡V ¡Left) ¡Pivot) ¡ ¡ ¡ ¡ ¡ ¡(if ¡(< ¡Low ¡Right) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡Left ¡(+ ¡Left ¡1))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(SingleCore-­‑QuickSort ¡V ¡Low ¡Right)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(while ¡(> ¡(vector-­‑ref ¡V ¡Right) ¡Pivot) ¡ ¡ ¡ ¡ ¡ ¡(if ¡(> ¡High ¡Left) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡Right ¡(-­‑ ¡Right ¡1))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(SingleCore-­‑QuickSort ¡V ¡Left ¡High))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(<= ¡Left ¡Right) ¡ ¡ ¡ ¡(Sort ¡V ¡Low ¡High ¡SingleCore-­‑Recurse)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(begin ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡Save ¡(vector-­‑ref ¡V ¡Left)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(vector-­‑set! ¡V ¡Left ¡(vector-­‑ref ¡V ¡Right)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(vector-­‑set! ¡V ¡Right ¡Save) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡Left ¡(+ ¡Left ¡1)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡Right ¡(-­‑ ¡Right ¡1))))) ¡ ¡(define ¡(MultiCore-­‑QuickSort ¡Depth ¡V ¡Low ¡High) ¡ ¡ ¡ ¡(Recurse ¡Left ¡Right)) ¡ ¡ ¡ ¡(define ¡(MultiCore-­‑Recurse ¡Left ¡Right) ¡ ¡ ¡ ¡ ¡ ¡(if ¡(> ¡Depth ¡0) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(begin ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡promise ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(< ¡Low ¡Right) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(spawn ¡(MultiCore-­‑QuickSort ¡(-­‑ ¡Depth ¡1) ¡V ¡Low ¡Right)))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(> ¡High ¡Left) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(MultiCore-­‑QuickSort ¡(-­‑ ¡Depth ¡1) ¡V ¡Left ¡High)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(sync ¡promise)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(SingleCore-­‑QuickSort ¡V ¡Low ¡High))) ¡ ¡ ¡ ¡(Sort ¡V ¡Low ¡High ¡MultiCore-­‑Recurse)) 93 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 93

  85. Theo D’Hondt SLIP: a simple language implementation platform SLIP/C multicore quicksort (cont'd) (define ¡size ¡1000000) ¡ ¡(define ¡V ¡(make-­‑vector ¡size ¡0)) ¡ ¡(define ¡Low ¡0) ¡ ¡(define ¡High ¡(-­‑ ¡(vector-­‑length ¡V) ¡1)) ¡ ¡(define ¡depth ¡0) ¡ ¡(define ¡threads ¡1) ¡ ¡(display ¡"multicore ¡quicksort ¡of ¡") ¡ ¡(display ¡size) ¡ ¡(display ¡" ¡integers") ¡ ¡(newline) ¡ ¡(while ¡(< ¡depth ¡2) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(display ¡"number ¡of ¡threads ¡= ¡") ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(display ¡threads) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡x ¡0) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡y ¡1) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(while ¡(<= ¡x ¡High) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(vector-­‑set! ¡V ¡x ¡y) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡x ¡(+ ¡x ¡1)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡y ¡(remainder ¡(+ ¡y ¡4253171) ¡1235711))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡t ¡(clock)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(MultiCore-­‑QuickSort ¡depth ¡V ¡Low ¡High) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(display ¡" ¡ ¡elapsed ¡time ¡= ¡") ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(display ¡(-­‑ ¡(clock) ¡t)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(display ¡" ¡secs") ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡depth ¡(+ ¡depth ¡1)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡threads ¡(* ¡threads ¡2)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(newline))) 94 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 94

  86. Theo D’Hondt SLIP: a simple language implementation platform SLIP/C multicore quicksort (cont'd) (define ¡size ¡1000000) ¡ ¡(define ¡V ¡(make-­‑vector ¡size ¡0)) ¡ ¡(define ¡Low ¡0) ¡ ¡(define ¡High ¡(-­‑ ¡(vector-­‑length ¡V) ¡1)) ¡ ¡(define ¡depth ¡0) ¡ ¡(define ¡(report ¡text ¡c) ¡ ¡(define ¡threads ¡1) ¡ ¡ ¡ ¡(protect ¡ ¡(display ¡"multicore ¡quicksort ¡of ¡") ¡ ¡ ¡ ¡ ¡(display ¡text) ¡ ¡(display ¡size) ¡ ¡ ¡ ¡ ¡(display ¡c) ¡ ¡(display ¡" ¡integers") ¡ ¡ ¡ ¡ ¡(display ¡" ¡") ¡ ¡(newline) ¡ ¡ ¡ ¡ ¡(display ¡" ¡... ¡") ¡ ¡(while ¡(< ¡depth ¡2) ¡ ¡ ¡ ¡ ¡(display ¡(-­‑ ¡(clock) ¡t)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(display ¡"number ¡of ¡threads ¡= ¡") ¡ ¡ ¡ ¡ ¡(display ¡" ¡secs") ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(display ¡threads) ¡ ¡ ¡ ¡ ¡(newline))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡x ¡0) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡y ¡1) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(while ¡(<= ¡x ¡High) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(vector-­‑set! ¡V ¡x ¡y) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡x ¡(+ ¡x ¡1)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡y ¡(remainder ¡(+ ¡y ¡4253171) ¡1235711))) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(define ¡t ¡(clock)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(MultiCore-­‑QuickSort ¡depth ¡V ¡Low ¡High) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(display ¡" ¡ ¡elapsed ¡time ¡= ¡") ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(display ¡(-­‑ ¡(clock) ¡t)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(display ¡" ¡secs") ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡depth ¡(+ ¡depth ¡1)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(set! ¡threads ¡(* ¡threads ¡2)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(newline))) 95 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 95

  87. Theo D’Hondt SLIP: a simple language implementation platform Multicore quicksort on a 4core MacPro 4core 96 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 96

  88. Theo D’Hondt SLIP: a simple language implementation platform Multicore quicksort on a 4core (cont'd) 97 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 97

  89. Theo D’Hondt SLIP: a simple language implementation platform Multicore quicksort on a 4core (cont'd) 16 13 11 8 7 6 98 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 98

  90. Theo D’Hondt SLIP: a simple language implementation platform Multicore quicksort on a 4core (cont'd) clock vs. time in <time.h> 16 13 11 8 7 6 99 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 99

  91. Theo D’Hondt SLIP: a simple language implementation platform Multicore quicksort on a 4core (cont'd) ¡ ¡(define ¡(median-­‑of-­‑3 ¡V ¡Low ¡High) ¡ ¡ ¡ ¡(define ¡(random-­‑index) ¡ ¡ ¡ ¡ ¡ ¡(+ ¡Low ¡(remainder ¡(random) ¡(-­‑ ¡High ¡Low ¡-­‑1)))) ¡ ¡ ¡ ¡(define ¡first ¡ ¡(vector-­‑ref ¡V ¡(random-­‑index))) ¡ ¡ ¡ ¡(define ¡second ¡(vector-­‑ref ¡V ¡(random-­‑index))) ¡ ¡ ¡ ¡(define ¡third ¡ ¡(vector-­‑ref ¡V ¡(random-­‑index))) ¡ ¡ ¡ ¡(if ¡(> ¡first ¡second) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(> ¡second ¡third) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡second ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(> ¡first ¡third) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡first ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡third)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(> ¡first ¡third) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡first ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(if ¡(> ¡second ¡third) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡second ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡third)))) clock vs. time in <time.h> 16 13 11 8 7 6 100 SOFT Research Presentation November 9th, 2010 Wednesday 9 March 2011 100

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend