Skip to content

Commit

Permalink
Refactor and document more the types modules
Browse files Browse the repository at this point in the history
  • Loading branch information
edubart committed Aug 16, 2020
1 parent bf8b171 commit a336a42
Show file tree
Hide file tree
Showing 7 changed files with 741 additions and 468 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ nelua_cache
.vscode
tempCodeRunner.*
neluacfg.lua
.neluacfg.lua
/play
7 changes: 3 additions & 4 deletions nelua/analyzer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -654,8 +654,7 @@ function visitors.EnumType(context, node)
fields[i] = field
end
attr.type = primtypes.type
local type = types.EnumType(subtype, fields)
type.node = node
local type = types.EnumType(subtype, fields, node)
attr.value = type
node.done = true
end
Expand Down Expand Up @@ -860,7 +859,7 @@ local function visitor_Call_type_cast(context, node, argnodes, type)
argnode:raisef("in type cast: %s", err)
end
if argattr.comptime then
attr.value = type:normalize_value(argattr.value)
attr.value = type:wrap_value(argattr.value)
if attr.value or argtype == type then
attr.comptime = true
end
Expand Down Expand Up @@ -984,7 +983,7 @@ local function visitor_Call(context, node, argnodes, calleetype, calleesym, call
calleetype = nil
calleesym = nil
if knownallargs then
local polyeval = polycalleetype:eval_poly_for_args(polyargs)
local polyeval = polycalleetype:eval_poly(polyargs)
if polyeval and polyeval.node and polyeval.node.attr.type then
calleesym = polyeval.node.attr
calleetype = polyeval.node.attr.type
Expand Down
4 changes: 2 additions & 2 deletions nelua/cemitter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ function CEmitter:add_numeric_literal(valattr, valtype)

if valtype.is_integral then
if bn.isneg(val) and valtype.is_unsigned then
val = valtype:normalize_value(val)
val = valtype:wrap_value(val)
elseif not valtype:is_inrange(val) then
val = valtype:normalize_value(val)
val = valtype:wrap_value(val)
end
end

Expand Down
4 changes: 2 additions & 2 deletions nelua/typedefs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ local cintsize = math.max(math.min(cpusize, 4), 2)
-- C long is at least 4 bytes
local clongsize = math.max(cpusize, 4)

-- primitive types
-- Primitive types
primtypes.niltype = types.NiltypeType('niltype')
primtypes.void = types.VoidType('void', 0) -- the type for nothing
primtypes.any = types.AnyType('any', 2*cpusize) -- the type for anything
Expand All @@ -39,7 +39,7 @@ primtypes.table = types.TableType('table')
primtypes.nilptr = types.NilptrType('nilptr', cpusize)
primtypes.pointer = types.PointerType(primtypes.void)

-- for C compability
-- Types for C compatibility
primtypes.cschar = types.IntegralType('cschar', 1)
primtypes.cshort = types.IntegralType('cshort', 2)
primtypes.cint = types.IntegralType('cint', cintsize)
Expand Down
Loading

0 comments on commit a336a42

Please sign in to comment.