aboutsummaryrefslogtreecommitdiff
path: root/lux-c++
diff options
context:
space:
mode:
Diffstat (limited to 'lux-c++')
-rw-r--r--lux-c++/source/program.lux65
1 files changed, 45 insertions, 20 deletions
diff --git a/lux-c++/source/program.lux b/lux-c++/source/program.lux
index cb2b96029..3c3a037fc 100644
--- a/lux-c++/source/program.lux
+++ b/lux-c++/source/program.lux
@@ -52,6 +52,8 @@
[translation
["[0]" reference]
[c++
+ ["[0]" runtime]
+ ["[0]" type]
["[0]" primitive]]]]]]
[default
["[0]" platform (.only Platform)]]
@@ -70,26 +72,49 @@
("static" cppdef [Text] "io" Bit)
("static" gbl (ffi.Object Any)))
+(def standard_out (_.global [_.standard "cout"] (list)))
+(def \n (_.global [_.standard "endl"] (list)))
+
(def (print it)
(-> _.Expression
- Text)
- (%.format "std::cout << "
- (_.code it)
- " << std::endl;"))
+ _.Statement)
+ (|> standard_out
+ (_.<< it)
+ (_.<< \n)
+ _.;))
+
+(with_expansions [<say_hello> "say_hello"]
+ (def _
+ (program []
+ (do io.monad
+ [? (cppyy::cppdef [(_.code (all _.then
+ runtime.declaration
+
+ (_.include "iostream")
+ (_.function (_.local <say_hello>)
+ (list)
+ (list)
+ _.void
+ (all _.then
+ ... (print (primitive.bit true))
+ ... (print (primitive.i64 +123))
+ ... (print (primitive.f64 -456.789))
+ ... (print (primitive.text "YOLO"))
+
+ ... (print (runtime.lux_value type.bit (primitive.bit true)))
+ ... (print (runtime.lux_value type.i64 (primitive.i64 +123)))
+ ... (print (runtime.lux_value type.f64 (primitive.f64 -456.789)))
+ ... (print (runtime.lux_value type.text (primitive.text "YOLO")))
-(def _
- (program []
- (do io.monad
- [? (cppyy::cppdef [(%.format "void say_hello() { "
- (print (primitive.bit true))
- (print (primitive.i64 +123))
- (print (primitive.f64 -456.789))
- (print (primitive.text "YOLO"))
- " }")])
- .let [_ (debug.log! (%.format "BEFORE " (%.bit ?)))]
- global (cppyy::gbl)
- .let [say_hello (as ffi.Function
- (.python_object_get# "say_hello" global))
- _ (debug.log! "AFTER")
- _ (.python_apply# say_hello [])]]
- (in (debug.log! "Hello, C++")))))
+ ... (print (_.deref (runtime.host_value type.bit (runtime.lux_value type.bit (primitive.bit true)))))
+ (print (_.deref (runtime.host_value type.i64 (runtime.lux_value type.i64 (primitive.i64 +123)))))
+ ... (print (_.deref (runtime.host_value type.f64 (runtime.lux_value type.f64 (primitive.f64 -456.789)))))
+ ... (print (_.deref (runtime.host_value type.text (runtime.lux_value type.text (primitive.text "YOLO")))))
+ ))))])
+ .let [_ (debug.log! (%.format "BEFORE " (%.bit ?)))]
+ global (cppyy::gbl)
+ .let [say_hello (as ffi.Function
+ (.python_object_get# <say_hello> global))
+ _ (debug.log! "AFTER")
+ _ (.python_apply# say_hello [])]]
+ (in (debug.log! "Hello, C++"))))))