]> gitweb.factorcode.org Git - factor.git/commitdiff
added alien.cxx
authorJeremy Hughes <jedahu@gmail.com>
Wed, 22 Jul 2009 04:00:38 +0000 (16:00 +1200)
committerJeremy Hughes <jedahu@gmail.com>
Wed, 22 Jul 2009 04:38:01 +0000 (16:38 +1200)
extra/alien/cxx/authors.txt [new file with mode: 0644]
extra/alien/cxx/cxx.factor [new file with mode: 0644]
extra/alien/cxx/parser/authors.txt [new file with mode: 0644]
extra/alien/cxx/parser/parser.factor [new file with mode: 0644]
extra/alien/cxx/syntax/authors.txt [new file with mode: 0644]
extra/alien/cxx/syntax/syntax-tests.factor [new file with mode: 0644]
extra/alien/cxx/syntax/syntax.factor [new file with mode: 0644]
extra/alien/marshall/marshall.factor

diff --git a/extra/alien/cxx/authors.txt b/extra/alien/cxx/authors.txt
new file mode 100644 (file)
index 0000000..c45c6f3
--- /dev/null
@@ -0,0 +1 @@
+Jeremy Hughes
\ No newline at end of file
diff --git a/extra/alien/cxx/cxx.factor b/extra/alien/cxx/cxx.factor
new file mode 100644 (file)
index 0000000..71144e6
--- /dev/null
@@ -0,0 +1,22 @@
+! Copyright (C) 2009 Jeremy Hughes.
+! 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 ;
+IN: alien.cxx
+
+<PRIVATE
+: class-mixin ( str -- word )
+    create-class-in [ define-mixin-class ] keep ;
+
+: class-tuple-word ( word -- word' )
+    "#" append create-in ;
+
+: define-class-tuple ( word mixin -- )
+    [ drop class-wrapper { } define-tuple-class ]
+    [ add-mixin-instance ] 2bi ;
+PRIVATE>
+
+: define-c++-class ( str superclass-mixin -- )
+    [ [ class-tuple-word ] [ class-mixin ] bi dup ] dip
+    add-mixin-instance define-class-tuple ;
diff --git a/extra/alien/cxx/parser/authors.txt b/extra/alien/cxx/parser/authors.txt
new file mode 100644 (file)
index 0000000..c45c6f3
--- /dev/null
@@ -0,0 +1 @@
+Jeremy Hughes
\ No newline at end of file
diff --git a/extra/alien/cxx/parser/parser.factor b/extra/alien/cxx/parser/parser.factor
new file mode 100644 (file)
index 0000000..4614a4a
--- /dev/null
@@ -0,0 +1,7 @@
+! Copyright (C) 2009 Jeremy Hughes.
+! See http://factorcode.org/license.txt for BSD license.
+USING: parser lexer ;
+IN: alien.cxx.parser
+
+: parse-c++-class-definition ( -- class superclass-mixin )
+    scan scan-word ;
diff --git a/extra/alien/cxx/syntax/authors.txt b/extra/alien/cxx/syntax/authors.txt
new file mode 100644 (file)
index 0000000..c45c6f3
--- /dev/null
@@ -0,0 +1 @@
+Jeremy Hughes
\ No newline at end of file
diff --git a/extra/alien/cxx/syntax/syntax-tests.factor b/extra/alien/cxx/syntax/syntax-tests.factor
new file mode 100644 (file)
index 0000000..f9fb9a2
--- /dev/null
@@ -0,0 +1,24 @@
+! Copyright (C) 2009 Jeremy Hughes.
+! See http://factorcode.org/license.txt for BSD license.
+USING: tools.test alien.cxx.syntax alien.inline.syntax
+alien.marshall.syntax alien.marshall ;
+IN: alien.cxx.syntax.tests
+
+DELETE-C-LIBRARY: test
+C-LIBRARY: test
+
+COMPILE-AS-C++
+
+C-INCLUDE: <string>
+
+C-TYPEDEF: std::string string
+
+C++-CLASS: std::string c++-root
+
+CM-FUNCTION: std::string* new_string ( const-char* s )
+    return new std::string(s);
+;
+
+;C-LIBRARY
+
+{ 1 1 } [ new_string ] must-infer-as
diff --git a/extra/alien/cxx/syntax/syntax.factor b/extra/alien/cxx/syntax/syntax.factor
new file mode 100644 (file)
index 0000000..741950f
--- /dev/null
@@ -0,0 +1,6 @@
+! Copyright (C) 2009 Jeremy Hughes.
+! See http://factorcode.org/license.txt for BSD license.
+USING: alien.cxx alien.cxx.parser ;
+IN: alien.cxx.syntax
+
+SYNTAX: C++-CLASS: parse-c++-class-definition define-c++-class ;
index 2aede320aa4bf8524c8ed50fd9361250d890c05f..eec0cadcbb65d84280bd1df1aed694da4897bfe4 100644 (file)
@@ -22,6 +22,8 @@ TUPLE: alien-wrapper { underlying alien } ;
 TUPLE: struct-wrapper < alien-wrapper disposed ;
 TUPLE: class-wrapper < alien-wrapper disposed ;
 
+MIXIN: c++-root
+
 GENERIC: unmarshall-cast ( alien-wrapper -- alien-wrapper' )
 
 M: alien-wrapper unmarshall-cast ;