force snake_case in variable names

pull/1170/head
Alexander Medvednikov 2019-07-15 22:44:26 +02:00
parent 100bcc2034
commit 840e496a51
5 changed files with 33 additions and 30 deletions

View File

@ -41,6 +41,7 @@ fn (f &Fn) find_var(name string) Var {
return Var{} return Var{}
} }
fn (f mut Fn) open_scope() { fn (f mut Fn) open_scope() {
f.scope_level++ f.scope_level++
} }
@ -297,20 +298,19 @@ fn (p mut Parser) fn_decl() {
p.cur_fn = f p.cur_fn = f
// Register the method // Register the method
if receiver_typ != '' { if receiver_typ != '' {
mut receiver_T := p.table.find_type(receiver_typ) mut receiver_t := p.table.find_type(receiver_typ)
// No such type yet? It could be defined later. Create a new type. // No such type yet? It could be defined later. Create a new type.
// struct declaration later will modify it instead of creating a new one. // struct declaration later will modify it instead of creating a new one.
if p.first_run() && receiver_T.name == '' { if p.first_run() && receiver_t.name == '' {
// println('fn decl !!!!!!! REG PH $receiver_typ') // println('fn decl !!!!!!! REG PH $receiver_typ')
ttyp := Type { p.table.register_type2(Type {
name: receiver_typ.replace('*', '') name: receiver_typ.replace('*', '')
mod: p.mod mod: p.mod
is_placeholder: true is_placeholder: true
} })
p.table.register_type2(ttyp)
} }
// f.idx = p.table.fn_cnt // f.idx = p.table.fn_cnt
receiver_T.add_method(f) receiver_t.add_method(f)
} }
else { else {
// println('register_fn typ=$typ isg=$is_generic') // println('register_fn typ=$typ isg=$is_generic')
@ -734,7 +734,7 @@ fn (p mut Parser) fn_call_args(f *Fn) *Fn {
if ! (expected == 'void*' && got == 'int') && if ! (expected == 'void*' && got == 'int') &&
! (expected == 'byte*' && got.contains(']byte')) && ! (expected == 'byte*' && got.contains(']byte')) &&
! (expected == 'byte*' && got == 'string') { ! (expected == 'byte*' && got == 'string') {
p.cgen.set_placeholder(ph, '& /*11 EXP:"$expected" .key_goT:"$got" */') p.cgen.set_placeholder(ph, '& /*11 EXP:"$expected" GOT:"$got" */')
} }
} }
} }

View File

@ -1152,6 +1152,9 @@ fn (p mut Parser) var_decl() {
v := p.cur_fn.find_var(name) v := p.cur_fn.find_var(name)
p.error('redefinition of `$name`') p.error('redefinition of `$name`')
} }
if name.len > 1 && contains_capital(name) {
p.error('variable names cannot contain uppercase letters, use snake_case instead')
}
p.check_space(.decl_assign) // := p.check_space(.decl_assign) // :=
// Generate expression to tmp because we need its type first // Generate expression to tmp because we need its type first
// [TYP .name =] bool_expression() // [TYP .name =] bool_expression()

View File

