aboutsummaryrefslogtreecommitdiff
path: root/lux-c++
diff options
context:
space:
mode:
authorEduardo Julian2022-12-23 20:58:58 -0400
committerEduardo Julian2022-12-23 20:58:58 -0400
commitad1391ea1cdd33167339d25dbff2567f5a8d5c68 (patch)
tree7b8c1154e3cdbc9a79fc7c3e468f07544c51f910 /lux-c++
parent6f1bf11af05bd03183fee7721ac99eca826ca041 (diff)
Began work on C++ back-end.
Diffstat (limited to 'lux-c++')
-rw-r--r--lux-c++/commands.md79
-rw-r--r--lux-c++/project.lux24
-rw-r--r--lux-c++/source/program.lux87
3 files changed, 190 insertions, 0 deletions
diff --git a/lux-c++/commands.md b/lux-c++/commands.md
new file mode 100644
index 000000000..53ad68455
--- /dev/null
+++ b/lux-c++/commands.md
@@ -0,0 +1,79 @@
+# Develop
+```
+cd ~/lux/lux-c++/ \
+&& lux clean \
+&& lux with python auto build
+```
+
+# Build
+
+```
+cd ~/lux/lux-c++/ \
+&& lux clean \
+&& lux with c++ auto build
+
+## Build JVM-based compiler
+cd ~/lux/lux-c++/ \
+&& lux clean \
+&& lux with jvm build \
+&& mv target/program.jar jvm_based_compiler.jar
+
+## Use JVM-based compiler to produce a c++/Node-based compiler.
+cd ~/lux/lux-c++/ \
+&& lux clean \
+&& time java -jar jvm_based_compiler.jar build --source ~/lux/lux-c++/source --target ~/lux/lux-c++/target --module program --program _ \
+&& mv target/program.c++ node_based_compiler.c++
+
+## Use C++/Node-based compiler to produce another c++/Node-based compiler.
+cd ~/lux/lux-c++/ \
+&& lux clean \
+&& node --stack_size=8192 node_based_compiler.c++ build --source ~/lux/lux-c++/source --target ~/lux/lux-c++/target --module program --program _
+```
+
+# Try
+
+```
+cd ~/lux/lux-c++/ \
+&& conda activate WORK \
+&& python3 target/program.py
+
+## Compile Lux's Standard Library's tests using a c++/Node-based compiler.
+cd ~/lux/stdlib/ \
+&& lux clean \
+&& node --stack_size=8192 ~/lux/lux-c++/target/program.c++ build --source ~/lux/stdlib/source --target ~/lux/stdlib/target --module test/lux --program _ \
+&& node ~/lux/stdlib/target/program.c++
+```
+
+# Deploy
+
+```
+cd ~/lux/lux-c++/ \
+&& mvn install:install-file -Dfile=target/program.c++ -DgroupId=com.github.luxlang -DartifactId=lux-c++ -Dversion=0.8.0-SNAPSHOT -Dpackaging=c++
+
+cd ~/lux/lux-c++/ && mvn deploy:deploy-file \
+-Durl=https://$NEXUS_USERNAME:$NEXUS_PASSWORD@oss.sonatype.org/content/repositories/snapshots/ \
+-Dfile=target/program.c++ \
+-DgroupId=com.github.luxlang \
+-DartifactId=lux-c++ \
+-Dversion=0.8.0-SNAPSHOT \
+-Dpackaging=c++
+```
+
+# Release
+
+```
+LUX_PROJECT=lux-c++ && \
+LUX_VERSION=0.7.0 && \
+cd ~/lux/$LUX_PROJECT/ && \
+lux pom && \
+mv pom.xml RELEASE/$LUX_PROJECT-$LUX_VERSION.pom && \
+mv target/program.c++ RELEASE/$LUX_PROJECT-$LUX_VERSION.c++ && \
+cd RELEASE && \
+touch README.md && \
+zip $LUX_PROJECT-$LUX_VERSION-sources.jar README.md && \
+zip $LUX_PROJECT-$LUX_VERSION-javadoc.jar README.md && \
+zip $LUX_PROJECT-$LUX_VERSION.jar README.md && \
+rm README.md && \
+for file in *.*; do gpg -ab $file; done
+```
+
diff --git a/lux-c++/project.lux b/lux-c++/project.lux
new file mode 100644
index 000000000..564c47f28
--- /dev/null
+++ b/lux-c++/project.lux
@@ -0,0 +1,24 @@
+[""
+ ["identity" ["com.github.luxlang" "lux-c++" "0.8.0-SNAPSHOT"]
+ "info" ["description" "A C++ compiler for Lux."
+ "url" "https://github.com/LuxLang/lux"
+ "scm" "https://github.com/LuxLang/lux.git"
+ "licenses" [["name" "Lux License v0.1.2"
+ "url" "https://github.com/LuxLang/lux/blob/master/license.txt"
+ "type" "repo"]]
+ "developers" [["name" "Eduardo Julian"
+ "url" "https://github.com/eduardoejp"]]]
+
+ "deploy_repositories" {"snapshots" "https://oss.sonatype.org/content/repositories/snapshots/"
+ "releases" "https://oss.sonatype.org/service/local/staging/deploy/maven2/"}
+
+ "repositories" ["https://oss.sonatype.org/content/repositories/snapshots/"
+ "https://oss.sonatype.org/service/local/staging/deploy/maven2/"]
+
+ "dependencies" [... ["com.github.luxlang" "stdlib" "0.8.0-SNAPSHOT" "tar"]
+ ]
+
+ "program" program._]
+
+ "python"
+ ["lux" ["com.github.luxlang" "lux-python" "0.8.0-SNAPSHOT" "jar"]]]
diff --git a/lux-c++/source/program.lux b/lux-c++/source/program.lux
new file mode 100644
index 000000000..6bfa65d4f
--- /dev/null
+++ b/lux-c++/source/program.lux
@@ -0,0 +1,87 @@
+... https://github.com/wlav/cppyy
+(.require
+ [library
+ [lux (.except)
+ [program (.only program)]
+ ["[0]" ffi (.only import)]
+ ["[0]" debug]
+ [abstract
+ [monad (.only do)]]
+ [control
+ ["[0]" maybe (.use "[1]#[0]" monad)]
+ ["[0]" try (.only Try)]
+ ["[0]" exception (.only Exception)]
+ ["[0]" io (.only IO io)]
+ ["[0]" function]
+ [concurrency
+ ["[0]" async (.only Async)]]]
+ [data
+ ["[0]" product]
+ [text
+ ["%" \\format (.only format)]
+ [encoding
+ ["[0]" utf8]]]
+ [collection
+ ["[0]" array (.only Array)]]]
+ [math
+ [number
+ ["n" nat]
+ ["i" int]
+ ["[0]" i64]]]
+ ["[0]" world
+ ["[0]" file]
+ ["[1]/[0]" environment]]
+ [meta
+ ["@" target (.only)
+ ["_" js]]
+ [macro
+ ["^" pattern]
+ ["[0]" template]]
+ [compiler
+ [reference
+ [variable (.only Register)]]
+ [language
+ [lux
+ [program (.only Program)]
+ [translation (.only Host)]
+ [analysis
+ [macro (.only Expander)]]
+ ["[0]" phase (.only Operation Phase)
+ ["[0]" extension (.only Extender Handler)
+ ["[0]" analysis
+ ["[1]" js]]
+ ["[0]" translation
+ ["[1]" js]]]
+ [translation
+ ["[0]" reference]
+ ["[0]" js (.only)
+ ["[0]" runtime]
+ ["[1]/[0]" reference]]]]]]
+ [default
+ ["[0]" platform (.only Platform)]]
+ [meta
+ ["[0]" cli]
+ ["[0]" context]
+ [archive (.only Archive)
+ ["[0]" unit]]
+ ["[0]" packager
+ ["[1]" script]]]]]]]
+ [program
+ ["/" compositor]])
+
+(import cppyy
+ "[1]::[0]"
+ ("static" cppdef [Text] "io" Bit)
+ ("static" gbl (ffi.Object Any)))
+
+(def _
+ (program []
+ (do io.monad
+ [? (cppyy::cppdef ["void say_hello() { std::cout << 123 << std::endl; }"])
+ .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++")))))