array: make left/right/slice private

pull/2940/head
Alexander Medvednikov 2019-11-30 12:37:34 +03:00
parent b38283dcf1
commit 7e4799334f
5 changed files with 12 additions and 12 deletions

View File

@ -289,7 +289,7 @@ fn (g mut Game) generate_tetro() {
// Get the right tetro from cache // Get the right tetro from cache
fn (g mut Game) get_tetro() { fn (g mut Game) get_tetro() {
idx := g.tetro_idx * TetroSize * TetroSize + g.rotation_idx * TetroSize idx := g.tetro_idx * TetroSize * TetroSize + g.rotation_idx * TetroSize
g.tetro = g.tetros_cache.slice(idx, idx + TetroSize) g.tetro = g.tetros_cache[idx..idx+TetroSize]
} }
// TODO mut // TODO mut
@ -403,7 +403,7 @@ fn key_down(wnd voidptr, key, code, action, mods int) {
} }
} }
} }
if game.state != .running { if game.state != .running {
return return
} }

View File

@ -173,7 +173,7 @@ pub fn (a array) last() voidptr {
// array.left returns a new array using the same buffer as the given array // array.left returns a new array using the same buffer as the given array
// with the first `n` elements of the given array. // with the first `n` elements of the given array.
pub fn (a array) left(n int) array { fn (a array) left(n int) array {
if n < 0 { if n < 0 {
panic('array.left: index is negative (n == $n)') panic('array.left: index is negative (n == $n)')
} }
@ -187,7 +187,7 @@ pub fn (a array) left(n int) array {
// but starting with the element of the given array beyond the index `n`. // but starting with the element of the given array beyond the index `n`.
// If `n` is bigger or equal to the length of the given array, // If `n` is bigger or equal to the length of the given array,
// returns an empty array of the same type as the given array. // returns an empty array of the same type as the given array.
pub fn (a array) right(n int) array { fn (a array) right(n int) array {
if n < 0 { if n < 0 {
panic('array.right: index is negative (n == $n)') panic('array.right: index is negative (n == $n)')
} }
@ -207,7 +207,7 @@ fn (a array) slice2(start, _end int, end_max bool) array {
// but starting from the `start` element and ending with the element before // but starting from the `start` element and ending with the element before
// the `end` element of the original array with the length and capacity // the `end` element of the original array with the length and capacity
// set to the number of the elements in the slice. // set to the number of the elements in the slice.
pub fn (a array) slice(start, _end int) array { fn (a array) slice(start, _end int) array {
mut end := _end mut end := _end
if start > end { if start > end {
panic('array.slice: invalid slice index ($start > $end)') panic('array.slice: invalid slice index ($start > $end)')
@ -315,7 +315,7 @@ pub fn (a []bool) str() string {
sb.write('true') sb.write('true')
} else { } else {
sb.write('false') sb.write('false')
} }
if i < a.len - 1 { if i < a.len - 1 {
sb.write(', ') sb.write(', ')
} }

View File

@ -42,7 +42,7 @@ pub fn (cmd mut Command) parse(args []string) {
cmd.add_default_flags() cmd.add_default_flags()
cmd.add_default_commands() cmd.add_default_commands()
cmd.args = args.right(1) cmd.args = args[1..]
for i := 0; i < cmd.commands.len; i++ { for i := 0; i < cmd.commands.len; i++ {
cmd.commands[i].parent = cmd cmd.commands[i].parent = cmd
} }
@ -110,7 +110,7 @@ fn (cmd mut Command) parse_commands() {
for flag in global_flags { for flag in global_flags {
command.add_flag(flag) command.add_flag(flag)
} }
command.parse(cmd.args.right(i)) command.parse(cmd.args[i..])
return return
} }
} }
@ -187,4 +187,4 @@ fn (cmds []Command) get(name string) ?Command {
} }
} }
return error('command \'${name}\' not found.') return error('command \'${name}\' not found.')
} }

View File

@ -547,7 +547,7 @@ fn (p mut Parser) parse(pass Pass) {
} }
p.genln('') p.genln('')
end := p.cgen.lines.len end := p.cgen.lines.len
lines := p.cgen.lines.slice(start, end) lines := p.cgen.lines[start..end]
//mut line := p.cgen.fn_main + lines.join('\n') //mut line := p.cgen.fn_main + lines.join('\n')
//line = line.trim_space() //line = line.trim_space()
p.cgen.fn_main = p.cgen.fn_main + lines.join('\n') p.cgen.fn_main = p.cgen.fn_main + lines.join('\n')

View File

@ -80,7 +80,7 @@ pub fn (f File) read_bytes_at(size, pos int) []byte {
C.fseek(f.cfile, pos, C.SEEK_SET) C.fseek(f.cfile, pos, C.SEEK_SET)
nreadbytes := C.fread(arr.data, 1, size, f.cfile) nreadbytes := C.fread(arr.data, 1, size, f.cfile)
C.fseek(f.cfile, 0, C.SEEK_SET) C.fseek(f.cfile, 0, C.SEEK_SET)
return arr.slice(0, nreadbytes) return arr[0..nreadbytes]
} }
pub fn read_bytes(path string) ?[]byte { pub fn read_bytes(path string) ?[]byte {
@ -95,7 +95,7 @@ pub fn read_bytes(path string) ?[]byte {
mut res := [`0`].repeat(fsize) mut res := [`0`].repeat(fsize)
nreadbytes := C.fread(res.data, fsize, 1, fp) nreadbytes := C.fread(res.data, fsize, 1, fp)
C.fclose(fp) C.fclose(fp)
return res.slice(0, nreadbytes ) return res[0..nreadbytes]
} }
// read_file reads the file in `path` and returns the contents. // read_file reads the file in `path` and returns the contents.