@ -43,9 +43,9 @@ fn advance(sys System, dt f64) {
dy := sys.s[i].y - sys.s[j].y dy := sys.s[i].y - sys.s[j].y
dz := sys.s[i].z - sys.s[j].z dz := sys.s[i].z - sys.s[j].z
dSquared := dx * dx + dy * dy + dz * dz dsquared := dx * dx + dy * dy + dz * dz
distance := math.sqrt(dSquared) distance := math.sqrt(dsquared)
mag := (dt / (dSquared * distance)) mag := (dt / (dsquared * distance))
mi := sys.v[i].m mi := sys.v[i].m
_vx -= dx * sys.v[j].m * mag _vx -= dx * sys.v[j].m * mag

View File

@ -107,9 +107,9 @@ pub fn new_context(cfg Cfg) *GG {
// i := glm.identity3() // i := glm.identity3()
shader.set_mat4('projection', glm.identity()) shader.set_mat4('projection', glm.identity())
} }
VAO := gl.gen_vertex_array() vao := gl.gen_vertex_array()
//println('new gg context VAO=$VAO') //println('new gg context VAO=$VAO')
VBO := gl.gen_buffer() vbo := gl.gen_buffer()
mut scale := 1 mut scale := 1
if cfg.retina { if cfg.retina {
scale = 2 scale = 2
@ -126,8 +126,8 @@ pub fn new_context(cfg Cfg) *GG {
shader: shader shader: shader
width: cfg.width width: cfg.width
height: cfg.height height: cfg.height
VAO: VAO VAO: vao
VBO: VBO VBO: vbo
// /line_vao: gl.gen_vertex_array() // /line_vao: gl.gen_vertex_array()
// /line_vbo: gl.gen_buffer() // /line_vbo: gl.gen_buffer()
//text_ctx: new_context_text(cfg, scale), //text_ctx: new_context_text(cfg, scale),
@ -272,11 +272,11 @@ fn todo_remove_me(cfg Cfg, scale int) {
// projection_new := ortho(0, width, 0, height)// 0 at BOT // projection_new := ortho(0, width, 0, height)// 0 at BOT
// projection := gl.ortho(0, width,height,0) // 0 at TOP // projection := gl.ortho(0, width,height,0) // 0 at TOP
shader.set_mat4('projection', projection) shader.set_mat4('projection', projection)
VAO := gl.gen_vertex_array() vao := gl.gen_vertex_array()
//println('new gg text context VAO=$VAO') //println('new gg text context VAO=$VAO')
VBO := gl.gen_buffer() vbo := gl.gen_buffer()
gl.bind_vao(VAO) gl.bind_vao(vao)
gl.bind_buffer(GL_ARRAY_BUFFER, VBO) gl.bind_buffer(GL_ARRAY_BUFFER, vbo)
gl.enable_vertex_attrib_array(0) gl.enable_vertex_attrib_array(0)
gl.vertex_attrib_pointer(0, 4, GL_FLOAT, false, 4, 0) gl.vertex_attrib_pointer(0, 4, GL_FLOAT, false, 4, 0)
} }

View File

@ -87,15 +87,15 @@ pub fn delete_shader(shader int) {
} }
pub fn shader_info_log(shader int) string { pub fn shader_info_log(shader int) string {
infoLog := [512]byte info_log := [512]byte
C.glGetShaderInfoLog(shader, 512, 0, infoLog) C.glGetShaderInfoLog(shader, 512, 0, info_log)
return tos_clone(infoLog) return tos_clone(info_log)
} }
pub fn get_program_info_log(program int) string { pub fn get_program_info_log(program int) string {
infoLog := [1024]byte info_log := [1024]byte
C.glGetProgramInfoLog(program, 1024, 0, infoLog) C.glGetProgramInfoLog(program, 1024, 0, info_log)
return tos_clone(infoLog) return tos_clone(info_log)
} }
pub fn bind_vao(vao u32) { pub fn bind_vao(vao u32) {
@ -166,9 +166,9 @@ pub fn use_program(program int) {
} }
pub fn gen_vertex_array() u32 { pub fn gen_vertex_array() u32 {
VAO := u32(0) vao := u32(0)
C.glGenVertexArrays(1, &VAO) C.glGenVertexArrays(1, &vao)
return VAO return vao
} }
pub fn enable_vertex_attrib_array(n int) { pub fn enable_vertex_attrib_array(n int) {
@ -176,9 +176,9 @@ pub fn enable_vertex_attrib_array(n int) {
} }
pub fn gen_buffer() u32 { pub fn gen_buffer() u32 {
VBO := u32(0) vbo := u32(0)
C.glGenBuffers(1, &VBO) C.glGenBuffers(1, &vbo)
return VBO return vbo
} }
pub fn vertex_attrib_pointer(index, size int, typ int, normalized bool, stride int, ptr int) { pub fn vertex_attrib_pointer(index, size int, typ int, normalized bool, stride int, ptr int) {