# .tlv file generated by https://github.com/akkartik/teliva # You may edit it if you are careful; however, you may see cryptic errors if you # violate Teliva's assumptions. # # .tlv files are representations of Teliva programs. Teliva programs consist of # sequences of definitions. Each definition is a table of key/value pairs. Keys # and values are both strings. # # Lines in .tlv files always follow exactly one of the following forms: # - comment lines at the top of the file starting with '#' at column 0 # - beginnings of definitions starting with '- ' at column 0, followed by a # key/value pair # - key/value pairs consisting of ' ' at column 0, containing either a # spaceless value on the same line, or a multi-line value # - multiline values indented by more than 2 spaces, starting with a '>' # # If these constraints are violated, Teliva may unceremoniously crash. Please # report bugs at http://akkartik.name/contact - __teliva_timestamp: original str_helpers: >-- some string helpers from http://lua-users.org/wiki/StringIndexing > >-- index characters using [] >getmetatable('').__index = function(str,i) > if type(i) == 'number' then > return string.sub(str,i,i) > else > return string[i] > end >end > >-- ranges using (), selected bytes using {} >getmetatable('').__call = function(str,i,j) > if type(i)~='table' then > return string.sub(str,i,j) > else > local t={} > for k,v in ipairs(i) do > t[k]=string.sub(str,v,v) > end > return table.concat(t) > end >end > >-- iterate over an ordered sequence >function q(x) > if type(x) == 'string' then > return x:gmatch('.') > else > return ipairs(x) > end >end > >-- insert within string >function string.insert(str1, str2, pos) > return str1:sub(1,pos)..str2..str1:sub(pos+1) >end > >function string.remove(s, pos) > return s:sub(1,pos-1)..s:sub(pos+1) >end > >-- TODO: backport utf-8 support from Lua 5.3 - __teliva_timestamp: original map: >-- only for arrays >function map(l, f) > result = {} > for _, x in ipairs(l) do > table.insert(result, f(x)) > end > return result >end - __teliva_timestamp: original reduce: >-- only for arrays >function reduce(l, f, init) > result = init > for _, x in ipairs(l) do > result = f(result, x) > end > return result >end - __teliva_timestamp: original filter: >-- only for arrays >function filter(l, f) > result = {} > for _, x in ipairs(l) do > if f(x) then > table.insert(result, x) > end > end > return result >end - __teliva_timestamp: original find_index: >function find_index(arr, x) > for n, y in ipairs(arr) do > if x == y then > return n > end > end >end - __teliva_timestamp: original trim: >function trim(s) > return s:gsub('^%s*', ''):gsub('%s*$', '') >end - __teliva_timestamp: original split: >function split(s, d) > result = {} > for match in (s..d):gmatch("(.-)"..d) do > table.insert(result, match); > end > return result >end - __teliva_timestamp: original window: >window = curses.stdscr() - __teliva_timestamp: original render: >function render(window) > window:clear() > -- draw stuff to screen here > window:attron(curses.A_BOLD) > window:mvaddstr(1, 5, "example app") > window:attrset(curses.A_NORMAL) > for i=0,15 do > window:attrset(curses.color_pair(i)) > window:mvaddstr(3+i, 5, "========================") > end > curses.refresh() >end - __teliva_timestamp: original menu: >menu = {} - __teliva_timestamp: original update: >function update(window) > local key = curses.getch() > -- process key here >end - __teliva_timestamp: original init_colors: >function init_colors() > for i=0,7 do > curses.init_pair(i, i, -1) > end > curses.init_pair(8, 7, 0) > curses.init_pair(9, 7, 1) > curses.init_pair(10, 7, 2) > curses.init_pair(11, 7, 3) > curses.init_pair(12, 7, 4) > curses.init_pair(13, 7, 5) > curses.init_pair(14, 7, 6) > curses.init_pair(15, -1, 15) >end - main: >function main() > init_colors() > > while true do > render(window) > update(window) > end >end __teliva_timestamp: original - __teliva_timestamp: >Tue Dec 14 17:21:28 2021 prose: >prose = '' - render: >function render(window) > window:clear() > -- draw stuff to screen here > window:addstr(prose) > curses.refresh() >end __teliva_timestamp: >Tue Dec 14 17:21:58 2021 - render: >function render(window) > window:clear() > -- draw stuff to screen here > window:addstr(prose) > curses.refresh() >end __teliva_timestamp: >Tue Dec 14 17:22:02 2021 - __teliva_timestamp: >Tue Dec 14 17:22:05 2021 prose: >prose = 'abc' - __teliva_timestamp: >Tue Dec 14 17:22:08 2021 prose: >prose = 'abc' - render: >function render(window) > window:clear() > -- draw stuff to screen here > print(string.len(prose)) > window:addstr(prose) > curses.refresh() >end __teliva_timestamp: >Tue Dec 14 17:22:33 2021 - render: >function render(window) > window:clear() > -- draw stuff to screen here > print(string.len(prose)) > window:addstr(prose) > curses.refresh() >end __teliva_timestamp: >Tue Dec 14 17:22:39 2021 - __teliva_timestamp: >Tue Dec 14 17:22:44 2021 prose: >prose = 'abc%def' - __teliva_timestamp: >Tue Dec 14 17:22:48 2021 prose: >prose = 'abc%def' - __teliva_timestamp: >Tue Dec 14 17:22:53 2021 prose: >prose = 'abc%def' - render: >function render(window) > window:clear() > -- draw stuff to screen here > local toots = split(prose, '\n\n===\n\n') > for _, toot in ipairs(toots) do > print(string.format('=== %d\n\n', string.len(toot)) > print(toot) > end > curses.refresh() >end __teliva_timestamp: >Tue Dec 14 17:25:23 2021 - render: >function render(window) > window:clear() > -- draw stuff to screen here > local toots = split(prose, '\n\n===\n\n') > for _, toot in ipairs(toots) do > print(string.format('=== %d\n\n', string.len(toot))) > print(toot) > end > curses.refresh() >end __teliva_timestamp: >Tue Dec 14 17:25:29 2021 - render: >function render(window) > window:clear() > -- draw stuff to screen here > local toots = split(prose, '\n\n===\n\n') > for _, toot in ipairs(toots) do > print(string.format('=== %d\n\n', string.len(toot))) > print(toot) > end > curses.refresh() >end __teliva_timestamp: >Tue Dec 14 17:26:44 2021 - render: >function render(window) > window:clear() > -- draw stuff to screen here > local toots = split(prose, '\n\n===\n\n') > for _, toot in ipairs(toots) do > print(string.format('=== %d\n\n', string.len(toot))) > print(toot) > end > curses.refresh() >end __teliva_timestamp: >Tue Dec 14 17:27:53 2021 - __teliva_timestamp: >Tue Dec 14 17:28:01 2021 prose: >prose = 'abc\n\n===\n\ndef' - __teliva_timestamp: >Tue Dec 14 17:28:10 2021 prose: >prose = 'abc\n\n===\n\ndef' - __teliva_timestamp: >Tue Dec 14 17:28:12 2021 prose: >prose = 'abc\n\n===\n\ndef' - render: >function render(window) > window:clear() > -- draw stuff to screen here > local toots = split(prose, '\n\n===\n\n') > for _, toot in ipairs(toots) do > print(string.format('=== %d\n', string.len(toot))) > print(toot) > end > curses.refresh() >end __teliva_timestamp: >Tue Dec 14 17:28:25 2021 - render: >function render(window) > window:clear() > -- draw stuff to screen here > local toots = split(prose, '\n\n===\n\n') > for _, toot in ipairs(toots) do > print(string.format('=== %d\n', string.len(toot))) > print(toot) > print('\n') > end > curses.refresh() >end __teliva_timestamp: >Tue Dec 14 17:28:45 2021 - render: >function render(window) > window:clear() > local toots = split(prose, '\n\n===\n\n') > for _, toot in ipairs(toots) do > print(string.format('=== %d\n', string.len(toot))) > print(toot) > print('\n') > end > curses.refresh() >end __teliva_timestamp: >Tue Dec 14 17:28:59 2021 - render: >function render(window) > window:clear() > local toots = split(prose, '\n\n===\n\n') > for _, toot in ipairs(toots) do > print(string.format('=== %d\n', string.len(toot))) > print(toot) > print('\n') > end > curses.refresh() >end __teliva_timestamp: >Tue Dec 14 17:29:01 2021 - __teliva_timestamp: >Tue Dec 14 17:29:11 2021 prose: >prose = 'abc\n\n===\n\ndef' - cursor: >cursor = string.len(prose) __teliva_timestamp: >Tue Dec 14 17:29:27 2021 - cursor: >cursor = 0 __teliva_timestamp: >Tue Dec 14 17:29:51 2021 - cursor: >cursor = 0 __teliva_timestamp: >Tue Dec 14 17:29:58 2021 - render: >function render(window) > window:clear() > local toots = split(prose, '\n\n===\n\n') > for _, toot in ipairs(toots) do > print(string.format('=== %d\n', string.len(toot))) > print(toot) > print('\n') > end > curses.refresh() >end __teliva_timestamp: >Tue Dec 14 17:52:23 2021 - render: >function render(window) > window:clear() > local toots = split(prose, '\n\n===\n\n') > for _, toot in ipairs(toots) do > print(string.format('=== %d\n', string.len(toot))) > print(toot) >--? print('\n') > end > curses.refresh() >end __teliva_timestamp: >Tue Dec 14 17:52:49 2021 - render: >function render(window) > window:clear() > local toots = split(prose, '\n\n===\n\n') > for _, toot in ipairs(toots) do > print(string.format('=== %d\n', string.len(toot))) > print(toot) >--? print('\n') > end > curses.refresh() >end __teliva_timestamp: >Tue Dec 14 17:53:04 2021 - render: >function render(window) > window:clear() > local toots = split(prose, '\n\n===\n\n') > for _, toot in ipairs(toots) do > print(string.format('=== %d\n', string.len(toot))) > print(toot) > print('') > end > curses.refresh() >end __teliva_timestamp: >Tue Dec 14 17:53:11 2021 - render: >function render(window) > window:clear() > local toots = split(prose, '\n\n===\n\n') > for _, toot in ipairs(toots) do > print(string.format('=== %d\n', string.len(toot))) > print(toot) > print('') > end > curses.refresh() >end __teliva_timestamp: >Tue Dec 14 17:58:27 2021 - cursor: >cursor = 0 __teliva_timestamp: >Tue Dec 14 17:58:32 2021 - __teliva_timestamp: >Tue Dec 14 17:58:43 2021 prose: >prose = 'abc\n\n===\n\ndef' - cursor: >cursor = 14 __teliva_timestamp: >Tue Dec 14 17:58:49 2021 - render: >function render(window) > window:clear() > local toots = split(prose, '\n\n===\n\n') > pos = 1 > for _, toot in ipairs(toots) do > pos = render_text('\n\n===\n\n', pos, cursor) > pos = render_text(toot, pos, cursor) > > for i=1,string.len(toot) do > local c = toot[i] > if pos == cursor then > window:attron(curses.A_REVERSE) > window:addch(c) > window:attroff(curses.A_REVERSE) > else > window:addch(c) > end > end > > > print('') > end > curses.refresh() >end __teliva_timestamp: >Tue Dec 14 18:03:35 2021 - __teliva_timestamp: >Tue Dec 14 18:04:02 2021 prose: >prose = 'abc\n\n===\n\ndef' - render: >function render(window) > window:clear() > local toots = split(prose, '\n\n===\n\n') > pos = 1 > for _, toot in ipairs(toots) do > pos = render_text('\n\n===\n\n', pos, cursor) > pos = render_text(toot, pos, cursor) > > for i=1,string.len(toot) do > local c = toot[i] > if pos == cursor then > window:attron(curses.A_REVERSE) > window:addch(c) > window:attroff(curses.A_REVERSE) > else > window:addch(c) > end > end > > > print('') > end > curses.refresh() >end __teliva_timestamp: >Tue Dec 14 18:08:53 2021 - render: >function render(window) > window:clear() > local toots = split(prose, '\n\n===\n\n') > pos = 1 > for _, toot in ipairs(toots) do > pos = render_text('\n\n===\n\n', pos, cursor) > pos = render_text(toot, pos, cursor) > print('') > window:attron(curses.A_BOLD) > window:addstr(string.len(toot)) > window:attroff(curses.A_BOLD) > print('') > end > curses.refresh() >end __teliva_timestamp: >Tue Dec 14 18:16:46 2021 - render: >function render(window) > window:clear() > local toots = split(prose, '\n\n===\n\n') > pos = 1 > for _, toot in ipairs(toots) do > pos = render_text('\n\n===\n\n', pos, cursor) > pos = render_text(toot, pos, cursor) > print('') > window:attron(curses.A_BOLD) > window:addstr(string.len(toot)) > window:attroff(curses.A_BOLD) > print('') > end > curses.refresh() >end __teliva_timestamp: >Tue Dec 14 18:17:53 2021 - __teliva_timestamp: >Tue Dec 14 18:18:06 2021 render_text: - render: >function render(window) > window:clear() > local toots = split(prose, '\n\n===\n\n') > pos = 1 > for _, toot in ipairs(toots) do > pos = render_text('\n\n===\n\n', pos, cursor) > pos = render_text(toot, pos, cursor) > print('') > window:attron(curses.A_BOLD) > window:addstr(string.len(toot)) > window:attroff(curses.A_BOLD) > print('') > end > curses.refresh() >end __teliva_timestamp: >Tue Dec 14 18:18:09 2021 - __teliva_timestamp: >Tue Dec 14 19:04:22 2021 render_text: > - render: >function render(window) > window:clear() > local toots = split(prose, '\n\n===\n\n') > pos = 1 > for _, toot in ipairs(toots) do > pos = render_text('\n\n===\n\n', pos, cursor) > pos = render_text(toot, pos, cursor) > print('') > window:attron(curses.A_BOLD) > window:addstr(string.len(toot)) > window:attroff(curses.A_BOLD) > print('') > end > curses.refresh() >end __teliva_timestamp: >Tue Dec 14 19:04:45 2021 - __teliva_timestamp: >Tue Dec 14 19:05:34 2021 render_text: >function render_text(window, s, pos, cursor) > for i=1,string.len(s) do > window:addch(s[i]) > end >end - render: >function render(window) > window:clear() > local toots = split(prose, '\n\n===\n\n') > pos = 1 > for _, toot in ipairs(toots) do > pos = render_text(window, '\n\n===\n\n', pos, cursor) > pos = render_text(window, toot, pos, cursor) > print('') > window:attron(curses.A_BOLD) > window:addstr(string.len(toot)) > window:attroff(curses.A_BOLD) > print('') > end > curses.refresh() >end __teliva_timestamp: >Tue Dec 14 19:05:49 2021 - render: >function render(window) > window:clear() > local toots = split(prose, '\n\n===\n\n') > pos = 1 > for _, toot in ipairs(toots) do > pos = render_text(window, '\n\n===\n\n', pos, cursor) > pos = render_text(window, toot, pos, cursor) > print('') > window:attron(curses.A_BOLD) > window:addstr(string.len(toot)) > window:attroff(curses.A_BOLD) > print('') > end > curses.refresh() >end __teliva_timestamp: >Tue Dec 14 19:15:33 2021 - render: >function render(window) > window:clear() > local toots = split(prose, '\n\n===\n\n') > pos = 1 > for _, toot in ipairs(toots) do > pos = render_text(window, '\n\n===\n\n', pos, cursor) > pos = render_text(window, toot, pos, cursor) > print('') > window:attron(curses.A_BOLD) > window:addstr(string.len(toot)) > window:attroff(curses.A_BOLD) > print('') > end > curses.refresh() >end __teliva_timestamp: >Tue Dec 14 19:15:51 2021 - render: >function render(window) > window:clear() > local toots = split(prose, '\n\n===\n\n') > pos = 1 > for _, toot in ipairs(toots) do > pos = render_text(window, '\n\n===\n\n', pos, cursor) > pos = render_text(window, toot, pos, cursor) > print('') > window:attron(curses.A_BOLD) > window:addstr(string.len(toot)) > window:attroff(curses.A_BOLD) > print('') > end > curses.refresh() >end __teliva_timestamp: >Tue Dec 14 19:16:57 2021 - render: >function render(window) > window:clear() > local toots = split(prose, '\n\n===\n\n') > pos = 1 > for _, toot in ipairs(toots) do > pos = render_text(window, '\n\n===\n\n', pos, cursor) > pos = render_text(window, toot, pos, cursor) > print('') > window:attron(curses.A_BOLD) > window:addstr(string.len(toot)) > window:attroff(curses.A_BOLD) > print('') > end > curses.refresh() >end __teliva_timestamp: >Tue Dec 14 19:17:02 2021 - __teliva_timestamp: >Tue Dec 14 19:18:15 2021 render_text: >function render_text(window, s, pos, cursor) > for i=1,string.len(s) do > window:addch(sub(s, i, i)) > end >end - __teliva_timestamp: >Tue Dec 14 19:18:23 2021 render_text: >function render_text(window, s, pos, cursor) > for i=1,string.len(s) do > window:addch(s:sub(i, i)) > end >end - __teliva_timestamp: >Tue Dec 14 19:18:43 2021 render_text: >function render_text(window, s, pos, cursor) > for i=1,string.len(s) do > window:addch(s:sub(i, i)) > end >end - __teliva_timestamp: >Tue Dec 14 19:18:45 2021 render_text: >function render_text(window, s, pos, cursor) > for i=1,string.len(s) do > window:addch(s:sub(i, i)) > end >end - __teliva_timestamp: >Tue Dec 14 19:18:51 2021 render_text: >function render_text(window, s, pos, cursor) > for i=1,string.len(s) do > window:addch(s:sub(i, i)) > end >end - render: >function render(window) > window:clear() > local toots = split(prose, '\n\n===\n\n') > pos = 1 > for _, toot in ipairs(toots) do > pos = render_text(window, '\n\n===\n\n', pos, cursor) > pos = render_text(window, toot, pos, cursor) > print('') > window:attron(curses.A_BOLD) > window:addstr(string.len(toot)) > window:attroff(curses.A_BOLD) > print('') > end > curses.refresh() >end __teliva_timestamp: >Tue Dec 14 19:21:42 2021 - __teliva_timestamp: >Tue Dec 14 19:24:22 2021 render_text: >function render_text(window, s, pos, cursor) > for i=1,string.len(s) do > window:addch(s[i]) > end >end - __teliva_timestamp: >Tue Dec 14 19:38:16 2021 render_text: >function render_text(window, s, pos, cursor) > local newpos = pos > for i=1,string.len(s) do > if newpos == cursor then > window:attron(curses.A_REVERSE) > window:addch(s[i]) > window:attroff(curses.A_REVERSE) > else > window:addch(s[i]) > end > newpos = newpos+1 > end > return newpos >end - __teliva_timestamp: >Tue Dec 14 19:38:25 2021 render_text: >function render_text(window, s, pos, cursor) > local newpos = pos > for i=1,string.len(s) do > if newpos == cursor then > window:attron(curses.A_REVERSE) > window:addch(s[i]) > window:attroff(curses.A_REVERSE) > else > window:addch(s[i]) > end > newpos = newpos+1 > end > return newpos >end - __teliva_timestamp: >Tue Dec 14 19:39:04 2021 prose: >prose = 'abc\n\n===\n\ndef' - cursor: >cursor = 14 __teliva_timestamp: >Tue Dec 14 19:39:21 2021 - cursor: >cursor = 21 __teliva_timestamp: >Tue Dec 14 19:39:47 2021 - cursor: >cursor = 20 __teliva_timestamp: >Tue Dec 14 19:39:52 2021 - cursor: >cursor = 21 __teliva_timestamp: >Tue Dec 14 19:39:57 2021 - cursor: >cursor = 14 __teliva_timestamp: >Tue Dec 14 19:40:21 2021 - cursor: >cursor = 14 __teliva_timestamp: >Tue Dec 14 19:40:26 2021 - render: >function render(window) > window:clear() > local toots = split(prose, '\n\n===\n\n') > pos = 1 > for i, toot in ipairs(toots) do > if i > 1 then > pos = render_text(window, '\n\n===\n\n', pos, cursor) > end > pos = render_text(window, toot, pos, cursor) > print('') > window:attron(curses.A_BOLD) > window:addstr(string.len(toot)) > window:attroff(curses.A_BOLD) > print('') > end > curses.refresh() >end __teliva_timestamp: >Tue Dec 14 19:41:24 2021 - render: >function render(window) > window:clear() > local toots = split(prose, '\n\n===\n\n') > pos = 1 > for i, toot in ipairs(toots) do > if i > 1 then > pos = render_text(window, '\n\n===\n\n', pos, cursor) > end > pos = render_text(window, toot, pos, cursor) > if pos == cursor then > window:attron(curses.A_REVERSE) > window:addch(' ') > window:attroff(curses.A_REVERSE) > end > print('') > window:attron(curses.A_BOLD) > window:addstr(string.len(toot)) > window:attroff(curses.A_BOLD) > print('') > end > curses.refresh() >end __teliva_timestamp: >Tue Dec 14 19:42:11 2021 - render: >function render(window) > window:clear() > local toots = split(prose, '\n\n===\n\n') > pos = 1 > for i, toot in ipairs(toots) do > if i > 1 then > pos = render_text(window, '\n\n===\n\n', pos, cursor) > end > pos = render_text(window, toot, pos, cursor) > if pos == cursor then > window:attron(curses.A_REVERSE) > window:addch(' ') > window:attroff(curses.A_REVERSE) > end > print('') > window:attron(curses.A_BOLD) > window:addstr(string.len(toot)) > window:attroff(curses.A_BOLD) > print('') > end > curses.refresh() >end __teliva_timestamp: >Tue Dec 14 19:42:23 2021 - update: >function update(window) > local key = curses.getch() > prose:insert(key, cursor) > cursor = cursor+1 >end __teliva_timestamp: >Tue Dec 14 19:42:57 2021 - update: >function update(window) > local key = curses.getch() > prose:insert(key, cursor) > cursor = cursor+1 >end __teliva_timestamp: >Tue Dec 14 19:43:33 2021 - update: >function update(window) > local key = curses.getch() > prose:insert(key, cursor) > cursor = cursor+1 >end __teliva_timestamp: >Tue Dec 14 19:43:36 2021 - render: >function render(window) > window:clear() > local toots = split(prose, '\n\n===\n\n') > pos = 1 > for i, toot in ipairs(toots) do > if i > 1 then > pos = render_text(window, '\n\n===\n\n', pos, cursor) > end > pos = render_text(window, toot, pos, cursor) > if pos == cursor then > window:attron(curses.A_REVERSE) > window:addch(' ') > window:attroff(curses.A_REVERSE) > end > print('') > window:attron(curses.A_BOLD) > window:addstr(string.len(toot)) > window:attroff(curses.A_BOLD) > print('') > end > curses.refresh() >end __teliva_timestamp: >Tue Dec 14 19:44:48 2021 - update: >function update(window) > local key = curses.getch() > prose = prose:insert(key, cursor) > cursor = cursor+1 >end __teliva_timestamp: >Tue Dec 14 19:44:57 2021 - update: >function update(window) > local key = curses.getch() > prose = prose:insert(string.char(key), cursor) > cursor = cursor+1 >end __teliva_timestamp: >Tue Dec 14 19:45:15 2021 - update: >function update(window) > local key = curses.getch() > if key == curses.KEY_LEFT then > cursor = cursor-1 > end > prose = prose:insert(string.char(key), cursor) > cursor = cursor+1 >end __teliva_timestamp: >Tue Dec 14 19:47:04 2021 - update: >function update(window) > local key = curses.getch() > if key == curses.KEY_LEFT then > cursor = cursor-1 > return > end > prose = prose:insert(string.char(key), cursor) > cursor = cursor+1 >end __teliva_timestamp: >Tue Dec 14 19:47:22 2021 - update: >function update(window) > local key = curses.getch() > if key == curses.KEY_LEFT then > cursor = cursor-1 > return > end > prose = prose:insert(string.char(key), cursor-1) > cursor = cursor+1 >end __teliva_timestamp: >Tue Dec 14 19:47:37 2021 - update: >function update(window) > local key = curses.getch() > if key == curses.KEY_LEFT then > cursor = cursor-1 > return > end > prose = prose:insert(string.char(key), cursor) > cursor = cursor+1 >end __teliva_timestamp: >Tue Dec 14 19:47:49 2021 - cursor: >cursor = 14 __teliva_timestamp: >Tue Dec 14 19:47:52 2021 - render: >function render(window) > window:clear() > local toots = split(prose, '\n\n===\n\n') > pos = 1 > for i, toot in ipairs(toots) do > if i > 1 then > pos = render_text(window, '\n\n===\n\n', pos, cursor) > end > pos = render_text(window, toot, pos, cursor) > if pos == cursor then > window:attron(curses.A_REVERSE) > window:addch(' ') > window:attroff(curses.A_REVERSE) > end > print('') > window:attron(curses.A_BOLD) > window:addstr(string.len(toot)) > window:attroff(curses.A_BOLD) > pri
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Mu - 101run_sandboxed.cc</title>
<meta name="Generator" content="Vim/7.4">
<meta name="plugin-version" content="vim7.4_v2">
<meta name="syntax" content="cpp">
<meta name="settings" content="number_lines,use_css,pre_wrap,no_foldcolumn,expand_tabs,line_ids,prevent_copy=">
<meta name="colorscheme" content="minimal">
<style type="text/css">
<!--
pre { white-space: pre-wrap; font-family: monospace; color: #aaaaaa; background-color: #080808; }
body { font-size: 12pt; font-family: monospace; color: #aaaaaa; background-color: #080808; }
a { color:#eeeeee; text-decoration: none; }
a:hover { text-decoration: underline; }
* { font-size: 12pt; font-size: 1em; }
.Constant { color: #00a0a0; }
.Special { color: #c00000; }
.muRecipe { color: #ff8700; }
.Comment { color: #9090ff; }
.Comment a { color:#0000ee; text-decoration:underline; }
.Delimiter { color: #800080; }
.LineNr { color: #444444; }
.CommentedCode { color: #6c6c6c; }
.Normal { color: #aaaaaa; background-color: #080808; padding-bottom: 1px; }
.traceContains { color: #008000; }
.Identifier { color: #c0a020; }
.cSpecial { color: #008000; }
-->
</style>

<script type='text/javascript'>
<!--

/* function to open any folds containing a jumped-to line before jumping to it */
function JumpToLine()
{
  var lineNum;
  lineNum = window.location.hash;
  lineNum = lineNum.substr(1); /* strip off '#' */

  if (lineNum.indexOf('L') == -1) {
    lineNum = 'L'+lineNum;
  }
  lineElem = document.getElementById(lineNum);
  /* Always jump to new location even if the line was hidden inside a fold, or
   * we corrected the raw number to a line ID.
   */
  if (lineElem) {
    lineElem.scrollIntoView(true);
  }
  return true;
}
if ('onhashchange' in window) {
  window.onhashchange = JumpToLine;
}

-->
</script>
</head>
<body onload='JumpToLine();'>
<pre id='vimCodeElement'>
<span id="L1" class="LineNr">  1 </span><span class="Comment">//: Helper for various programming environments: run arbitrary Mu code and</span>
<span id="L2" class="LineNr">  2 </span><span class="Comment">//: return some result in text form.</span>
<span id="L3" class="LineNr">  3 </span>
<span id="L4" class="LineNr">  4 </span><span class="Delimiter">:(scenario run_interactive_code)</span>
<span id="L5" class="LineNr">  5 </span><span class="muRecipe">def</span> <a href='000organization.cc.html#L113'>main</a> [
<span id="L6" class="LineNr">  6 </span>  <span class="Constant">1</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>  <span class="Comment"># reserve space for the sandbox</span>
<span id="L7" class="LineNr">  7 </span>  <span class="Constant">10</span>:text<span class="Special"> &lt;- </span><span class="Normal">new</span> [<span class="Constant">1</span>:num/<span class="Special">raw &lt;- </span>copy <span class="Constant">34</span>]
<span id="L8" class="LineNr">  8 </span><span class="CommentedCode">#?   $print 10:num [|] 11:num [: ] 1000:num [|] *10:text [ (] 10:text [)] 10/newline</span>
<span id="L9" class="LineNr">  9 </span>  run-sandboxed <span class="Constant">10</span>:text
<span id="L10" class="LineNr"> 10 </span>  <span class="Constant">20</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">1</span>:num
<span id="L11" class="LineNr"> 11 </span>]
<span id="L12" class="LineNr"> 12 </span><span class="traceContains">+mem: storing 34 in location 20</span>
<span id="L13" class="LineNr"> 13 </span>
<span id="L14" class="LineNr"> 14 </span><span class="Delimiter">:(scenario run_interactive_empty)</span>
<span id="L15" class="LineNr"> 15 </span><span class="muRecipe">def</span> <a href='000organization.cc.html#L113'>main</a> [
<span id="L16" class="LineNr"> 16 </span>  <span class="Constant">10</span>:text<span class="Special"> &lt;- </span>copy<span class="Constant"> null</span>
<span id="L17" class="LineNr"> 17 </span>  <span class="Constant">20</span>:text<span class="Special"> &lt;- </span>run-sandboxed <span class="Constant">10</span>:text
<span id="L18" class="LineNr"> 18 </span>]
<span id="L19" class="LineNr"> 19 </span><span class="Comment"># result is null</span>
<span id="L20" class="LineNr"> 20 </span><span class="traceContains">+mem: storing 0 in location 20</span>
<span id="L21" class="LineNr"> 21 </span><span class="traceContains">+mem: storing 0 in location 21</span>
<span id="L22" class="LineNr"> 22 </span>
<span id="L23" class="LineNr"> 23 </span><span class="Comment">//: As the name suggests, 'run-sandboxed' will prevent certain operations that</span>
<span id="L24" class="LineNr"> 24 </span><span class="Comment">//: regular Mu code can perform.</span>
<span id="L25" class="LineNr"> 25 </span><span class="Delimiter">:(before &quot;End Globals&quot;)</span>
<span id="L26" class="LineNr"> 26 </span><span class="Normal">bool</span> Sandbox_mode =<span class="Constant"> false</span><span class="Delimiter">;</span>
<span id="L27" class="LineNr"> 27 </span><span class="Comment">//: for starters, users can't override 'main' when the environment is running</span>
<span id="L28" class="LineNr"> 28 </span><span class="Delimiter">:(before &quot;End Load Recipe Name&quot;)</span>
<span id="L29" class="LineNr"> 29 </span><span class="Normal">if</span> <span class="Delimiter">(</span>Sandbox_mode &amp;&amp; result<span class="Delimiter">.</span>name == <span class="Constant">&quot;main&quot;</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
<span id="L30" class="LineNr"> 30 </span>  <a href='016dilated_reagent.cc.html#L57'>slurp_balanced_bracket</a><span class="Delimiter">(</span>in<span class="Delimiter">);</span>
<span id="L31" class="LineNr"> 31 </span>  <span class="Identifier">return</span> -<span class="Constant">1</span><span class="Delimiter">;</span>
<span id="L32" class="LineNr"> 32 </span><span class="Delimiter">}</span>
<span id="L33" class="LineNr"> 33 </span>
<span id="L34" class="LineNr"> 34 </span><span class="Comment">//: run code in 'interactive mode', i.e. with errors off and return:</span>
<span id="L35" class="LineNr"> 35 </span><span class="Comment">//:   stringified output in case we want to print it to screen</span>
<span id="L36" class="LineNr"> 36 </span><span class="Comment">//:   any errors encountered</span>
<span id="L37" class="LineNr"> 37 </span><span class="Comment">//:   simulated screen any prints went to</span>
<span id="L38" class="LineNr"> 38 </span><span class="Comment">//:   any 'app' layer traces generated</span>
<span id="L39" class="LineNr"> 39 </span><span class="Delimiter">:(before &quot;End Primitive Recipe Declarations&quot;)</span>
<span id="L40" class="LineNr"> 40 </span>RUN_SANDBOXED<span class="Delimiter">,</span>
<span id="L41" class="LineNr"> 41 </span><span class="Delimiter">:(before &quot;End Primitive Recipe Numbers&quot;)</span>
<span id="L42" class="LineNr"> 42 </span><a href='001help.cc.html#L221'>put</a><span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">&quot;run-sandboxed&quot;</span><span class="Delimiter">,</span> RUN_SANDBOXED<span class="Delimiter">);</span>
<span id="L43" class="LineNr"> 43 </span><span class="Delimiter">:(before &quot;End Primitive Recipe Checks&quot;)</span>
<span id="L44" class="LineNr"> 44 </span><span class="Normal">case</span> RUN_SANDBOXED: <span class="Delimiter">{</span>
<span id="L45" class="LineNr"> 45 </span>  <span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L141'>SIZE</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
<span id="L46" class="LineNr"> 46 </span>    <a href='003trace.cc.html#L197'>raise</a> &lt;&lt; <a href='013update_operation.cc.html#L25'>maybe</a><span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;'run-sandboxed' requires exactly one ingredient, but got '&quot;</span> &lt;&lt; inst<span class="Delimiter">.</span>original_string &lt;&lt; <span class="Constant">&quot;'</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; <a href='003trace.cc.html#L226'>end</a><span class="Delimiter">();</span>
<span id="L47" class="LineNr"> 47 </span>    <span class="Identifier">break</span><span class="Delimiter">;</span>
<span id="L48" class="LineNr"> 48 </span>  <span class="Delimiter">}</span>
<span id="L49" class="LineNr"> 49 </span>  <span class="Normal">if</span> <span class="Delimiter">(</span>!is_mu_text<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span>
<span id="L50" class="LineNr"> 50 </span>    <a href='003trace.cc.html#L197'>raise</a> &lt;&lt; <a href='013update_operation.cc.html#L25'>maybe</a><span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;first ingredient of 'run-sandboxed' should be a string, but got '&quot;</span> &lt;&lt; to_string<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">))</span> &lt;&lt; <span class="Constant">&quot;'</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; <a href='003trace.cc.html#L226'>end</a><span class="Delimiter">();</span>
<span id="L51" class="LineNr"> 51 </span>    <span class="Identifier">break</span><span class="Delimiter">;</span>
<span id="L52" class="LineNr"> 52 </span>  <span class="Delimiter">}</span>
<span id="L53" class="LineNr"> 53 </span>  <span class="Identifier">break</span><span class="Delimiter">;</span>
<span id="L54" class="LineNr"> 54 </span><span class="Delimiter">}</span>
<span id="L55" class="LineNr"> 55 </span><span class="Delimiter">:(before &quot;End Primitive Recipe Implementations&quot;)</span>
<span id="L56" class="LineNr"> 56 </span><span class="Normal">case</span> RUN_SANDBOXED: <span class="Delimiter">{</span>
<span id="L57" class="LineNr"> 57 </span>  <span class="Normal">bool</span> new_code_pushed_to_stack = <a href='101run_sandboxed.cc.html#L98'>run_interactive</a><span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">skip alloc id</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">));</span>
<span id="L58" class="LineNr"> 58 </span>  <span class="Normal">if</span> <span class="Delimiter">(</span>!new_code_pushed_to_stack<span class="Delimiter">)</span> <span class="Delimiter">{</span>
<span id="L59" class="LineNr"> 59 </span>    products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">5</span><span class="Delimiter">);</span>
<span id="L60" class="LineNr"> 60 </span>    products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">alloc id</span><span class="Comment">*/</span><span class="Constant">0</span><span class="Delimiter">);</span>
<span id="L61" class="LineNr"> 61 </span>    products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span>
<span id="L62" class="LineNr"> 62 </span>    products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">alloc id</span><span class="Comment">*/</span><span class="Constant">0</span><span class="Delimiter">);</span>
<span id="L63" class="LineNr"> 63 </span>    products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span><a href='101run_sandboxed.cc.html#L515'>trace_error_contents</a><span class="Delimiter">());</span>
<span id="L64" class="LineNr"> 64 </span>    products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">alloc id</span><span class="Comment">*/</span><span class="Constant">0</span><span class="Delimiter">);</span>
<span id="L65" class="LineNr"> 65 </span>    products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span>
<span id="L66" class="LineNr"> 66 </span>    products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">3</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">alloc id</span><span class="Comment">*/</span><span class="Constant">0</span><span class="Delimiter">);</span>
<span id="L67" class="LineNr"> 67 </span>    products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">3</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span><a href='101run_sandboxed.cc.html#L529'>trace_app_contents</a><span class="Delimiter">());</span>
<span id="L68" class="LineNr"> 68 </span>    products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">4</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span>  <span class="Comment">// completed</span>
<span id="L69" class="LineNr"> 69 </span>    <a href='101run_sandboxed.cc.html#L166'>run_code_end</a><span class="Delimiter">();</span>
<span id="L70" class="LineNr"> 70 </span>    <span class="Identifier">break</span><span class="Delimiter">;</span>  <span class="Comment">// done with this instruction</span>
<span id="L71" class="LineNr"> 71 </span>  <span class="Delimiter">}</span>
<span id="L72" class="LineNr"> 72 </span>  <span class="Normal">else</span> <span class="Delimiter">{</span>
<span id="L73" class="LineNr"> 73 </span>    <span class="Identifier">continue</span><span class="Delimiter">;</span>  <span class="Comment">// not done with caller; don't increment current_step_index()</span>
<span id="L74" class="LineNr"> 74 </span>  <span class="Delimiter">}</span>
<span id="L75" class="LineNr"> 75 </span><span class="Delimiter">}</span>
<span id="L76" class="LineNr"> 76 </span>
<span id="L77" class="LineNr"> 77 </span><span class="Comment">//: To show results in the sandbox Mu uses a hack: it saves the products</span>
<span id="L78" class="LineNr"> 78 </span><span class="Comment">//: returned by each instruction while Track_most_recent_products is true, and</span>
<span id="L79" class="LineNr"> 79 </span><span class="Comment">//: keeps the most recent such result around so that it can be returned as the</span>
<span id="L80" class="LineNr"> 80 </span><span class="Comment">//: result of a sandbox.</span>
<span id="L81" class="LineNr"> 81 </span>
<span id="L82" class="LineNr"> 82 </span><span class="Delimiter">:(before &quot;End Globals&quot;)</span>
<span id="L83" class="LineNr"> 83 </span><span class="Normal">bool</span> Track_most_recent_products =<span class="Constant"> false</span><span class="Delimiter">;</span>
<span id="L84" class="LineNr"> 84 </span><span class="Normal">int</span> Call_depth_to_track_most_recent_products_at = <span class="Constant">0</span><span class="Delimiter">;</span>
<span id="L85" class="LineNr"> 85 </span>string Most_recent_products<span class="Delimiter">;</span>
<span id="L86" class="LineNr"> 86 </span><span class="Delimiter">:(before &quot;End Reset&quot;)</span>
<span id="L87" class="LineNr"> 87 </span>Track_most_recent_products =<span class="Constant"> false</span><span class="Delimiter">;</span>
<span id="L88" class="LineNr"> 88 </span>Call_depth_to_track_most_recent_products_at = <span class="Constant">0</span><span class="Delimiter">;</span>
<span id="L89" class="LineNr"> 89 </span>Most_recent_products = <span class="Constant">&quot;&quot;</span><span class="Delimiter">;</span>
<span id="L90" class="LineNr"> 90 </span>
<span id="L91" class="LineNr"> 91 </span><span class="Delimiter">:(before &quot;End Globals&quot;)</span>
<span id="L92" class="LineNr"> 92 </span>trace_stream* Save_trace_stream = <span class="Constant">NULL</span><span class="Delimiter">;</span>
<span id="L93" class="LineNr"> 93 </span>string Save_trace_file<span class="Delimiter">;</span>
<span id="L94" class="LineNr"> 94 </span><span class="Delimiter">:(code)</span>
<span id="L95" class="LineNr"> 95 </span><span class="Comment">// reads a string, tries to call it as code (treating it as a test), saving</span>
<span id="L96" class="LineNr"> 96 </span><span class="Comment">// all errors.</span>
<span id="L97" class="LineNr"> 97 </span><span class="Comment">// returns true if successfully called (no errors found during load and transform)</span>
<span id="L98" class="LineNr"> 98 </span><span class="Normal">bool</span> <a href='101run_sandboxed.cc.html#L98'>run_interactive</a><span class="Delimiter">(</span><span class="Normal">int</span> <a href='043space.cc.html#L101'>address</a><span class="Delimiter">)</span> <span class="Delimiter">{</span>
<span id="L99" class="LineNr"> 99 </span><span class="CommentedCode">//?   cerr &lt;&lt; &quot;run_interactive: &quot; &lt;&lt; address &lt;&lt; '\n';</span>
<span id="L100" class="LineNr">100 </span>  assert<span class="Delimiter">(</span><a href='001help.cc.html#L226'>contains_key</a><span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">&quot;interactive&quot;</span><span class="Delimiter">)</span> &amp;&amp; get<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">&quot;interactive&quot;</span><span class="Delimiter">)</span> != <span class="Constant">0</span><span class="Delimiter">);</span>
<span id="L101" class="LineNr">101 </span>  <span class="Comment">// try to sandbox the run as best you can</span>
<span id="L102" class="LineNr">102 </span>  <span class="Comment">// todo: test this</span>
<span id="L103" class="LineNr">103 </span>  <span class="Normal">if</span> <span class="Delimiter">(</span>!Current_scenario<span class="Delimiter">)</span> <span class="Delimiter">{</span>
<span id="L104" class="LineNr">104 </span>    <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">1</span><span class="Delimiter">;</span> i &lt; Reserved_for_tests<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span>
<span id="L105" class="LineNr">105 </span>      Memory<span class="Delimiter">.</span>erase<span class="Delimiter">(</span>i<span class="Delimiter">);</span>
<span id="L106" class="LineNr">106 </span>  <span class="Delimiter">}</span>
<span id="L107" class="LineNr">107 </span>  string command = <a href='003trace.cc.html#L391'>trim</a><span class="Delimiter">(</span><a href='101run_sandboxed.cc.html#L494'>strip_comments</a><span class="Delimiter">(</span><a href='038new_text.cc.html#L142'>read_mu_text</a><span class="Delimiter">(</span><a href='043space.cc.html#L101'>address</a><span class="Delimiter">)));</span>
<span id="L108" class="LineNr">108 </span><span class="CommentedCode">//?   cerr &lt;&lt; &quot;command: &quot; &lt;&lt; command &lt;&lt; '\n';</span>
<span id="L109" class="LineNr">109 </span>  Name[get<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">&quot;interactive&quot;</span><span class="Delimiter">)</span>]<span class="Delimiter">.</span><a href='050scenario.cc.html#L60'>clear</a><span class="Delimiter">();</span>
<span id="L110" class="LineNr">110 </span>  <a href='101run_sandboxed.cc.html#L153'>run_code_begin</a><span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">should_stash_snapshots</span><span class="Comment">*/</span><span class="Constant">true</span><span class="Delimiter">);</span>
<span id="L111" class="LineNr">111 </span>  <span class="Normal">if</span> <span class="Delimiter">(</span>command<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Constant"> false</span><span class="Delimiter">;</span>
<span id="L112" class="LineNr">112 </span>  <span class="Comment">// don't kill the current routine on parse errors</span>
<span id="L113" class="LineNr">113 </span>  routine* save_current_routine = Current_routine<span class="Delimiter">;</span>
<span id="L114" class="LineNr">114 </span>  Current_routine = <span class="Constant">NULL</span><span class="Delimiter">;</span>
<span id="L115" class="LineNr">115 </span>  <span class="Comment">// call run(string) but without the scheduling</span>
<span id="L116" class="LineNr">116 </span>  load<span class="Delimiter">(</span>string<span class="Delimiter">(</span><span class="Constant">&quot;recipe! interactive [</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span><span class="Delimiter">)</span> +
<span id="L117" class="LineNr">117 </span>          <span class="Constant">&quot;local-scope</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> +
<span id="L118" class="LineNr">118 </span>          <span class="Constant">&quot;screen:&amp;:screen &lt;- next-ingredient</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> +
<span id="L119" class="LineNr">119 </span>          <span class="Constant">&quot;$start-tracking-products</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> +
<span id="L120" class="LineNr">120 </span>          command + <span class="Constant">&quot;</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> +
<span id="L121" class="LineNr">121 </span>          <span class="Constant">&quot;$stop-tracking-products</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> +
<span id="L122" class="LineNr">122 </span>          <span class="Constant">&quot;return screen</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> +
<span id="L123" class="LineNr">123 </span>       <span class="Constant">&quot;]</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span><span class="Delimiter">);</span>
<span id="L124" class="LineNr">124 </span>  <a href='012transform.cc.html#L46'>transform_all</a><span class="Delimiter">();</span>
<span id="L125" class="LineNr">125 </span>  Current_routine = save_current_routine<span class="Delimiter">;</span>
<span id="L126" class="LineNr">126 </span>  <span class="Normal">if</span> <span class="Delimiter">(</span>trace_count<span class="Delimiter">(</span><span class="Constant">&quot;error&quot;</span><span class="Delimiter">)</span> &gt; <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Constant"> false</span><span class="Delimiter">;</span>
<span id="L127" class="LineNr">127 </span>  <span class="Comment">// now call 'sandbox' which will run 'interactive' in a separate routine,</span>
<span id="L128" class="LineNr">128 </span>  <span class="Comment">// and wait for it</span>
<span id="L129" class="LineNr">129 </span>  <span class="Normal">if</span> <span class="Delimiter">(</span>Save_trace_stream<span class="Delimiter">)</span> <span class="Delimiter">{</span>
<span id="L130" class="LineNr">130 </span>    ++Save_trace_stream<span class="Delimiter">-&gt;</span>callstack_depth<span class="Delimiter">;</span>
<span id="L131" class="LineNr">131 </span>    <a href='003trace.cc.html#L190'>trace</a><span class="Delimiter">(</span><span class="Constant">9999</span><span class="Delimiter">,</span> <span class="Constant">&quot;trace&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;run-sandboxed: incrementing callstack depth to &quot;</span> &lt;&lt; Save_trace_stream<span class="Delimiter">-&gt;</span>callstack_depth &lt;&lt; <a href='003trace.cc.html#L226'>end</a><span class="Delimiter">();</span>
<span id="L132" class="LineNr">132 </span>    assert<span class="Delimiter">(</span>Save_trace_stream<span class="Delimiter">-&gt;</span>callstack_depth &lt; <span class="Constant">9000</span><span class="Delimiter">);</span>  <span class="Comment">// 9998-101 plus cushion</span>
<span id="L133" class="LineNr">133 </span>  <span class="Delimiter">}</span>
<span id="L134" class="LineNr">134 </span>  Current_routine<span class="Delimiter">-&gt;</span>calls<span class="Delimiter">.</span>push_front<span class="Delimiter">(</span>call<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">&quot;sandbox&quot;</span><span class="Delimiter">)));</span>
<span id="L135" class="LineNr">135 </span>  <span class="Identifier">return</span><span class="Constant"> true</span><span class="Delimiter">;</span>
<span id="L136" class="LineNr">136 </span><span class="Delimiter">}</span>
<span id="L137" class="LineNr">137 </span>
<span id="L138" class="LineNr">138 </span><span class="Comment">//: Carefully update all state to exactly how it was -- including snapshots.</span>
<span id="L139" class="LineNr">139 </span>
<span id="L140" class="LineNr">140 </span><span class="Delimiter">:(before &quot;End Globals&quot;)</span>
<span id="L141" class="LineNr">141 </span><span class="Normal">bool</span> Run_profiler_stash =<span class="Constant"> false</span><span class="Delimiter">;</span>
<span id="L142" class="LineNr">142 </span>map&lt;string<span class="Delimiter">,</span> recipe_ordinal&gt; Recipe_ordinal_snapshot_stash<span class="Delimiter">;</span>
<span id="L143" class="LineNr">143 </span>map&lt;recipe_ordinal<span class="Delimiter">,</span> recipe&gt; Recipe_snapshot_stash<span class="Delimiter">;</span>
<span id="L144" class="LineNr">144 </span>map&lt;string<span class="Delimiter">,</span> type_ordinal&gt; Type_ordinal_snapshot_stash<span class="Delimiter">;</span>
<span id="L145" class="LineNr">145 </span>map&lt;type_ordinal<span class="Delimiter">,</span> type_info&gt; Type_snapshot_stash<span class="Delimiter">;</span>
<span id="L146" class="LineNr">146 </span>map&lt;recipe_ordinal<span class="Delimiter">,</span> map&lt;string<span class="Delimiter">,</span> <span class="Normal">int</span>&gt; &gt; Name_snapshot_stash<span class="Delimiter">;</span>
<span id="L147" class="LineNr">147 </span>map&lt;string<span class="Delimiter">,</span> vector&lt;recipe_ordinal&gt; &gt; Recipe_variants_snapshot_stash<span class="Delimiter">;</span>
<span id="L148" class="LineNr">148 </span>map&lt;string<span class="Delimiter">,</span> type_tree*&gt; Type_abbreviations_snapshot_stash<span class="Delimiter">;</span>
<span id="L149" class="LineNr">149 </span>vector&lt;scenario&gt; Scenarios_snapshot_stash<span class="Delimiter">;</span>
<span id="L150" class="LineNr">150 </span>set&lt;string&gt; Scenario_names_snapshot_stash<span class="Delimiter">;</span>
<span id="L151" class="LineNr">151 </span>
<span id="L152" class="LineNr">152 </span><span class="Delimiter">:(code)</span>
<span id="L153" class="LineNr">153 </span><span class="Normal">void</span> <a href='101run_sandboxed.cc.html#L153'>run_code_begin</a><span class="Delimiter">(</span><span class="Normal">bool</span> should_stash_snapshots<span class="Delimiter">)</span> <span class="Delimiter">{</span>
<span id="L154" class="LineNr">154 </span>  <span class="Comment">// stuff to undo later, in run_code_end()</span>
<span id="L155" class="LineNr">155 </span>  Hide_errors =<span class="Constant"> true</span><span class="Delimiter">;</span>
<span id="L156" class="LineNr">156 </span>  Disable_redefine_checks =<span class="Constant"> true</span><span class="Delimiter">;</span>
<span id="L157" class="LineNr">157 </span>  Run_profiler_stash = Run_profiler<span class="Delimiter">;</span>
<span id="L158" class="LineNr">158 </span>  Run_profiler =<span class="Constant"> false</span><span class="Delimiter">;</span>
<span id="L159" class="LineNr">159 </span>  <span class="Normal">if</span> <span class="Delimiter">(</span>should_stash_snapshots<span class="Delimiter">)</span>
<span id="L160" class="LineNr">160 </span>    <a href='101run_sandboxed.cc.html#L184'>stash_snapshots</a><span class="Delimiter">();</span>
<span id="L161" class="LineNr">161 </span>  Save_trace_stream = Trace_stream<span class="Delimiter">;</span>
<span id="L162" class="LineNr">162 </span>  Trace_stream = <span class="Normal">new</span> trace_stream<span class="Delimiter">;</span>
<span id="L163" class="LineNr">163 </span>  Trace_stream<span class="Delimiter">-&gt;</span>collect_depth = App_depth<span class="Delimiter">;</span>
<span id="L164" class="LineNr">164 </span><span class="Delimiter">}</span>
<span id="L165" class="LineNr">165 </span>
<span id="L166" class="LineNr">166 </span><span class="Normal">void</span> <a href='101run_sandboxed.cc.html#L166'>run_code_end</a><span class="Delimiter">()</span> <span class="Delimiter">{</span>
<span id="L167" class="LineNr">167 </span>  Hide_errors =<span class="Constant"> false</span><span class="Delimiter">;</span>
<span id="L168" class="LineNr">168 </span>  Disable_redefine_checks =<span class="Constant"> false</span><span class="Delimiter">;</span>
<span id="L169" class="LineNr">169 </span>  Run_profiler = Run_profiler_stash<span class="Delimiter">;</span>
<span id="L170" class="LineNr">170 </span>  Run_profiler_stash =<span class="Constant"> false</span><span class="Delimiter">;</span>
<span id="L171" class="LineNr">171 </span><span class="CommentedCode">//?   ofstream fout(&quot;sandbox.log&quot;);</span>
<span id="L172" class="LineNr">172 </span><span class="CommentedCode">//?   fout &lt;&lt; Trace_stream-&gt;readable_contents(&quot;&quot;);</span>
<span id="L173" class="LineNr">173 </span><span class="CommentedCode">//?   fout.close();</span>
<span id="L174" class="LineNr">174 </span>  <span class="Normal">delete</span> Trace_stream<span class="Delimiter">;</span>
<span id="L175" class="LineNr">175 </span>  Trace_stream = Save_trace_stream<span class="Delimiter">;</span>
<span id="L176" class="LineNr">176 </span>  Save_trace_stream = <span class="Constant">NULL</span><span class="Delimiter">;</span>
<span id="L177" class="LineNr">177 </span>  Save_trace_file<span class="Delimiter">.</span><a href='050scenario.cc.html#L60'>clear</a><span class="Delimiter">();</span>
<span id="L178" class="LineNr">178 </span>  Recipe<span class="Delimiter">.</span>erase<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">&quot;interactive&quot;</span><span class="Delimiter">));</span>  <span class="Comment">// keep past sandboxes from inserting errors</span>
<span id="L179" class="LineNr">179 </span>  <span class="Normal">if</span> <span class="Delimiter">(</span>!Recipe_snapshot_stash<span class="Delimiter">.</span>empty<span class="Delimiter">())</span>
<span id="L180" class="LineNr">180 </span>    <a href='101run_sandboxed.cc.html#L205'>unstash_snapshots</a><span class="Delimiter">();</span>
<span id="L181" class="LineNr">181 </span><span class="Delimiter">}</span>
<span id="L182" class="LineNr">182 </span>
<span id="L183" class="LineNr">183 </span><span class="Comment">// keep sync'd with save_snapshots and restore_snapshots</span>
<span id="L184" class="LineNr">184 </span><span class="Normal">void</span> <a href='101run_sandboxed.cc.html#L184'>stash_snapshots</a><span class="Delimiter">()</span> <span class="Delimiter">{</span>
<span id="L185" class="LineNr">185 </span>  assert<span class="Delimiter">(</span>Recipe_ordinal_snapshot_stash<span class="Delimiter">.</span>empty<span class="Delimiter">());</span>
<span id="L186" class="LineNr">186 </span>  Recipe_ordinal_snapshot_stash = Recipe_ordinal_snapshot<span class="Delimiter">;</span>
<span id="L187" class="LineNr">187 </span>  assert<span class="Delimiter">(</span>Recipe_snapshot_stash<span class="Delimiter">.</span>empty<span class="Delimiter">());</span>
<span id="L188" class="LineNr">188 </span>  Recipe_snapshot_stash = Recipe_snapshot<span class="Delimiter">;</span>
<span id="L189" class="LineNr">189 </span>  assert<span class="Delimiter">(</span>Type_ordinal_snapshot_stash<span class="Delimiter">.</span>empty<span class="Delimiter">());</span>
<span id="L190" class="LineNr">190 </span>  Type_ordinal_snapshot_stash = Type_ordinal_snapshot<span class="Delimiter">;</span>
<span id="L191" class="LineNr">191 </span>  assert<span class="Delimiter">(</span>Type_snapshot_stash<span class="Delimiter">.</span>empty<span class="Delimiter">());</span>
<span id="L192" class="LineNr">192 </span>  Type_snapshot_stash = Type_snapshot<span class="Delimiter">;</span>
<span id="L193" class="LineNr">193 </span>  assert<span class="Delimiter">(</span>Name_snapshot_stash<span class="Delimiter">.</span>empty<span class="Delimiter">());</span>
<span id="L194" class="LineNr">194 </span>  Name_snapshot_stash = Name_snapshot<span class="Delimiter">;</span>
<span id="L195" class="LineNr">195 </span>  assert<span class="Delimiter">(</span>Recipe_variants_snapshot_stash<span class="Delimiter">.</span>empty<span class="Delimiter">());</span>
<span id="L196" class="LineNr">196 </span>  Recipe_variants_snapshot_stash = Recipe_variants_snapshot<span class="Delimiter">;</span>
<span id="L197" class="LineNr">197 </span>  assert<span class="Delimiter">(</span>Type_abbreviations_snapshot_stash<span class="Delimiter">.</span>empty<span class="Delimiter">());</span>
<span id="L198" class="LineNr">198 </span>  Type_abbreviations_snapshot_stash = Type_abbreviations_snapshot<span class="Delimiter">;</span>
<span id="L199" class="LineNr">199 </span>  assert<span class="Delimiter">(</span>Scenarios_snapshot_stash<span class="Delimiter">.</span>empty<span class="Delimiter">());</span>
<span id="L200" class="LineNr">200 </span>  Scenarios_snapshot_stash = Scenarios_snapshot<span class="Delimiter">;</span>
<span id="L201" class="LineNr">201 </span>  assert<span class="Delimiter">(</span>Scenario_names_snapshot_stash<span class="Delimiter">.</span>empty<span class="Delimiter">());</span>
<span id="L202" class="LineNr">202 </span>  Scenario_names_snapshot_stash = Scenario_names_snapshot<span class="Delimiter">;</span>
<span id="L203" class="LineNr">203 </span>  save_snapshots<span class="Delimiter">();</span>
<span id="L204" class="LineNr">204 </span><span class="Delimiter">}</span>
<span id="L205" class="LineNr">205 </span><span class="Normal">void</span> <a href='101run_sandboxed.cc.html#L205'>unstash_snapshots</a><span class="Delimiter">()</span> <span class="Delimiter">{</span>
<span id="L206" class="LineNr">206 </span>  restore_snapshots<span class="Delimiter">();</span>
<span id="L207" class="LineNr">207 </span>  Recipe_ordinal_snapshot = Recipe_ordinal_snapshot_stash<span class="Delimiter">;</span>  Recipe_ordinal_snapshot_stash<span class="Delimiter">.</span><a href='050scenario.cc.html#L60'>clear</a><span class="Delimiter">();</span>
<span id="L208" class="LineNr">208 </span>  Recipe_snapshot = Recipe_snapshot_stash<span class="Delimiter">;</span>  Recipe_snapshot_stash<span class="Delimiter">.</span><a href='050scenario.cc.html#L60'>clear</a><span class="Delimiter">();</span>
<span id="L209" class="LineNr">209 </span>  Type_ordinal_snapshot = Type_ordinal_snapshot_stash<span class="Delimiter">;</span>  Type_ordinal_snapshot_stash<span class="Delimiter">.</span><a href='050scenario.cc.html#L60'>clear</a><span class="Delimiter">();</span>
<span id="L210" class="LineNr">210 </span>  Type_snapshot = Type_snapshot_stash<span class="Delimiter">;</span>  Type_snapshot_stash<span class="Delimiter">.</span><a href='050scenario.cc.html#L60'>clear</a><span class="Delimiter">();</span>
<span id="L211" class="LineNr">211 </span>  Name_snapshot = Name_snapshot_stash<span class="Delimiter">;</span>  Name_snapshot_stash<span class="Delimiter">.</span><a href='050scenario.cc.html#L60'>clear</a><span class="Delimiter">();</span>
<span id="L212" class="LineNr">212 </span>  Recipe_variants_snapshot = Recipe_variants_snapshot_stash<span class="Delimiter">;</span>  Recipe_variants_snapshot_stash<span class="Delimiter">.</span><a href='050scenario.cc.html#L60'>clear</a><span class="Delimiter">();</span>
<span id="L213" class="LineNr">213 </span>  Type_abbreviations_snapshot = Type_abbreviations_snapshot_stash<span class="Delimiter">;</span>  Type_abbreviations_snapshot_stash<span class="Delimiter">.</span><a href='050scenario.cc.html#L60'>clear</a><span class="Delimiter">();</span>
<span id="L214" class="LineNr">214 </span>  Scenarios_snapshot = Scenarios_snapshot_stash<span class="Delimiter">;</span>  Scenarios_snapshot_stash<span class="Delimiter">.</span><a href='050scenario.cc.html#L60'>clear</a><span class="Delimiter">();</span>
<span id="L215" class="LineNr">215 </span>  Scenario_names_snapshot = Scenario_names_snapshot_stash<span class="Delimiter">;</span>  Scenario_names_snapshot_stash<span class="Delimiter">.</span><a href='050scenario.cc.html#L60'>clear</a><span class="Delimiter">();</span>
<span id="L216" class="LineNr">216 </span><span class="Delimiter">}</span>
<span id="L217" class="LineNr">217 </span>
<span id="L218" class="LineNr">218 </span><span class="Delimiter">:(before &quot;End Mu Prelude&quot;)</span>
<span id="L219" class="LineNr">219 </span>load<span class="Delimiter">(</span>string<span class="Delimiter">(</span>
<span id="L220" class="LineNr">220 </span><span class="Constant">&quot;recipe interactive [</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span><span class="Delimiter">)</span> +  <span class="Comment">// just a dummy version to initialize the Recipe_ordinal and so on</span>
<span id="L221" class="LineNr">221 </span><span class="Constant">&quot;]</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> +
<span id="L222" class="LineNr">222 </span><span class="Constant">&quot;recipe sandbox [</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> +
<span id="L223" class="LineNr">223 </span>  <span class="Constant">&quot;local-scope</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> +
<span id="L224" class="LineNr">224 </span><span class="CommentedCode">//?   &quot;$print [aaa] 10/newline\n&quot; +</span>
<span id="L225" class="LineNr">225 </span>  <span class="Constant">&quot;screen:&amp;:screen &lt;- new-fake-screen 30, 5</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> +
<span id="L226" class="LineNr">226 </span>  <span class="Constant">&quot;routine-id:num &lt;- start-running interactive, screen</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> +
<span id="L227" class="LineNr">227 </span>  <span class="Constant">&quot;limit-time routine-id, 100000/instructions</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> +
<span id="L228" class="LineNr">228 </span>  <span class="Constant">&quot;wait-for-routine routine-id</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> +
<span id="L229" class="LineNr">229 </span><span class="Commen