From ae2d5697d93a45dcbff768c32c4dc8fb291096cd Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sat, 7 Jan 2023 18:55:20 -0400 Subject: Now wrapping C++ values inside a universal box. --- lux-c++/source/program.lux | 65 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 20 deletions(-) (limited to 'lux-c++') 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"] + (def _ + (program [] + (do io.monad + [? (cppyy::cppdef [(_.code (all _.then + runtime.declaration + + (_.include "iostream") + (_.function (_.local ) + (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# global)) + _ (debug.log! "AFTER") + _ (.python_apply# say_hello [])]] + (in (debug.log! "Hello, C++")))))) -- cgit v1.2.3