Skip to content

Commit cf85a69

Browse files
committed
more work on bootstrapping
wip table typing
1 parent d30107b commit cf85a69

11 files changed

Lines changed: 283 additions & 203 deletions

File tree

nattlua/analyzer/base/base_analyzer.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ return function(META--[[#: any]])
131131
end
132132

133133
return new_tup
134-
elseif tbl.PotentialSelf then
134+
elseif tbl.potential_self then
135135
local meta = tbl
136-
local self = tbl.PotentialSelf
136+
local self = tbl.potential_self
137137

138138
if self.Type == "union" then
139139
for _, obj in ipairs(self:GetData()) do

nattlua/analyzer/operators/call.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ local function any_call(self, analyzer, input, call_node)
271271
if arg:GetContract() then
272272
-- error if we call any with tables that have contracts
273273
-- since anything might happen to them in an any call
274-
analyzer:Error(error_messages.argument_contract_mutation(arg:GetContract()))
274+
analyzer:Warning(error_messages.argument_contract_mutation(arg, arg:GetContract()))
275275
else
276276
-- if we pass a table without a contract to an any call, we add any to its key values
277277
for _, keyval in ipairs(arg:GetData()) do

nattlua/analyzer/operators/function_call_body.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ return function(self, obj, input)
331331
if contract.Type == "union" then
332332
local t = contract:GetType("table")
333333

334-
if t and t.PotentialSelf then doit = false end
334+
if t and t.potential_self then doit = false end
335335
end
336336

337337
if doit then

nattlua/base_environment.lua

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ end
3838
local function load_definitions(root_node, parent_config)
3939
local path = "nattlua/definitions/index.nlua"
4040
local config = {}
41+
4142
if parent_config then
4243
for k, v in pairs(parent_config) do
4344
config[k] = v
4445
end
4546
end
47+
4648
config.file_path = config.file_path or path
4749
config.file_name = config.file_name or "@" .. path
4850
config.root_directory = ROOT_PATH
@@ -79,24 +81,25 @@ return {
7981
local typesystem_env = Table()
8082
typesystem_env.string_metatable = Table()
8183
compiler:SetEnvironments(runtime_env, typesystem_env)
82-
8384
-- Use parent analyzer's config if it exists or just use a fresh analyzer
8485
local analyzer
86+
8587
if parent_analyzer then
8688
analyzer = require("nattlua.analyzer.analyzer").New(parent_analyzer.config)
87-
-- Ensure we're using a common statement count if we want to track it
88-
-- but for base environment it might be noisy. Let's at least record parsed paths.
89+
-- Ensure we're using a common statement count if we want to track it
90+
-- but for base environment it might be noisy. Let's at least record parsed paths.
8991
end
90-
92+
9193
assert(compiler:Analyze(analyzer))
92-
94+
9395
if parent_analyzer then
9496
for path, _ in pairs(compiler.analyzer.parsed_paths) do
9597
parent_analyzer.parsed_paths[path] = true
9698
end
99+
97100
parent_analyzer.statement_count = (parent_analyzer.statement_count or 0) + (compiler.analyzer.statement_count or 0)
98101
end
99-
102+
100103
typesystem_env.string_metatable:Set(
101104
LStringNoMeta("__index"),
102105
assert(typesystem_env:Get(LStringNoMeta("string")), "failed to find string table")

nattlua/definitions/lua/ffi/main.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,8 @@ function cparser.metatype(ctype, meta)
296296
local val = analyzer:Assert(analyzer:Call(new, Tuple({ctype, ...}))):GetFirstValue()
297297

298298
if analyzer:IsRuntime() then
299-
meta.PotentialSelf = meta.PotentialSelf or Union()
300-
meta.PotentialSelf:AddType(val)
299+
meta.potential_self = meta.potential_self or Union()
300+
meta.potential_self:AddType(val)
301301
end
302302

303303
return val

nattlua/definitions/lua/globals.nlua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,8 +508,8 @@ analyzer function setmetatable(tbl: Table, meta: Table | nil)
508508
-- clear mutations so that when looking up values in the table they won't return their initial value
509509
tbl:ClearMutations()
510510
elseif analyzer:IsRuntime() then
511-
meta.PotentialSelf = meta.PotentialSelf or types.Union()
512-
meta.PotentialSelf:AddType(tbl)
511+
meta.potential_self = meta.potential_self or types.Union()
512+
meta.potential_self:AddType(tbl)
513513
end
514514

515515
tbl:SetMetaTable(meta)

nattlua/definitions/utility.nlua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ analyzer function copy(obj: any)
156156

157157
if copy.Type == "table" then
158158
copy:SetCreationScope(false)
159-
copy.PotentialSelf = false
159+
copy.potential_self = false
160160
end
161161

162162
return copy

nattlua/error_messages.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,11 @@ function error_messages.argument_mutation(i--[[#: number]], arg--[[#: any]])--[[
290290
}
291291
end
292292

293-
function error_messages.argument_contract_mutation(obj--[[#: any]])--[[#: Reason]]
293+
function error_messages.argument_contract_mutation(obj--[[#: any]], obj--[[#: any]])--[[#: Reason]]
294294
return {
295-
"cannot mutate argument with contract ",
295+
"cannot mutate argument ",
296+
obj,
297+
" with contract ",
296298
obj,
297299
}
298300
end

0 commit comments

Comments
 (0)