parser: do no allow var names with __; cgen: use __argc
parent
95a1bd8470
commit
f748390172
|
@ -506,12 +506,12 @@ pub fn (a []char) index(v char) int {
|
|||
// []int.reduce executes a given reducer function on each element of the array,
|
||||
// resulting in a single output value.
|
||||
pub fn (a []int) reduce(iter fn(accum, curr int)int, accum_start int) int {
|
||||
mut _accum := accum_start
|
||||
mut accum_ := accum_start
|
||||
for i in a {
|
||||
_accum = iter(_accum, i)
|
||||
accum_ = iter(accum_, i)
|
||||
}
|
||||
|
||||
return _accum
|
||||
return accum_
|
||||
}
|
||||
|
||||
// array_eq<T> checks if two arrays contain all the same elements in the same order.
|
||||
|
|
|
@ -757,9 +757,9 @@ fn (g mut Gen) gen_fn_decl(it ast.FnDecl) {
|
|||
is_main := it.name == 'main'
|
||||
if is_main {
|
||||
if g.pref.os == .windows {
|
||||
g.write('int wmain(int argc, wchar_t *argv[], wchar_t *envp[]')
|
||||
g.write('int wmain(int __argc, wchar_t *__argv[], wchar_t *__envp[]')
|
||||
} else {
|
||||
g.write('int ${it.name}(int argc, char** argv')
|
||||
g.write('int ${it.name}(int __argc, char** __argv')
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -817,9 +817,9 @@ fn (g mut Gen) gen_fn_decl(it ast.FnDecl) {
|
|||
g.writeln('free(_const_os__args.data); // empty, inited in _vinit()')
|
||||
}
|
||||
if g.pref.os == .windows {
|
||||
g.writeln('_const_os__args = os__init_os_args_wide(argc, argv);')
|
||||
g.writeln('_const_os__args = os__init_os_args_wide(__argc, __argv);')
|
||||
} else {
|
||||
g.writeln('_const_os__args = os__init_os_args(argc, (byteptr*)argv);')
|
||||
g.writeln('_const_os__args = os__init_os_args(__argc, (byteptr*)__argv);')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1686,6 +1686,9 @@ fn (p mut Parser) assign_stmt() ast.Stmt {
|
|||
p.error('unknown variable `$ident.name`')
|
||||
}
|
||||
if is_decl && ident.kind != .blank_ident {
|
||||
if ident.name.starts_with('__') {
|
||||
p.error('variable names cannot start with `__`')
|
||||
}
|
||||
if p.scope.known_var(ident.name) {
|
||||
p.error('redefinition of `$ident.name`')
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue