Differences From
Artifact [7b59e1e979]:
39 39 if v.tree.type == ty then return fn(v,...) end
40 40 end
41 41 return (tbl[false])(v,...)
42 42 end)
43 43 end;
44 44 emit_unitary = function(nl,fd,...)
45 45 local code = {}
46 + local defs = {}
46 47 for i,v in ipairs{...} do
47 - if type(v) == 'string' or type(v) == 'number' then
48 - local str = tostring(v)
49 - code[#code+1] = `lib.io.send(2, str, [#str])
50 - elseif type(v) == 'table' and #v == 2 then
51 - code[#code+1] = `lib.io.send(2, [v[1]], [v[2]])
52 - elseif v.tree:is 'constant' then
53 - local str = tostring(v:asvalue())
54 - code[#code+1] = `lib.io.send(2, str, [#str])
48 + local str, ct
49 + if type(v) == 'table' and v.tree and not (v.tree:is 'constant') then
50 + if v.tree.type.convertible == 'tuple' then
51 + str = `v._0
52 + ct = `v._1
53 + else
54 + local n = symbol(v.tree.type)
55 + defs[#defs + 1] = quote var [n] = v end
56 + str = n
57 + ct = `lib.str.sz(n)
58 + end
55 59 else
56 - code[#code+1] = quote var n = v in
57 - lib.io.send(2, n, lib.str.sz(n)) end
60 + if type(v) == 'string' or type(v) == 'number' then
61 + str = tostring(v)
62 + else--if v.tree:is 'constant' then
63 + str = tostring(v:asvalue())
64 + end
65 + ct = ct or #str
58 66 end
67 +
68 + code[#code+1] = `lib.io.send(fd, str, ct)
59 69 end
60 70 if nl == true then code[#code+1] = `lib.io.send(fd, '\n', 1)
61 71 elseif nl then code[#code+1] = `lib.io.send(fd, nl, [#nl]) end
62 - return code
72 + return quote [defs] in [code] end
63 73 end;
64 74 emitv = function(nl,fd,...)
65 75 local vec = {}
66 76 local defs = {}
67 77 for i,v in ipairs{...} do
68 78 local str, ct
69 79 if type(v) == 'table' and v.tree and not (v.tree:is 'constant') then
................................................................................
160 170 end;
161 171 osclock = terralib.includec 'time.h';
162 172 }
163 173 if config.posix then
164 174 lib.uio = terralib.includec 'sys/uio.h';
165 175 lib.emit = lib.emitv -- use more efficient call where available
166 176 else lib.emit = lib.emit_unitary end
167 -
168 177
169 178 lib.noise = {
170 179 level = global(uint8,1);
171 180 starttime = global(lib.osclock.time_t);
172 181 lasttime = global(lib.osclock.time_t);
173 182 header = function(code,txt,mod)
174 183 if mod then