You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2024/06/06 19:27:47 UTC
(nuttx-apps) branch master updated: dlang-app added
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new 6db9d5e58 dlang-app added
6db9d5e58 is described below
commit 6db9d5e58235640a5419669e82bdb8c426954506
Author: Matheus Catarino <ma...@hotmail.com>
AuthorDate: Wed Jun 5 14:15:15 2024 -0300
dlang-app added
---
.gitignore | 3 +-
Application.mk | 30 ++++++++--
Make.defs | 1 +
examples/hello_d/Kconfig | 29 ++++++++++
examples/hello_d/Make.defs | 23 ++++++++
examples/hello_d/Makefile | 35 ++++++++++++
examples/hello_d/hello_d_main.d | 122 ++++++++++++++++++++++++++++++++++++++++
7 files changed, 237 insertions(+), 6 deletions(-)
diff --git a/.gitignore b/.gitignore
index 092c3d11f..578b989f8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,7 +1,6 @@
*.a
*.adb
*.asm
-*.d
*.dSYM
*.exe
*.gcno
@@ -41,4 +40,4 @@ Make.dep
.DS_Store
build
.ccls-cache
-compile_commands.json
\ No newline at end of file
+compile_commands.json
diff --git a/Application.mk b/Application.mk
index b482ea347..c12903d59 100644
--- a/Application.mk
+++ b/Application.mk
@@ -76,25 +76,28 @@ COBJS = $(CSRCS:=$(SUFFIX)$(OBJEXT))
CXXOBJS = $(CXXSRCS:=$(SUFFIX)$(OBJEXT))
RUSTOBJS = $(RUSTSRCS:=$(SUFFIX)$(OBJEXT))
ZIGOBJS = $(ZIGSRCS:=$(SUFFIX)$(OBJEXT))
+DOBJS = $(DSRCS:=$(SUFFIX)$(OBJEXT))
MAINCXXSRCS = $(filter %$(CXXEXT),$(MAINSRC))
MAINCSRCS = $(filter %.c,$(MAINSRC))
MAINRUSTSRCS = $(filter %$(RUSTEXT),$(MAINSRC))
MAINZIGSRCS = $(filter %$(ZIGEXT),$(MAINSRC))
+MAINDSRCS = $(filter %$(DEXT),$(MAINSRC))
MAINCXXOBJ = $(MAINCXXSRCS:=$(SUFFIX)$(OBJEXT))
MAINCOBJ = $(MAINCSRCS:=$(SUFFIX)$(OBJEXT))
MAINRUSTOBJ = $(MAINRUSTSRCS:=$(SUFFIX)$(OBJEXT))
MAINZIGOBJ = $(MAINZIGSRCS:=$(SUFFIX)$(OBJEXT))
+MAINDOBJ = $(MAINDSRCS:=$(SUFFIX)$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS) $(MAINSRC)
-OBJS = $(RAOBJS) $(CAOBJS) $(COBJS) $(CXXOBJS) $(RUSTOBJS) $(ZIGOBJS) $(EXTOBJS)
+OBJS = $(RAOBJS) $(CAOBJS) $(COBJS) $(CXXOBJS) $(RUSTOBJS) $(ZIGOBJS) $(DOBJS) $(EXTOBJS)
ifneq ($(BUILD_MODULE),y)
- OBJS += $(MAINCOBJ) $(MAINCXXOBJ) $(MAINRUSTOBJ) $(MAINZIGOBJ)
+ OBJS += $(MAINCOBJ) $(MAINCXXOBJ) $(MAINRUSTOBJ) $(MAINZIGOBJ) $(MAINDOBJ)
endif
ifneq ($(strip $(PROGNAME)),)
- PROGOBJ := $(MAINCOBJ) $(MAINCXXOBJ) $(MAINRUSTOBJ) $(MAINZIGOBJ)
+ PROGOBJ := $(MAINCOBJ) $(MAINCXXOBJ) $(MAINRUSTOBJ) $(MAINZIGOBJ) $(MAINDOBJ)
PROGLIST := $(addprefix $(BINDIR)$(DELIM),$(PROGNAME))
REGLIST := $(addprefix $(BUILTIN_REGISTRY)$(DELIM),$(addsuffix .bdat,$(PROGNAME)))
@@ -131,6 +134,7 @@ endif
ZIGELFFLAGS ?= $(ZIGFLAGS)
RUSTELFFLAGS ?= $(RUSTFLAGS)
+DELFFLAGS ?= $(DFLAGS)
DEPPATH += --dep-path .
DEPPATH += --obj-path .
@@ -175,6 +179,12 @@ define ELFCOMPILEZIG
$(ECHO_END)
endef
+define ELFCOMPILED
+ $(ECHO_BEGIN)"DC: $1 "
+ $(Q) $(DC) -c $(DELFFLAGS) $($(strip $1)_DELFFLAGS) $1 -of $2
+ $(ECHO_END)
+endef
+
define ELFLD
$(ECHO_BEGIN)"LD: $2 "
$(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) $(ARCHCRT0OBJ) $1 $(LDSTARTGROUP) $(LDLIBS) $(LDENDGROUP) -o $2
@@ -212,6 +222,10 @@ $(ZIGOBJS): %$(ZIGEXT)$(SUFFIX)$(OBJEXT): %$(ZIGEXT)
$(if $(and $(CONFIG_BUILD_LOADABLE), $(CELFFLAGS)), \
$(call ELFCOMPILEZIG, $<, $@), $(call COMPILEZIG, $<, $@))
+$(DOBJS): %$(DEXT)$(SUFFIX)$(OBJEXT): %$(DEXT)
+ $(if $(and $(CONFIG_BUILD_LOADABLE), $(CELFFLAGS)), \
+ $(call ELFCOMPILED, $<, $@), $(call COMPILED, $<, $@))
+
AROBJS :=
ifneq ($(OBJS),)
SORTOBJS := $(sort $(OBJS))
@@ -246,7 +260,11 @@ $(MAINZIGOBJ): %$(ZIGEXT)$(SUFFIX)$(OBJEXT): %$(ZIGEXT)
$(if $(and $(CONFIG_BUILD_LOADABLE),$(CELFFLAGS)), \
$(call ELFCOMPILEZIG, $<, $@), $(call COMPILEZIG, $<, $@))
-$(PROGLIST): $(MAINCOBJ) $(MAINCXXOBJ) $(MAINRUSTOBJ) $(MAINZIGOBJ)
+$(MAINDOBJ): %$(DEXT)$(SUFFIX)$(OBJEXT): %$(DEXT)
+ $(if $(and $(CONFIG_BUILD_LOADABLE),$(CELFFLAGS)), \
+ $(call ELFCOMPILED, $<, $@), $(call COMPILED, $<, $@))
+
+$(PROGLIST): $(MAINCOBJ) $(MAINCXXOBJ) $(MAINRUSTOBJ) $(MAINZIGOBJ) $(MAINDOBJ)
$(Q) mkdir -p $(BINDIR)
$(call ELFLD, $(PROGOBJ_$@), $(call CONVERT_PATH,$@))
$(Q) chmod +x $@
@@ -281,6 +299,10 @@ $(MAINZIGOBJ): %$(ZIGEXT)$(SUFFIX)$(OBJEXT): %$(ZIGEXT)
$(call ELFCOMPILEZIG, $(basename $<)_tmp.zig, $@), $(call COMPILEZIG, $(basename $<)_tmp.zig, $@))
$(Q) rm -f $(basename $<)_tmp.zig
+$(MAINDOBJ): %$(DEXT)$(SUFFIX)$(OBJEXT): %$(DEXT)
+ $(if $(and $(CONFIG_BUILD_LOADABLE),$(CELFFLAGS)), \
+ $(call ELFCOMPILED, $<, $@), $(call COMPILED, $<, $@))
+
install::
@:
diff --git a/Make.defs b/Make.defs
index 10aa51ead..4f97aa804 100644
--- a/Make.defs
+++ b/Make.defs
@@ -54,6 +54,7 @@ $(foreach BDIR, $(BUILDIRS), $(eval $(call Add_Application,$(BDIR))))
CXXEXT ?= .cxx
RUSTEXT ?= .rs
ZIGEXT ?= .zig
+DEXT ?= .d
# Library path
diff --git a/examples/hello_d/Kconfig b/examples/hello_d/Kconfig
new file mode 100644
index 000000000..04fb65a61
--- /dev/null
+++ b/examples/hello_d/Kconfig
@@ -0,0 +1,29 @@
+#
+# For a description of the syntax of this configuration file,
+# see the file kconfig-language.txt in the NuttX tools repository.
+#
+
+config EXAMPLES_HELLO_D
+ tristate "\"Hello, D!\" D example"
+ default n
+ ---help---
+ Enable the \"Hello, D!\" D example
+
+if EXAMPLES_HELLO_D
+
+config EXAMPLES_HELLO_D_PROGNAME
+ string "Program name"
+ default "hello_d"
+ ---help---
+ This is the name of the program that will be used when the
+ program is installed.
+
+config EXAMPLES_HELLO_D_PRIORITY
+ int "Hello D task priority"
+ default 100
+
+config EXAMPLES_HELLO_D_STACKSIZE
+ int "Hello D stack size"
+ default DEFAULT_TASK_STACKSIZE
+
+endif
diff --git a/examples/hello_d/Make.defs b/examples/hello_d/Make.defs
new file mode 100644
index 000000000..b267da14f
--- /dev/null
+++ b/examples/hello_d/Make.defs
@@ -0,0 +1,23 @@
+############################################################################
+# apps/examples/hello_d/Make.defs
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership. The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+############################################################################
+
+ifneq ($(CONFIG_EXAMPLES_HELLO_D),)
+CONFIGURED_APPS += $(APPDIR)/examples/hello_d
+endif
diff --git a/examples/hello_d/Makefile b/examples/hello_d/Makefile
new file mode 100644
index 000000000..a66e165c6
--- /dev/null
+++ b/examples/hello_d/Makefile
@@ -0,0 +1,35 @@
+############################################################################
+# apps/examples/hello_d/Makefile
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership. The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+############################################################################
+
+include $(APPDIR)/Make.defs
+
+# Hello, World! D Example
+
+MAINSRC = hello_d_main.d
+
+# hello_d built-in application info
+
+DFLAGS += -oq -betterC
+PROGNAME = $(CONFIG_EXAMPLES_HELLO_D_PROGNAME)
+PRIORITY = $(CONFIG_EXAMPLES_HELLO_D_PRIORITY)
+STACKSIZE = $(CONFIG_EXAMPLES_HELLO_D_STACKSIZE)
+MODULE = $(CONFIG_EXAMPLES_HELLO_D)
+
+include $(APPDIR)/Application.mk
diff --git a/examples/hello_d/hello_d_main.d b/examples/hello_d/hello_d_main.d
new file mode 100644
index 000000000..b679c4b30
--- /dev/null
+++ b/examples/hello_d/hello_d_main.d
@@ -0,0 +1,122 @@
+//***************************************************************************
+// apps/examples/hello_d/hello_d_main.d
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership. The
+// ASF licenses this file to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance with the
+// License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations
+// under the License.
+//
+//***************************************************************************
+module examples.hello_d_main;
+
+//***************************************************************************
+// Imports module
+//***************************************************************************
+/// Type issues, need make own D runtime (object.d file)
+// import core.stdc.stdio : printf;
+// import core.stdc.stdlib : malloc, free;
+
+///
+pragma(printf)
+extern (C) int printf(scope const(char)* fmt, scope...) @nogc nothrow @trusted;
+///
+extern (C) void* malloc(size_t size) @nogc nothrow @trusted;
+///
+extern (C) void free(void* ptr) @nogc nothrow @trusted;
+
+//***************************************************************************
+// Private module content
+//***************************************************************************
+private:
+
+// based heloxx class layout
+extern (C++,class)
+struct DHelloWorld
+{
+@nogc nothrow:
+
+ @disable this();
+ @disable this(this);
+ this(int secret) @safe pure
+ {
+ mSecret = secret;
+ debug printf("Constructor\n");
+ }
+
+ ~this() @safe pure
+ {
+ debug printf("Destructor\n");
+ }
+
+ bool HelloWorld() @safe
+ {
+ debug printf("HelloWorld: mSecret=%d\n", mSecret);
+
+ if (mSecret != 42)
+ {
+ printf("DHelloWorld.HelloWorld: CONSTRUCTION FAILED!\n");
+ return false;
+ }
+ else
+ {
+ printf("DHelloWorld.HelloWorld: Hello, World!!\n");
+ return true;
+ }
+ }
+
+ private int mSecret;
+}
+
+//***************************************************************************
+// Private Data
+//***************************************************************************
+
+// Define a statically constructed DHellowWorld instance if D static
+// initializers are supported by the platform
+// --d-version=D_Initialize
+version (D_Initialize)
+{
+ static DHelloWorld g_HelloWorld;
+}
+
+//***************************************************************************
+// Public Functions
+//***************************************************************************
+
+/****************************************************************************
+ * Name: hello_d_main
+ ****************************************************************************/
+// betterC need main function no-mangle.
+extern (C)
+int hello_d_main(int argc, char*[] argv) nothrow @nogc
+{
+ version (LDC)
+ {
+ /// need LLVM targetinfo
+ printf("Hello World, [%s]!\n", __traits(targetCPU).ptr);
+ }
+ // Exercise an explicitly instantiated C++ object
+ auto pHelloWorld = cast(DHelloWorld*) malloc(DHelloWorld.sizeof);
+ scope (exit)
+ free(pHelloWorld);
+
+ printf("hello_d_main: Saying hello from the dynamically constructed instance\n");
+ pHelloWorld.HelloWorld();
+
+ // Exercise an D object instantiated on the stack
+ auto HelloWorld = DHelloWorld(42);
+
+ printf("hello_d_main: Saying hello from the instance constructed on the stack\n");
+ HelloWorld.HelloWorld();
+ return 0;
+}