minor fixes and cleaning up
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)
|
||||
}
|
||||
// TODO Write all memory functions (like memcpy) in V
|
||||
C.memcpy(
|
||||
arr.data,
|
||||
c_array, len * elm_size)
|
||||
C.memcpy(arr.data, c_array, len * elm_size)
|
||||
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) {
|
||||
if required > a.cap {
|
||||
mut cap := if a.cap == 0 { 2 } else { a.cap * 2 }
|
||||
for required > cap {
|
||||
for required > cap && true {
|
||||
cap *= 2
|
||||
}
|
||||
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
|
||||
// repeated `nr_repeat` times
|
||||
pub fn (a array) repeat(nr_repeats int) array {
|
||||
|
|
|
@ -441,7 +441,7 @@ fn (c mut V) cc_windows_cross() {
|
|||
mut cmd := ''
|
||||
cmd = ''
|
||||
$if macos {
|
||||
cmd = 'x86_64-w64-mingw32-gcc $args -municode'
|
||||
cmd = 'x86_64-w64-mingw32-gcc -std=gnu11 $args -municode'
|
||||
}
|
||||
$else {
|
||||
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') {
|
||||
p.gen('"$f"')
|
||||
if p.os == .windows {
|
||||
p.gen('L"$f"')
|
||||
}
|
||||
else {
|
||||
p.gen('"$f"')
|
||||
}
|
||||
}
|
||||
else if p.is_sql {
|
||||
p.gen("'$str'")
|
||||
|
|
|
@ -236,24 +236,6 @@ pub fn new_context(cfg gg.Cfg) &FreeType {
|
|||
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) {
|
||||
//utext := text.ustring_tmp()
|
||||
utext := text.ustring()
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
ui
|
||||
gx
|
||||
os
|
||||
darwin
|
||||
//darwin
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
@ -8,6 +8,14 @@ fn main() {
|
|||
c := -a
|
||||
a == 1
|
||||
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) {
|
||||
|
|
|
@ -229,7 +229,7 @@ pub fn (p &Parser) error_at_line(s string, line_nr int) {
|
|||
}
|
||||
|
||||
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
|
||||
|
@ -332,7 +332,7 @@ pub fn (p mut Parser) expr(rbp int) (ast.Expr,types.Type) {
|
|||
typ = t2
|
||||
}
|
||||
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()
|
||||
mut t2 := types.Type{}
|
||||
// left denotation (infix / postfix)
|
||||
if prev_tok.is_right_assoc() &&
|
||||
!p.tok.kind in [.plus, .minus] && // think of better way to handle this
|
||||
!p.peek_tok.kind in [.number, .name] { // supposed to be only unary, additive handled in left asssoc
|
||||
|
||||
if prev_tok.is_right_assoc() && !p.tok.kind in [.plus, .minus] && // think of better way to handle this
|
||||
!p.peek_tok.kind in [.number, .name] {
|
||||
// supposed to be only unary, additive handled in left asssoc
|
||||
mut expr := ast.Expr{}
|
||||
expr,t2 = p.expr(prev_tok.precedence() - 1)
|
||||
node = ast.BinaryExpr{
|
||||
|
@ -460,8 +459,10 @@ fn (p mut Parser) if_expr() (ast.Expr,types.Type) {
|
|||
}
|
||||
mut typ := types.void_type
|
||||
// mut left := ast.Expr{}
|
||||
// If the last statement is an expression, return its type
|
||||
match stmts[stmts.len - 1] {
|
||||
ast.ExprStmt {
|
||||
p.warn('if expr ret $it.typ.name')
|
||||
typ = it.typ
|
||||
// return node,it.typ
|
||||
// left =
|
||||
|
|
Loading…
Reference in New Issue