interface fix
parent
c1cc203c17
commit
29564ed63d
|
@ -143,23 +143,21 @@ fn main() {
|
||||||
window_title: 'V Tetris'
|
window_title: 'V Tetris'
|
||||||
window_user_ptr: game
|
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.gg.window.set_user_ptr(game) // TODO remove this when `window_user_ptr:` works
|
||||||
game.init_game()
|
game.init_game()
|
||||||
game.gg.window.onkeydown(key_down)
|
game.gg.window.onkeydown(key_down)
|
||||||
go game.run() // Run the game loop in a new thread
|
go game.run() // Run the game loop in a new thread
|
||||||
gg.clear(BackgroundColor)
|
gg.clear(BackgroundColor)
|
||||||
// Try to load font
|
game.font_loaded = game.ft != 0
|
||||||
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 )
|
|
||||||
for {
|
for {
|
||||||
gg.clear(BackgroundColor)
|
gg.clear(BackgroundColor)
|
||||||
game.draw_scene()
|
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?)
|
// Is the next token `=`, `+=` etc? (Are we modifying the field?)
|
||||||
next := p.peek()
|
next := p.peek()
|
||||||
modifying := next.is_assign() || next == .inc || next == .dec || (field.typ.starts_with('array_') && next == .left_shift)
|
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 {
|
if !p.builtin_mod && !p.pref.translated && modifying && p.has_immutable_field {
|
||||||
f := p.first_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:`
|
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 {
|
// vals.len == 0 {
|
||||||
if exp_array {
|
if exp_array {
|
||||||
type_expected := p.expected_type[6..].replace('ptr_', '&')
|
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()
|
typ = p.get_type()
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,6 +73,7 @@ fn (p mut Parser) enum_decl(no_name bool) {
|
||||||
}
|
}
|
||||||
if p.tok == .comma {
|
if p.tok == .comma {
|
||||||
p.next()
|
p.next()
|
||||||
|
p.fremove_last()
|
||||||
}
|
}
|
||||||
p.fgen_nl()
|
p.fgen_nl()
|
||||||
val++
|
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
|
if p.inside_return_expr && p.expected_type.contains('_MulRet_') { //is_ret { // return a,b hack TODO
|
||||||
expected = p.expected_type
|
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
|
if expected != typ && expected in p.table.sum_types { // TODO perf
|
||||||
//p.warn('SUM CAST exp=$expected typ=$typ p.exp=$p.expected_type')
|
//p.warn('SUM CAST exp=$expected typ=$typ p.exp=$p.expected_type')
|
||||||
T := p.table.find_type(typ)
|
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()
|
field_name := p.check_name()
|
||||||
println('# $ti.name $ti.idx - $field_name')
|
println('# $ti.name $ti.idx - $field_name')
|
||||||
if ti.kind != .void {
|
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
|
struc := p.table.types[ti.idx] as types.Struct
|
||||||
// Method call
|
// 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
|
return node,types.int_ti
|
||||||
}
|
}
|
||||||
if !p.table.struct_has_field(struc, field_name) {
|
if !p.table.struct_has_field(struc, field_name) {
|
||||||
// t :=
|
// t :=
|
||||||
p.error('type `$struc.name` has no field `$field_name`')
|
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
|
t.types[ti.idx] = struc
|
||||||
*/
|
*/
|
||||||
|
|
||||||
println('register method `$new_fn.name` struct=$ti.name ')
|
println('register method `$new_fn.name` struct=$ti.name ')
|
||||||
|
|
||||||
println('##### $ti.idx - $t.methods.len')
|
println('##### $ti.idx - $t.methods.len')
|
||||||
|
|
||||||
t.methods[ti.idx] << new_fn
|
t.methods[ti.idx] << new_fn
|
||||||
return true
|
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.type_idxs[name] = idx
|
||||||
t.types << typ
|
t.types << typ
|
||||||
t.methods << []Fn
|
t.methods << []Fn // TODO [] breaks V
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (t mut Table) register_struct(typ types.Struct) int {
|
pub fn (t mut Table) register_struct(typ types.Struct) int {
|
||||||
|
|
|
@ -25,35 +25,35 @@ pub const (
|
||||||
|
|
||||||
pub enum Kind {
|
pub enum Kind {
|
||||||
placeholder
|
placeholder
|
||||||
void,
|
void
|
||||||
voidptr,
|
voidptr
|
||||||
charptr,
|
charptr
|
||||||
byteptr,
|
byteptr
|
||||||
const_,
|
const_
|
||||||
enum_,
|
enum_
|
||||||
struct_,
|
struct_
|
||||||
int,
|
int
|
||||||
i8,
|
i8
|
||||||
i16,
|
i16
|
||||||
i64,
|
i64
|
||||||
byte,
|
byte
|
||||||
u16,
|
u16
|
||||||
u32,
|
u32
|
||||||
u64,
|
u64
|
||||||
f32,
|
f32
|
||||||
f64,
|
f64
|
||||||
string,
|
string
|
||||||
char,
|
char
|
||||||
bool,
|
bool
|
||||||
array,
|
array
|
||||||
array_fixed,
|
array_fixed
|
||||||
map,
|
map
|
||||||
multi_return,
|
multi_return
|
||||||
variadic
|
variadic
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type Type = Placeholder | Primitive | Const | Enum | Struct | Int | Float |
|
pub type Type = Placeholder | Primitive | Const | Enum | Struct | Int | Float |
|
||||||
String | Bool | Array | ArrayFixed | Map | MultiReturn | Variadic
|
String | Bool | Array | ArrayFixed | Map | MultiReturn | Variadic
|
||||||
|
|
||||||
pub struct TypeIdent {
|
pub struct TypeIdent {
|
||||||
pub:
|
pub:
|
||||||
|
@ -228,7 +228,6 @@ pub:
|
||||||
name string
|
name string
|
||||||
// kind Kind
|
// kind Kind
|
||||||
}
|
}
|
||||||
|
|
||||||
// Void | Voidptr | Charptr | Byteptr
|
// Void | Voidptr | Charptr | Byteptr
|
||||||
pub struct Primitive {
|
pub struct Primitive {
|
||||||
pub:
|
pub:
|
||||||
|
@ -266,7 +265,7 @@ pub:
|
||||||
|
|
||||||
pub struct Int {
|
pub struct Int {
|
||||||
pub:
|
pub:
|
||||||
idx int
|
idx int
|
||||||
bit_size u32
|
bit_size u32
|
||||||
is_unsigned bool
|
is_unsigned bool
|
||||||
}
|
}
|
||||||
|
@ -335,27 +334,26 @@ pub:
|
||||||
|
|
||||||
pub fn (t Primitive) str() string {
|
pub fn (t Primitive) str() string {
|
||||||
s := match t.kind {
|
s := match t.kind {
|
||||||
.void {
|
.void{
|
||||||
'void'
|
'void'
|
||||||
}
|
}
|
||||||
.voidptr {
|
.voidptr{
|
||||||
'voidptr'
|
'voidptr'
|
||||||
}
|
}
|
||||||
.charptr {
|
.charptr{
|
||||||
'charptr'
|
'charptr'
|
||||||
}
|
}
|
||||||
.byteptr {
|
.byteptr{
|
||||||
'byteptr'
|
'byteptr'
|
||||||
}
|
}
|
||||||
.char {
|
.char{
|
||||||
'char'
|
'char'
|
||||||
}
|
}
|
||||||
.byte {
|
.byte{
|
||||||
'byte'
|
'byte'
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
'unknown'
|
'unknown'}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue