
allocate-cons-function-id := ();
allocate-cons := λ . (tail(
   (if allocate-cons-function-id () (
      (set allocate-cons-function-id (uuid()))
      (local initialized)
      (set initialized (uuid()))
      (local assemble_cons_tail)
      (set assemble_cons_tail (uuid()))
      (local page-size)
      (set page-size 1073741824)

      (set assemble-data-section ( assemble-data-section (
         assemble_cons_tail ':                       \n
         \t '.zero \s '8                             \n
      )))

      (set assemble-text-section ( assemble-text-section (
         'show_cons_tail:                            \n
         \t 'mov \s '$ assemble_cons_tail , \s '%r12 \n
         \t 'mov \s '0 \[ '%r12 \] , \s '%r12        \n
         \t 'mov \s '$0 , \s '%r13                   \n
         allocate-cons-function-id ':                \n
         \t 'push \s '%r9                            \n
         \t 'push \s '%rax                           \n
         \t 'push \s '%rdi                           \n
         \t 'mov \s '$ assemble_cons_tail , \s '%rdi \n
         \t 'mov \s '0 \[ '%rdi \] , \s '%r8         \n
         \t 'cmp \s '$0, \s '%r8                     \n
         \t 'jne \s initialized                      \n
         \t 'mov \s '$12, \s '%rax                   \n  # system call brk
         \t 'mov \s '$0, \s '%rdi                    \n  # sbrk(0)
         \t 'syscall                                 \n
         \t 'mov \s '%rax, '%r8                      \n
         \t 'add \s '$ page-size , \s '%r8           \n
         \t 'add \s '$ page-size , \s '%r8           \n
         \t 'add \s '$ page-size , \s '%r8           \n
         \t 'add \s '$ page-size , \s '%r8           \n
         \t 'mov \s '$12, \s '%rax                   \n  # system call brk
         \t 'mov \s '%r8, \s '%rdi                   \n  # new requested brk
         \t 'syscall                                 \n
         \t 'sub \s '$ page-size , \s '%r8           \n
         \t 'sub \s '$ page-size , \s '%r8           \n
         \t 'sub \s '$ page-size , \s '%r8           \n
         \t 'sub \s '$ page-size , \s '%r8           \n
         initialized ':                              \n
         \t 'add \s '$16, \s '%r8                    \n
         \t 'mov \s '$ assemble_cons_tail , \s '%r9  \n
         \t 'mov \s '%r8, \s '0 \[ '%r9 \]           \n
         \t 'sub \s '$16, \s '%r8                    \n
         \t 'pop \s '%rdi                            \n
         \t 'pop \s '%rax                            \n
         \t 'pop \s '%r9                             \n
         \t 'ret                                     \n
      )))
   ))
   ( \t 'call \s allocate-cons-function-id \n )
));
