Skip to content

Commit 531d5fa

Browse files
committed
Fix luac-lex in face of gc, run lexers for bootrt in parallel
1 parent 67f90a6 commit 531d5fa

File tree

6 files changed

+107
-73
lines changed

6 files changed

+107
-73
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
quire.js
33
rt.wasm
44
scripts/lex.wasm
5-
bootrt.lua
5+
./bootrt.lua
66
lua-5.3.4-tests/

luart/bootrt.lua

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
local astgen = require 'astgen'
2+
local bcgen = require 'bcgen'
3+
4+
return function(...)
5+
local result = {}
6+
local prevsult = {
7+
integer = {},
8+
float = {},
9+
string = {},
10+
}
11+
12+
local funcnums, funcprefix
13+
local strconst = {}
14+
local function func2lua(func, toplevel)
15+
local name = funcprefix .. funcnums
16+
funcnums = funcnums + 1
17+
local subfuncs = {}
18+
local consts = {}
19+
for i=1, #func.consts do
20+
local c = func.consts[i]
21+
local ct = math.type(c) or type(c)
22+
consts[#consts+1] = strconst[ct](c)
23+
end
24+
if #consts == 0 then
25+
consts = nil
26+
end
27+
result[#result+1] = {
28+
name,
29+
#func.params,
30+
func.isdotdotdot,
31+
string.char(table.unpack(func.bc)),
32+
consts,
33+
#func.locals,
34+
}
35+
return name
36+
end
37+
function strconst.integer(c)
38+
if prevsult.integer[c] then
39+
return prevsult.integer[c]
40+
else
41+
local pack = string.pack('<i8', c)
42+
result[#result+1] = c
43+
prevsult.integer[c] = function() return GN.integer[pack] end
44+
return prevsult.integer[c]
45+
end
46+
end
47+
function strconst.float(c)
48+
if prevsult.float[c] then
49+
return prevsult.float[c]
50+
else
51+
local pack = string.pack('<d', c)
52+
result[#result+1] = c
53+
prevsult.float[c] = function() return GN.float[pack] end
54+
return prevsult.float[c]
55+
end
56+
end
57+
function strconst.string(c)
58+
if prevsult.string[c] then
59+
return prevsult.string[c]
60+
else
61+
result[#result+1] = c
62+
prevsult.string[c] = function() return GS[c] end
63+
return prevsult.string[c]
64+
end
65+
end
66+
function strconst.table(c)
67+
local pack = func2lua(c)
68+
return function() return GF[pack] end
69+
end
70+
local lexers = {}
71+
for i=1,select('#', ...) do
72+
local srcfile = select(i, ...)
73+
lexers[srcfile] = io.popen("./scripts/luac-lex.js '" .. srcfile:gsub("'", "'\\''") .. "'")
74+
end
75+
for i=1,select('#', ...) do
76+
local srcfile = select(i, ...)
77+
local data = lexers[srcfile]:read('a')
78+
local lx, offs = string.unpack('<s4', data)
79+
local vlen, offs = string.unpack('<i4', data, offs)
80+
local vals = {}
81+
for i=1,vlen do
82+
local ty = data:byte(offs)
83+
if ty == 0 then
84+
vals[i], offs = string.unpack('<i8', data, offs+1)
85+
elseif ty == 1 then
86+
vals[i], offs = string.unpack('<d', data, offs+1)
87+
else
88+
vals[i], offs = string.unpack('<s4', data, offs+1)
89+
end
90+
end
91+
92+
funcnums = 0
93+
funcprefix = srcfile:gsub('^.*/(.*)%.lua$', '%1')
94+
print(funcprefix)
95+
func2lua(bcgen(astgen(lx, vals)))
96+
end
97+
return result
98+
end

luart/util.lua

Lines changed: 0 additions & 70 deletions
This file was deleted.

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ I'll try avoid my usual stream of consciousness here, instead that's at [my devl
88

99
WASM runtime is in `rt/`. [`rt/make.lua`](rt/make.lua) is the entry point for the assmembler. This produces an `rt.wasm` which [`rt.js`](rt.js) contains glue code for
1010

11-
The GC is a LISP2 compacting GC. GC performance is a low priority given the WASM GC RFC
11+
The GC is a LISP2 compacting GC. GC performance is a low priority given the WASM GC RFC. See [`rt/gc.lua`](rt/gc.lua)
1212

1313
The VM needs to be reentrant. The currently running coroutine is oluastack. Builtins which call functions work by returning after setting up a necessary callstack. See [`rt/vm.lua`](rt/vm.lua)
1414

scripts/luac-lex.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env node
22
"use strict";
33
const fs = require('fs'),
4+
util = require('../util'),
45
{ promisify } = require('util'),
56
readFile = promisify(fs.readFile);
67

scripts/luac.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,14 @@ end
104104
function strconst.table(c)
105105
return 'function() return GF.' .. func2lua(c) .. ' end'
106106
end
107+
local lexers = {}
107108
for i=2,select('#', ...) do
108109
local srcfile = select(i, ...)
109-
local data = io.popen("./scripts/luac-lex.js '" .. srcfile:gsub("'", "'\\''") .. "'"):read('a')
110+
lexers[srcfile] = io.popen("./scripts/luac-lex.js '" .. srcfile:gsub("'", "'\\''") .. "'")
111+
end
112+
for i=2,select('#', ...) do
113+
local srcfile = select(i, ...)
114+
local data = lexers[srcfile]:read('a')
110115
local lx, offs = string.unpack('<s4', data)
111116
local vlen, offs = string.unpack('<i4', data, offs)
112117
local vals = {}

0 commit comments

Comments
 (0)