aboutsummaryrefslogtreecommitdiff
path: root/lux-c++
diff options
context:
space:
mode:
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!)