👍 Fix up redundant type declare and remove space (#603)

pull/667/head
Ryota.I (yabu) 2019-06-26 23:39:40 +09:00 committed by Alexander Medvednikov
parent 32e61b23d0
commit 61e4367aa8
6 changed files with 57 additions and 57 deletions

View File

@ -15,7 +15,7 @@ pub:
}
// Private function, used by V (`nums := []int`)
fn new_array(mylen int, cap, elm_size int) array {
fn new_array(mylen, cap, elm_size int) array {
arr := array {
len: mylen
cap: cap
@ -50,7 +50,7 @@ fn new_array_from_c_array_no_alloc(len, cap, elm_size int, c_array voidptr) arra
}
// Private function, used by V (`[0; 100]`)
fn array_repeat(val voidptr, nr_repeats int, elm_size int) array {
fn array_repeat(val voidptr, nr_repeats, elm_size int) array {
arr := array {
len: nr_repeats
cap: nr_repeats

View File

@ -25,7 +25,7 @@ pub:
// next *Entry
}
fn new_map(cap int, elm_size int) map {
fn new_map(cap, elm_size int) map {
res := map {
// len: len,
element_size: elm_size

View File

@ -84,7 +84,7 @@ const (
'panic',
'register'
]
)
// This is used in generated C code
@ -164,7 +164,7 @@ fn (table &Table) known_pkg(pkg string) bool {
return pkg in table.packages
}
fn (t mut Table) register_const(name, typ string, pkg string, is_imported bool) {
fn (t mut Table) register_const(name, typ, pkg string, is_imported bool) {
t.consts << Var {
name: name
typ: typ
@ -273,11 +273,11 @@ fn (t mut Table) register_type_with_parent(typ, parent string) {
return
}
}
/*
mut pkg := ''
/*
mut pkg := ''
if parent == 'array' {
pkg = 'builtin'
}
pkg = 'builtin'
}
*/
datyp := Type {
name: typ

View File

@ -93,8 +93,8 @@ struct Game {
field array_array_int
// TODO: tetro Tetro
tetro []Block
// TODO: tetros_cache []Tetro
tetros_cache []Block
// TODO: tetros_cache []Tetro
tetros_cache []Block
// Index of the current tetro. Refers to its color.
tetro_idx int
// Index of the rotation (0-3)
@ -106,7 +106,7 @@ struct Game {
fn main() {
glfw.init()
mut game := &Game{gg: 0} // TODO
game.parse_tetros()
game.parse_tetros()
game.init_game()
mut window := glfw.create_window(glfw.WinCfg {
width: WinWidth
@ -155,13 +155,13 @@ fn (g mut Game) init_game() {
fn (g mut Game) parse_tetros() {
for b_tetros in BTetros {
for b_tetro in b_tetros {
for t in parse_binary_tetro(b_tetro) {
for b_tetro in b_tetros {
for t in parse_binary_tetro(b_tetro) {
g.tetros_cache << t
}
}
}
}
}
}
}
}
fn (g mut Game) run() {
for {
@ -196,7 +196,7 @@ fn (g mut Game) move_tetro() {
}
fn (g mut Game) move_right(dx int) {
// Reached left/right edge or another tetro?
// Reached left/right edge or another tetro?
for i := 0; i < TetroSize; i++ {
tetro := g.tetro[i]
y := tetro.y + g.pos_y
@ -238,15 +238,15 @@ fn (g mut Game) generate_tetro() {
g.pos_y = 0
g.pos_x = FieldWidth / 2 - TetroSize / 2
g.tetro_idx = rand.next(BTetros.len)
g.rotation_idx = 0
g.get_tetro()
g.rotation_idx = 0
g.get_tetro()
}
// Get the right tetro from cache
// Get the right tetro from cache
fn (g mut Game) get_tetro() {
idx := g.tetro_idx * TetroSize * TetroSize + g.rotation_idx * TetroSize
g.tetro = g.tetros_cache.slice(idx, idx + TetroSize)
}
idx := g.tetro_idx * TetroSize * TetroSize + g.rotation_idx * TetroSize
g.tetro = g.tetros_cache.slice(idx, idx + TetroSize)
}
fn (g mut Game) drop_tetro() {
for i := 0; i < TetroSize; i++ {
@ -267,8 +267,8 @@ fn (g &Game) draw_tetro() {
}
}
fn (g &Game) draw_block(i, j int, color_idx int) {
g.gg.draw_rect((j - 1) * BlockSize, (i - 1) * BlockSize,
fn (g &Game) draw_block(i, j, color_idx int) {
g.gg.draw_rect((j - 1) * BlockSize, (i - 1) * BlockSize,
BlockSize - 1, BlockSize - 1, Colors[color_idx])
}
@ -315,7 +315,7 @@ fn parse_binary_tetro(t int) []Block {
}
// TODO: this exposes the unsafe C interface, clean up
fn key_down(wnd voidptr, key int, code int, action, mods int) {
fn key_down(wnd voidptr, key, code, action, mods int) {
if action != 2 && action != 1 {
return
}
@ -328,7 +328,7 @@ fn key_down(wnd voidptr, key int, code int, action, mods int) {
if game.rotation_idx == TetroSize {
game.rotation_idx = 0
}
game.get_tetro()
game.get_tetro()
if game.pos_x < 0 {
game.pos_x = 1
}

View File

@ -28,7 +28,7 @@ fn init_glad() {
}
}
pub fn viewport(a int, b int, c int, d int) {
pub fn viewport(a, b, c, d int) {
C.glViewport(a, b, c, d)
}
@ -48,7 +48,7 @@ pub fn create_program() int {
return C.glCreateProgram()
}
pub fn shader_source(shader int, a int, source string, b int) {
pub fn shader_source(shader, a int, source string, b int) {
C.glShaderSource(shader, a, &source.str, b)
}
@ -62,7 +62,7 @@ pub fn shader_compile_status(shader int) int {
return success
}
pub fn attach_shader(program int, shader int) {
pub fn attach_shader(program, shader int) {
// fn (s Shader) attach(program int) {
C.glAttachShader(program, shader)
}
@ -123,7 +123,7 @@ pub fn delete_texture(texture u32) {
C.glDeleteTextures(1, &texture)
}
pub fn buffer_data(typ int, size int, arr voidptr, draw_typ int) {
pub fn buffer_data(typ, size int, arr voidptr, draw_typ int) {
C.glBufferData(typ, size, arr, draw_typ)
}

48
os/os.v
View File

@ -89,8 +89,8 @@ pub fn file_size(path string) int {
}
pub fn mv(old, new string) {
C.rename(old.cstr(), new.cstr())
}
C.rename(old.cstr(), new.cstr())
}
pub fn file_last_mod_unix(path string) int {
# struct stat attr;
@ -99,7 +99,7 @@ pub fn file_last_mod_unix(path string) int {
return 0
}
/*
/*
pub fn file_last_mod_time(path string) time.Time {
return time.now()
q := C.tm{}
@ -202,7 +202,7 @@ fn open_file_a(file string) File {
return create_file2(file, 'a')
}
fn create_file2(file string, mode string) File {
fn create_file2(file, mode string) File {
res := File {
cfile: C.fopen(file.cstr(), mode.cstr())
}
@ -286,7 +286,7 @@ pub fn system(cmd string) string {
if isnil(f) {
println('popen $cmd failed')
}
max := 1000
max := 1000
# char buf[max];
# while (fgets(buf, max, f) != NULL) {
# res = string_add(res, tos(buf, strlen(buf)));
@ -297,13 +297,13 @@ pub fn system(cmd string) string {
fn system_into_lines(s string) []string {
mut res := []string
cmd := '$s 2>&1'
max := 5000
$if windows {
max := 5000
$if windows {
# FILE* f = _popen(cmd.str, "r");
}
$else {
$else {
# FILE* f = popen(cmd.str, "r");
}
}
# char * buf = malloc(sizeof(char) * max);
# while (fgets(buf, max, f) != NULL)
{
@ -328,12 +328,12 @@ pub fn getenv(key string) string {
pub fn file_exists(path string) bool {
// # return access( path.str, F_OK ) != -1 ;
res := false
$if windows {
$if windows {
# res = _access( path.str, 0 ) != -1 ;
}
$else {
$else {
# res = access( path.str, 0 ) != -1 ;
}
}
return res
}
@ -368,19 +368,19 @@ pub fn rm(path string) {
// C.unlink(path.cstr())
}
/*
// TODO
fn rmdir(path string, guard string) {
/*
// TODO
fn rmdir(path, guard string) {
if !path.contains(guard) {
println('rmdir canceled because the path doesnt contain $guard')
return
}
$if !windows {
}
$else {
}
$if !windows {
}
$else {
}
}
*/
*/
fn print_c_errno() {
# printf("errno=%d err='%s'\n", errno, strerror(errno));
@ -458,16 +458,16 @@ pub fn write_file(path, text string) {
}
fn on_segfault(f voidptr) {
$if windows {
$if windows {
return
}
$if mac {
}
$if mac {
# struct sigaction sa;
# memset(&sa, 0, sizeof(struct sigaction));
# sigemptyset(&sa.sa_mask);
# sa.sa_sigaction = f;
# sa.sa_flags = SA_SIGINFO;
# sigaction(SIGSEGV, &sa, 0);
}
}
}