Skip to content

Commit

Permalink
Fix #80
Browse files Browse the repository at this point in the history
  • Loading branch information
edubart committed Jul 15, 2021
1 parent b26302f commit cc7dde5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion nelua/cemitter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ function CEmitter:add_qualified_declaration(attr, type, name)
self:add(context:ensure_builtin('nelua_noreturn'), ' ')
end
-- type qualifiers
if attr.const then
if attr.const and not attr.ignoreconst then
if traits.is_type(type) and (type.is_pointer or type.is_scalar or type.is_boolean) then
-- only allow const on some basic types
self:add('const ')
Expand Down
11 changes: 5 additions & 6 deletions nelua/cgenerator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1065,21 +1065,20 @@ function visitors.VarDecl(context, node, emitter)
local declared, defined
if varattr.staticstorage then -- declare variables in the top scope
local decemitter = CEmitter(context)
local custominit = valnode and valnode.attr.initializer
declared = true
defined = custominit or (not valnode and not lastcallindex)
varnode.attr.ignoreconst = not defined
decemitter:add_indent(varnode)
if valnode and valnode.attr.initializer then -- initialize to const values
if custominit then -- initialize to const values
assert(not lastcallindex)
decemitter:add(' = ')
context:push_forked_state{ininitializer = true}
decemitter:add_converted_val(vartype, valnode)
context:pop_state()
defined = true
elseif zeroinit then -- pre initialize with zeros
-- C static storage variables are always initialized to zeros already
defined = not valnode and not lastcallindex
end
decemitter:add_ln(';')
context:add_declaration(decemitter:generate())
declared = true
end
if varattr:must_define_at_runtime() then
local asgnvalname, asgnvaltype = valnode, valtype
Expand Down

0 comments on commit cc7dde5

Please sign in to comment.