all: fix immutable fn args

pull/1498/head
Alexander Medvednikov 2019-08-06 18:13:04 +02:00
parent 76def48f01
commit 52f473d1c7
5 changed files with 24 additions and 21 deletions

View File

@ -666,6 +666,7 @@ fn (p mut Parser) fn_args(f mut Fn) {
}
f.args << int_arg
}
// `(int, string, int)`
// Just register fn arg types
types_only := p.tok == .mul || (p.peek() == .comma && p.table.known_type(p.lit)) || p.peek() == .rpar// (int, string)
if types_only {
@ -684,12 +685,12 @@ fn (p mut Parser) fn_args(f mut Fn) {
}
}
}
// (a int, b,c string) syntax
// `(a int, b, c string)` syntax
for p.tok != .rpar {
mut names := [
p.check_name()
]
// a,b,c int syntax
// `a,b,c int` syntax
for p.tok == .comma {
p.check(.comma)
p.fspace()

View File

@ -694,13 +694,13 @@ pub fn (s string) ustring_tmp() ustring {
return res
}
pub fn (u ustring) substr(start, end int) string {
start = u.runes[start]
if end >= u.runes.len {
end = u.s.len
pub fn (u ustring) substr(_start, _end int) string {
start := u.runes[_start]
end := if _end >= u.runes.len {
u.s.len
}
else {
end = u.runes[end]
u.runes[_end]
}
return u.s.substr(start, end)
}

View File

@ -102,7 +102,8 @@ pub fn exp(a f64) f64 {
}
// digits returns an array of the digits of n in the given base.
pub fn digits(n, base int) []int {
pub fn digits(_n, base int) []int {
mut n := _n
mut sign := 1
if n < 0 {
sign = -1
@ -132,6 +133,7 @@ pub fn exp2(a f64) f64 {
}
// factorial calculates the factorial of the provided value.
// TODO bring back once multiple value functions are implemented
fn recursive_product( n int, current_number_ptr &int) int{
mut m := n / 2
if (m == 0){

View File

@ -337,8 +337,8 @@ fn popen(path string) *FILE {
}
// exec starts the specified command, waits for it to complete, and returns its output.
pub fn exec(cmd string) string {
cmd = '$cmd 2>&1'
pub fn exec(_cmd string) string {
cmd := '$_cmd 2>&1'
f := popen(cmd)
if isnil(f) {
// TODO optional or error code
@ -397,19 +397,19 @@ pub fn unsetenv(name string) int {
}
// `file_exists` returns true if `path` exists.
pub fn file_exists(path string) bool {
pub fn file_exists(_path string) bool {
$if windows {
path = path.replace('/', '\\')
return C._waccess( path.to_wide(), 0 ) != -1
path := _path.replace('/', '\\')
return C._waccess(path.to_wide(), 0) != -1
} $else {
return C.access( path.str, 0 ) != -1
return C.access(_path.str, 0 ) != -1
}
}
pub fn dir_exists(path string) bool {
$if windows {
path = path.replace('/', '\\')
attr := int(C.GetFileAttributes(path.to_wide()))
_path := path.replace('/', '\\')
attr := int(C.GetFileAttributes(_path.to_wide()))
if attr == INVALID_FILE_ATTRIBUTES {
return false
}
@ -431,13 +431,13 @@ pub fn dir_exists(path string) bool {
// mkdir creates a new directory with the specified path.
pub fn mkdir(path string) {
$if windows {
path = path.replace('/', '\\')
_path := path.replace('/', '\\')
// Windows doesnt recursively create the folders
// so we need to help it out here
if path.last_index('\\') != -1 {
mkdir(path.all_before_last('\\'))
if _path.last_index('\\') != -1 {
mkdir(_path.all_before_last('\\'))
}
C.CreateDirectory(path.to_wide(), 0)
C.CreateDirectory(_path.to_wide(), 0)
}
$else {
C.mkdir(path.str, 511)// S_IRWXU | S_IRWXG | S_IRWXO

View File

@ -34,7 +34,7 @@ pub fn (b Builder) str() string {
return string(b.buf, b.len)
}
pub fn (b Builder) cut(n int) {
pub fn (b mut Builder) cut(n int) {
b.len -= n
}