dlang-app added

This commit is contained in:
Matheus Catarino 2024-06-05 14:15:15 -03:00 committed by Xiang Xiao
parent b32cf5f0b7
commit 6db9d5e582
7 changed files with 237 additions and 6 deletions

3
.gitignore vendored
View File

@ -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
compile_commands.json

View File

@ -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::
@:

View File

@ -54,6 +54,7 @@ $(foreach BDIR, $(BUILDIRS), $(eval $(call Add_Application,$(BDIR))))
CXXEXT ?= .cxx
RUSTEXT ?= .rs
ZIGEXT ?= .zig
DEXT ?= .d
# Library path

29
examples/hello_d/Kconfig Normal file
View File

@ -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

View File

@ -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

35
examples/hello_d/Makefile Normal file
View File

@ -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

View File

@ -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;
}