From dfe09eb7a90dbf164bc0c78085b2d340e0928190 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Tue, 17 Jan 2023 01:14:08 -0400 Subject: Added compilation of (almost all non-loop) control structures for C++. --- lux-c++/commands.md | 4 ---- lux-c++/source/program.lux | 60 +++++++++++++--------------------------------- 2 files changed, 17 insertions(+), 47 deletions(-) (limited to 'lux-c++') diff --git a/lux-c++/commands.md b/lux-c++/commands.md index af26bf44e..91c715f39 100644 --- a/lux-c++/commands.md +++ b/lux-c++/commands.md @@ -33,10 +33,6 @@ cd ~/lux/lux-c++/ \ # Try ``` -cd ~/lux/lux-c++/ \ -&& conda activate WORK \ -&& python3 target/program.py - cd ~/lux/lux-c++/ \ && conda activate WORK \ && python3 target/program.py build --source ~/lux/stdlib/source --target ~/lux/stdlib/target --module test/lux --program _ diff --git a/lux-c++/source/program.lux b/lux-c++/source/program.lux index 9f7721aed..6261269f5 100644 --- a/lux-c++/source/program.lux +++ b/lux-c++/source/program.lux @@ -80,45 +80,13 @@ ("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 -... _.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 (_.deref (/runtime.host_value /type.bit (/runtime.simple /type.bit (/primitive.bit true))))) -... (print (_.deref (/runtime.host_value /type.i64 (/runtime.simple /type.i64 (/primitive.i64 +123))))) -... (print (_.deref (/runtime.host_value /type.f64 (/runtime.simple /type.f64 (/primitive.f64 -456.789))))) -... ... (print (_.deref (/runtime.host_value /type.text (/runtime.simple /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++")))))) - (ffi.import (getattr [(ffi.Object Any) Text] Any)) +(def nested + (-> Text + Text) + (text.replaced text.\n (%.format text.\n text.\t))) + (def host (IO (Host /runtime.Value /runtime.Declaration)) (io (let [\n\t (%.format text.\n text.\t) @@ -126,15 +94,21 @@ (function (evaluate! context [_ input]) (let [global (reference.artifact context) definition (_.constant (_.local global) /type.value input)] - (if (io.run! (cppyy::cppdef (_.code definition))) - {try.#Success (getattr (io.run! (cppyy::gbl)) global)} - {try.#Failure "Cannot evaluate!"})))) + (exec + (.log!# "[evaluate!]") + (.log!# (..nested (_.code definition))) + (if (io.run! (cppyy::cppdef (_.code definition))) + {try.#Success (getattr (io.run! (cppyy::gbl)) global)} + {try.#Failure "Cannot evaluate!"}))))) execute! (is (-> /runtime.Declaration (Try Any)) (function (execute! input) - (if (io.run! (cppyy::cppdef (_.code input))) - {try.#Success []} - {try.#Failure "Cannot execute!"})))] + (exec + (.log!# "[execute!]") + (.log!# (..nested (_.code input))) + (if (io.run! (cppyy::cppdef (_.code input))) + {try.#Success []} + {try.#Failure "Cannot execute!"}))))] (is (Host /runtime.Value /runtime.Declaration) (implementation (def evaluate evaluate!) -- cgit v1.2.3