mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
minor fixes and cleaning up
This commit is contained in:
parent
aeda48d94e
commit
3344111a03
@ -42,9 +42,7 @@ fn new_array_from_c_array(len, cap, elm_size int, c_array voidptr) array {
|
|||||||
data: calloc(cap_ * elm_size)
|
data: calloc(cap_ * elm_size)
|
||||||
}
|
}
|
||||||
// TODO Write all memory functions (like memcpy) in V
|
// TODO Write all memory functions (like memcpy) in V
|
||||||
C.memcpy(
|
C.memcpy(arr.data, c_array, len * elm_size)
|
||||||
arr.data,
|
|
||||||
c_array, len * elm_size)
|
|
||||||
return arr
|
return arr
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,7 +61,7 @@ fn new_array_from_c_array_no_alloc(len, cap, elm_size int, c_array voidptr) arra
|
|||||||
fn (a mut array) ensure_cap(required int) {
|
fn (a mut array) ensure_cap(required int) {
|
||||||
if required > a.cap {
|
if required > a.cap {
|
||||||
mut cap := if a.cap == 0 { 2 } else { a.cap * 2 }
|
mut cap := if a.cap == 0 { 2 } else { a.cap * 2 }
|
||||||
for required > cap {
|
for required > cap && true {
|
||||||
cap *= 2
|
cap *= 2
|
||||||
}
|
}
|
||||||
if a.cap == 0 {
|
if a.cap == 0 {
|
||||||
@ -76,23 +74,6 @@ fn (a mut array) ensure_cap(required int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Private function, used by V (`[0; 100]`)
|
|
||||||
fn array_repeat_old(val voidptr, nr_repeats, elm_size int) array {
|
|
||||||
if nr_repeats < 0 {
|
|
||||||
panic('[0; len]: `len` is negative (len == $nr_repeats)')
|
|
||||||
}
|
|
||||||
arr := array{
|
|
||||||
len: nr_repeats
|
|
||||||
cap: nr_repeats
|
|
||||||
element_size: elm_size
|
|
||||||
data: calloc(nr_repeats * elm_size)
|
|
||||||
}
|
|
||||||
for i := 0; i < nr_repeats; i++ {
|
|
||||||
C.memcpy(arr.data + i * elm_size, val, elm_size)
|
|
||||||
}
|
|
||||||
return arr
|
|
||||||
}
|
|
||||||
|
|
||||||
// array.repeat returns new array with the given array elements
|
// array.repeat returns new array with the given array elements
|
||||||
// repeated `nr_repeat` times
|
// repeated `nr_repeat` times
|
||||||
pub fn (a array) repeat(nr_repeats int) array {
|
pub fn (a array) repeat(nr_repeats int) array {
|
||||||
|
@ -441,7 +441,7 @@ fn (c mut V) cc_windows_cross() {
|
|||||||
mut cmd := ''
|
mut cmd := ''
|
||||||
cmd = ''
|
cmd = ''
|
||||||
$if macos {
|
$if macos {
|
||||||
cmd = 'x86_64-w64-mingw32-gcc $args -municode'
|
cmd = 'x86_64-w64-mingw32-gcc -std=gnu11 $args -municode'
|
||||||
}
|
}
|
||||||
$else {
|
$else {
|
||||||
panic('your platform is not supported yet')
|
panic('your platform is not supported yet')
|
||||||
|
@ -20,7 +20,12 @@ fn (p mut Parser) string_expr() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
if (p.calling_c && p.peek() != .dot) || is_cstr || (p.pref.translated && p.mod == 'main') {
|
if (p.calling_c && p.peek() != .dot) || is_cstr || (p.pref.translated && p.mod == 'main') {
|
||||||
p.gen('"$f"')
|
if p.os == .windows {
|
||||||
|
p.gen('L"$f"')
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
p.gen('"$f"')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if p.is_sql {
|
else if p.is_sql {
|
||||||
p.gen("'$str'")
|
p.gen("'$str'")
|
||||||
|
@ -236,24 +236,6 @@ pub fn new_context(cfg gg.Cfg) &FreeType {
|
|||||||
return ctx
|
return ctx
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
// A dirty hack to implement rendering of cyrillic letters.
|
|
||||||
// All UTF-8 must be supported. update: no longer needed
|
|
||||||
fn (ctx mut FreeType) init_utf8_runes() {
|
|
||||||
s := '≈≠⩽⩾йцукенгшщзхъфывапролджэячсмитьбюЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ'
|
|
||||||
print('init utf8 runes: ')
|
|
||||||
//println(s)
|
|
||||||
us := s.ustring()
|
|
||||||
for i := 0; i < us.len; i++ {
|
|
||||||
_rune := us.at(i)
|
|
||||||
ch := ft_load_char(ctx.face, _rune.utf32_code())
|
|
||||||
// ctx.utf_rune_map.set(rune, ch)
|
|
||||||
ctx.utf_runes << _rune
|
|
||||||
ctx.utf_chars << ch
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
pub fn (ctx mut FreeType) draw_text(_x, _y int, text string, cfg gx.TextCfg) {
|
pub fn (ctx mut FreeType) draw_text(_x, _y int, text string, cfg gx.TextCfg) {
|
||||||
//utext := text.ustring_tmp()
|
//utext := text.ustring_tmp()
|
||||||
utext := text.ustring()
|
utext := text.ustring()
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
ui
|
ui
|
||||||
gx
|
gx
|
||||||
os
|
os
|
||||||
darwin
|
//darwin
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -8,6 +8,14 @@ fn main() {
|
|||||||
c := -a
|
c := -a
|
||||||
a == 1
|
a == 1
|
||||||
foo(3)
|
foo(3)
|
||||||
|
/*
|
||||||
|
user := User{}
|
||||||
|
user.age = 10
|
||||||
|
mut x := if user.age == 10 { 20 } else { user.age * 2 }
|
||||||
|
for x > 3 {
|
||||||
|
|
||||||
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
fn foo(a int) {
|
fn foo(a int) {
|
||||||
|
@ -229,7 +229,7 @@ pub fn (p &Parser) error_at_line(s string, line_nr int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn (p &Parser) warn(s string) {
|
pub fn (p &Parser) warn(s string) {
|
||||||
println(term.blue('x.v:$p.tok.line_nr: $s'))
|
println(term.blue('$p.file_name:$p.tok.line_nr: $s'))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implementation of Pratt Precedence
|
// Implementation of Pratt Precedence
|
||||||
@ -332,7 +332,7 @@ pub fn (p mut Parser) expr(rbp int) (ast.Expr,types.Type) {
|
|||||||
typ = t2
|
typ = t2
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
p.error('!unknown token ' + p.tok.str())
|
p.error('expr(): unknown token ' + p.tok.str() + ' kind=$p.tok.kind')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -342,10 +342,9 @@ pub fn (p mut Parser) expr(rbp int) (ast.Expr,types.Type) {
|
|||||||
p.next()
|
p.next()
|
||||||
mut t2 := types.Type{}
|
mut t2 := types.Type{}
|
||||||
// left denotation (infix / postfix)
|
// left denotation (infix / postfix)
|
||||||
if prev_tok.is_right_assoc() &&
|
if prev_tok.is_right_assoc() && !p.tok.kind in [.plus, .minus] && // think of better way to handle this
|
||||||
!p.tok.kind in [.plus, .minus] && // think of better way to handle this
|
!p.peek_tok.kind in [.number, .name] {
|
||||||
!p.peek_tok.kind in [.number, .name] { // supposed to be only unary, additive handled in left asssoc
|
// supposed to be only unary, additive handled in left asssoc
|
||||||
|
|
||||||
mut expr := ast.Expr{}
|
mut expr := ast.Expr{}
|
||||||
expr,t2 = p.expr(prev_tok.precedence() - 1)
|
expr,t2 = p.expr(prev_tok.precedence() - 1)
|
||||||
node = ast.BinaryExpr{
|
node = ast.BinaryExpr{
|
||||||
@ -460,8 +459,10 @@ fn (p mut Parser) if_expr() (ast.Expr,types.Type) {
|
|||||||
}
|
}
|
||||||
mut typ := types.void_type
|
mut typ := types.void_type
|
||||||
// mut left := ast.Expr{}
|
// mut left := ast.Expr{}
|
||||||
|
// If the last statement is an expression, return its type
|
||||||
match stmts[stmts.len - 1] {
|
match stmts[stmts.len - 1] {
|
||||||
ast.ExprStmt {
|
ast.ExprStmt {
|
||||||
|
p.warn('if expr ret $it.typ.name')
|
||||||
typ = it.typ
|
typ = it.typ
|
||||||
// return node,it.typ
|
// return node,it.typ
|
||||||
// left =
|
// left =
|
||||||
|
Loading…
Reference in New Issue
Block a user