interim commit of various experiments

This commit is contained in:
hyunghwan.chung 2017-06-16 09:45:22 +00:00
parent 9b3c3007fd
commit d311c7cb6e
20 changed files with 444 additions and 1463 deletions

View File

@ -7,7 +7,7 @@ class(#pointer,#limited) Class(Apex)
var spec, selfspec, superclass, subclasses, name, modname. var spec, selfspec, superclass, subclasses, name, modname.
var instvars, classinstvars, classvars, pooldics. var instvars, classinstvars, classvars, pooldics.
var instmthdic, classmthdic, nsup, nsdic. var instmthdic, classmthdic, nsup, nsdic.
var trsize, initv, initv_ci. var trsize, trgc, initv, initv_ci.
method(#class) initialize { ^self } method(#class) initialize { ^self }

View File

@ -451,7 +451,7 @@ class Dictionary(Set)
{ {
(* [NOTE] (* [NOTE]
* VM require Dictionary to implement new: and __put_assoc * VM require Dictionary to implement new: and __put_assoc
* for the dictionary expression notation - :{ } * for the dictionary expression notation - %{ }
*) *)
## TODO: implement Dictionary as a Hashed List/Table or Red-Black Tree ## TODO: implement Dictionary as a Hashed List/Table or Red-Black Tree
@ -466,7 +466,7 @@ class Dictionary(Set)
* to a dictionary with the dictionary/association expression notation * to a dictionary with the dictionary/association expression notation
* like this: * like this:
* *
* :{ 1 -> 20, #moo -> 999 } * %{ 1 -> 20, #moo -> 999 }
* *
* it must return self for the way VM works. * it must return self for the way VM works.
*) *)

View File

@ -216,28 +216,24 @@ class MyObject(Object)
a :=999. a :=999.
a := #{ a := %(
1, 1,
2, 2,
a, a,
4, 4,
1 + 1, 1 + 1,
#{ 1, 2, #{a, a := a + 1, a, if (a > 10) { a + 20 } }, 3}, %( 1, 2, %(a, a := a + 1, a, if (a > 10) { a + 20 } ), 3),
2 + 2, 2 + 2,
#'a b c' #'a b c'
}. ).
(* Dictionary ??? (* Dictionary ???
a := #{ a := %{
key -> value , key -> value ,
key -> value , key -> value ,
key -> value , key -> value ,
key -> value key -> value
} ),.
a := :{
key -> value,
}
*) *)
a do: [ :v | v dump]. a do: [ :v | v dump].
@ -278,7 +274,7 @@ class MyObject(Object)
}.*) }.*)
a := :{ a := %{
'aaa' -> 10, 'aaa' -> 10,
'bbb' -> 20, 'bbb' -> 20,
'bbb' -> 30, 'bbb' -> 30,
@ -368,6 +364,6 @@ a free.
(* (*
pooldic XXD { pooldic XXD {
#abc := #(1 2 3). #abc := #(1 2 3).
#def := #{ 1, 3, 4 }. ## syntax error - literal expected where #{ is #def := %( 1, 3, 4 ). ## syntax error - literal expected where %( is
} }
*) *)

File diff suppressed because it is too large Load Diff

View File

@ -108,7 +108,7 @@ extend MyObject
{ {
| tc limit | | tc limit |
tc := #{ tc := %(
## 0 - 4 ## 0 - 4
[MyObject.Donkey v == 901982], [MyObject.Donkey v == 901982],
[selfns.MyObject.Donkey v == 901982], [selfns.MyObject.Donkey v == 901982],
@ -160,7 +160,7 @@ extend MyObject
## 35 - 39 ## 35 - 39
[MyObject.System.System.System KING == #KING] [MyObject.System.System.System KING == #KING]
}. ).
limit := tc size. limit := tc size.
MyObject.System.System a: XX.AAAA. MyObject.System.System a: XX.AAAA.

View File

@ -21,11 +21,11 @@ class MyObject(Object)
{ {
| tc limit | | tc limit |
tc := #{ tc := %(
## 0 - 4 ## 0 - 4
[ self proc1 == 100 ], [ self proc1 == 100 ],
[ Processor sleepFor: 2. self proc1 == 200 ] [ Processor sleepFor: 2. self proc1 == 200 ]
}. ).
limit := tc size. limit := tc size.

View File

@ -273,14 +273,18 @@ static MOO_INLINE int is_binselchar (moo_ooci_t c)
{ {
/* /*
* binary-selector-character := * binary-selector-character :=
* '%' | '&' | '*' | '+' | '-' | * '&' | '*' | '+' | '-' | '/' |
* '/' | '<' | '>' | '=' | '?' | * '<' | '>' | '=' | '?' | '@' |
* '@' | '\' | '~' | '|' * '\' | '~' | '|'
*
* - a comma is special in moo and doesn't form a binary selector.
* - a percent sign is special in moo and doesn't form a binary selector.
* - an exclamation mark is excluded intentioinally because i can't tell
* the method symbol #! from the comment introducer #!.
*/ */
switch (c) switch (c)
{ {
case '%':
case '&': case '&':
case '*': case '*':
case '+': case '+':
@ -1652,11 +1656,6 @@ retry:
SET_TOKEN_TYPE (moo, MOO_IOTOK_ASSIGN); SET_TOKEN_TYPE (moo, MOO_IOTOK_ASSIGN);
ADD_TOKEN_CHAR (moo, c); ADD_TOKEN_CHAR (moo, c);
} }
else if (c == '{')
{
SET_TOKEN_TYPE (moo, MOO_IOTOK_DICBRACE);
ADD_TOKEN_CHAR (moo, c);
}
else else
{ {
unget_char (moo, &moo->c->lxc); unget_char (moo, &moo->c->lxc);
@ -1708,6 +1707,34 @@ retry:
SET_TOKEN_TYPE (moo, MOO_IOTOK_SEMICOLON); SET_TOKEN_TYPE (moo, MOO_IOTOK_SEMICOLON);
goto single_char_token; goto single_char_token;
case '%':
SET_TOKEN_TYPE (moo, MOO_IOTOK_PERCENT);
ADD_TOKEN_CHAR(moo, c);
GET_CHAR_TO (moo, c);
/* TODO: byte array expression token -> %[ */
if (c == '(')
{
/* %( - array expression */
ADD_TOKEN_CHAR(moo, c);
SET_TOKEN_TYPE (moo, MOO_IOTOK_PERCPAREN);
}
else if (c == '{')
{
/* %{ - dictionary expression */
ADD_TOKEN_CHAR(moo, c);
SET_TOKEN_TYPE (moo, MOO_IOTOK_PERCBRACE);
}
else
{
/* NOTE the percent sign not followed by ( or } is
* meaningless at this moment. however, i return
* it as a token so that the compiler anyway
* will fail eventually */
unget_char (moo, &moo->c->lxc);
}
break;
case '#': case '#':
ADD_TOKEN_CHAR(moo, c); ADD_TOKEN_CHAR(moo, c);
GET_CHAR_TO (moo, c); GET_CHAR_TO (moo, c);
@ -1720,19 +1747,14 @@ retry:
case '(': case '(':
/* #( - array literal */ /* #( - array literal */
ADD_TOKEN_CHAR(moo, c); ADD_TOKEN_CHAR(moo, c);
SET_TOKEN_TYPE (moo, MOO_IOTOK_APAREN); SET_TOKEN_TYPE (moo, MOO_IOTOK_HASHPAREN);
break; break;
case '[': case '[':
/* #[ - byte array literal */ /* #[ - byte array literal */
ADD_TOKEN_CHAR(moo, c); ADD_TOKEN_CHAR(moo, c);
SET_TOKEN_TYPE (moo, MOO_IOTOK_BABRACK); SET_TOKEN_TYPE (moo, MOO_IOTOK_HASHBRACK);
break; break;
case '{':
/* #{ - array expression */
ADD_TOKEN_CHAR(moo, c);
SET_TOKEN_TYPE (moo, MOO_IOTOK_ABRACE);
break; break;
case '\'': case '\'':
@ -1923,7 +1945,7 @@ retry:
break; break;
} }
MOO_DEBUG2 (moo, "TOKEN: [%.*js]\n", (moo_ooi_t)moo->c->tok.name.len, moo->c->tok.name.ptr); MOO_DEBUG3 (moo, "TOKEN: [%.*js] %d\n", (moo_ooi_t)moo->c->tok.name.len, moo->c->tok.name.ptr, (int)moo->c->tok.type);
return 0; return 0;
} }
@ -4604,7 +4626,7 @@ static int compile_byte_array_literal (moo_t* moo)
moo_oow_t index; moo_oow_t index;
MOO_ASSERT (moo, moo->c->balit.count == 0); MOO_ASSERT (moo, moo->c->balit.count == 0);
MOO_ASSERT (moo, TOKEN_TYPE(moo) == MOO_IOTOK_BABRACK); MOO_ASSERT (moo, TOKEN_TYPE(moo) == MOO_IOTOK_HASHBRACK);
if (read_byte_array_literal(moo, &lit) <= -1 || if (read_byte_array_literal(moo, &lit) <= -1 ||
add_literal(moo, lit, &index) <= -1 || add_literal(moo, lit, &index) <= -1 ||
@ -4620,7 +4642,7 @@ static int compile_array_literal (moo_t* moo)
moo_oow_t index; moo_oow_t index;
MOO_ASSERT (moo, moo->c->arlit.count == 0); MOO_ASSERT (moo, moo->c->arlit.count == 0);
MOO_ASSERT (moo, TOKEN_TYPE(moo) == MOO_IOTOK_APAREN); MOO_ASSERT (moo, TOKEN_TYPE(moo) == MOO_IOTOK_HASHPAREN);
if (read_array_literal(moo, 0, &lit) <= -1 || if (read_array_literal(moo, 0, &lit) <= -1 ||
add_literal(moo, lit, &index) <= -1 || add_literal(moo, lit, &index) <= -1 ||
@ -4635,7 +4657,7 @@ static int compile_array_expression (moo_t* moo)
moo_oow_t maip; moo_oow_t maip;
moo_ioloc_t aeloc; moo_ioloc_t aeloc;
MOO_ASSERT (moo, TOKEN_TYPE(moo) == MOO_IOTOK_ABRACE); MOO_ASSERT (moo, TOKEN_TYPE(moo) == MOO_IOTOK_PERCPAREN);
maip = moo->c->mth.code.len; maip = moo->c->mth.code.len;
if (emit_single_param_instruction(moo, BCODE_MAKE_ARRAY, 0) <= -1) return -1; if (emit_single_param_instruction(moo, BCODE_MAKE_ARRAY, 0) <= -1) return -1;
@ -4659,7 +4681,7 @@ static int compile_array_expression (moo_t* moo)
return -1; return -1;
} }
if (TOKEN_TYPE(moo) == MOO_IOTOK_RBRACE) break; if (TOKEN_TYPE(moo) == MOO_IOTOK_RPAREN) break;
if (TOKEN_TYPE(moo) != MOO_IOTOK_COMMA) if (TOKEN_TYPE(moo) != MOO_IOTOK_COMMA)
{ {
@ -4689,7 +4711,7 @@ static int compile_dictionary_expression (moo_t* moo)
{ {
moo_oow_t mdip; moo_oow_t mdip;
MOO_ASSERT (moo, TOKEN_TYPE(moo) == MOO_IOTOK_DICBRACE); MOO_ASSERT (moo, TOKEN_TYPE(moo) == MOO_IOTOK_PERCBRACE);
GET_TOKEN (moo); /* read a token after :{ */ GET_TOKEN (moo); /* read a token after :{ */
@ -4931,21 +4953,21 @@ static int compile_expression_primary (moo_t* moo, const moo_oocs_t* ident, cons
GET_TOKEN (moo); GET_TOKEN (moo);
break; break;
case MOO_IOTOK_BABRACK: /* #[ */ case MOO_IOTOK_HASHBRACK: /* #[ */
/*GET_TOKEN (moo);*/ /*GET_TOKEN (moo);*/
if (compile_byte_array_literal(moo) <= -1) return -1; if (compile_byte_array_literal(moo) <= -1) return -1;
break; break;
case MOO_IOTOK_APAREN: /* #( */ case MOO_IOTOK_HASHPAREN: /* #( */
/*GET_TOKEN (moo);*/ /*GET_TOKEN (moo);*/
if (compile_array_literal(moo) <= -1) return -1; if (compile_array_literal(moo) <= -1) return -1;
break; break;
case MOO_IOTOK_ABRACE: /* #{ */ case MOO_IOTOK_PERCPAREN: /* %( */
if (compile_array_expression(moo) <= -1) return -1; if (compile_array_expression(moo) <= -1) return -1;
break; break;
case MOO_IOTOK_DICBRACE: /* :{ */ case MOO_IOTOK_PERCBRACE: /* %{ */
if (compile_dictionary_expression(moo) <= -1) return -1; if (compile_dictionary_expression(moo) <= -1) return -1;
break; break;
@ -6940,7 +6962,6 @@ static int make_defined_class (moo_t* moo)
if (make_getters_and_setters (moo) <= -1) return -1; if (make_getters_and_setters (moo) <= -1) return -1;
if (just_made) if (just_made)
{ {
/* register the class to the system dictionary. kernel classes have /* register the class to the system dictionary. kernel classes have
@ -7456,6 +7477,7 @@ static int __compile_class_definition (moo_t* moo, int extend)
* inherit so that the inherited methods work well when they * inherit so that the inherited methods work well when they
* access the trailer space */ * access the trailer space */
moo->c->cls.self_oop->trsize = ((moo_oop_class_t)moo->c->cls.self_oop->superclass)->trsize; moo->c->cls.self_oop->trsize = ((moo_oop_class_t)moo->c->cls.self_oop->superclass)->trsize;
moo->c->cls.self_oop->trgc = ((moo_oop_class_t)moo->c->cls.self_oop->superclass)->trgc;
} }
} }
@ -7614,10 +7636,9 @@ static moo_oop_t token_to_literal (moo_t* moo, int rdonly)
} }
/* [NOTE] i don't mark RDONLY on a value resolved via an identifier */ /* [NOTE] i don't mark RDONLY on a value resolved via an identifier */
} }
case MOO_IOTOK_BABRACK: /* #[ - byte array literal parenthesis */ case MOO_IOTOK_HASHBRACK: /* #[ - byte array literal parenthesis */
{ {
moo_oop_t lit; moo_oop_t lit;
if (read_byte_array_literal(moo, &lit) <= -1) return MOO_NULL; if (read_byte_array_literal(moo, &lit) <= -1) return MOO_NULL;
@ -7629,7 +7650,7 @@ static moo_oop_t token_to_literal (moo_t* moo, int rdonly)
return lit; return lit;
} }
case MOO_IOTOK_APAREN: /* #( - array literal parenthesis */ case MOO_IOTOK_HASHPAREN: /* #( - array literal parenthesis */
{ {
moo_oop_t lit; moo_oop_t lit;
if (read_array_literal(moo, rdonly, &lit) <= -1) return MOO_NULL; if (read_array_literal(moo, rdonly, &lit) <= -1) return MOO_NULL;

View File

@ -47,7 +47,7 @@ static moo_ooch_t errstr_13[] = {'n','o','t',' ','a',' ','d','i','r','e','c','t'
static moo_ooch_t errstr_14[] = {'i','n','t','e','r','r','u','p','t','e','d','\0'}; static moo_ooch_t errstr_14[] = {'i','n','t','e','r','r','u','p','t','e','d','\0'};
static moo_ooch_t errstr_15[] = {'p','i','p','e',' ','e','r','r','o','r','\0'}; static moo_ooch_t errstr_15[] = {'p','i','p','e',' ','e','r','r','o','r','\0'};
static moo_ooch_t errstr_16[] = {'r','e','s','o','u','r','c','e',' ','t','e','m','p','o','r','a','r','i','l','y',' ','u','n','a','v','a','i','l','a','b','l','e','\0'}; static moo_ooch_t errstr_16[] = {'r','e','s','o','u','r','c','e',' ','t','e','m','p','o','r','a','r','i','l','y',' ','u','n','a','v','a','i','l','a','b','l','e','\0'};
static moo_ooch_t errstr_17[] = {'d','a','t','a',' ','t','o','o',' ','l','a','r','g','e','\0'}; static moo_ooch_t errstr_17[] = {'d','a','t','a',' ','n','o','t',' ','a','v','a','i','l','a','b','l','e','\0'};
static moo_ooch_t errstr_18[] = {'m','e','s','s','a','g','e',' ','r','e','c','e','i','v','e','r',' ','e','r','r','o','r','\0'}; static moo_ooch_t errstr_18[] = {'m','e','s','s','a','g','e',' ','r','e','c','e','i','v','e','r',' ','e','r','r','o','r','\0'};
static moo_ooch_t errstr_19[] = {'m','e','s','s','a','g','e',' ','s','e','n','d','i','n','g',' ','e','r','r','o','r','\0'}; static moo_ooch_t errstr_19[] = {'m','e','s','s','a','g','e',' ','s','e','n','d','i','n','g',' ','e','r','r','o','r','\0'};
static moo_ooch_t errstr_20[] = {'w','r','o','n','g',' ','n','u','m','b','e','r',' ','o','f',' ','a','r','g','u','m','e','n','t','s','\0'}; static moo_ooch_t errstr_20[] = {'w','r','o','n','g',' ','n','u','m','b','e','r',' ','o','f',' ','a','r','g','u','m','e','n','t','s','\0'};

View File

@ -232,6 +232,18 @@ static int ignite_1 (moo_t* moo)
!moo->_small_pointer || !moo->_system) return -1; !moo->_small_pointer || !moo->_system) return -1;
MOO_OBJ_SET_CLASS (moo->_nil, (moo_oop_t)moo->_undefined_object); MOO_OBJ_SET_CLASS (moo->_nil, (moo_oop_t)moo->_undefined_object);
#if defined(MOO_USE_METHOD_TRAILER)
/* an instance of a method class stores byte codes in the trailer space
* when compiled with MOO_USE_METHOD_TRAILER. unlike other classes with
* trailer size set, the size of the trailer space is not really determined
* by the traailer size set in the class. the compiler determines the
* actual size of the trailer space depending on the byte codes generated.
* i should set the following fields to avoid confusion at the GC phase. */
moo->_method->trsize = MOO_SMOOI_TO_OOP(0);
moo->_method->trgc = MOO_SMPTR_TO_OOP(0);
#endif
return 0; return 0;
} }
@ -419,7 +431,6 @@ static MOO_INLINE moo_oow_t get_payload_bytes (moo_t* moo, moo_oop_t oop)
{ {
moo_oow_t nbytes_aligned; moo_oow_t nbytes_aligned;
#if defined(MOO_USE_METHOD_TRAILER)
if (MOO_OBJ_GET_FLAGS_TRAILER(oop)) if (MOO_OBJ_GET_FLAGS_TRAILER(oop))
{ {
moo_oow_t nbytes; moo_oow_t nbytes;
@ -446,12 +457,9 @@ static MOO_INLINE moo_oow_t get_payload_bytes (moo_t* moo, moo_oop_t oop)
} }
else else
{ {
#endif
/* calculate the payload size in bytes */ /* calculate the payload size in bytes */
nbytes_aligned = MOO_ALIGN (MOO_OBJ_BYTESOF(oop), MOO_SIZEOF(moo_oop_t)); nbytes_aligned = MOO_ALIGN (MOO_OBJ_BYTESOF(oop), MOO_SIZEOF(moo_oop_t));
#if defined(MOO_USE_METHOD_TRAILER)
} }
#endif
return nbytes_aligned; return nbytes_aligned;
} }
@ -517,7 +525,6 @@ static moo_uint8_t* scan_new_heap (moo_t* moo, moo_uint8_t* ptr)
oop = (moo_oop_t)ptr; oop = (moo_oop_t)ptr;
#if defined(MOO_USE_METHOD_TRAILER)
if (MOO_OBJ_GET_FLAGS_TRAILER(oop)) if (MOO_OBJ_GET_FLAGS_TRAILER(oop))
{ {
moo_oow_t nbytes; moo_oow_t nbytes;
@ -532,11 +539,8 @@ static moo_uint8_t* scan_new_heap (moo_t* moo, moo_uint8_t* ptr)
} }
else else
{ {
#endif
nbytes_aligned = MOO_ALIGN (MOO_OBJ_BYTESOF(oop), MOO_SIZEOF(moo_oop_t)); nbytes_aligned = MOO_ALIGN (MOO_OBJ_BYTESOF(oop), MOO_SIZEOF(moo_oop_t));
#if defined(MOO_USE_METHOD_TRAILER)
} }
#endif
MOO_OBJ_SET_CLASS (oop, moo_moveoop(moo, (moo_oop_t)MOO_OBJ_GET_CLASS(oop))); MOO_OBJ_SET_CLASS (oop, moo_moveoop(moo, (moo_oop_t)MOO_OBJ_GET_CLASS(oop)));
if (MOO_OBJ_GET_FLAGS_TYPE(oop) == MOO_OBJ_TYPE_OOP) if (MOO_OBJ_GET_FLAGS_TYPE(oop) == MOO_OBJ_TYPE_OOP)
@ -566,6 +570,25 @@ static moo_uint8_t* scan_new_heap (moo_t* moo, moo_uint8_t* ptr)
} }
} }
if (MOO_OBJ_GET_FLAGS_TRAILER(oop))
{
moo_oop_class_t c;
moo_trgc_t trgc;
/* i use SMPTR(0) to indicate no trailer gc callback.
* i don't use moo->_nil because c->trgc field may not have
* been updated to a new nil address while moo->_nil could
* have been updated in the process of garbage collection.
* this comment will be invalidated when moo->_nil is
* stored in a permanent heap or GC gets changed to
* a non-copying collector. no matter what GC implementation
* i choose, using SMPTR(0) for this purpose is safe. */
c = MOO_OBJ_GET_CLASS(oop);
MOO_ASSERT(moo, MOO_OOP_IS_SMPTR(c->trgc));
trgc = MOO_OOP_TO_SMPTR(c->trgc);
if (trgc) trgc (moo, oop);
}
ptr = ptr + MOO_SIZEOF(moo_obj_t) + nbytes_aligned; ptr = ptr + MOO_SIZEOF(moo_obj_t) + nbytes_aligned;
} }

View File

@ -345,8 +345,9 @@ struct moo_iotok_t
MOO_IOTOK_IDENT_DOTTED, MOO_IOTOK_IDENT_DOTTED,
MOO_IOTOK_BINSEL, MOO_IOTOK_BINSEL,
MOO_IOTOK_KEYWORD, MOO_IOTOK_KEYWORD,
MOO_IOTOK_ASSIGN, MOO_IOTOK_ASSIGN, /* := */
MOO_IOTOK_COLON, MOO_IOTOK_COLON, /* : */
MOO_IOTOK_PERCENT, /* % */
MOO_IOTOK_RETURN, /* ^ */ MOO_IOTOK_RETURN, /* ^ */
MOO_IOTOK_LOCAL_RETURN, /* ^^ */ MOO_IOTOK_LOCAL_RETURN, /* ^^ */
MOO_IOTOK_LBRACE, MOO_IOTOK_LBRACE,
@ -355,10 +356,10 @@ struct moo_iotok_t
MOO_IOTOK_RBRACK, MOO_IOTOK_RBRACK,
MOO_IOTOK_LPAREN, MOO_IOTOK_LPAREN,
MOO_IOTOK_RPAREN, MOO_IOTOK_RPAREN,
MOO_IOTOK_APAREN, /* #( - array literal */ MOO_IOTOK_HASHPAREN, /* #( - array literal */
MOO_IOTOK_BABRACK, /* #[ - byte array literal */ MOO_IOTOK_HASHBRACK, /* #[ - byte array literal */
MOO_IOTOK_ABRACE, /* #{ - array expression */ MOO_IOTOK_PERCPAREN, /* %{ - array expression */
MOO_IOTOK_DICBRACE, /* :{ - dictionary expression */ MOO_IOTOK_PERCBRACE, /* %{ - dictionary expression */
MOO_IOTOK_PERIOD, MOO_IOTOK_PERIOD,
MOO_IOTOK_COMMA, MOO_IOTOK_COMMA,
MOO_IOTOK_SEMICOLON MOO_IOTOK_SEMICOLON
@ -1009,14 +1010,12 @@ moo_oop_t moo_allocoopobj (
moo_oow_t size moo_oow_t size
); );
#if defined(MOO_USE_METHOD_TRAILER)
moo_oop_t moo_allocoopobjwithtrailer ( moo_oop_t moo_allocoopobjwithtrailer (
moo_t* moo, moo_t* moo,
moo_oow_t size, moo_oow_t size,
const moo_oob_t* tptr, const moo_oob_t* tptr,
moo_oow_t tlen moo_oow_t tlen
); );
#endif
moo_oop_t moo_alloccharobj ( moo_oop_t moo_alloccharobj (
moo_t* moo, moo_t* moo,

View File

@ -829,23 +829,35 @@ int moo_genpfmethods (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class, const
moo_pfbase_t* moo_findpfbase (moo_t* moo, moo_pfinfo_t* pfinfo, moo_oow_t pfcount, const moo_ooch_t* name, moo_oow_t namelen) moo_pfbase_t* moo_findpfbase (moo_t* moo, moo_pfinfo_t* pfinfo, moo_oow_t pfcount, const moo_ooch_t* name, moo_oow_t namelen)
{ {
moo_oow_t left, right, mid;
int n; int n;
/* binary search */ /* binary search */
#if 0
/* [NOTE] this algorithm is NOT underflow safe with moo_oow_t types */
int left, right, mid;
left = 0; right = pfcount - 1; for (left = 0, right = pfcount - 1; left <= right; )
while (left <= right)
{ {
/*mid = (left + right) / 2;*/ /*mid = (left + right) / 2;*/
mid = left + ((right - left) / 2); mid = left + ((right - left) / 2);
n = moo_compoocharsoocstr (name, namelen, pfinfo[mid].mthname); n = moo_compoocharsoocstr (name, namelen, pfinfo[mid].mthname);
if (n < 0) right = mid - 1; if (n < 0) right = mid - 1; /* this substraction can make right negative. so i can't use moo_oow_t for the variable */
else if (n > 0) left = mid + 1; else if (n > 0) left = mid + 1;
else return &pfinfo[mid].base; else return &pfinfo[mid].base;
} }
#else
/* [NOTE] this algorithm is underflow safe with moo_oow_t types */
moo_oow_t base, mid, lim;
for (base = 0, lim = pfcount; lim > 0; lim >>= 1)
{
mid = base + (lim >> 1);
n = moo_compoocharsoocstr (name, namelen, pfinfo[mid].mthname);
if (n == 0) return &pfinfo[mid].base;
if (n > 0) { base = mid + 1; lim--; }
}
#endif
moo_seterrnum (moo, MOO_ENOENT); moo_seterrnum (moo, MOO_ENOENT);
return MOO_NULL; return MOO_NULL;
@ -853,7 +865,7 @@ moo_pfbase_t* moo_findpfbase (moo_t* moo, moo_pfinfo_t* pfinfo, moo_oow_t pfcoun
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
int moo_setclasstrsize (moo_t* moo, moo_oop_class_t _class, moo_oow_t size) int moo_setclasstrsize (moo_t* moo, moo_oop_class_t _class, moo_oow_t size, moo_trgc_t trgc)
{ {
moo_oop_class_t sc; moo_oop_class_t sc;
moo_oow_t spec; moo_oow_t spec;
@ -884,12 +896,14 @@ int moo_setclasstrsize (moo_t* moo, moo_oop_class_t _class, moo_oow_t size)
if (_class->trsize != moo->_nil) if (_class->trsize != moo->_nil)
{ {
MOO_ASSERT (moo, _class->trgc != moo->_nil);
MOO_DEBUG3 (moo, "Not allowed to re-set trailer size to %zu on the %.*js class\n", MOO_DEBUG3 (moo, "Not allowed to re-set trailer size to %zu on the %.*js class\n",
size, size,
MOO_OBJ_GET_SIZE(_class->name), MOO_OBJ_GET_SIZE(_class->name),
MOO_OBJ_GET_CHAR_SLOT(_class->name)); MOO_OBJ_GET_CHAR_SLOT(_class->name));
goto eperm; goto eperm;
} }
MOO_ASSERT (moo, _class->trgc == moo->_nil);
sc = (moo_oop_class_t)_class->superclass; sc = (moo_oop_class_t)_class->superclass;
if (MOO_OOP_IS_SMOOI(sc->trsize) && size < MOO_OOP_TO_SMOOI(sc->trsize)) if (MOO_OOP_IS_SMOOI(sc->trsize) && size < MOO_OOP_TO_SMOOI(sc->trsize))
@ -906,10 +920,13 @@ int moo_setclasstrsize (moo_t* moo, moo_oop_class_t _class, moo_oow_t size)
/* you can only set the trailer size once when it's not set yet */ /* you can only set the trailer size once when it's not set yet */
_class->trsize = MOO_SMOOI_TO_OOP(size); _class->trsize = MOO_SMOOI_TO_OOP(size);
MOO_DEBUG3 (moo, "Set trailer size to %zu on the %.*js class\n", _class->trgc = MOO_SMPTR_TO_OOP(trgc); /* i don't replace NULL by nil for GC safety. */
MOO_DEBUG5 (moo, "Set trailer size to %zu on the %.*js class with gc callback of %p(%p)\n",
size, size,
MOO_OBJ_GET_SIZE(_class->name), MOO_OBJ_GET_SIZE(_class->name),
MOO_OBJ_GET_CHAR_SLOT(_class->name)); MOO_OBJ_GET_CHAR_SLOT(_class->name),
MOO_SMPTR_TO_OOP(trgc), trgc);
return 0; return 0;
eperm: eperm:

View File

@ -64,7 +64,7 @@ enum moo_errnum_t
MOO_EPIPE, MOO_EPIPE,
MOO_EAGAIN, MOO_EAGAIN,
MOO_ETOOBIG, /**< data too large */ MOO_ENOAVAIL, /**< data not available*/
MOO_EMSGRCV, /**< mesasge receiver error */ MOO_EMSGRCV, /**< mesasge receiver error */
MOO_EMSGSND, /**< message sending error. even doesNotUnderstand: is not found */ MOO_EMSGSND, /**< message sending error. even doesNotUnderstand: is not found */
MOO_ENUMARGS, /**< wrong number of arguments */ MOO_ENUMARGS, /**< wrong number of arguments */
@ -494,7 +494,7 @@ struct moo_dic_t
typedef struct moo_nsdic_t moo_nsdic_t; typedef struct moo_nsdic_t moo_nsdic_t;
typedef struct moo_nsdic_t* moo_oop_nsdic_t; typedef struct moo_nsdic_t* moo_oop_nsdic_t;
#define MOO_CLASS_NAMED_INSTVARS 17 #define MOO_CLASS_NAMED_INSTVARS 18
typedef struct moo_class_t moo_class_t; typedef struct moo_class_t moo_class_t;
typedef struct moo_class_t* moo_oop_class_t; typedef struct moo_class_t* moo_oop_class_t;
@ -538,6 +538,7 @@ struct moo_class_t
moo_oop_nsdic_t nsdic; /* dictionary used for namespacing - may be nil when there are no subitems underneath */ moo_oop_nsdic_t nsdic; /* dictionary used for namespacing - may be nil when there are no subitems underneath */
moo_oop_t trsize; /* trailer size for new instances */ moo_oop_t trsize; /* trailer size for new instances */
moo_oop_t trgc; /* trailer gc callback */
/* [0] - initial values for instance variables of new instances /* [0] - initial values for instance variables of new instances
* [1] - initial values for class instance variables */ * [1] - initial values for class instance variables */
@ -980,7 +981,6 @@ struct moo_mod_data_t
}; };
typedef struct moo_mod_data_t moo_mod_data_t; typedef struct moo_mod_data_t moo_mod_data_t;
struct moo_sbuf_t struct moo_sbuf_t
{ {
moo_ooch_t* ptr; moo_ooch_t* ptr;
@ -989,6 +989,9 @@ struct moo_sbuf_t
}; };
typedef struct moo_sbuf_t moo_sbuf_t; typedef struct moo_sbuf_t moo_sbuf_t;
/* special callback to be called for trailer */
typedef void (*moo_trgc_t) (moo_t* moo, moo_oop_t obj);
/* ========================================================================= /* =========================================================================
* MOO VM * MOO VM
* ========================================================================= */ * ========================================================================= */
@ -1623,7 +1626,8 @@ MOO_EXPORT moo_oop_t moo_findclass (
MOO_EXPORT int moo_setclasstrsize ( MOO_EXPORT int moo_setclasstrsize (
moo_t* moo, moo_t* moo,
moo_oop_class_t _class, moo_oop_class_t _class,
moo_oow_t size moo_oow_t size,
moo_trgc_t trgc
); );
MOO_EXPORT void* moo_getobjtrailer ( MOO_EXPORT void* moo_getobjtrailer (

View File

@ -78,7 +78,6 @@ moo_oop_t moo_allocoopobj (moo_t* moo, moo_oow_t size)
return (moo_oop_t)hdr; return (moo_oop_t)hdr;
} }
#if defined(MOO_USE_METHOD_TRAILER)
moo_oop_t moo_allocoopobjwithtrailer (moo_t* moo, moo_oow_t size, const moo_oob_t* bptr, moo_oow_t blen) moo_oop_t moo_allocoopobjwithtrailer (moo_t* moo, moo_oow_t size, const moo_oob_t* bptr, moo_oow_t blen)
{ {
moo_oop_oop_t hdr; moo_oop_oop_t hdr;
@ -112,7 +111,6 @@ moo_oop_t moo_allocoopobjwithtrailer (moo_t* moo, moo_oow_t size, const moo_oob_
return (moo_oop_t)hdr; return (moo_oop_t)hdr;
} }
#endif
static MOO_INLINE moo_oop_t alloc_numeric_array (moo_t* moo, const void* ptr, moo_oow_t len, moo_obj_type_t type, moo_oow_t unit, int extra) static MOO_INLINE moo_oop_t alloc_numeric_array (moo_t* moo, const void* ptr, moo_oow_t len, moo_obj_type_t type, moo_oow_t unit, int extra)
{ {

View File

@ -70,8 +70,8 @@ libmoo_stdio_la_LDFLAGS = $(LDFLAGS_COMMON)
libmoo_stdio_la_LIBADD = $(LIBADD_COMMON) libmoo_stdio_la_LIBADD = $(LIBADD_COMMON)
if ENABLE_MOD_X11 if ENABLE_MOD_X11
libmoo_x11_la_SOURCES = x11.c _x11.h libmoo_x11_la_SOURCES = x11.c x11-win.c _x11.h
libmoo_x11_la_CPPFLAGS = $(CPPFLAGS_COMMON) libmoo_x11_la_CPPFLAGS = $(CPPFLAGS_COMMON)
libmoo_x11_la_LDFLAGS = $(LDFLAGS_COMMON) libmoo_x11_la_LDFLAGS = $(LDFLAGS_COMMON)
libmoo_x11_la_LIBADD = $(LIBADD_COMMON) -lxcb libmoo_x11_la_LIBADD = $(LIBADD_COMMON) -lX11
endif endif

View File

@ -182,8 +182,9 @@ libmoo_stdio_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
@ENABLE_STATIC_MODULE_TRUE@am_libmoo_stdio_la_rpath = @ENABLE_STATIC_MODULE_TRUE@am_libmoo_stdio_la_rpath =
@ENABLE_MOD_X11_TRUE@libmoo_x11_la_DEPENDENCIES = \ @ENABLE_MOD_X11_TRUE@libmoo_x11_la_DEPENDENCIES = \
@ENABLE_MOD_X11_TRUE@ $(am__DEPENDENCIES_1) @ENABLE_MOD_X11_TRUE@ $(am__DEPENDENCIES_1)
am__libmoo_x11_la_SOURCES_DIST = x11.c _x11.h am__libmoo_x11_la_SOURCES_DIST = x11.c x11-win.c _x11.h
@ENABLE_MOD_X11_TRUE@am_libmoo_x11_la_OBJECTS = libmoo_x11_la-x11.lo @ENABLE_MOD_X11_TRUE@am_libmoo_x11_la_OBJECTS = libmoo_x11_la-x11.lo \
@ENABLE_MOD_X11_TRUE@ libmoo_x11_la-x11-win.lo
libmoo_x11_la_OBJECTS = $(am_libmoo_x11_la_OBJECTS) libmoo_x11_la_OBJECTS = $(am_libmoo_x11_la_OBJECTS)
libmoo_x11_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ libmoo_x11_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
@ -454,10 +455,10 @@ libmoo_stdio_la_SOURCES = stdio.c _stdio.h
libmoo_stdio_la_CPPFLAGS = $(CPPFLAGS_COMMON) libmoo_stdio_la_CPPFLAGS = $(CPPFLAGS_COMMON)
libmoo_stdio_la_LDFLAGS = $(LDFLAGS_COMMON) libmoo_stdio_la_LDFLAGS = $(LDFLAGS_COMMON)
libmoo_stdio_la_LIBADD = $(LIBADD_COMMON) libmoo_stdio_la_LIBADD = $(LIBADD_COMMON)
@ENABLE_MOD_X11_TRUE@libmoo_x11_la_SOURCES = x11.c _x11.h @ENABLE_MOD_X11_TRUE@libmoo_x11_la_SOURCES = x11.c x11-win.c _x11.h
@ENABLE_MOD_X11_TRUE@libmoo_x11_la_CPPFLAGS = $(CPPFLAGS_COMMON) @ENABLE_MOD_X11_TRUE@libmoo_x11_la_CPPFLAGS = $(CPPFLAGS_COMMON)
@ENABLE_MOD_X11_TRUE@libmoo_x11_la_LDFLAGS = $(LDFLAGS_COMMON) @ENABLE_MOD_X11_TRUE@libmoo_x11_la_LDFLAGS = $(LDFLAGS_COMMON)
@ENABLE_MOD_X11_TRUE@libmoo_x11_la_LIBADD = $(LIBADD_COMMON) -lxcb @ENABLE_MOD_X11_TRUE@libmoo_x11_la_LIBADD = $(LIBADD_COMMON) -lX11
all: all-am all: all-am
.SUFFIXES: .SUFFIXES:
@ -559,6 +560,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_console_la-console.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_console_la-console.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_ffi_la-ffi.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_ffi_la-ffi.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_stdio_la-stdio.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_stdio_la-stdio.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_x11_la-x11-win.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_x11_la-x11.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_x11_la-x11.Plo@am__quote@
.c.o: .c.o:
@ -613,6 +615,13 @@ libmoo_x11_la-x11.lo: x11.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_x11_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmoo_x11_la-x11.lo `test -f 'x11.c' || echo '$(srcdir)/'`x11.c @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_x11_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmoo_x11_la-x11.lo `test -f 'x11.c' || echo '$(srcdir)/'`x11.c
libmoo_x11_la-x11-win.lo: x11-win.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_x11_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmoo_x11_la-x11-win.lo -MD -MP -MF $(DEPDIR)/libmoo_x11_la-x11-win.Tpo -c -o libmoo_x11_la-x11-win.lo `test -f 'x11-win.c' || echo '$(srcdir)/'`x11-win.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmoo_x11_la-x11-win.Tpo $(DEPDIR)/libmoo_x11_la-x11-win.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='x11-win.c' object='libmoo_x11_la-x11-win.lo' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_x11_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmoo_x11_la-x11-win.lo `test -f 'x11-win.c' || echo '$(srcdir)/'`x11-win.c
mostlyclean-libtool: mostlyclean-libtool:
-rm -f *.lo -rm -f *.lo

View File

@ -29,6 +29,42 @@
#include <moo.h> #include <moo.h>
#include <X11/Xlib.h>
/* [NOTE] this header is for internal use only.
* so most of the declarations here don't have the moo_ prefix */
#define MC MOO_METHOD_CLASS
#define MI MOO_METHOD_INSTANCE
typedef struct x11_t x11_t;
struct x11_t
{
Display* disp;
XEvent* curevt;
};
typedef struct x11_win_t x11_win_t;
struct x11_win_t
{
Display* disp;
Window wind;
};
typedef struct x11_t* oop_x11_t;
struct x11_t
{
Display* disp;
};
typedef struct x11_trailer_t x11_trailer_t;
struct x11_trailer_t
{
XEvent* curevt;
};
#if defined(__cplusplus) #if defined(__cplusplus)
extern "C" { extern "C" {
#endif #endif

View File

@ -261,7 +261,7 @@ static moo_pfinfo_t pfinfos[] =
static int import (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class) static int import (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class)
{ {
if (moo_setclasstrsize (moo, _class, MOO_SIZEOF(console_t)) <= -1) return -1; if (moo_setclasstrsize (moo, _class, MOO_SIZEOF(console_t), MOO_NULL) <= -1) return -1;
return 0; return 0;
} }

View File

@ -541,7 +541,7 @@ static moo_pfinfo_t pfinfos[] =
static int import (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class) static int import (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class)
{ {
if (moo_setclasstrsize (moo, _class, MOO_SIZEOF(ffi_t)) <= -1) return -1; if (moo_setclasstrsize (moo, _class, MOO_SIZEOF(ffi_t), MOO_NULL) <= -1) return -1;
return 0; return 0;
} }

View File

@ -222,9 +222,8 @@ static moo_pfinfo_t pfinfos[] =
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */
static int import (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class) static int import (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class)
{ {
if (moo_setclasstrsize (moo, _class, MOO_SIZEOF(stdio_t)) <= -1) return -1; if (moo_setclasstrsize (moo, _class, MOO_SIZEOF(stdio_t), MOO_NULL) <= -1) return -1;
return 0; return 0;
/*return moo_genpfmethods (moo, mod, _class, pfinfos, MOO_COUNTOF(pfinfos));*/
} }
static moo_pfbase_t* query (moo_t* moo, moo_mod_t* mod, const moo_ooch_t* name, moo_oow_t namelen) static moo_pfbase_t* query (moo_t* moo, moo_mod_t* mod, const moo_ooch_t* name, moo_oow_t namelen)

View File

@ -28,26 +28,8 @@
#include <moo-utl.h> #include <moo-utl.h>
#include <errno.h> #include <errno.h>
#include <xcb/xcb.h>
#include <stdlib.h> #include <stdlib.h>
#define C MOO_METHOD_CLASS
#define I MOO_METHOD_INSTANCE
/**
* @brief Bit mask to find event type regardless of event source.
*
* Each event in the X11 protocol contains an 8-bit type code.
* The most-significant bit in this code is set if the event was
* generated from a SendEvent request. This mask can be used to
* determine the type of event regardless of how the event was
* generated. See the X11R6 protocol specification for details.
*/
#define XCB_EVENT_RESPONSE_TYPE_MASK (0x7f)
#define XCB_EVENT_RESPONSE_TYPE(e) (e->response_type & XCB_EVENT_RESPONSE_TYPE_MASK)
#define XCB_EVENT_SENT(e) (e->response_type & ~XCB_EVENT_RESPONSE_TYPE_MASK)
typedef struct x11_modctx_t x11_modctx_t; typedef struct x11_modctx_t x11_modctx_t;
struct x11_modctx_t struct x11_modctx_t
@ -55,159 +37,158 @@ struct x11_modctx_t
moo_oop_class_t x11_class; moo_oop_class_t x11_class;
}; };
typedef struct x11_t x11_t;
struct x11_t
{
xcb_connection_t* c;
xcb_screen_t* screen;
xcb_generic_event_t* curevt; /* most recent event received */
};
typedef struct x11_win_t x11_win_t;
struct x11_win_t
{
xcb_window_t id;
xcb_intern_atom_reply_t* dwar;
xcb_connection_t* c;
};
typedef struct x11_gc_t x11_gc_t;
struct x11_gc_t
{
xcb_gcontext_t id;
xcb_window_t wid;
xcb_connection_t* c;
};
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */
static moo_pfrc_t pf_connect (moo_t* moo, moo_ooi_t nargs) static moo_pfrc_t pf_connect (moo_t* moo, moo_ooi_t nargs)
{ {
x11_t* x11; x11_trailer_t* x11;
xcb_connection_t* c; Display* disp = MOO_NULL;
XEvent* curevt = MOO_NULL;
char* dispname = MOO_NULL;
x11 = (x11_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL); x11 = (x11_trailer_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL);
/* TODO: accept display target as a parameter */ if (x11->disp)
if (x11->c)
{ {
MOO_DEBUG0 (moo, "<x11.connect> Unable to connect multiple times\n"); MOO_DEBUG0 (moo, "<x11.connect> Unable to open a display multiple times\n");
MOO_STACK_SETRETTOERROR (moo, nargs, MOO_EEXIST); MOO_STACK_SETRETTOERROR (moo, nargs, MOO_EEXIST);
return MOO_PF_SUCCESS; goto oops;
} }
/* if (nargs >= 1)
name = MOO_STACK_GETARG(moo, nargs, 0);
if (!MOO_OBJ_IS_CHAR_POINTER(name))
{ {
moo_seterrnum (moo, MOO_EINVAL); moo_oop_t np;
goto softfail;
np = MOO_STACK_GETARG(moo, nargs, 0);
if (np != moo->_nil)
{
moo_oow_t bl;
if (!MOO_OBJ_IS_CHAR_POINTER(np))
{
MOO_STACK_SETRETTOERROR (moo, nargs, MOO_EINVAL);
goto oops;
} }
MOO_DEBUG3 (moo, "<x11.connect> %.*js => %p\n", MOO_OBJ_GET_SIZE(name), ((moo_oop_char_t)name)->slot, rcv->handle); bl = MOO_OBJ_GET_SIZE(np);
*/ dispname = moo_dupootobcstr (moo, MOO_OBJ_GET_CHAR_SLOT(np), &bl);
if (!dispname)
c = xcb_connect (MOO_NULL, MOO_NULL);
if (!c || xcb_connection_has_error(c))
{ {
MOO_DEBUG0 (moo, "<x11.connect> Cannot connect to X11 server\n"); MOO_DEBUG2 (moo, "<x11.connect> Cannot convert display name %.*js\n", MOO_OBJ_GET_SIZE(np), MOO_OBJ_GET_CHAR_SLOT(np));
MOO_STACK_SETRETTOERRNUM (moo, nargs);
goto oops;
}
}
}
curevt = moo_allocmem (moo, MOO_SIZEOF(*x11->curevt));
if (!curevt)
{
MOO_STACK_SETRETTOERRNUM (moo, nargs);
goto oops;
}
disp = XOpenDisplay(dispname);
if (!disp)
{
MOO_DEBUG1 (moo, "<x11.connect> Cannot connect to X11 server %hs\n", XDisplayName(dispname));
MOO_STACK_SETRETTOERROR (moo, nargs, MOO_ESYSERR); MOO_STACK_SETRETTOERROR (moo, nargs, MOO_ESYSERR);
return MOO_PF_SUCCESS; goto oops;
} }
x11->screen = xcb_setup_roots_iterator(xcb_get_setup(c)).data; x11->disp = disp;
x11->c = c; x11->curevt = curevt;
MOO_ASSERT (moo, MOO_IN_SMPTR_RANGE(c)); MOO_ASSERT (moo, MOO_IN_SMPTR_RANGE(disp));
MOO_STACK_SETRET (moo, nargs, MOO_SMPTR_TO_OOP(c)); MOO_STACK_SETRET (moo, nargs, MOO_SMPTR_TO_OOP(disp));
if (dispname) moo_freemem (moo, dispname);
return MOO_PF_SUCCESS;
oops:
if (disp) XCloseDisplay (disp);
if (curevt) moo_freemem (moo, curevt);
if (dispname) moo_freemem (moo, dispname);
return MOO_PF_SUCCESS; return MOO_PF_SUCCESS;
} }
static moo_pfrc_t pf_disconnect (moo_t* moo, moo_ooi_t nargs) static moo_pfrc_t pf_disconnect (moo_t* moo, moo_ooi_t nargs)
{ {
x11_t* x11; x11_trailer_t* x11;
x11 = (x11_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL); x11 = (x11_trailer_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL);
if (x11->curevt) if (x11->curevt)
{ {
free (x11->curevt); moo_freemem (moo, x11->curevt);
x11->curevt = MOO_NULL; x11->curevt = MOO_NULL;
} }
if (x11->c)
if (x11->disp)
{ {
xcb_disconnect (x11->c); XCloseDisplay (x11->disp);
x11->c = MOO_NULL; x11->disp = MOO_NULL;
} }
MOO_STACK_SETRETTORCV (moo, nargs); MOO_STACK_SETRETTORCV (moo, nargs);
return MOO_PF_SUCCESS; return MOO_PF_SUCCESS;
} }
static moo_pfrc_t pf_get_fd (moo_t* moo, moo_ooi_t nargs) static moo_pfrc_t pf_get_base (moo_t* moo, moo_ooi_t nargs)
{ {
x11_t* x11; x11_trailer_t* x11;
x11 = (x11_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL); x11 = (x11_trailer_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL);
if (x11->c) if (x11->disp)
{ {
int c; MOO_STACK_SETRET (moo, nargs, MOO_SMPTR_TO_OOP (x11->disp));
c = xcb_get_file_descriptor(x11->c);
if (!MOO_IN_SMOOI_RANGE(c)) goto error;
MOO_STACK_SETRET (moo, nargs, MOO_SMOOI_TO_OOP(c));
} }
else else
{ {
error: MOO_STACK_SETRETTOERROR (moo, nargs, MOO_ENOAVAIL);
MOO_STACK_SETRETTOERRNUM (moo, nargs); /* TODO: be more specific about error code */
} }
return MOO_PF_SUCCESS; return MOO_PF_SUCCESS;
} }
static moo_pfrc_t pf_getevent (moo_t* moo, moo_ooi_t nargs) static moo_pfrc_t pf_get_fd (moo_t* moo, moo_ooi_t nargs)
{ {
x11_t* x11; x11_trailer_t* x11;
xcb_generic_event_t* evt;
int e;
x11 = (x11_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL); x11 = (x11_trailer_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL);
evt = xcb_poll_for_event(x11->c); if (x11->disp)
if (x11->curevt) free (x11->curevt);
x11->curevt = evt;
if (evt)
{ {
moo_oop_t llevt; int c;
/*uint8_t evttype;
evttype = evt->response_type & 0x7F;*/ c = ConnectionNumber(x11->disp);
x11->curevt = evt; if (!MOO_IN_SMOOI_RANGE(c))
/*
llevt = moo_oowtoint (moo, (moo_oow_t)evt);
if (!llevt)
{ {
llevt = MOO_ERROR_TO_OOP(moo->errnum); MOO_STACK_SETRETTOERROR (moo, nargs, MOO_ERANGE);
free (evt);
x11->curevt = MOO_NULL;
}*/
MOO_ASSERT (moo, MOO_IN_SMPTR_RANGE(evt));
llevt = MOO_SMPTR_TO_OOP(evt);
MOO_STACK_SETRET (moo, nargs, llevt);
} }
else if ((e = xcb_connection_has_error(x11->c))) else
{ {
/* TODO: to be specific about the error */ MOO_STACK_SETRET (moo, nargs, MOO_SMOOI_TO_OOP(c));
MOO_DEBUG1 (moo, "<x11.getevent> Error detected while getting an event - %d\n", e); }
MOO_STACK_SETRETTOERRNUM (moo, nargs); }
else
{
MOO_STACK_SETRETTOERROR (moo, nargs, MOO_ENOAVAIL);
}
return MOO_PF_SUCCESS;
}
static moo_pfrc_t pf_get_event (moo_t* moo, moo_ooi_t nargs)
{
x11_trailer_t* x11;
x11 = (x11_trailer_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL);
if (XPending(x11->disp))
{
XNextEvent (x11->disp, x11->curevt);
MOO_STACK_SETRET (moo, nargs, MOO_SMPTR_TO_OOP(x11->curevt));
} }
else else
{ {
@ -220,453 +201,19 @@ static moo_pfrc_t pf_getevent (moo_t* moo, moo_ooi_t nargs)
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */
static moo_pfrc_t pf_gc_draw_line (moo_t* moo, moo_ooi_t nargs)
{
x11_gc_t* gc;
xcb_point_t pt[2];
moo_oop_t a[4];
gc = (x11_gc_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL);
a[0] = MOO_STACK_GETARG(moo, nargs, 0);
a[1] = MOO_STACK_GETARG(moo, nargs, 1);
a[2] = MOO_STACK_GETARG(moo, nargs, 2);
a[3] = MOO_STACK_GETARG(moo, nargs, 3);
if (!MOO_OOP_IS_SMOOI(a[0]) || !MOO_OOP_IS_SMOOI(a[1]) ||
!MOO_OOP_IS_SMOOI(a[2]) || !MOO_OOP_IS_SMOOI(a[0])) goto reterr;
pt[0].x = MOO_OOP_TO_SMOOI(a[0]);
pt[0].y = MOO_OOP_TO_SMOOI(a[1]);
pt[1].x = MOO_OOP_TO_SMOOI(a[2]);
pt[1].y = MOO_OOP_TO_SMOOI(a[3]);
xcb_poly_line (gc->c, XCB_COORD_MODE_ORIGIN, gc->wid, gc->id, 2, pt);
xcb_flush (gc->c);
MOO_STACK_SETRETTORCV (moo, nargs);
return MOO_PF_SUCCESS;
reterr:
MOO_STACK_SETRETTOERRNUM (moo, nargs); /* More specific error code*/
return MOO_PF_SUCCESS;
}
static moo_pfrc_t pf_gc_draw_rect (moo_t* moo, moo_ooi_t nargs)
{
x11_gc_t* gc;
xcb_rectangle_t r;
moo_oop_t a[4];
gc = (x11_gc_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL);
a[0] = MOO_STACK_GETARG(moo, nargs, 0);
a[1] = MOO_STACK_GETARG(moo, nargs, 1);
a[2] = MOO_STACK_GETARG(moo, nargs, 2);
a[3] = MOO_STACK_GETARG(moo, nargs, 3);
if (!MOO_OOP_IS_SMOOI(a[0]) || !MOO_OOP_IS_SMOOI(a[1]) ||
!MOO_OOP_IS_SMOOI(a[2]) || !MOO_OOP_IS_SMOOI(a[0]))
{
MOO_STACK_SETRETTOERROR (moo, nargs, MOO_EINVAL);
return MOO_PF_SUCCESS;
}
r.x = MOO_OOP_TO_SMOOI(a[0]);
r.y = MOO_OOP_TO_SMOOI(a[1]);
r.width = MOO_OOP_TO_SMOOI(a[2]);
r.height = MOO_OOP_TO_SMOOI(a[3]);
xcb_poly_rectangle (gc->c, gc->wid, gc->id, 1, &r);
xcb_flush (gc->c);
MOO_STACK_SETRETTORCV (moo, nargs);
return MOO_PF_SUCCESS;
}
static moo_pfrc_t pf_gc_fill_rect (moo_t* moo, moo_ooi_t nargs)
{
x11_gc_t* gc;
xcb_rectangle_t r;
moo_oop_t a[4];
gc = (x11_gc_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL);
a[0] = MOO_STACK_GETARG(moo, nargs, 0);
a[1] = MOO_STACK_GETARG(moo, nargs, 1);
a[2] = MOO_STACK_GETARG(moo, nargs, 2);
a[3] = MOO_STACK_GETARG(moo, nargs, 3);
if (!MOO_OOP_IS_SMOOI(a[0]) || !MOO_OOP_IS_SMOOI(a[1]) ||
!MOO_OOP_IS_SMOOI(a[2]) || !MOO_OOP_IS_SMOOI(a[0]))
{
MOO_STACK_SETRETTOERROR (moo, nargs, MOO_EINVAL);
return MOO_PF_SUCCESS;
}
r.x = MOO_OOP_TO_SMOOI(a[0]);
r.y = MOO_OOP_TO_SMOOI(a[1]);
r.width = MOO_OOP_TO_SMOOI(a[2]);
r.height = MOO_OOP_TO_SMOOI(a[3]);
xcb_poly_fill_rectangle (gc->c, gc->wid, gc->id, 1, &r);
xcb_flush (gc->c);
MOO_STACK_SETRETTORCV (moo, nargs);
return MOO_PF_SUCCESS;
}
static moo_pfrc_t pf_gc_change (moo_t* moo, moo_ooi_t nargs)
{
x11_gc_t* gc;
moo_oop_t t;
moo_oow_t tmpoow;
uint32_t value;
gc = (x11_gc_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL);
t = MOO_STACK_GETARG(moo, nargs, 0);
if (!MOO_OOP_IS_SMOOI(t))
{
einval:
MOO_STACK_SETRETTOERROR (moo, nargs, MOO_EINVAL);
return MOO_PF_SUCCESS;
}
if (moo_inttooow (moo, MOO_STACK_GETARG(moo, nargs, 1), &tmpoow) <= 0) goto einval;
value = tmpoow;
/* XCB_GC_FUNCTION, XCB_GC_PLANE_MASK, XCB_GC_FOREGROUND, XCB_GC_BACKGROUND, etc
* this primitive allows only 1 value to be used. you must not specify
* a bitwise-ORed mask of more than 1 XCB_GC_XXX enumerator. */
xcb_change_gc (gc->c, gc->id, MOO_OOP_TO_SMOOI(t), &value);
xcb_flush (gc->c);
MOO_STACK_SETRETTORCV (moo, nargs);
return MOO_PF_SUCCESS;
}
static moo_pfrc_t pf_gc_get_id (moo_t* moo, moo_ooi_t nargs)
{
x11_gc_t* gc;
moo_oop_t x;
gc = (x11_gc_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL);
x = moo_oowtoint (moo, gc->id);
if (!x) return MOO_PF_HARD_FAILURE;
MOO_STACK_SETRET (moo, nargs, x);
return MOO_PF_SUCCESS;
}
static moo_pfrc_t pf_gc_kill (moo_t* moo, moo_ooi_t nargs)
{
x11_gc_t* gc;
gc = (x11_gc_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL);
/* TODO: check on gc id */
xcb_free_gc (gc->c, gc->id);
xcb_flush (gc->c);
MOO_STACK_SETRETTORCV (moo, nargs);
return MOO_PF_SUCCESS;
}
static moo_pfrc_t pf_gc_make (moo_t* moo, moo_ooi_t nargs)
{
x11_gc_t* gc;
moo_oop_t t;
moo_oow_t tmpoow;
xcb_connection_t* c;
xcb_window_t wid;
xcb_gcontext_t gcid;
gc = (x11_gc_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL);
t = MOO_STACK_GETARG(moo, nargs, 0);
if (!MOO_OOP_IS_SMPTR(t))
{
einval:
MOO_STACK_SETRETTOERROR (moo, nargs, MOO_EINVAL);
return MOO_PF_SUCCESS;
}
c = MOO_OOP_TO_SMPTR(t);
t = MOO_STACK_GETARG(moo, nargs, 1);
if (moo_inttooow (moo, t, &tmpoow) <= 0) goto einval;
wid = tmpoow;
gcid = xcb_generate_id (c);
t = moo_oowtoint (moo, gcid);
if (!t)
{
MOO_STACK_SETRETTOERRNUM (moo, nargs);
return MOO_PF_SUCCESS;
}
xcb_create_gc (c, gcid, wid, 0, 0);
/*TODO: use xcb_request_check() for error handling. xcb_create_gc_checked??? xxx_checked()... */
xcb_flush (c);
gc->id = gcid;
gc->wid = wid;
gc->c = c;
MOO_STACK_SETRET (moo, nargs, t);
return MOO_PF_SUCCESS;
}
/* ------------------------------------------------------------------------ */
static moo_pfrc_t pf_win_get_dwatom (moo_t* moo, moo_ooi_t nargs)
{
x11_win_t* win;
moo_oop_t x;
win = (x11_win_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL);
x = moo_oowtoint (moo, win->dwar->atom);
if (!x)
{
MOO_STACK_SETRETTOERRNUM (moo, nargs);
return MOO_PF_SUCCESS;
}
MOO_STACK_SETRET (moo, nargs, x);
return MOO_PF_SUCCESS;
}
static moo_pfrc_t pf_win_get_geometry (moo_t* moo, moo_ooi_t nargs)
{
x11_win_t* win;
moo_oop_t t;
xcb_get_geometry_cookie_t gc;
xcb_get_geometry_reply_t* geom;
win = (x11_win_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL);
t = MOO_STACK_GETARG(moo, nargs, 0);
/* expecting an object composed of 4 object pointers */
if (!MOO_OOP_IS_POINTER(t) || MOO_OBJ_GET_FLAGS_TYPE(t) != MOO_OBJ_TYPE_OOP || MOO_OBJ_GET_SIZE(t) != 4)
{
MOO_STACK_SETRETTOERROR (moo, nargs, MOO_EINVAL);
return MOO_PF_SUCCESS;
}
gc = xcb_get_geometry (win->c, win->id);
geom = xcb_get_geometry_reply (win->c, gc, NULL);
((moo_oop_oop_t)t)->slot[0] = MOO_SMOOI_TO_OOP(geom->x);
((moo_oop_oop_t)t)->slot[1] = MOO_SMOOI_TO_OOP(geom->y);
((moo_oop_oop_t)t)->slot[2] = MOO_SMOOI_TO_OOP(geom->width);
((moo_oop_oop_t)t)->slot[3] = MOO_SMOOI_TO_OOP(geom->height);
free (geom);
MOO_STACK_SETRET (moo, nargs, t);
return MOO_PF_SUCCESS;
}
static moo_pfrc_t pf_win_set_geometry (moo_t* moo, moo_ooi_t nargs)
{
x11_win_t* win;
moo_oop_t t;
uint32_t values[4];
int flags = 0, vcount = 0;
win = (x11_win_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL);
t = MOO_STACK_GETARG(moo, nargs, 0);
/* expecting an object composed of 4 object pointers */
if (!MOO_OOP_IS_POINTER(t) || MOO_OBJ_GET_FLAGS_TYPE(t) != MOO_OBJ_TYPE_OOP || MOO_OBJ_GET_SIZE(t) != 4)
{
MOO_STACK_SETRETTOERROR (moo, nargs, MOO_EINVAL);
return MOO_PF_SUCCESS;
}
if (MOO_OOP_IS_SMOOI(((moo_oop_oop_t)t)->slot[0]))
{
flags |= XCB_CONFIG_WINDOW_X;
values[vcount++] = MOO_OOP_TO_SMOOI(((moo_oop_oop_t)t)->slot[0]);
}
if (MOO_OOP_IS_SMOOI(((moo_oop_oop_t)t)->slot[1]))
{
flags |= XCB_CONFIG_WINDOW_Y;
values[vcount++] = MOO_OOP_TO_SMOOI(((moo_oop_oop_t)t)->slot[1]);
}
if (MOO_OOP_IS_SMOOI(((moo_oop_oop_t)t)->slot[2]))
{
flags |= XCB_CONFIG_WINDOW_WIDTH;
values[vcount++] = MOO_OOP_TO_SMOOI(((moo_oop_oop_t)t)->slot[2]);
}
if (MOO_OOP_IS_SMOOI(((moo_oop_oop_t)t)->slot[3]))
{
flags |= XCB_CONFIG_WINDOW_HEIGHT;
values[vcount++] = MOO_OOP_TO_SMOOI(((moo_oop_oop_t)t)->slot[3]);
}
xcb_configure_window (win->c, win->id, flags, values);
MOO_STACK_SETRETTORCV (moo, nargs);
return MOO_PF_SUCCESS;
}
static moo_pfrc_t pf_win_get_id (moo_t* moo, moo_ooi_t nargs)
{
x11_win_t* win;
moo_oop_t x;
win = (x11_win_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL);
x = moo_oowtoint (moo, win->id);
if (!x)
{
MOO_STACK_SETRETTOERRNUM (moo, nargs);
return MOO_PF_SUCCESS;
}
MOO_STACK_SETRET (moo, nargs, x);
return MOO_PF_SUCCESS;
}
static moo_pfrc_t pf_win_kill (moo_t* moo, moo_ooi_t nargs)
{
x11_win_t* win;
win = (x11_win_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL);
/* TODO: check on windows id */
xcb_unmap_window (win->c, win->id); /* TODO: check error code */
xcb_destroy_window (win->c, win->id);
xcb_flush (win->c);
MOO_STACK_SETRETTORCV (moo, nargs);
return MOO_PF_SUCCESS;
}
static moo_pfrc_t pf_win_make (moo_t* moo, moo_ooi_t nargs)
{
x11_win_t* win;
xcb_window_t wid;
uint32_t mask;
uint32_t values[2];
xcb_intern_atom_cookie_t cookie;
xcb_intern_atom_reply_t* reply;
moo_oop_t a0, a1, a2, a3, a4;
xcb_connection_t* c;
xcb_window_t parent;
xcb_screen_t* screen;
win = (x11_win_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL);
a0 = MOO_STACK_GETARG(moo, nargs, 0); /* connection - SmallPointer (xcb_connection_t*) */
a1 = MOO_STACK_GETARG(moo, nargs, 1); /* x - SmallInteger */
a2 = MOO_STACK_GETARG(moo, nargs, 2); /* y - SmallInteger */
a3 = MOO_STACK_GETARG(moo, nargs, 3); /* width - SmallInteger */
a4 = MOO_STACK_GETARG(moo, nargs, 4); /* height - SmallInteger */
if (!MOO_OOP_IS_SMPTR(a0) || !MOO_OOP_IS_SMOOI(a1) ||
!MOO_OOP_IS_SMOOI(a2) || !MOO_OOP_IS_SMOOI(a3) || !MOO_OOP_IS_SMOOI(a4))
{
einval:
MOO_STACK_SETRETTOERROR (moo, nargs, MOO_EINVAL);
return MOO_PF_SUCCESS;
}
c = MOO_OOP_TO_SMPTR(a0);
screen = xcb_setup_roots_iterator(xcb_get_setup(c)).data;
a0 = MOO_STACK_GETARG(moo, nargs, 5); /* parent - Integer (xcb_window_t - uint32_t) */
if (a0 == moo->_nil)
{
parent = screen->root;
}
else
{
moo_oow_t tmpoow;
if (moo_inttooow(moo, a0, &tmpoow) <= 0) goto einval;
parent = tmpoow;
}
wid = xcb_generate_id (c);
a0 = moo_oowtoint (moo, wid);
if (!a0)
{
MOO_STACK_SETRETTOERRNUM (moo, nargs);
return MOO_PF_SUCCESS;
}
mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
values[0] = screen->white_pixel;
values[1] = XCB_EVENT_MASK_KEY_RELEASE |
XCB_EVENT_MASK_BUTTON_PRESS |
XCB_EVENT_MASK_BUTTON_RELEASE |
XCB_EVENT_MASK_BUTTON_RELEASE |
/*XCB_EVENT_MASK_BUTTON_MOTION |*/
XCB_EVENT_MASK_EXPOSURE |
XCB_EVENT_MASK_STRUCTURE_NOTIFY |
/*XCB_EVENT_MASK_POINTER_MOTION |*/
XCB_EVENT_MASK_ENTER_WINDOW |
XCB_EVENT_MASK_LEAVE_WINDOW/* |
XCB_EVENT_MASK_VISIBILITY_CHANGE */;
xcb_create_window (
c,
XCB_COPY_FROM_PARENT, /* depth */
wid, /* wid */
parent, /* parent */
MOO_OOP_TO_SMOOI(a1), /* x */
MOO_OOP_TO_SMOOI(a2), /* y */
MOO_OOP_TO_SMOOI(a3), /* width */
MOO_OOP_TO_SMOOI(a4), /* height */
1, /* border width */
XCB_WINDOW_CLASS_INPUT_OUTPUT, /* class */
XCB_COPY_FROM_PARENT,
mask,
values
);
if (parent == screen->root)
{
cookie = xcb_intern_atom(c, 1, 12, "WM_PROTOCOLS");
reply = xcb_intern_atom_reply(c, cookie, 0);
cookie = xcb_intern_atom(c, 0, 16, "WM_DELETE_WINDOW");
win->dwar = xcb_intern_atom_reply(c, cookie, 0);
xcb_change_property(c, XCB_PROP_MODE_REPLACE, wid, reply->atom, 4, 32, 1, &win->dwar->atom);
}
xcb_map_window (c, wid);
xcb_flush (c);
win->id = wid;
win->c = c;
MOO_STACK_SETRET (moo, nargs, a0);
return MOO_PF_SUCCESS;
}
/* ------------------------------------------------------------------------ */
static moo_pfinfo_t x11_pfinfo[] = static moo_pfinfo_t x11_pfinfo[] =
{ {
{ I, { '_','c','o','n','n','e','c','t','\0' }, 0, { pf_connect, 0, 0 } },
{ I, { '_','d','i','s','c','o','n','n','e','c','t','\0' }, 0, { pf_disconnect, 0, 0 } }, { MI, { '_','c','o','n','n','e','c','t','\0' }, 0, { pf_connect, 0, 1 } },
{ I, { '_','g','e','t','_','e','v','e','n','t','\0'}, 0, { pf_getevent, 0, 0 } }, { MI, { '_','d','i','s','c','o','n','n','e','c','t','\0' }, 0, { pf_disconnect, 0, 0 } },
{ I, { '_','g','e','t','_','f','d','\0' }, 0, { pf_get_fd, 0, 0 } } { MI, { '_','g','e','t','_','b','a','s','e','\0' }, 0, { pf_get_base, 0, 0 } },
{ MI, { '_','g','e','t','_','e','v','e','n','t','\0'}, 0, { pf_get_event, 0, 0 } },
{ MI, { '_','g','e','t','_','f','d','\0' }, 0, { pf_get_fd, 0, 0 } }
}; };
static int x11_import (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class) static int x11_import (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class)
{ {
if (moo_setclasstrsize(moo, _class, MOO_SIZEOF(x11_t)) <= -1) return -1; if (moo_setclasstrsize(moo, _class, MOO_SIZEOF(x11_t), MOO_NULL) <= -1) return -1;
/*return moo_genpfmethods(moo, mod, _class, x11_pfinfo, MOO_COUNTOF(x11_pfinfo));*/
return 0; return 0;
} }
@ -681,7 +228,7 @@ static void x11_unload (moo_t* moo, moo_mod_t* mod)
moo_freemem (moo, mod->ctx); moo_freemem (moo, mod->ctx);
} }
static void x11_gc (moo_t* moo, moo_mod_t* mod) static void gc_mod_x11 (moo_t* moo, moo_mod_t* mod)
{ {
x11_modctx_t* ctx = mod->ctx; x11_modctx_t* ctx = mod->ctx;
@ -714,7 +261,7 @@ int moo_mod_x11 (moo_t* moo, moo_mod_t* mod)
return -1; return -1;
} }
mod->gc = x11_gc; mod->gc = gc_mod_x11;
mod->ctx = ctx; mod->ctx = ctx;
} }
@ -727,82 +274,3 @@ int moo_mod_x11 (moo_t* moo, moo_mod_t* mod)
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */
static moo_pfinfo_t x11_gc_pfinfo[] =
{
{ I, { '_','c','h','a','n','g','e','\0' }, 0, { pf_gc_change, 2, 2,} },
{ I, { '_','d','r','a','w','L','i','n','e','\0' }, 0, { pf_gc_draw_line, 4, 4 } },
{ I, { '_','d','r','a','w','R','e','c','t','\0' }, 0, { pf_gc_draw_rect, 4, 4 } },
{ I, { '_','f','i','l','l','R','e','c','t' }, 0, { pf_gc_fill_rect, 4, 4 } },
{ I, { '_','g','e','t','_','i','d','\0' }, 0, { pf_gc_get_id, 0, 0 } },
{ I, { '_','k','i','l','l','\0' }, 0, { pf_gc_kill, 0, 0 } },
{ I, { '_','m','a','k','e','\0' }, 0, { pf_gc_make, 2, 2 } }
};
static int x11_gc_import (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class)
{
if (moo_setclasstrsize(moo, _class, MOO_SIZEOF(x11_gc_t)) <= -1) return -1;
return 0;
}
static moo_pfbase_t* x11_gc_query (moo_t* moo, moo_mod_t* mod, const moo_ooch_t* name, moo_oow_t namelen)
{
return moo_findpfbase(moo, x11_gc_pfinfo, MOO_COUNTOF(x11_gc_pfinfo), name, namelen);
}
static void x11_gc_unload (moo_t* moo, moo_mod_t* mod)
{
/* anything? */
}
int moo_mod_x11_gc (moo_t* moo, moo_mod_t* mod)
{
mod->import = x11_gc_import;
mod->query = x11_gc_query;
mod->unload = x11_gc_unload;
mod->gc = MOO_NULL;
mod->ctx = MOO_NULL;
return 0;
}
/* ------------------------------------------------------------------------ */
static moo_pfinfo_t x11_win_pfinfo[] =
{
{ I, { '_','g','e','t','_','w','i','n','d','o','w','_','d','w','a','t','o','m','\0'}, 0, { pf_win_get_dwatom, 0, 0 } },
{ I, { '_','g','e','t','_','w','i','n','d','o','w','_','g','e','o','m','e','t','r','y','\0'}, 0, { pf_win_get_geometry, 1, 1 } },
{ I, { '_','g','e','t','_','w','i','n','d','o','w','_','i','d','\0' }, 0, { pf_win_get_id, 0, 0 } },
{ I, { '_','k','i','l','l','_','w','i','n','d','o','w','\0' }, 0, { pf_win_kill, 0, 0 } },
{ I, { '_','m','a','k','e','_','w','i','n','d','o','w','\0' }, 0, { pf_win_make, 6, 6 } },
{ I, { '_','s','e','t','_','w','i','n','d','o','w','_','g','e','o','m','e','t','r','y','\0'}, 0, { pf_win_set_geometry, 1, 1 } }
};
static int x11_win_import (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class)
{
if (moo_setclasstrsize(moo, _class, MOO_SIZEOF(x11_win_t)) <= -1) return -1;
/*return moo_genpfmethods(moo, mod, _class, x11_win_pfinfo, MOO_COUNTOF(x11_win_pfinfo));*/
return 0;
}
static moo_pfbase_t* x11_win_query (moo_t* moo, moo_mod_t* mod, const moo_ooch_t* name, moo_oow_t namelen)
{
return moo_findpfbase(moo, x11_win_pfinfo, MOO_COUNTOF(x11_win_pfinfo), name, namelen);
}
static void x11_win_unload (moo_t* moo, moo_mod_t* mod)
{
/* anything? */
}
int moo_mod_x11_win (moo_t* moo, moo_mod_t* mod)
{
mod->import = x11_win_import;
mod->query = x11_win_query;
mod->unload = x11_win_unload;
mod->gc = MOO_NULL;
mod->ctx = MOO_NULL;
return 0;
}