aboutsummaryrefslogtreecommitdiff
path: root/lux-c++
diff options
context:
space:
mode:
authorEduardo Julian2023-01-17 01:14:08 -0400
committerEduardo Julian2023-01-17 01:14:08 -0400
commitdfe09eb7a90dbf164bc0c78085b2d340e0928190 (patch)
treea7591cf3c196d2586da8c2cf0493b937c2e9adad /lux-c++
parent2351250b79656014eb441c39dc8c9a02cad1ee40 (diff)
Added compilation of (almost all non-loop) control structures for C++.
Diffstat (limited to 'lux-c++')
-rw-r--r--lux-c++/commands.md4
-rw-r--r--lux-c++/source/program.lux60
2 files changed, 17 insertions, 47 deletions
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
@@ -35,10 +35,6 @@ cd ~/lux/lux-c++/ \
```
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 _
## Compile Lux's Standard Library's tests using a c++/Node-based compiler.
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> "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 (_.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# <say_hello> 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!)