Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Init command will now add test-sources to project.json #1520 #1604

Closed
wants to merge 10 commits into from
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,6 @@ TAGS
/.cache/
/compile_commands.json

# 'nix build' resulting symlink
result

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ fn void main()

### Current status

The current stable version of the compiler is **version 0.6.3**.
The current stable version of the compiler is **version 0.6.4**.

The upcoming 0.6.x releases will focus on expanding the standard library.
Follow the issues [here](https://github.com/c3lang/c3c/issues).
Expand Down
61 changes: 61 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
description = "C3 compiler flake";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
};

outputs = { self, ... } @ inputs: inputs.flake-utils.lib.eachDefaultSystem
(system:
let pkgs = import inputs.nixpkgs { inherit system; }; in
{
packages = {
default = self.packages.${system}.c3c;

c3c = pkgs.callPackage ./nix/default.nix {};

c3c-debug = pkgs.callPackage ./nix/default.nix {
debug = true;
};

c3c-nochecks = pkgs.callPackage ./nix/default.nix {
debug = true;
checks = false;
};
};

devShells = {
default = pkgs.callPackage ./nix/shell.nix {
c3c = self.packages.${system}.c3c-nochecks;
};
};
}
);
}
85 changes: 85 additions & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
lib,
llvmPackages,
cmake,
python3,
curl,
libxml2,
libffi,
xar,
debug ? false,
checks ? true,
}: let
inherit (builtins) baseNameOf toString readFile elemAt;
inherit (lib.sources) cleanSourceWith cleanSource;
inherit (lib.lists) findFirst;
inherit (lib.asserts) assertMsg;
inherit (lib.strings) hasInfix hasSuffix splitString removeSuffix removePrefix optionalString;
in
llvmPackages.stdenv.mkDerivation (finalAttrs: {
pname = "c3c${optionalString debug "-debug"}";
version = let
findLine = findFirst (x: hasInfix "COMPILER_VERSION" x) "none";
foundLine = findLine ( splitString "\n" ( readFile ../src/version.h ) );
version = removeSuffix "\"" ( removePrefix "\"" ( elemAt ( splitString " " foundLine ) 2 ) );
in
assert assertMsg (foundLine != "none") "No COMPILER_VERSION substring was found in version.h";
version;

src = cleanSourceWith {
filter = _path: _type: !(hasSuffix ".nix" (baseNameOf(toString _path)));
src = cleanSource ../.;
};

postPatch = ''
substituteInPlace CMakeLists.txt \
--replace-fail "\''${LLVM_LIBRARY_DIRS}" "${llvmPackages.lld.lib}/lib ${llvmPackages.llvm.lib}/lib"
'';

cmakeBuildType = if debug then "Debug" else "Release";

cmakeFlags = [
"-DC3_ENABLE_CLANGD_LSP=${if debug then "ON" else "OFF"}"
];

nativeBuildInputs = [ cmake ];

postBuild = optionalString debug ''
mkdir $out
substituteInPlace compile_commands.json \
--replace "/build/source/" "$src/"
cp compile_commands.json $out/compile_commands.json
'';

buildInputs = [
llvmPackages.llvm
llvmPackages.lld
curl
libxml2
libffi
] ++ lib.optionals llvmPackages.stdenv.hostPlatform.isDarwin [ xar ];

nativeCheckInputs = [ python3 ];

doCheck = llvmPackages.stdenv.system == "x86_64-linux" && checks;

checkPhase = ''
runHook preCheck
( cd ../resources/testproject; ../../build/c3c build )
( cd ../test; python src/tester.py ../build/c3c test_suite )
runHook postCheck
'';

meta = with lib; {
description = "Compiler for the C3 language";
homepage = "https://github.com/c3lang/c3c";
license = licenses.lgpl3Only;
maintainers = with maintainers; [
luc65r
anas
];
platforms = platforms.all;
mainProgram = "c3c";
};
})

20 changes: 20 additions & 0 deletions nix/shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
mkShell,
clang-tools,
c3c,
}:

mkShell {
inputsFrom = [
c3c
];

packages = [
clang-tools
c3c
];

shellHook = ''
ln -sf ${c3c}/compile_commands.json compile_commands.json
'';
}
11 changes: 11 additions & 0 deletions releasenotes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# C3C Release Notes

## 0.6.5 Change list

### Changes / improvements
- Allow splat in initializers.
- Init command will now add `test-sources` to `project.json` #1520

### Fixes
- Fix bug where `a > 0 ? f() : g()` could cause a compiler crash if both returned `void!`.

### Stdlib changes

## 0.6.4 Change list

### Changes / improvements
Expand Down
2 changes: 1 addition & 1 deletion src/build/build_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,7 @@ static inline bool at_end()

static inline const char *next_arg()
{
assert(!at_end());
ASSERT0(!at_end());
current_arg = args[++arg_index];
return current_arg;
}
Expand Down
7 changes: 5 additions & 2 deletions src/build/project.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const char *project_default_keys[][2] = {
{"single-module", "Compile all modules together, enables more inlining."},
{"soft-float", "Output soft-float functions."},
{"sources", "Paths to project sources for all targets."},
{"test-sources", "Paths to project test sources for all targets."},
{"strip-unused", "Strip unused code and globals from the output. (default: true)"},
{"symtab", "Sets the preferred symtab size."},
{"target", "Compile for a particular architecture + OS target."},
Expand Down Expand Up @@ -116,6 +117,8 @@ const char* project_target_keys[][2] = {
{"soft-float", "Output soft-float functions."},
{"sources", "Additional paths to project sources for the target."},
{"sources-override", "Paths to project sources for this target, overriding global settings."},
{"test-sources", "Additional paths to project test sources for the target."},
{"test-sources-override", "Paths to project test sources for this target, overriding global settings."},
{"strip-unused", "Strip unused code and globals from the output. (default: true)"},
{"symtab", "Sets the preferred symtab size."},
{"target", "Compile for a particular architecture + OS target."},
Expand Down Expand Up @@ -424,7 +427,7 @@ static void load_into_build_target(const char *filename, JSONObject *json, const
static void project_add_target(const char *filename, Project *project, BuildTarget *default_target, JSONObject *json,
const char *name, const char *type, TargetType target_type)
{
assert(json->type == J_OBJECT);
ASSERT0(json->type == J_OBJECT);
BuildTarget *target = CALLOCS(BuildTarget);
*target = *default_target;
vec_add(project->targets, target);
Expand All @@ -444,7 +447,7 @@ static void project_add_target(const char *filename, Project *project, BuildTarg

static void project_add_targets(const char *filename, Project *project, JSONObject *project_data)
{
assert(project_data->type == J_OBJECT);
ASSERT0(project_data->type == J_OBJECT);

BuildTarget default_target = default_build_target;
load_into_build_target(filename, project_data, NULL, &default_target);
Expand Down
6 changes: 6 additions & 0 deletions src/build/project_creation.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const char* JSON_EXE =
" \"version\": \"0.1.0\",\n"
" // Sources compiled for all targets.\n"
" \"sources\": [ \"src/**\" ],\n"
" // Test sources compiled for all targets.\n"
" \"test-sources\": [ \"test/**\" ],\n"
" // C sources if the project also compiles C sources\n"
" // relative to the project file.\n"
" // \"c-sources\": [ \"csource/**\" ],\n"
Expand Down Expand Up @@ -63,6 +65,8 @@ const char* JSON_STATIC =
" \"version\": \"0.1.0\",\n"
" // Sources compiled for all targets.\n"
" \"sources\": [ \"src/**\" ],\n"
" // Test sources compiled for all targets.\n"
" \"test-sources\": [ \"test/**\" ],\n"
" // C sources if the project also compiles C sources\n"
" // relative to the project file.\n"
" // \"c-sources\": [ \"csource/**\" ],\n"
Expand Down Expand Up @@ -104,6 +108,8 @@ const char* JSON_DYNAMIC =
" \"version\": \"0.1.0\",\n"
" // Sources compiled for all targets.\n"
" \"sources\": [ \"src/**\" ],\n"
" // Test sources compiled for all targets.\n"
" \"test-sources\": [ \"test/**\" ],\n"
" // C sources if the project also compiles C sources\n"
" // relative to the project file.\n"
" // \"c-sources\": [ \"csource/**\" ],\n"
Expand Down
12 changes: 6 additions & 6 deletions src/compiler/abi/c_abi.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ bool abi_arg_is_indirect(ABIArgInfo *info)

ABIArgInfo *abi_arg_new_indirect_realigned(AlignSize alignment, Type *by_val_type)
{
assert(alignment > 0);
ASSERT0(alignment > 0);
ABIArgInfo *info = abi_arg_new(ABI_ARG_INDIRECT);
info->indirect.alignment = alignment;
assert(info->indirect.alignment);
ASSERT0(info->indirect.alignment);
info->attributes.realign = true;
info->indirect.type = by_val_type;
info->attributes.by_val = true;
Expand All @@ -77,15 +77,15 @@ ABIArgInfo *abi_arg_new_indirect_by_val(Type *by_val_type)
info->indirect.alignment = type_abi_alignment(by_val_type);
info->indirect.type = by_val_type;
info->attributes.by_val = true;
assert(info->indirect.alignment);
ASSERT0(info->indirect.alignment);
return info;
}

ABIArgInfo *abi_arg_new_indirect_not_by_val(Type *type)
{
ABIArgInfo *info = abi_arg_new(ABI_ARG_INDIRECT);
info->indirect.alignment = type_abi_alignment(type);
assert(info->indirect.alignment);
ASSERT0(info->indirect.alignment);
info->indirect.type = type;
info->attributes.by_val = false;
return info;
Expand Down Expand Up @@ -175,7 +175,7 @@ ABIArgInfo *abi_arg_new_direct_coerce_int(void)

ABIArgInfo *abi_arg_new_direct_coerce_type(Type *type)
{
assert(type);
ASSERT0(type);
ABIArgInfo *info = abi_arg_new(ABI_ARG_DIRECT_COERCE);
info->direct_coerce_type = type->canonical;
return info;
Expand All @@ -191,7 +191,7 @@ ABIArgInfo *abi_arg_new_direct_struct_expand_i32(uint8_t elements)

void c_abi_func_create(FunctionPrototype *proto)
{
assert(!proto->is_resolved);
ASSERT0(!proto->is_resolved);
proto->is_resolved = true;
switch (compiler.platform.abi)
{
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/abi/c_abi_aarch64.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ ABIArgInfo *aarch64_coerce_illegal_vector(Type *type)
UNREACHABLE
}*/
}
assert(type->type_kind == TYPE_VECTOR);
ASSERT0(type->type_kind == TYPE_VECTOR);
TypeSize size = type_size(type);

// CLANG: Android promotes char[<2>] to ushort, not uint
Expand Down Expand Up @@ -107,7 +107,7 @@ ABIArgInfo *aarch64_classify_argument_type(Type *type)
unsigned members = 0;
if (type_is_homogenous_aggregate(type, &base, &members))
{
assert(members < 128);
ASSERT0(members < 128);
if (members > 1)
{
return abi_arg_new_direct_coerce_type(type_get_array(base, members));
Expand All @@ -134,7 +134,7 @@ ABIArgInfo *aarch64_classify_argument_type(Type *type)
size = aligned_offset(size, alignment);
// We use a pair of i64 for 16-byte aggregate with 8-byte alignment.
// For aggregates with 16-byte alignment, we use i128.
assert(alignment == 8 || alignment == 16);
ASSERT0(alignment == 8 || alignment == 16);

if (alignment == 16) return abi_arg_new_direct_coerce_type(type_u128);
ArraySize m = size / alignment;
Expand Down
Loading