alien.cxx: C++ methods
parent
186cc7edb3
commit
1218d3fa9d
|
@ -2,7 +2,8 @@
|
|||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: accessors alien.c-types alien.cxx.parser alien.marshall
|
||||
alien.inline.types classes.mixin classes.tuple kernel namespaces
|
||||
assocs sequences parser classes.parser ;
|
||||
assocs sequences parser classes.parser alien.marshall.syntax
|
||||
interpolate locals effects io strings ;
|
||||
IN: alien.cxx
|
||||
|
||||
<PRIVATE
|
||||
|
@ -17,6 +18,13 @@ IN: alien.cxx
|
|||
[ add-mixin-instance ] 2bi ;
|
||||
PRIVATE>
|
||||
|
||||
: define-c++-class ( str superclass-mixin -- )
|
||||
: define-c++-class ( name superclass-mixin -- )
|
||||
[ [ class-tuple-word ] [ class-mixin ] bi dup ] dip
|
||||
add-mixin-instance define-class-tuple ;
|
||||
|
||||
:: define-c++-method ( class-name name types effect -- )
|
||||
effect [ in>> "self" suffix ] [ out>> ] bi <effect> :> effect'
|
||||
types class-name "*" append suffix :> types'
|
||||
effect in>> "," join :> args
|
||||
SBUF" " dup [ I[ return self->${name}(${args});]I ] with-output-stream >string :> body
|
||||
name types' effect' body define-c-marshalled ;
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
! Copyright (C) 2009 Jeremy Hughes.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: parser lexer ;
|
||||
USING: parser lexer alien.inline ;
|
||||
IN: alien.cxx.parser
|
||||
|
||||
: parse-c++-class-definition ( -- class superclass-mixin )
|
||||
scan scan-word ;
|
||||
|
||||
: parse-c++-method-definition ( -- class-name name types effect )
|
||||
scan function-types-effect ;
|
||||
|
|
|
@ -15,10 +15,18 @@ C-TYPEDEF: std::string string
|
|||
|
||||
C++-CLASS: std::string c++-root
|
||||
|
||||
C++-METHOD: std::string const-char* c_str ( )
|
||||
|
||||
CM-FUNCTION: std::string* new_string ( const-char* s )
|
||||
return new std::string(s);
|
||||
;
|
||||
|
||||
;C-LIBRARY
|
||||
|
||||
ALIAS: <std::string> new_string
|
||||
|
||||
ALIAS: to-string c_str
|
||||
|
||||
{ 1 1 } [ new_string ] must-infer-as
|
||||
{ 1 1 } [ c_str ] must-infer-as
|
||||
[ "abc" ] [ "abc" <std::string> to-string ] unit-test
|
||||
|
|
|
@ -3,4 +3,8 @@
|
|||
USING: alien.cxx alien.cxx.parser ;
|
||||
IN: alien.cxx.syntax
|
||||
|
||||
SYNTAX: C++-CLASS: parse-c++-class-definition define-c++-class ;
|
||||
SYNTAX: C++-CLASS:
|
||||
parse-c++-class-definition define-c++-class ;
|
||||
|
||||
SYNTAX: C++-METHOD:
|
||||
parse-c++-method-definition define-c++-method ;
|
||||
|
|
Loading…
Reference in New Issue