👍 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`) // 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 { arr := array {
len: mylen len: mylen
cap: cap 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]`) // 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 { arr := array {
len: nr_repeats len: nr_repeats
cap: nr_repeats cap: nr_repeats

View File

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

View File

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

View File

@ -93,8 +93,8 @@ struct Game {
field array_array_int field array_array_int
// TODO: tetro Tetro // TODO: tetro Tetro
tetro []Block tetro []Block
// TODO: tetros_cache []Tetro // TODO: tetros_cache []Tetro
tetros_cache []Block tetros_cache []Block
// Index of the current tetro. Refers to its color. // Index of the current tetro. Refers to its color.
tetro_idx int tetro_idx int
// Index of the rotation (0-3) // Index of the rotation (0-3)
@ -106,7 +106,7 @@ struct Game {
fn main() { fn main() {
glfw.init() glfw.init()
mut game := &Game{gg: 0} // TODO mut game := &Game{gg: 0} // TODO
game.parse_tetros() game.parse_tetros()
game.init_game() game.init_game()
mut window := glfw.create_window(glfw.WinCfg { mut window := glfw.create_window(glfw.WinCfg {
width: WinWidth width: WinWidth
@ -155,13 +155,13 @@ fn (g mut Game) init_game() {
fn (g mut Game) parse_tetros() { fn (g mut Game) parse_tetros() {
for b_tetros in BTetros { for b_tetros in BTetros {
for b_tetro in b_tetros { for b_tetro in b_tetros {
for t in parse_binary_tetro(b_tetro) { for t in parse_binary_tetro(b_tetro) {
g.tetros_cache << t g.tetros_cache << t
} }
} }
} }
} }
fn (g mut Game) run() { fn (g mut Game) run() {
for { for {
@ -196,7 +196,7 @@ fn (g mut Game) move_tetro() {
} }
fn (g mut Game) move_right(dx int) { 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++ { for i := 0; i < TetroSize; i++ {
tetro := g.tetro[i] tetro := g.tetro[i]
y := tetro.y + g.pos_y y := tetro.y + g.pos_y
@ -238,15 +238,15 @@ fn (g mut Game) generate_tetro() {
g.pos_y = 0 g.pos_y = 0
g.pos_x = FieldWidth / 2 - TetroSize / 2 g.pos_x = FieldWidth / 2 - TetroSize / 2
g.tetro_idx = rand.next(BTetros.len) g.tetro_idx = rand.next(BTetros.len)
g.rotation_idx = 0 g.rotation_idx = 0
g.get_tetro() g.get_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.slice(idx, idx + TetroSize)
} }
fn (g mut Game) drop_tetro() { fn (g mut Game) drop_tetro() {
for i := 0; i < TetroSize; i++ { 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) { fn (g &Game) draw_block(i, j, color_idx int) {
g.gg.draw_rect((j - 1) * BlockSize, (i - 1) * BlockSize, g.gg.draw_rect((j - 1) * BlockSize, (i - 1) * BlockSize,
BlockSize - 1, BlockSize - 1, Colors[color_idx]) 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 // 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 { if action != 2 && action != 1 {
return return
} }
@ -328,7 +328,7 @@ fn key_down(wnd voidptr, key int, code int, action, mods int) {
if game.rotation_idx == TetroSize { if game.rotation_idx == TetroSize {
game.rotation_idx = 0 game.rotation_idx = 0
} }
game.get_tetro() game.get_tetro()
if game.pos_x < 0 { if game.pos_x < 0 {
game.pos_x = 1 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) C.glViewport(a, b, c, d)
} }
@ -48,7 +48,7 @@ pub fn create_program() int {
return C.glCreateProgram() 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) C.glShaderSource(shader, a, &source.str, b)
} }
@ -62,7 +62,7 @@ pub fn shader_compile_status(shader int) int {
return success return success
} }
pub fn attach_shader(program int, shader int) { pub fn attach_shader(program, shader int) {
// fn (s Shader) attach(program int) { // fn (s Shader) attach(program int) {
C.glAttachShader(program, shader) C.glAttachShader(program, shader)
} }
@ -123,7 +123,7 @@ pub fn delete_texture(texture u32) {
C.glDeleteTextures(1, &texture) 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) 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) { 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 { pub fn file_last_mod_unix(path string) int {
# struct stat attr; # struct stat attr;
@ -99,7 +99,7 @@ pub fn file_last_mod_unix(path string) int {
return 0 return 0
} }
/* /*
pub fn file_last_mod_time(path string) time.Time { pub fn file_last_mod_time(path string) time.Time {
return time.now() return time.now()
q := C.tm{} q := C.tm{}
@ -202,7 +202,7 @@ fn open_file_a(file string) File {
return create_file2(file, 'a') return create_file2(file, 'a')
} }
fn create_file2(file string, mode string) File { fn create_file2(file, mode string) File {
res := File { res := File {
cfile: C.fopen(file.cstr(), mode.cstr()) cfile: C.fopen(file.cstr(), mode.cstr())
} }
@ -286,7 +286,7 @@ pub fn system(cmd string) string {
if isnil(f) { if isnil(f) {
println('popen $cmd failed') println('popen $cmd failed')
} }
max := 1000 max := 1000
# char buf[max]; # char buf[max];
# while (fgets(buf, max, f) != NULL) { # while (fgets(buf, max, f) != NULL) {
# res = string_add(res, tos(buf, strlen(buf))); # 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 { fn system_into_lines(s string) []string {
mut res := []string mut res := []string
cmd := '$s 2>&1' cmd := '$s 2>&1'
max := 5000 max := 5000
$if windows { $if windows {
# FILE* f = _popen(cmd.str, "r"); # FILE* f = _popen(cmd.str, "r");
} }
$else { $else {
# FILE* f = popen(cmd.str, "r"); # FILE* f = popen(cmd.str, "r");
} }
# char * buf = malloc(sizeof(char) * max); # char * buf = malloc(sizeof(char) * max);
# while (fgets(buf, max, f) != NULL) # while (fgets(buf, max, f) != NULL)
{ {
@ -328,12 +328,12 @@ pub fn getenv(key string) string {
pub fn file_exists(path string) bool { pub fn file_exists(path string) bool {
// # return access( path.str, F_OK ) != -1 ; // # return access( path.str, F_OK ) != -1 ;
res := false res := false
$if windows { $if windows {
# res = _access( path.str, 0 ) != -1 ; # res = _access( path.str, 0 ) != -1 ;
} }
$else { $else {
# res = access( path.str, 0 ) != -1 ; # res = access( path.str, 0 ) != -1 ;
} }
return res return res
} }
@ -368,19 +368,19 @@ pub fn rm(path string) {
// C.unlink(path.cstr()) // C.unlink(path.cstr())
} }
/* /*
// TODO // TODO
fn rmdir(path string, guard string) { fn rmdir(path, guard string) {
if !path.contains(guard) { if !path.contains(guard) {
println('rmdir canceled because the path doesnt contain $guard') println('rmdir canceled because the path doesnt contain $guard')
return return
} }
$if !windows { $if !windows {
} }
$else { $else {
} }
} }
*/ */
fn print_c_errno() { fn print_c_errno() {
# printf("errno=%d err='%s'\n", errno, strerror(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) { fn on_segfault(f voidptr) {
$if windows { $if windows {
return return
} }
$if mac { $if mac {
# struct sigaction sa; # struct sigaction sa;
# memset(&sa, 0, sizeof(struct sigaction)); # memset(&sa, 0, sizeof(struct sigaction));
# sigemptyset(&sa.sa_mask); # sigemptyset(&sa.sa_mask);
# sa.sa_sigaction = f; # sa.sa_sigaction = f;
# sa.sa_flags = SA_SIGINFO; # sa.sa_flags = SA_SIGINFO;
# sigaction(SIGSEGV, &sa, 0); # sigaction(SIGSEGV, &sa, 0);
} }
} }