mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
interface fix
This commit is contained in:
parent
c1cc203c17
commit
29564ed63d
@ -143,23 +143,21 @@ fn main() {
|
||||
window_title: 'V Tetris'
|
||||
window_user_ptr: game
|
||||
})
|
||||
ft: 0
|
||||
ft: freetype.new_context(gg.Cfg{
|
||||
width: WinWidth
|
||||
height: WinHeight
|
||||
use_ortho: true
|
||||
font_size: 18
|
||||
scale: 2
|
||||
window_user_ptr: 0
|
||||
})
|
||||
}
|
||||
game.gg.window.set_user_ptr(game) // TODO remove this when `window_user_ptr:` works
|
||||
game.init_game()
|
||||
game.gg.window.onkeydown(key_down)
|
||||
go game.run() // Run the game loop in a new thread
|
||||
gg.clear(BackgroundColor)
|
||||
// Try to load font
|
||||
game.ft = freetype.new_context(gg.Cfg{
|
||||
width: WinWidth
|
||||
height: WinHeight
|
||||
use_ortho: true
|
||||
font_size: 18
|
||||
scale: 2
|
||||
window_user_ptr: 0
|
||||
})
|
||||
game.font_loaded = (game.ft != 0 )
|
||||
game.font_loaded = game.ft != 0
|
||||
for {
|
||||
gg.clear(BackgroundColor)
|
||||
game.draw_scene()
|
||||
|
@ -2112,6 +2112,9 @@ fn (p mut Parser) dot(str_typ_ string, method_ph int) string {
|
||||
// Is the next token `=`, `+=` etc? (Are we modifying the field?)
|
||||
next := p.peek()
|
||||
modifying := next.is_assign() || next == .inc || next == .dec || (field.typ.starts_with('array_') && next == .left_shift)
|
||||
if modifying {
|
||||
p.expected_type = field.typ
|
||||
}
|
||||
if !p.builtin_mod && !p.pref.translated && modifying && p.has_immutable_field {
|
||||
f := p.first_immutable_field
|
||||
p.error_with_token_index('cannot modify immutable field `$f.name` (type `$f.parent_fn`)\n' + 'declare the field with `mut:`
|
||||
@ -2705,7 +2708,7 @@ fn (p mut Parser) array_init() string {
|
||||
// vals.len == 0 {
|
||||
if exp_array {
|
||||
type_expected := p.expected_type[6..].replace('ptr_', '&')
|
||||
p.error('no need to specify the full array type here, use `[]` instead of `[]$type_expected`')
|
||||
p.warn('no need to specify the full array type here, use `[]` instead of `[]$type_expected`')
|
||||
}
|
||||
typ = p.get_type()
|
||||
}
|
||||
|
@ -73,6 +73,7 @@ fn (p mut Parser) enum_decl(no_name bool) {
|
||||
}
|
||||
if p.tok == .comma {
|
||||
p.next()
|
||||
p.fremove_last()
|
||||
}
|
||||
p.fgen_nl()
|
||||
val++
|
||||
|
@ -50,6 +50,15 @@ fn (p mut Parser) bool_expression() string {
|
||||
if p.inside_return_expr && p.expected_type.contains('_MulRet_') { //is_ret { // return a,b hack TODO
|
||||
expected = p.expected_type
|
||||
}
|
||||
// `window.widget = button`, widget is an interface
|
||||
if expected != typ && expected.ends_with('er') && expected.contains('I') {
|
||||
tt := typ.replace('*', '_ptr')
|
||||
p.cgen.set_placeholder(start_ph,
|
||||
'($expected) { ._interface_idx = _${expected}_${tt}_index, ._object = ' )
|
||||
p.gen('}')
|
||||
//p.satisfies_interface(expected, typ, true)
|
||||
}
|
||||
// e.g. `return BinaryExpr{}` in a function expecting `Expr`
|
||||
if expected != typ && expected in p.table.sum_types { // TODO perf
|
||||
//p.warn('SUM CAST exp=$expected typ=$typ p.exp=$p.expected_type')
|
||||
T := p.table.find_type(typ)
|
||||
|
@ -425,7 +425,7 @@ fn (p mut Parser) dot_expr(left ast.Expr, ti types.TypeIdent) (ast.Expr,types.Ty
|
||||
field_name := p.check_name()
|
||||
println('# $ti.name $ti.idx - $field_name')
|
||||
if ti.kind != .void {
|
||||
println('#### void type in dot_expr - field: $field_name')
|
||||
p.warn('#### void type in dot_expr - field: $field_name')
|
||||
}
|
||||
struc := p.table.types[ti.idx] as types.Struct
|
||||
// Method call
|
||||
@ -445,7 +445,7 @@ fn (p mut Parser) dot_expr(left ast.Expr, ti types.TypeIdent) (ast.Expr,types.Ty
|
||||
return node,types.int_ti
|
||||
}
|
||||
if !p.table.struct_has_field(struc, field_name) {
|
||||
// t :=
|
||||
// t :=
|
||||
p.error('type `$struc.name` has no field `$field_name`')
|
||||
}
|
||||
/*
|
||||
|
@ -180,10 +180,9 @@ pub fn (t mut Table) register_method(ti types.TypeIdent, new_fn Fn) bool {
|
||||
}
|
||||
t.types[ti.idx] = struc
|
||||
*/
|
||||
|
||||
println('register method `$new_fn.name` struct=$ti.name ')
|
||||
|
||||
println('##### $ti.idx - $t.methods.len')
|
||||
|
||||
t.methods[ti.idx] << new_fn
|
||||
return true
|
||||
}
|
||||
@ -246,7 +245,7 @@ pub fn (t mut Table) register_type(typ types.Type, name string, idx int) {
|
||||
}
|
||||
t.type_idxs[name] = idx
|
||||
t.types << typ
|
||||
t.methods << []Fn
|
||||
t.methods << []Fn // TODO [] breaks V
|
||||
}
|
||||
|
||||
pub fn (t mut Table) register_struct(typ types.Struct) int {
|
||||
|
@ -25,35 +25,35 @@ pub const (
|
||||
|
||||
pub enum Kind {
|
||||
placeholder
|
||||
void,
|
||||
voidptr,
|
||||
charptr,
|
||||
byteptr,
|
||||
const_,
|
||||
enum_,
|
||||
struct_,
|
||||
int,
|
||||
i8,
|
||||
i16,
|
||||
i64,
|
||||
byte,
|
||||
u16,
|
||||
u32,
|
||||
u64,
|
||||
f32,
|
||||
f64,
|
||||
string,
|
||||
char,
|
||||
bool,
|
||||
array,
|
||||
array_fixed,
|
||||
map,
|
||||
multi_return,
|
||||
void
|
||||
voidptr
|
||||
charptr
|
||||
byteptr
|
||||
const_
|
||||
enum_
|
||||
struct_
|
||||
int
|
||||
i8
|
||||
i16
|
||||
i64
|
||||
byte
|
||||
u16
|
||||
u32
|
||||
u64
|
||||
f32
|
||||
f64
|
||||
string
|
||||
char
|
||||
bool
|
||||
array
|
||||
array_fixed
|
||||
map
|
||||
multi_return
|
||||
variadic
|
||||
}
|
||||
|
||||
pub type Type = Placeholder | Primitive | Const | Enum | Struct | Int | Float |
|
||||
String | Bool | Array | ArrayFixed | Map | MultiReturn | Variadic
|
||||
pub type Type = Placeholder | Primitive | Const | Enum | Struct | Int | Float |
|
||||
String | Bool | Array | ArrayFixed | Map | MultiReturn | Variadic
|
||||
|
||||
pub struct TypeIdent {
|
||||
pub:
|
||||
@ -228,7 +228,6 @@ pub:
|
||||
name string
|
||||
// kind Kind
|
||||
}
|
||||
|
||||
// Void | Voidptr | Charptr | Byteptr
|
||||
pub struct Primitive {
|
||||
pub:
|
||||
@ -266,7 +265,7 @@ pub:
|
||||
|
||||
pub struct Int {
|
||||
pub:
|
||||
idx int
|
||||
idx int
|
||||
bit_size u32
|
||||
is_unsigned bool
|
||||
}
|
||||
@ -335,27 +334,26 @@ pub:
|
||||
|
||||
pub fn (t Primitive) str() string {
|
||||
s := match t.kind {
|
||||
.void {
|
||||
.void{
|
||||
'void'
|
||||
}
|
||||
.voidptr {
|
||||
.voidptr{
|
||||
'voidptr'
|
||||
}
|
||||
.charptr {
|
||||
.charptr{
|
||||
'charptr'
|
||||
}
|
||||
.byteptr {
|
||||
.byteptr{
|
||||
'byteptr'
|
||||
}
|
||||
.char {
|
||||
.char{
|
||||
'char'
|
||||
}
|
||||
.byte {
|
||||
.byte{
|
||||
'byte'
|
||||
}
|
||||
else {
|
||||
'unknown'
|
||||
}
|
||||
'unknown'}
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user