free strings
							parent
							
								
									d1b732cbcc
								
							
						
					
					
						commit
						3a8cdadcf5
					
				| 
						 | 
					@ -1018,6 +1018,9 @@ fn (p mut Parser) close_scope() {
 | 
				
			||||||
			if v.typ.starts_with('array_') { 
 | 
								if v.typ.starts_with('array_') { 
 | 
				
			||||||
				p.genln('v_array_free($v.name); // close_scope free') 
 | 
									p.genln('v_array_free($v.name); // close_scope free') 
 | 
				
			||||||
			} 
 | 
								} 
 | 
				
			||||||
 | 
								else if v.typ == 'string' { 
 | 
				
			||||||
 | 
									p.genln('v_string_free($v.name); // close_scope free') 
 | 
				
			||||||
 | 
								} 
 | 
				
			||||||
			else { 
 | 
								else { 
 | 
				
			||||||
				p.genln('free($v.name); // close_scope free') 
 | 
									p.genln('free($v.name); // close_scope free') 
 | 
				
			||||||
			} 
 | 
								} 
 | 
				
			||||||
| 
						 | 
					@ -1839,6 +1842,7 @@ fn (p mut Parser) index_expr(typ string, fn_ph int) string {
 | 
				
			||||||
			p.gen(']/*r$typ $v.is_mut*/')
 | 
								p.gen(']/*r$typ $v.is_mut*/')
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						// TODO move this from index_expr() 
 | 
				
			||||||
	// TODO if p.tok in ...
 | 
						// TODO if p.tok in ...
 | 
				
			||||||
	// if p.tok in [.assign, .plus_assign, .minus_assign]
 | 
						// if p.tok in [.assign, .plus_assign, .minus_assign]
 | 
				
			||||||
	if p.tok == .assign || p.tok == .plus_assign || p.tok == .minus_assign ||
 | 
						if p.tok == .assign || p.tok == .plus_assign || p.tok == .minus_assign ||
 | 
				
			||||||
| 
						 | 
					@ -2335,6 +2339,7 @@ fn (p mut Parser) string_expr() {
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	// tmp := p.get_tmp()
 | 
						// tmp := p.get_tmp()
 | 
				
			||||||
 | 
						p.is_alloc = true // $ interpolation means there's allocation 
 | 
				
			||||||
	mut args := '"'
 | 
						mut args := '"'
 | 
				
			||||||
	mut format := '"'
 | 
						mut format := '"'
 | 
				
			||||||
	p.fgen('\'') 
 | 
						p.fgen('\'') 
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,7 +4,6 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module builtin
 | 
					module builtin
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// V strings are not null-terminated.
 | 
					 | 
				
			||||||
struct string {
 | 
					struct string {
 | 
				
			||||||
mut:
 | 
					mut:
 | 
				
			||||||
	hash_cache int 
 | 
						hash_cache int 
 | 
				
			||||||
| 
						 | 
					@ -25,7 +24,8 @@ fn C.strlen(s byteptr) int
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn todo() { } 
 | 
					fn todo() { } 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Converts a C string to a V string
 | 
					// Converts a C string to a V string. 
 | 
				
			||||||
 | 
					// String data is reused, not copied. 
 | 
				
			||||||
pub fn tos(s byteptr, len int) string {
 | 
					pub fn tos(s byteptr, len int) string {
 | 
				
			||||||
	// This should never happen.
 | 
						// This should never happen.
 | 
				
			||||||
	if isnil(s) {
 | 
						if isnil(s) {
 | 
				
			||||||
| 
						 | 
					@ -48,6 +48,7 @@ pub fn tos_clone(s byteptr) string {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Same as `tos`, but calculates the length. Called by `string(bytes)` casts. 
 | 
					// Same as `tos`, but calculates the length. Called by `string(bytes)` casts. 
 | 
				
			||||||
 | 
					// Used only internally. 
 | 
				
			||||||
fn tos2(s byteptr) string {
 | 
					fn tos2(s byteptr) string {
 | 
				
			||||||
	if isnil(s) {
 | 
						if isnil(s) {
 | 
				
			||||||
		panic('tos2: nil string')
 | 
							panic('tos2: nil string')
 | 
				
			||||||
| 
						 | 
					@ -730,7 +731,7 @@ pub fn (c byte) is_letter() bool {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub fn (s string) free() {
 | 
					pub fn (s string) free() {
 | 
				
			||||||
	C.free(s.str)
 | 
						free(s.str)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* 
 | 
					/* 
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue