pass more tests
This commit is contained in:
parent
f8bd7ad443
commit
e9991b8d9a
File diff suppressed because it is too large
Load Diff
@ -157,9 +157,17 @@ extern "C" DICompositeType* NativityLLVMDebugInfoBuilderCreateStructType(DIBuild
|
||||
auto type_array = ArrayRef<Metadata*>(reinterpret_cast<Metadata**>(element_type_ptr), element_type_count);
|
||||
|
||||
auto* struct_type = builder.createStructType(scope, name, file, line_number, bit_count, alignment, flags, derived_from, builder.getOrCreateArray(type_array));
|
||||
|
||||
return struct_type;
|
||||
}
|
||||
|
||||
extern "C" void NativityLLVMDebugInfoBuilderCompositeTypeReplaceTypes(DIBuilder& builder, DICompositeType& type, DIType** element_type_ptr, size_t element_type_count)
|
||||
{
|
||||
auto type_array = ArrayRef<Metadata*>(reinterpret_cast<Metadata**>(element_type_ptr), element_type_count);
|
||||
auto node_array = builder.getOrCreateArray(type_array);
|
||||
type.replaceElements(node_array);
|
||||
}
|
||||
|
||||
extern "C" DICompositeType* NativityLLVMDebugInfoBuilderCreateArrayType(DIBuilder& builder, uint64_t bit_size, uint32_t alignment, DIType* type, size_t element_count)
|
||||
{
|
||||
Metadata* subranges[1] = {
|
||||
@ -173,8 +181,6 @@ extern "C" DICompositeType* NativityLLVMDebugInfoBuilderCreateArrayType(DIBuilde
|
||||
|
||||
extern "C" DIEnumerator* NativityLLVMDebugInfoBuilderCreateEnumerator(DIBuilder& builder, const char* name_ptr, size_t name_len, uint64_t value, bool is_unsigned)
|
||||
{
|
||||
|
||||
// DIEnumerator *DIBuilder::createEnumerator(StringRef Name, uint64_t Val,
|
||||
auto name = StringRef(name_ptr, name_len);
|
||||
auto* enumerator = builder.createEnumerator(name, value, is_unsigned);
|
||||
return enumerator;
|
||||
@ -194,6 +200,19 @@ extern "C" DICompositeType* NativityLLVMDebugInfoBuilderCreateReplaceableComposi
|
||||
auto* composite_type = builder.createReplaceableCompositeType(tag, name, scope, file, line);
|
||||
return composite_type;
|
||||
}
|
||||
|
||||
extern "C" DIDerivedType* NativityLLVMDebugInfoBuilderCreateMemberType(DIBuilder& builder, DIScope *scope, const char* name_ptr, size_t name_len, DIFile* file, unsigned line_number, uint64_t bit_size, uint32_t alignment, uint64_t bit_offset, DINode::DIFlags flags, DIType* type)
|
||||
{
|
||||
auto name = StringRef(name_ptr, name_len);
|
||||
auto* member_type = builder.createMemberType(scope, name, file, line_number, bit_size, alignment, bit_offset, flags, type);
|
||||
return member_type;
|
||||
}
|
||||
|
||||
extern "C" bool NativityLLLVMDITypeIsResolved(DIType* type)
|
||||
{
|
||||
return type->isResolved();
|
||||
}
|
||||
|
||||
extern "C" DISubprogram* NativityLLVMDebugInfoScopeToSubprogram(DIScope* scope)
|
||||
{
|
||||
auto* subprogram = dyn_cast<DISubprogram>(scope);
|
||||
@ -418,9 +437,6 @@ extern "C" Value* NativityLLVMBuilderCreateCast(IRBuilder<>& builder, Instructio
|
||||
|
||||
extern "C" CallInst* NativityLLVMBuilderCreateCall(IRBuilder<>& builder, FunctionType* function_type, Value* callee, Value** argument_ptr, size_t argument_count, const char* name_ptr, size_t name_len, MDNode* fp_math_tag)
|
||||
{
|
||||
if (auto* foo = static_cast<FunctionType*>(callee->getType())) {
|
||||
int k = 0;
|
||||
}
|
||||
auto arguments = ArrayRef<Value*>(argument_ptr, argument_count);
|
||||
auto name = StringRef(name_ptr, name_len);
|
||||
auto* call = builder.CreateCall(function_type, callee, arguments, name, fp_math_tag);
|
||||
@ -539,6 +555,13 @@ extern "C" Value* NativityLLVMBuilderCreateGEP(IRBuilder<>& builder, Type* type,
|
||||
return GEP;
|
||||
}
|
||||
|
||||
extern "C" Value* NativityLLVMBuilderCreateStructGEP(IRBuilder<>& builder, Type* type, Value* pointer, unsigned index, const char* name_ptr, size_t name_len)
|
||||
{
|
||||
auto name = StringRef(name_ptr, name_len);
|
||||
auto* gep = builder.CreateStructGEP(type, pointer, index, name);
|
||||
return gep;
|
||||
}
|
||||
|
||||
extern "C" BranchInst* NativityLLVMBuilderCreateBranch(IRBuilder<>& builder, BasicBlock* basic_block)
|
||||
{
|
||||
auto* conditional_branch = builder.CreateBr(basic_block);
|
||||
@ -558,14 +581,6 @@ extern "C" Intrinsic::ID NativityLLVMLookupIntrinsic(const char* name_ptr, size_
|
||||
return id;
|
||||
}
|
||||
|
||||
extern "C" FunctionType* NativityLLVMContextGetIntrinsicType(LLVMContext& context, Intrinsic::ID intrinsic_id, Type** parameter_type_ptr, size_t parameter_type_count)
|
||||
{
|
||||
assert(intrinsic_id < Intrinsic::num_intrinsics);
|
||||
auto parameter_types = ArrayRef<Type*>(parameter_type_ptr, parameter_type_count);
|
||||
auto* function_type = Intrinsic::getType(context, intrinsic_id, parameter_types);
|
||||
return function_type;
|
||||
}
|
||||
|
||||
extern "C" Function* NativityLLVMModuleGetIntrinsicDeclaration(Module* module, Intrinsic::ID intrinsic_id, Type** parameter_types_ptr, size_t parameter_type_count)
|
||||
{
|
||||
auto parameter_types = ArrayRef<Type*>(parameter_types_ptr, parameter_type_count);
|
||||
@ -574,6 +589,23 @@ extern "C" Function* NativityLLVMModuleGetIntrinsicDeclaration(Module* module, I
|
||||
return function;
|
||||
}
|
||||
|
||||
extern "C" FunctionType* NativityLLVMFunctionGetType(Function& function)
|
||||
{
|
||||
auto* function_type = function.getFunctionType();
|
||||
return function_type;
|
||||
}
|
||||
|
||||
extern "C" Type* NativityLLVMFunctionTypeGetReturnType(FunctionType& function_type)
|
||||
{
|
||||
auto* return_type = function_type.getReturnType();
|
||||
return return_type;
|
||||
}
|
||||
|
||||
extern "C" bool NativityLLVMTypeIsVoid(Type& type)
|
||||
{
|
||||
bool is_void_type = type.isVoidTy();
|
||||
return is_void_type;
|
||||
}
|
||||
|
||||
extern "C" Value* NativityLLVMBuilderCreateExtractValue(IRBuilder<>& builder, Value* aggregate, unsigned* indices_ptr, size_t indices_len, const char* name_ptr, size_t name_len)
|
||||
{
|
||||
@ -672,12 +704,6 @@ extern "C" bool NativityLLVMVerifyModule(const Module& module, const char** mess
|
||||
return !result;
|
||||
}
|
||||
|
||||
extern "C" Type* NativityLLVMFunctionGetReturnType(const Function& function)
|
||||
{
|
||||
auto* return_type = function.getReturnType();
|
||||
return return_type;
|
||||
}
|
||||
|
||||
extern "C" const char* NativityLLVMFunctionToString(const Function& function, size_t* len)
|
||||
{
|
||||
std::string buf;
|
||||
@ -740,6 +766,12 @@ extern "C" FunctionType* NativityLLVMTypeToFunction(Type* type)
|
||||
return function_type;
|
||||
}
|
||||
|
||||
extern "C" Type* NativityLLVMFunctionTypeGetArgumentType(FunctionType& function_type, unsigned argument_index)
|
||||
{
|
||||
auto* type = function_type.getParamType(argument_index);
|
||||
return type;
|
||||
}
|
||||
|
||||
extern "C" ArrayType* NativityLLVMTypeToArray(Type* type)
|
||||
{
|
||||
auto* array_type = dyn_cast<ArrayType>(type);
|
||||
@ -752,6 +784,12 @@ extern "C" PointerType* NativityLLVMTypeToPointer(Type* type)
|
||||
return pointer_type;
|
||||
}
|
||||
|
||||
extern "C" ConstantPointerNull* NativityLLVMPointerTypeGetNull(PointerType* pointer_type)
|
||||
{
|
||||
auto* constant_pointer_null = ConstantPointerNull::get(pointer_type);
|
||||
return constant_pointer_null;
|
||||
}
|
||||
|
||||
extern "C" Type* NativityLLVMArrayTypeGetElementType(ArrayType* array_type)
|
||||
{
|
||||
auto* element_type = array_type->getElementType();
|
||||
@ -769,6 +807,17 @@ extern "C" const char* NativityLLVMModuleToString(const Module& module, size_t*
|
||||
return result;
|
||||
}
|
||||
|
||||
extern "C" const char* NativityLLVMValueToString(const Value& value, size_t* len)
|
||||
{
|
||||
std::string buf;
|
||||
raw_string_ostream os(buf);
|
||||
value.print(os, true);
|
||||
os.flush();
|
||||
*len = buf.size();
|
||||
auto* result = strdup(buf.c_str());
|
||||
return result;
|
||||
}
|
||||
|
||||
extern "C" BasicBlock* NativityLLVMBuilderGetInsertBlock(IRBuilder<>& builder)
|
||||
{
|
||||
return builder.GetInsertBlock();
|
||||
@ -820,39 +869,70 @@ namespace lld {
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" bool NativityLLVMGenerateMachineCode(Module& module, const char* object_file_path_ptr, size_t object_file_path_len, const char* file_path_ptr, size_t file_path_len)
|
||||
extern "C" void NativityLLVMInitializeCodeGeneration()
|
||||
{
|
||||
InitializeAllTargetInfos();
|
||||
InitializeAllTargets();
|
||||
InitializeAllTargetMCs(); InitializeAllAsmParsers();
|
||||
InitializeAllTargetMCs();
|
||||
InitializeAllAsmParsers();
|
||||
InitializeAllAsmPrinters();
|
||||
}
|
||||
|
||||
auto target_triple = "x86_64-linux-none";
|
||||
auto cpu = "generic";
|
||||
auto features = "";
|
||||
extern "C" const Target* NativityLLVMGetTarget(const char* target_triple_ptr, size_t target_triple_len, const char** message_ptr, size_t* message_len)
|
||||
{
|
||||
auto target_triple = StringRef(target_triple_ptr, target_triple_len);
|
||||
std::string error_message;
|
||||
const Target* target = TargetRegistry::lookupTarget(target_triple, error_message);
|
||||
|
||||
if (!target)
|
||||
{
|
||||
char* result = new char[error_message.length()];
|
||||
memcpy(result, error_message.c_str(), error_message.length());
|
||||
|
||||
*message_ptr = result;
|
||||
*message_len = error_message.length();
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
extern "C" TargetMachine* NativityLLVMTargetCreateTargetMachine(Target& target, const char* target_triple_ptr, size_t target_triple_len, const char* cpu_ptr, size_t cpu_len, const char* features_ptr, size_t features_len, Reloc::Model relocation_model, CodeModel::Model maybe_code_model, bool is_code_model_present, CodeGenOpt::Level optimization_level, bool jit)
|
||||
{
|
||||
auto target_triple = StringRef(target_triple_ptr, target_triple_len);
|
||||
auto cpu = StringRef(cpu_ptr, cpu_len);
|
||||
auto features = StringRef(features_ptr, features_len);
|
||||
TargetOptions target_options;
|
||||
std::optional<CodeModel::Model> code_model = std::nullopt;
|
||||
if (is_code_model_present) {
|
||||
code_model = maybe_code_model;
|
||||
}
|
||||
TargetMachine* target_machine = target.createTargetMachine(target_triple, cpu, features, target_options, relocation_model, code_model, optimization_level, jit);
|
||||
return target_machine;
|
||||
}
|
||||
|
||||
std::string error;
|
||||
auto* target = TargetRegistry::lookupTarget(target_triple, error);
|
||||
assert(target);
|
||||
extern "C" void NativityLLVMModuleSetTargetMachineDataLayout(Module& module, TargetMachine& target_machine)
|
||||
{
|
||||
module.setDataLayout(target_machine.createDataLayout());
|
||||
}
|
||||
|
||||
auto target_machine = target->createTargetMachine(target_triple, cpu, features, target_options, Reloc::Static);
|
||||
assert(target_machine);
|
||||
|
||||
module.setDataLayout(target_machine->createDataLayout());
|
||||
extern "C" void NativityLLVMModuleSetTargetTriple(Module& module, const char* target_triple_ptr, size_t target_triple_len)
|
||||
{
|
||||
auto target_triple = StringRef(target_triple_ptr, target_triple_len);
|
||||
module.setTargetTriple(target_triple);
|
||||
}
|
||||
|
||||
std::error_code EC;
|
||||
extern "C" bool NativityLLVMModuleAddPassesToEmitFile(Module& module, TargetMachine& target_machine, const char* object_file_path_ptr, size_t object_file_path_len, CodeGenFileType codegen_file_type, bool disable_verify)
|
||||
{
|
||||
std::error_code error_code;
|
||||
auto object_file_path = StringRef(object_file_path_ptr, object_file_path_len);
|
||||
raw_fd_ostream stream(object_file_path, EC, sys::fs::OF_None);
|
||||
if (EC) {
|
||||
raw_fd_ostream stream(object_file_path, error_code, sys::fs::OF_None);
|
||||
if (error_code) {
|
||||
return false;
|
||||
}
|
||||
|
||||
legacy::PassManager pass;
|
||||
bool result = target_machine->addPassesToEmitFile(pass, stream, nullptr, llvm::CGFT_ObjectFile, false);
|
||||
if (result) {
|
||||
// We invert the condition because LLVM conventions are just stupid
|
||||
if (target_machine.addPassesToEmitFile(pass, stream, nullptr, codegen_file_type, disable_verify)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -4,18 +4,20 @@ pub extern fn NativityLLVMCreateContext() ?*LLVM.Context;
|
||||
pub extern fn NativityLLVMCreateModule(module_name_ptr: [*:0]const u8, module_name_len: usize, context: *LLVM.Context) ?*LLVM.Module;
|
||||
pub extern fn NativityLLVMCreateBuilder(context: *LLVM.Context) ?*LLVM.Builder;
|
||||
pub extern fn NativityLLVMGetFunctionType(return_type: *LLVM.Type, argument_type_ptr: [*]const *LLVM.Type, argument_type_len: usize, is_var_args: bool) ?*LLVM.Type.Function;
|
||||
pub extern fn NativityLLVMFunctionTypeGetArgumentType(function_type: *LLVM.Type.Function, argument_index: c_uint) *LLVM.Type;
|
||||
pub extern fn NativityLLVMGetIntegerType(context: *LLVM.Context, bit_count: u32) ?*LLVM.Type.Integer;
|
||||
pub extern fn NativityLLVMGetPointerType(context: *LLVM.Context, address_space: u32) ?*LLVM.Type.Pointer;
|
||||
pub extern fn NativityLLVMPointerTypeGetNull(pointer_type: *LLVM.Type.Pointer) *LLVM.Value.Constant.PointerNull;
|
||||
pub extern fn NativityLLVMGetArrayType(element_type: *LLVM.Type, element_count: u64) ?*LLVM.Type.Array;
|
||||
pub extern fn NativityLLVMGetStructType(context: *LLVM.Context, type_ptr: [*]const *LLVM.Type, type_count: usize, is_packed: bool) ?*LLVM.Type.Struct;
|
||||
pub extern fn NativityLLVMConstantStruct(struct_type: *LLVM.Type.Struct, constant_ptr: [*]const *LLVM.Value.Constant, constant_count: usize) ?*LLVM.Value.Constant;
|
||||
pub extern fn NativityLLVMModuleGetFunction(module: *LLVM.Module, name_ptr: [*]const u8, name_len: usize) ?*LLVM.Value.Function;
|
||||
pub extern fn NativityLLVModuleCreateFunction(module: *LLVM.Module, function_type: *LLVM.Type.Function, linkage: LLVM.Linkage, address_space: c_uint, name_ptr: [*]const u8, name_len: usize) ?*LLVM.Value.Function;
|
||||
pub extern fn NativityLLVMModuleGetFunction(module: *LLVM.Module, name_ptr: [*]const u8, name_len: usize) ?*LLVM.Value.Constant.Function;
|
||||
pub extern fn NativityLLVModuleCreateFunction(module: *LLVM.Module, function_type: *LLVM.Type.Function, linkage: LLVM.Linkage, address_space: c_uint, name_ptr: [*]const u8, name_len: usize) ?*LLVM.Value.Constant.Function;
|
||||
pub extern fn NativityLLVMModuleCreateDebugInfoBuilder(module: *LLVM.Module) ?*LLVM.DebugInfo.Builder;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateFile(builder: *LLVM.DebugInfo.Builder, filename_ptr: [*]const u8, filename_len: usize, directory_ptr: [*]const u8, directory_len: usize) ?*LLVM.DebugInfo.File;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateCompileUnit(builder: *LLVM.DebugInfo.Builder, language: LLVM.DebugInfo.Language, file: *LLVM.DebugInfo.File, producer_ptr: [*]const u8, producer_len: usize, is_optimized: bool, flags_ptr: [*]const u8, flags_len: usize, runtime_version: c_uint, split_name_ptr: [*]const u8, split_name_len: usize, debug_info_emission_kind: LLVM.DebugInfo.CompileUnit.EmissionKind, DWOId: u64, split_debug_inlining: bool, debug_info_for_profiling: bool, debug_info_name_table_kind: LLVM.DebugInfo.CompileUnit.NameTableKind, ranges_base_address: bool, sysroot_ptr: [*]const u8, sysroot_len: usize, sdk_ptr: [*]const u8, sdk_len: usize) ?*LLVM.DebugInfo.CompileUnit;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateFunction(builder: *LLVM.DebugInfo.Builder, scope: *LLVM.DebugInfo.Scope, name_ptr: [*]const u8, name_len: usize, linkage_name_ptr: [*]const u8, linkage_name_len: usize, file: *LLVM.DebugInfo.File, line_number: c_uint, type: *LLVM.DebugInfo.SubroutineType, scope_line: c_uint, flags: LLVM.DebugInfo.Node.Flags, subprogram_flags: LLVM.DebugInfo.Subprogram.Flags, declaration: ?*LLVM.DebugInfo.Subprogram) ?*LLVM.DebugInfo.Subprogram;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateSubroutineType(builder: *LLVM.DebugInfo.Builder, parameter_types_ptr: [*]const *LLVM.DebugInfo.Type, parameter_type_count: usize, flags: LLVM.DebugInfo.Node.Flags, calling_convention: LLVM.DebugInfo.CallingConvention) ?*LLVM.DebugInfo.SubroutineType;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateFunction(builder: *LLVM.DebugInfo.Builder, scope: *LLVM.DebugInfo.Scope, name_ptr: [*]const u8, name_len: usize, linkage_name_ptr: [*]const u8, linkage_name_len: usize, file: *LLVM.DebugInfo.File, line_number: c_uint, type: *LLVM.DebugInfo.Type.Subroutine, scope_line: c_uint, flags: LLVM.DebugInfo.Node.Flags, subprogram_flags: LLVM.DebugInfo.Subprogram.Flags, declaration: ?*LLVM.DebugInfo.Subprogram) ?*LLVM.DebugInfo.Subprogram;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateSubroutineType(builder: *LLVM.DebugInfo.Builder, parameter_types_ptr: [*]const *LLVM.DebugInfo.Type, parameter_type_count: usize, flags: LLVM.DebugInfo.Node.Flags, calling_convention: LLVM.DebugInfo.CallingConvention) ?*LLVM.DebugInfo.Type.Subroutine;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateLexicalBlock(builder: *LLVM.DebugInfo.Builder, parent_scope: *LLVM.DebugInfo.Scope, parent_file: *LLVM.DebugInfo.File, line: c_uint, column: c_uint) ?*LLVM.DebugInfo.LexicalBlock;
|
||||
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateExpression(builder: *LLVM.DebugInfo.Builder, address: [*]const u64, length: usize) *LLVM.DebugInfo.Expression;
|
||||
@ -26,26 +28,31 @@ pub extern fn NativityLLVMDebugInfoBuilderInsertDeclare(builder: *LLVM.DebugInfo
|
||||
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateBasicType(builder: *LLVM.DebugInfo.Builder, name_ptr: [*]const u8, name_len: usize, bit_count: u64, dwarf_encoding: LLVM.DebugInfo.AttributeType, flags: LLVM.DebugInfo.Node.Flags) ?*LLVM.DebugInfo.Type;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreatePointerType(builder: *LLVM.DebugInfo.Builder, element_type: *LLVM.DebugInfo.Type, pointer_bit_count: u64, alignment: u32, name_ptr: [*]const u8, name_len: usize) ?*LLVM.DebugInfo.Type.Derived;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateStructType(builder: *LLVM.DebugInfo.Builder, scope: ?*LLVM.DebugInfo.Scope, name_ptr: [*]const u8, name_len: usize, file: ?*LLVM.DebugInfo.File, line_number: c_uint, bit_count: u64, alignment: u32, flags: LLVM.DebugInfo.Node.Flags, derived_from: ?*LLVM.DebugInfo.Type, element_type_ptr: [*]const *LLVM.DebugInfo.Type, element_type_count: usize) ?*LLVM.DebugInfo.Type.Composite;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateStructType(builder: *LLVM.DebugInfo.Builder, scope: ?*LLVM.DebugInfo.Scope, name_ptr: [*]const u8, name_len: usize, file: ?*LLVM.DebugInfo.File, line_number: c_uint, bit_count: u64, alignment: u32, flags: LLVM.DebugInfo.Node.Flags, derived_from: ?*LLVM.DebugInfo.Type, element_type_ptr: [*]const *LLVM.DebugInfo.Type, element_type_count: usize, forward_declaration: ?*LLVM.DebugInfo.Type.Composite) ?*LLVM.DebugInfo.Type.Composite;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateArrayType(builder: *LLVM.DebugInfo.Builder, bit_size: u64, alignment: u32, type: *LLVM.DebugInfo.Type, element_count: usize) ?*LLVM.DebugInfo.Type.Composite;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateEnumerationType(builder: *LLVM.DebugInfo.Builder, scope: ?*LLVM.DebugInfo.Scope, name_ptr: [*]const u8, name_len: usize, file: *LLVM.DebugInfo.File, line: c_uint, bit_size: u64, alignment: u32, enumerator_ptr: [*]const *LLVM.DebugInfo.Type.Enumerator, enumerator_count: usize, underlying_type: *LLVM.DebugInfo.Type) ?*LLVM.DebugInfo.Type.Composite;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateEnumerator(builder: *LLVM.DebugInfo.Builder, name_ptr: [*]const u8, name_len: usize, value: u64, is_unsigned: bool) ?*LLVM.DebugInfo.Type.Enumerator;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateReplaceableCompositeType(builder: *LLVM.DebugInfo.Builder, tag: c_uint, name_ptr: [*]const u8, name_len: usize, scope: ?*LLVM.DebugInfo.Scope, file: ?*LLVM.DebugInfo.File, line: c_uint) ?*LLVM.DebugInfo.Type.Composite;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderFinalizeSubprogram(builder: *LLVM.DebugInfo.Builder, subprogram: *LLVM.DebugInfo.Subprogram, function: *LLVM.Value.Function) void;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateMemberType(builder: *LLVM.DebugInfo.Builder, scope: ?*LLVM.DebugInfo.Scope, name_ptr: [*]const u8, name_len: usize, file: ?*LLVM.DebugInfo.File, line_number: c_uint, bit_size: u64, alignment: u32, bit_offset: u64, flags: LLVM.DebugInfo.Node.Flags, type: *LLVM.DebugInfo.Type) *LLVM.DebugInfo.Type.Derived;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCompositeTypeReplaceTypes(builder: *LLVM.DebugInfo.Builder, type: *LLVM.DebugInfo.Type.Composite, element_type_ptr: [*]const *LLVM.DebugInfo.Type, element_type_count: usize) void;
|
||||
pub extern fn NativityLLLVMDITypeIsResolved(type: *LLVM.DebugInfo.Type) bool;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderFinalizeSubprogram(builder: *LLVM.DebugInfo.Builder, subprogram: *LLVM.DebugInfo.Subprogram, function: *LLVM.Value.Constant.Function) void;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderFinalize(builder: *LLVM.DebugInfo.Builder) void;
|
||||
pub extern fn NativityLLVMDebugInfoSubprogramGetFile(subprogram: *LLVM.DebugInfo.Subprogram) ?*LLVM.DebugInfo.File;
|
||||
pub extern fn NativityLLVMDebugInfoSubprogramGetArgumentType(subprogram: *LLVM.DebugInfo.Subprogram, argument_index: usize) ?*LLVM.DebugInfo.Type;
|
||||
pub extern fn NativityLLVMDebugInfoScopeToSubprogram(scope: *LLVM.DebugInfo.Scope) ?*LLVM.DebugInfo.Subprogram;
|
||||
pub extern fn NativityLLVMCreateBasicBlock(context: *LLVM.Context, name_ptr: [*]const u8, name_len: usize, parent_function: ?*LLVM.Value.Function, insert_before: ?*LLVM.Value.BasicBlock) ?*LLVM.Value.BasicBlock;
|
||||
pub extern fn NativityLLVMCreateBasicBlock(context: *LLVM.Context, name_ptr: [*]const u8, name_len: usize, parent_function: ?*LLVM.Value.Constant.Function, insert_before: ?*LLVM.Value.BasicBlock) ?*LLVM.Value.BasicBlock;
|
||||
pub extern fn NativityLLVMBasicBlockRemoveFromParent(basic_block: *LLVM.Value.BasicBlock) void;
|
||||
pub extern fn NativityLLVMBuilderSetInsertPoint(builder: *LLVM.Builder, basic_block: *LLVM.Value.BasicBlock) void;
|
||||
pub extern fn NativityLLVMBuilderGetInsertBlock(builder: *LLVM.Builder) ?*LLVM.Value.BasicBlock;
|
||||
pub extern fn NativityLLVMBuilderSetCurrentDebugLocation(builder: *LLVM.Builder, context: *LLVM.Context, line: c_uint, column: c_uint, scope: *LLVM.DebugInfo.Scope, function: *LLVM.Value.Function) void;
|
||||
pub extern fn NativityLLVMBuilderSetCurrentDebugLocation(builder: *LLVM.Builder, context: *LLVM.Context, line: c_uint, column: c_uint, scope: *LLVM.DebugInfo.Scope, function: *LLVM.Value.Constant.Function) void;
|
||||
pub extern fn NativityLLVMValueSetName(value: *LLVM.Value, name_ptr: [*]const u8, name_len: usize) void;
|
||||
pub extern fn NativityLLVMValueGetType(value: *LLVM.Value) *LLVM.Type;
|
||||
pub extern fn NativityLLVMArgumentGetIndex(argument: *LLVM.Value.Argument) c_uint;
|
||||
pub extern fn NativityLLVMFunctionGetArguments(function: *LLVM.Value.Function, argument_ptr: [*]*LLVM.Value.Argument, argument_len: *usize) void;
|
||||
pub extern fn NativityLLVMFunctionGetReturnType(function: *LLVM.Value.Function) ?*LLVM.Type;
|
||||
pub extern fn NativityLLVMFunctionGetArguments(function: *LLVM.Value.Constant.Function, argument_ptr: [*]*LLVM.Value.Argument, argument_len: *usize) void;
|
||||
pub extern fn NativityLLVMFunctionGetType(function: *LLVM.Value.Constant.Function) *LLVM.Type.Function;
|
||||
pub extern fn NativityLLVMFunctionTypeGetReturnType(function_type: *LLVM.Type.Function) *LLVM.Type;
|
||||
pub extern fn NativityLLVMTypeIsVoid(type: *LLVM.Type) bool;
|
||||
pub extern fn NativityLLVMBuilderCreateAlloca(builder: *LLVM.Builder, type: *LLVM.Type, address_space: c_uint, array_size: ?*LLVM.Value, name_ptr: [*]const u8, name_len: usize) ?*LLVM.Value.Instruction.Alloca;
|
||||
pub extern fn NativityLLVMBuilderCreateStore(builder: *LLVM.Builder, value: *LLVM.Value, pointer: *LLVM.Value, is_volatile: bool) ?*LLVM.Value.Instruction.Store;
|
||||
pub extern fn NativityLLVMContextGetConstantInt(context: *LLVM.Context, bit_count: c_uint, value: u64, is_signed: bool) ?*LLVM.Value.Constant.Int;
|
||||
@ -56,7 +63,7 @@ pub extern fn NativityLLVMBuilderCreateICmp(builder: *LLVM.Builder, integer_comp
|
||||
pub extern fn NativityLLVMBuilderCreateLoad(builder: *LLVM.Builder, type: *LLVM.Type, value: *LLVM.Value, is_volatile: bool, name_ptr: [*]const u8, name_len: usize) ?*LLVM.Value.Instruction.Load;
|
||||
pub extern fn NativityLLVMBuilderCreateRet(builder: *LLVM.Builder, value: ?*LLVM.Value) ?*LLVM.Value.Instruction.Ret;
|
||||
pub extern fn NativityLLVMBuilderCreateCast(builder: *LLVM.Builder, cast_type: LLVM.Value.Instruction.Cast.Type, value: *LLVM.Value, type: *LLVM.Type, name_ptr: [*]const u8, name_len: usize) ?*LLVM.Value;
|
||||
pub extern fn NativityLLVMFunctionAddAttributeKey(builder: *LLVM.Value.Function, attribute_key: LLVM.Attribute) void;
|
||||
pub extern fn NativityLLVMFunctionAddAttributeKey(builder: *LLVM.Value.Constant.Function, attribute_key: LLVM.Attribute) void;
|
||||
pub extern fn NativityLLVMGetVoidType(context: *LLVM.Context) ?*LLVM.Type;
|
||||
pub extern fn NativityLLVMGetInlineAssembly(function_type: *LLVM.Type.Function, assembly_ptr: [*]const u8, assembly_len: usize, constraints_ptr: [*]const u8, constrains_len: usize, has_side_effects: bool, is_align_stack: bool, dialect: LLVM.Value.InlineAssembly.Dialect, can_throw: bool) ?*LLVM.Value.InlineAssembly;
|
||||
pub extern fn NativityLLVMBuilderCreateCall(builder: *LLVM.Builder, function_type: *LLVM.Type.Function, callee: *LLVM.Value, argument_ptr: [*]const *LLVM.Value, argument_count: usize, name_ptr: [*]const u8, name_len: usize, fp_math_tag: ?*LLVM.Metadata.Node) ?*LLVM.Value.Instruction.Call;
|
||||
@ -79,29 +86,30 @@ pub extern fn NativityLLVMBuilderCreateXor(builder: *LLVM.Builder, left: *LLVM.V
|
||||
pub extern fn NativityLLVMBuilderCreateAnd(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize) ?*LLVM.Value;
|
||||
pub extern fn NativityLLVMBuilderCreateOr(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize) ?*LLVM.Value;
|
||||
pub extern fn NativityLLVMBuilderCreateGEP(builder: *LLVM.Builder, type: *LLVM.Type, pointer: *LLVM.Value, index_ptr: [*]const *LLVM.Value, index_count: usize, name_ptr: [*]const u8, name_len: usize, in_bounds: bool) ?*LLVM.Value;
|
||||
pub extern fn NativityLLVMBuilderCreateStructGEP(builder: *LLVM.Builder, type: *LLVM.Type, pointer: *LLVM.Value, index: c_uint, name_ptr: [*]const u8, name_len: usize) ?*LLVM.Value;
|
||||
pub extern fn NativityLLVMBuilderCreateBranch(builder: *LLVM.Builder, basic_block: *LLVM.Value.BasicBlock) ?*LLVM.Value.Instruction.Branch;
|
||||
pub extern fn NativityLLVMBuilderCreateConditionalBranch(builder: *LLVM.Builder, condition: *LLVM.Value, true_block: *LLVM.Value.BasicBlock, false_block: *LLVM.Value.BasicBlock, branch_weights: ?*LLVM.Metadata.Node, unpredictable: ?*LLVM.Metadata.Node) ?*LLVM.Value.Instruction.Branch;
|
||||
|
||||
pub extern fn NativityLLVMVerifyFunction(function: *LLVM.Value.Function, message_ptr: *[*]const u8, message_len: *usize) bool;
|
||||
pub extern fn NativityLLVMVerifyFunction(function: *LLVM.Value.Constant.Function, message_ptr: *[*]const u8, message_len: *usize) bool;
|
||||
pub extern fn NativityLLVMVerifyModule(module: *LLVM.Module, message_ptr: *[*]const u8, message_len: *usize) bool;
|
||||
|
||||
pub extern fn NativityLLVMModuleToString(module: *LLVM.Module, message_len: *usize) [*]const u8;
|
||||
pub extern fn NativityLLVMFunctionToString(function: *LLVM.Value.Function, message_len: *usize) [*]const u8;
|
||||
|
||||
pub extern fn NativityLLVMFunctionToString(function: *LLVM.Value.Constant.Function, message_len: *usize) [*]const u8;
|
||||
pub extern fn NativityLLVMValueToString(value: *LLVM.Value, message_len: *usize) [*]const u8;
|
||||
|
||||
pub extern fn NativityLLVMBuilderIsCurrentBlockTerminated(builder: *LLVM.Builder) bool;
|
||||
pub extern fn NativityLLVMGetUndefined(type: *LLVM.Type) ?*LLVM.Value.Constant.Undefined;
|
||||
pub extern fn NativityLLVMGetPoisonValue(type: *LLVM.Type) ?*LLVM.Value.Constant.Poison;
|
||||
pub extern fn NativityLLVMFunctionSetCallingConvention(function: *LLVM.Value.Function, calling_convention: LLVM.Value.Function.CallingConvention) void;
|
||||
pub extern fn NativityLLVMFunctionGetCallingConvention(function: *LLVM.Value.Function) LLVM.Value.Function.CallingConvention;
|
||||
pub extern fn NativityLLVMFunctionSetSubprogram(function: *LLVM.Value.Function, subprogram: *LLVM.DebugInfo.Subprogram) void;
|
||||
pub extern fn NativityLLVMFunctionGetSubprogram(function: *LLVM.Value.Function) ?*LLVM.DebugInfo.Subprogram;
|
||||
pub extern fn NativityLLVMFunctionSetCallingConvention(function: *LLVM.Value.Constant.Function, calling_convention: LLVM.Value.Constant.Function.CallingConvention) void;
|
||||
pub extern fn NativityLLVMFunctionGetCallingConvention(function: *LLVM.Value.Constant.Function) LLVM.Value.Constant.Function.CallingConvention;
|
||||
pub extern fn NativityLLVMFunctionSetSubprogram(function: *LLVM.Value.Constant.Function, subprogram: *LLVM.DebugInfo.Subprogram) void;
|
||||
pub extern fn NativityLLVMFunctionGetSubprogram(function: *LLVM.Value.Constant.Function) ?*LLVM.DebugInfo.Subprogram;
|
||||
|
||||
pub extern fn NativityLLVMCallSetCallingConvention(instruction: *LLVM.Value.Instruction.Call, calling_convention: LLVM.Value.Function.CallingConvention) void;
|
||||
pub extern fn NativityLLVMCallSetCallingConvention(instruction: *LLVM.Value.Instruction.Call, calling_convention: LLVM.Value.Constant.Function.CallingConvention) void;
|
||||
pub extern fn NativityLLVMGetStruct(struct_type: *LLVM.Type.Struct, constant_ptr: [*]const *LLVM.Value.Constant, constant_len: usize) ?*LLVM.Value.Constant;
|
||||
|
||||
pub extern fn NativityLLVMValueToConstant(value: *LLVM.Value) ?*LLVM.Value.Constant;
|
||||
pub extern fn NativityLLVMValueToFunction(value: *LLVM.Value) ?*LLVM.Value.Function;
|
||||
pub extern fn NativityLLVMValueToFunction(value: *LLVM.Value) ?*LLVM.Value.Constant.Function;
|
||||
|
||||
pub extern fn NativityLLVMTypeIsPointer(type: *LLVM.Type) bool;
|
||||
pub extern fn NativityLLVMTypeIsInteger(type: *LLVM.Type) bool;
|
||||
@ -113,7 +121,7 @@ pub extern fn NativityLLVMTypeToPointer(Type: *LLVM.Type) ?*LLVM.Type.Pointer;
|
||||
|
||||
pub extern fn NativityLLVMArrayTypeGetElementType(array_type: *LLVM.Type.Array) ?*LLVM.Type;
|
||||
pub extern fn NativityLLVMLookupIntrinsic(name_ptr: [*]const u8, name_len: usize) LLVM.Value.IntrinsicID;
|
||||
pub extern fn NativityLLVMModuleGetIntrinsicDeclaration(module: *LLVM.Module, intrinsic_id: LLVM.Value.IntrinsicID, parameter_types_ptr: [*]const *LLVM.Type, parameter_type_count: usize) ?*LLVM.Value.Function;
|
||||
pub extern fn NativityLLVMModuleGetIntrinsicDeclaration(module: *LLVM.Module, intrinsic_id: LLVM.Value.IntrinsicID, parameter_types_ptr: [*]const *LLVM.Type, parameter_type_count: usize) ?*LLVM.Value.Constant.Function;
|
||||
pub extern fn NativityLLVMContextGetIntrinsicType(context: *LLVM.Context, intrinsic_id: LLVM.Value.IntrinsicID, parameter_type_ptr: [*]const *LLVM.Type, parameter_type_count: usize) ?*LLVM.Type.Function;
|
||||
pub extern fn NativityLLVMBuilderCreateExtractValue(builder: *LLVM.Builder, aggregate: *LLVM.Value, indices_ptr: [*]const c_uint, indices_len: usize, name_ptr: [*]const u8, name_len: usize) ?*LLVM.Value;
|
||||
pub extern fn NativityLLVMBuilderCreateInsertValue(builder: *LLVM.Builder, aggregate: *LLVM.Value, value: *LLVM.Value, indices_ptr: [*]const c_uint, indices_len: usize, name_ptr: [*]const u8, name_len: usize) ?*LLVM.Value;
|
||||
@ -127,5 +135,10 @@ pub extern fn NativityLLVMAllocatGetAllocatedType(alloca: *LLVM.Value.Instructio
|
||||
pub extern fn NativityLLVMValueToAlloca(value: *LLVM.Value) ?*LLVM.Value.Instruction.Alloca;
|
||||
pub extern fn NativityLLVMGlobalVariableSetInitializer(global_variable: *LLVM.Value.Constant.GlobalVariable, constant_initializer: *LLVM.Value.Constant) void;
|
||||
|
||||
pub extern fn NativityLLVMGenerateMachineCode(module: *LLVM.Module, object_file_path_ptr: [*]const u8, object_file_path_len: usize, file_path_ptr: [*]const u8, file_path_len: usize) bool;
|
||||
pub extern fn NativityLLVMInitializeCodeGeneration() void;
|
||||
pub extern fn NativityLLVMGetTarget(target_triple_ptr: [*]const u8, target_triple_len: usize, message_ptr: *[*]const u8, message_len: *usize) ?*LLVM.Target;
|
||||
pub extern fn NativityLLVMTargetCreateTargetMachine(target: *LLVM.Target, target_triple_ptr: [*]const u8, target_triple_len: usize, cpu_ptr: [*]const u8, cpu_len: usize, features_ptr: [*]const u8, features_len: usize, relocation_model: LLVM.RelocationModel, maybe_code_model: LLVM.CodeModel, is_code_model_present: bool, optimization_level: LLVM.OptimizationLevel, jit: bool) ?*LLVM.Target.Machine;
|
||||
pub extern fn NativityLLVMModuleSetTargetMachineDataLayout(module: *LLVM.Module, target_machine: *LLVM.Target.Machine) void;
|
||||
pub extern fn NativityLLVMModuleSetTargetTriple(module: *LLVM.Module, target_triple_ptr: [*]const u8, target_triple_len: usize) void;
|
||||
pub extern fn NativityLLVMModuleAddPassesToEmitFile(module: *LLVM.Module, target_machine: *LLVM.Target.Machine, object_file_path_ptr: [*]const u8, object_file_path_len: usize, codegen_file_type: LLVM.CodeGenFileType, disable_verify: bool) bool;
|
||||
pub extern fn NativityLLDLink(format: llvm.Format, argument_ptr: [*]const [*:0]const u8, argument_count: usize, stdout_ptr: *[*]const u8, stdout_len: *usize, stderr_ptr: *[*]const u8, stderr_len: *usize) bool;
|
||||
|
@ -1433,6 +1433,7 @@ const Analyzer = struct {
|
||||
}
|
||||
|
||||
logln(.parser, .suffix, "[DEPTH={}] Ending suffix call-like expression", .{analyzer.suffix_depth});
|
||||
logln(.parser, .suffix, "Callee node: {s}", .{@tagName(analyzer.nodes.get(result).id)});
|
||||
|
||||
_ = try analyzer.expectToken(.operator_right_parenthesis);
|
||||
// const is_comma = analyzer.tokens[analyzer.token_i].id == .comma;
|
||||
|
@ -5,6 +5,7 @@ pub fn build(b: *std.Build) !void {
|
||||
const self_hosted_ci = b.option(bool, "self_hosted_ci", "This option enables the self-hosted CI behavior") orelse false;
|
||||
const third_party_ci = b.option(bool, "third_party_ci", "This option enables the third-party CI behavior") orelse false;
|
||||
const is_ci = self_hosted_ci or third_party_ci;
|
||||
const print_stack_trace = b.option(bool, "print_stack_trace", "This option enables printing stack traces inside the compiler") orelse is_ci;
|
||||
const native_target = b.resolveTargetQuery(.{});
|
||||
const optimization = b.standardOptimizeOption(.{});
|
||||
var target_query = b.standardTargetOptionsQueryOnly(.{});
|
||||
@ -69,7 +70,7 @@ pub fn build(b: *std.Build) !void {
|
||||
}
|
||||
};
|
||||
const compiler_options = b.addOptions();
|
||||
compiler_options.addOption(bool, "print_stack_trace", is_ci);
|
||||
compiler_options.addOption(bool, "print_stack_trace", print_stack_trace);
|
||||
|
||||
const compiler = b.addExecutable(.{
|
||||
.name = "nat",
|
||||
@ -78,8 +79,8 @@ pub fn build(b: *std.Build) !void {
|
||||
.optimize = optimization,
|
||||
});
|
||||
compiler.root_module.addOptions("configuration", compiler_options);
|
||||
compiler.formatted_panics = is_ci;
|
||||
compiler.root_module.unwind_tables = is_ci;
|
||||
compiler.formatted_panics = print_stack_trace;
|
||||
compiler.root_module.unwind_tables = print_stack_trace;
|
||||
compiler.root_module.omit_frame_pointer = false;
|
||||
compiler.want_lto = false;
|
||||
|
||||
|
@ -100,7 +100,7 @@ pub fn main() !void {
|
||||
}
|
||||
|
||||
std.debug.print("\nTOTAL COMPILATIONS: {}. FAILED: {}\n", .{total_compilation_count, failed_compilation_count});
|
||||
std.debug.print("\nTOTAL TESTS: {}. RAN: {}. FAILED: {}\n", .{total_test_count, ran_test_count, failed_test_count});
|
||||
std.debug.print("TOTAL TESTS: {}. RAN: {}. FAILED: {}\n", .{total_test_count, ran_test_count, failed_test_count});
|
||||
|
||||
if (failed_compilation_count > 0 or failed_test_count > 0) {
|
||||
return error.fail;
|
||||
|
@ -160,7 +160,9 @@ const duplicate_process = fn () ?Process.Id {
|
||||
switch (current) {
|
||||
.linux => {
|
||||
if (linux.unwrap_syscall(syscall_result = linux.fork())) |fork_result| {
|
||||
return #cast(fork_result);
|
||||
const unsigned: u32 = #cast(fork_result);
|
||||
const signed: s32 = #cast(unsigned);
|
||||
return signed;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -411,7 +411,9 @@ const get_map_flags = fn(flags: std.os.MapFlags) MapFlags{
|
||||
}
|
||||
|
||||
const mmap = fn(address: ?[&]u8, length: usize, protection_flags: ProtectionFlags, map_flags: MapFlags, fd: s32, offset: u64) usize {
|
||||
const result = #syscall(#cast(Syscall.mmap), #cast(address), length, #cast(protection_flags), #cast(map_flags), #cast(fd), offset);
|
||||
const flat_protection_flags: u32 = #cast(protection_flags);
|
||||
const flat_map_flags: u32 = #cast(map_flags);
|
||||
const result = #syscall(#cast(Syscall.mmap), #cast(address), length, flat_protection_flags, flat_map_flags, #cast(fd), offset);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
27
test/standalone/bit_struct/main.nat
Normal file
27
test/standalone/bit_struct/main.nat
Normal file
@ -0,0 +1,27 @@
|
||||
const BitStruct = struct(u8) {
|
||||
a: bool,
|
||||
b: bool,
|
||||
c: bool,
|
||||
d: u5,
|
||||
};
|
||||
|
||||
const main = fn () s32 {
|
||||
var bs = BitStruct{
|
||||
.a = false,
|
||||
.b = true,
|
||||
.c = true,
|
||||
.d = 0,
|
||||
};
|
||||
const bitcast_bs: u8 = #cast(bs);
|
||||
#assert(bitcast_bs == 6);
|
||||
|
||||
const const_bs = BitStruct{
|
||||
.a = true,
|
||||
.b = false,
|
||||
.c = true,
|
||||
.d = 0,
|
||||
};
|
||||
const bitcast_const_bs: u8 = #cast(const_bs);
|
||||
#assert(bitcast_const_bs == 5);
|
||||
return 0;
|
||||
}
|
28
test/standalone/bit_struct_call/main.nat
Normal file
28
test/standalone/bit_struct_call/main.nat
Normal file
@ -0,0 +1,28 @@
|
||||
const A = struct(u8) {
|
||||
a: u4,
|
||||
b: u4,
|
||||
};
|
||||
const B = struct(u8) {
|
||||
b: u4,
|
||||
a: u4,
|
||||
};
|
||||
|
||||
const transform = fn (a: A) B {
|
||||
return B{
|
||||
.a = a.a,
|
||||
.b = a.b,
|
||||
};
|
||||
}
|
||||
|
||||
const main = fn () s32 {
|
||||
var a = A{
|
||||
.a = 3,
|
||||
.b = 8,
|
||||
};
|
||||
|
||||
const b = transform(a);
|
||||
#assert(a.a == b.a);
|
||||
#assert(a.b == b.b);
|
||||
|
||||
return 0;
|
||||
}
|
@ -5,7 +5,7 @@ const main = fn() s32 {
|
||||
if (pid == 0) {
|
||||
std.print(bytes = "Hello from child\n");
|
||||
const argv = [_:null] ?[&:0]const u8{"/usr/bin/ls"};
|
||||
std.os.execute(path = "/usr/bin/ls", argv = argv.&, env = std.start.environment_values);
|
||||
_ = std.os.execute(path = "/usr/bin/ls", argv = argv.&, env = std.start.environment_values);
|
||||
return 1;
|
||||
} else {
|
||||
std.print(bytes = "Hello from parent\n");
|
11
test/standalone/function_pointer/main.nat
Normal file
11
test/standalone/function_pointer/main.nat
Normal file
@ -0,0 +1,11 @@
|
||||
const expected_number = 123;
|
||||
|
||||
const foo = fn () s32 {
|
||||
return expected_number;
|
||||
}
|
||||
|
||||
const main = fn () s32 {
|
||||
var function_pointer = foo.&;
|
||||
const result = function_pointer();
|
||||
return result - expected_number;
|
||||
}
|
23
test/standalone/function_pointer_struct/main.nat
Normal file
23
test/standalone/function_pointer_struct/main.nat
Normal file
@ -0,0 +1,23 @@
|
||||
const expected_number = 123;
|
||||
|
||||
const foo = fn () s32 {
|
||||
return expected_number;
|
||||
}
|
||||
|
||||
const Struct = struct{
|
||||
a: s32,
|
||||
handler: &const fn(s: &Struct) s32,
|
||||
|
||||
const handler_function = fn (s: &Struct) s32 {
|
||||
return s.a;
|
||||
}
|
||||
};
|
||||
|
||||
const main = fn () s32 {
|
||||
var s = Struct{
|
||||
.a = expected_number,
|
||||
.handler = Struct.handler_function.&,
|
||||
};
|
||||
|
||||
return s.handler(s.&) - expected_number;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user