mirror of
https://github.com/ziglang/zig.git
synced 2025-01-07 10:45:17 +00:00
Merge remote-tracking branch 'origin/master' into llvm8
This commit is contained in:
commit
0714e19598
@ -13,28 +13,28 @@ tasks:
|
||||
- test: |
|
||||
cd zig/build
|
||||
bin/zig test ../test/stage1/behavior.zig
|
||||
bin/zig test ../std/special/compiler_rt/index.zig
|
||||
bin/zig test ../std/special/compiler_rt.zig
|
||||
|
||||
bin/zig test ../test/stage1/behavior.zig --library c
|
||||
bin/zig test ../std/special/compiler_rt/index.zig --library c
|
||||
bin/zig test ../std/special/compiler_rt.zig --library c
|
||||
|
||||
bin/zig test ../test/stage1/behavior.zig --release-fast
|
||||
bin/zig test ../std/special/compiler_rt/index.zig --release-fast
|
||||
bin/zig test ../std/special/compiler_rt.zig --release-fast
|
||||
|
||||
bin/zig test ../test/stage1/behavior.zig --release-fast --library c
|
||||
bin/zig test ../std/special/compiler_rt/index.zig --release-fast --library c
|
||||
bin/zig test ../std/special/compiler_rt.zig --release-fast --library c
|
||||
|
||||
bin/zig test ../test/stage1/behavior.zig --release-small --library c
|
||||
bin/zig test ../std/special/compiler_rt/index.zig --release-small --library c
|
||||
bin/zig test ../std/special/compiler_rt.zig --release-small --library c
|
||||
|
||||
bin/zig test ../test/stage1/behavior.zig --release-small
|
||||
bin/zig test ../std/special/compiler_rt/index.zig --release-small
|
||||
bin/zig test ../std/special/compiler_rt.zig --release-small
|
||||
|
||||
bin/zig test ../test/stage1/behavior.zig --release-safe
|
||||
bin/zig test ../std/special/compiler_rt/index.zig --release-safe
|
||||
bin/zig test ../std/special/compiler_rt.zig --release-safe
|
||||
|
||||
bin/zig test ../test/stage1/behavior.zig --release-safe --library c
|
||||
bin/zig test ../std/special/compiler_rt/index.zig --release-safe --library c
|
||||
bin/zig test ../std/special/compiler_rt.zig --release-safe --library c
|
||||
# TODO enable all tests
|
||||
#bin/zig build --build-file ../build.zig test
|
||||
# TODO integrate with the download page updater and make a
|
||||
|
@ -442,7 +442,7 @@ set(ZIG_CPP_SOURCES
|
||||
|
||||
set(ZIG_STD_FILES
|
||||
"array_list.zig"
|
||||
"atomic/index.zig"
|
||||
"atomic.zig"
|
||||
"atomic/int.zig"
|
||||
"atomic/queue.zig"
|
||||
"atomic/stack.zig"
|
||||
@ -452,17 +452,17 @@ set(ZIG_STD_FILES
|
||||
"buffer.zig"
|
||||
"build.zig"
|
||||
"build/fmt.zig"
|
||||
"c.zig"
|
||||
"c/darwin.zig"
|
||||
"c/freebsd.zig"
|
||||
"c/index.zig"
|
||||
"c/linux.zig"
|
||||
"c/netbsd.zig"
|
||||
"c/windows.zig"
|
||||
"coff.zig"
|
||||
"crypto.zig"
|
||||
"crypto/blake2.zig"
|
||||
"crypto/chacha20.zig"
|
||||
"crypto/hmac.zig"
|
||||
"crypto/index.zig"
|
||||
"crypto/md5.zig"
|
||||
"crypto/poly1305.zig"
|
||||
"crypto/sha1.zig"
|
||||
@ -470,8 +470,8 @@ set(ZIG_STD_FILES
|
||||
"crypto/sha3.zig"
|
||||
"crypto/x25519.zig"
|
||||
"cstr.zig"
|
||||
"debug.zig"
|
||||
"debug/failing_allocator.zig"
|
||||
"debug/index.zig"
|
||||
"dwarf.zig"
|
||||
"dynamic_library.zig"
|
||||
"elf.zig"
|
||||
@ -488,25 +488,25 @@ set(ZIG_STD_FILES
|
||||
"event/net.zig"
|
||||
"event/rwlock.zig"
|
||||
"event/rwlocked.zig"
|
||||
"fmt.zig"
|
||||
"fmt/errol.zig"
|
||||
"fmt/errol/enum3.zig"
|
||||
"fmt/errol/index.zig"
|
||||
"fmt/errol/lookup.zig"
|
||||
"fmt/index.zig"
|
||||
"fmt/parse_float.zig"
|
||||
"hash.zig"
|
||||
"hash/adler.zig"
|
||||
"hash/crc.zig"
|
||||
"hash/fnv.zig"
|
||||
"hash/index.zig"
|
||||
"hash/siphash.zig"
|
||||
"hash_map.zig"
|
||||
"heap.zig"
|
||||
"index.zig"
|
||||
"io.zig"
|
||||
"io/seekable_stream.zig"
|
||||
"json.zig"
|
||||
"lazy_init.zig"
|
||||
"linked_list.zig"
|
||||
"macho.zig"
|
||||
"math.zig"
|
||||
"math/acos.zig"
|
||||
"math/acosh.zig"
|
||||
"math/asin.zig"
|
||||
@ -514,10 +514,11 @@ set(ZIG_STD_FILES
|
||||
"math/atan.zig"
|
||||
"math/atan2.zig"
|
||||
"math/atanh.zig"
|
||||
"math/big/index.zig"
|
||||
"math/big.zig"
|
||||
"math/big/int.zig"
|
||||
"math/cbrt.zig"
|
||||
"math/ceil.zig"
|
||||
"math/complex.zig"
|
||||
"math/complex/abs.zig"
|
||||
"math/complex/acos.zig"
|
||||
"math/complex/acosh.zig"
|
||||
@ -530,7 +531,6 @@ set(ZIG_STD_FILES
|
||||
"math/complex/cos.zig"
|
||||
"math/complex/cosh.zig"
|
||||
"math/complex/exp.zig"
|
||||
"math/complex/index.zig"
|
||||
"math/complex/ldexp.zig"
|
||||
"math/complex/log.zig"
|
||||
"math/complex/pow.zig"
|
||||
@ -553,7 +553,6 @@ set(ZIG_STD_FILES
|
||||
"math/frexp.zig"
|
||||
"math/hypot.zig"
|
||||
"math/ilogb.zig"
|
||||
"math/index.zig"
|
||||
"math/inf.zig"
|
||||
"math/isfinite.zig"
|
||||
"math/isinf.zig"
|
||||
@ -578,50 +577,51 @@ set(ZIG_STD_FILES
|
||||
"math/tanh.zig"
|
||||
"math/trunc.zig"
|
||||
"mem.zig"
|
||||
"meta/index.zig"
|
||||
"meta.zig"
|
||||
"meta/trait.zig"
|
||||
"mutex.zig"
|
||||
"net.zig"
|
||||
"os.zig"
|
||||
"os/child_process.zig"
|
||||
"os/darwin.zig"
|
||||
"os/darwin/errno.zig"
|
||||
"os/epoch.zig"
|
||||
"os/file.zig"
|
||||
"os/freebsd.zig"
|
||||
"os/freebsd/errno.zig"
|
||||
"os/freebsd/index.zig"
|
||||
"os/get_app_data_dir.zig"
|
||||
"os/get_user_id.zig"
|
||||
"os/index.zig"
|
||||
"os/linux.zig"
|
||||
"os/linux/arm64.zig"
|
||||
"os/linux/errno.zig"
|
||||
"os/linux/index.zig"
|
||||
"os/linux/vdso.zig"
|
||||
"os/linux/x86_64.zig"
|
||||
"os/netbsd.zig"
|
||||
"os/netbsd/errno.zig"
|
||||
"os/netbsd/index.zig"
|
||||
"os/path.zig"
|
||||
"os/time.zig"
|
||||
"os/uefi.zig"
|
||||
"os/windows.zig"
|
||||
"os/windows/advapi32.zig"
|
||||
"os/windows/error.zig"
|
||||
"os/windows/index.zig"
|
||||
"os/windows/kernel32.zig"
|
||||
"os/windows/ntdll.zig"
|
||||
"os/windows/ole32.zig"
|
||||
"os/windows/shell32.zig"
|
||||
"os/windows/tls.zig"
|
||||
"os/windows/util.zig"
|
||||
"os/zen.zig"
|
||||
"pdb.zig"
|
||||
"priority_queue.zig"
|
||||
"rand/index.zig"
|
||||
"rand.zig"
|
||||
"rand/ziggurat.zig"
|
||||
"segmented_list.zig"
|
||||
"sort.zig"
|
||||
"special/bootstrap.zig"
|
||||
"special/bootstrap_lib.zig"
|
||||
"special/bootstrap_windows_tls.zig"
|
||||
"special/build_runner.zig"
|
||||
"special/builtin.zig"
|
||||
"special/compiler_rt.zig"
|
||||
"special/compiler_rt/addXf3.zig"
|
||||
"special/compiler_rt/aulldiv.zig"
|
||||
"special/compiler_rt/aullrem.zig"
|
||||
@ -656,7 +656,6 @@ set(ZIG_STD_FILES
|
||||
"special/compiler_rt/floatuntidf.zig"
|
||||
"special/compiler_rt/floatuntisf.zig"
|
||||
"special/compiler_rt/floatuntitf.zig"
|
||||
"special/compiler_rt/index.zig"
|
||||
"special/compiler_rt/muloti4.zig"
|
||||
"special/compiler_rt/multi3.zig"
|
||||
"special/compiler_rt/truncXfYf2.zig"
|
||||
@ -674,10 +673,11 @@ set(ZIG_STD_FILES
|
||||
"special/test_runner.zig"
|
||||
"spinlock.zig"
|
||||
"statically_initialized_mutex.zig"
|
||||
"std.zig"
|
||||
"testing.zig"
|
||||
"unicode.zig"
|
||||
"zig.zig"
|
||||
"zig/ast.zig"
|
||||
"zig/index.zig"
|
||||
"zig/parse.zig"
|
||||
"zig/parse_string_literal.zig"
|
||||
"zig/render.zig"
|
||||
|
@ -115,9 +115,9 @@ pub fn build(b: *Builder) !void {
|
||||
|
||||
test_step.dependOn(tests.addPkgTests(b, test_filter, "test/stage1/behavior.zig", "behavior", "Run the behavior tests", modes));
|
||||
|
||||
test_step.dependOn(tests.addPkgTests(b, test_filter, "std/index.zig", "std", "Run the standard library tests", modes));
|
||||
test_step.dependOn(tests.addPkgTests(b, test_filter, "std/std.zig", "std", "Run the standard library tests", modes));
|
||||
|
||||
test_step.dependOn(tests.addPkgTests(b, test_filter, "std/special/compiler_rt/index.zig", "compiler-rt", "Run the compiler_rt tests", modes));
|
||||
test_step.dependOn(tests.addPkgTests(b, test_filter, "std/special/compiler_rt.zig", "compiler-rt", "Run the compiler_rt tests", modes));
|
||||
|
||||
test_step.dependOn(tests.addCompareOutputTests(b, test_filter, modes));
|
||||
test_step.dependOn(tests.addBuildExampleTests(b, test_filter, modes));
|
||||
|
@ -6116,7 +6116,7 @@ test "main" {
|
||||
{#header_close#}
|
||||
|
||||
{#header_open|@frameAddress#}
|
||||
<pre>{#syntax#}@frameAddress(){#endsyntax#}</pre>
|
||||
<pre>{#syntax#}@frameAddress() usize{#endsyntax#}</pre>
|
||||
<p>
|
||||
This function returns the base pointer of the current stack frame.
|
||||
</p>
|
||||
@ -6482,17 +6482,18 @@ test "call foo" {
|
||||
{#header_close#}
|
||||
|
||||
{#header_open|@returnAddress#}
|
||||
<pre>{#syntax#}@returnAddress(){#endsyntax#}</pre>
|
||||
<pre>{#syntax#}@returnAddress() usize{#endsyntax#}</pre>
|
||||
<p>
|
||||
This function returns a pointer to the return address of the current stack
|
||||
frame.
|
||||
This function returns the address of the next machine code instruction that will be executed
|
||||
when the current function returns.
|
||||
</p>
|
||||
<p>
|
||||
The implications of this are target specific and not consistent across
|
||||
all platforms.
|
||||
</p>
|
||||
<p>
|
||||
This function is only valid within function scope.
|
||||
This function is only valid within function scope. If the function gets inlined into
|
||||
a calling function, the returned address will apply to the calling function.
|
||||
</p>
|
||||
{#header_close#}
|
||||
{#header_open|@setAlignStack#}
|
||||
@ -6785,7 +6786,6 @@ pub const TypeId = enum {
|
||||
Enum,
|
||||
Union,
|
||||
Fn,
|
||||
Namespace,
|
||||
Block,
|
||||
BoundFn,
|
||||
ArgTuple,
|
||||
@ -6820,7 +6820,6 @@ pub const TypeInfo = union(TypeId) {
|
||||
Enum: Enum,
|
||||
Union: Union,
|
||||
Fn: Fn,
|
||||
Namespace: void,
|
||||
BoundFn: Fn,
|
||||
ArgTuple: void,
|
||||
Opaque: void,
|
||||
@ -6829,18 +6828,18 @@ pub const TypeInfo = union(TypeId) {
|
||||
|
||||
pub const Int = struct {
|
||||
is_signed: bool,
|
||||
bits: u8,
|
||||
bits: comptime_int,
|
||||
};
|
||||
|
||||
pub const Float = struct {
|
||||
bits: u8,
|
||||
bits: comptime_int,
|
||||
};
|
||||
|
||||
pub const Pointer = struct {
|
||||
size: Size,
|
||||
is_const: bool,
|
||||
is_volatile: bool,
|
||||
alignment: u32,
|
||||
alignment: comptime_int,
|
||||
child: type,
|
||||
|
||||
pub const Size = enum {
|
||||
@ -6851,7 +6850,7 @@ pub const TypeInfo = union(TypeId) {
|
||||
};
|
||||
|
||||
pub const Array = struct {
|
||||
len: usize,
|
||||
len: comptime_int,
|
||||
child: type,
|
||||
};
|
||||
|
||||
@ -6863,7 +6862,7 @@ pub const TypeInfo = union(TypeId) {
|
||||
|
||||
pub const StructField = struct {
|
||||
name: []const u8,
|
||||
offset: ?usize,
|
||||
offset: ?comptime_int,
|
||||
field_type: type,
|
||||
};
|
||||
|
||||
@ -6884,7 +6883,7 @@ pub const TypeInfo = union(TypeId) {
|
||||
|
||||
pub const Error = struct {
|
||||
name: []const u8,
|
||||
value: usize,
|
||||
value: comptime_int,
|
||||
};
|
||||
|
||||
pub const ErrorSet = struct {
|
||||
@ -6893,7 +6892,7 @@ pub const TypeInfo = union(TypeId) {
|
||||
|
||||
pub const EnumField = struct {
|
||||
name: []const u8,
|
||||
value: usize,
|
||||
value: comptime_int,
|
||||
};
|
||||
|
||||
pub const Enum = struct {
|
||||
@ -8167,17 +8166,18 @@ coding style.
|
||||
</p>
|
||||
<ul>
|
||||
<li>
|
||||
If {#syntax#}x{#endsyntax#} is a {#syntax#}struct{#endsyntax#} (or an alias of a {#syntax#}struct{#endsyntax#}),
|
||||
then {#syntax#}x{#endsyntax#} should be {#syntax#}TitleCase{#endsyntax#}.
|
||||
If {#syntax#}x{#endsyntax#} is a {#syntax#}type{#endsyntax#}
|
||||
then {#syntax#}x{#endsyntax#} should be {#syntax#}TitleCase{#endsyntax#}, unless it
|
||||
is a {#syntax#}struct{#endsyntax#} with 0 fields and is never meant to be instantiated,
|
||||
in which case it is considered to be a "namespace" and uses {#syntax#}snake_case{#endsyntax#}.
|
||||
</li>
|
||||
<li>
|
||||
If {#syntax#}x{#endsyntax#} otherwise identifies a type, {#syntax#}x{#endsyntax#} should have {#syntax#}snake_case{#endsyntax#}.
|
||||
If {#syntax#}x{#endsyntax#} is callable, and {#syntax#}x{#endsyntax#}'s return type is
|
||||
{#syntax#}type{#endsyntax#}, then {#syntax#}x{#endsyntax#} should be {#syntax#}TitleCase{#endsyntax#}.
|
||||
</li>
|
||||
<li>
|
||||
If {#syntax#}x{#endsyntax#} is callable, and {#syntax#}x{#endsyntax#}'s return type is {#syntax#}type{#endsyntax#}, then {#syntax#}x{#endsyntax#} should be {#syntax#}TitleCase{#endsyntax#}.
|
||||
</li>
|
||||
<li>
|
||||
If {#syntax#}x{#endsyntax#} is otherwise callable, then {#syntax#}x{#endsyntax#} should be {#syntax#}camelCase{#endsyntax#}.
|
||||
If {#syntax#}x{#endsyntax#} is otherwise callable, then {#syntax#}x{#endsyntax#} should
|
||||
be {#syntax#}camelCase{#endsyntax#}.
|
||||
</li>
|
||||
<li>
|
||||
Otherwise, {#syntax#}x{#endsyntax#} should be {#syntax#}snake_case{#endsyntax#}.
|
||||
@ -8203,7 +8203,9 @@ const const_name = 42;
|
||||
const primitive_type_alias = f32;
|
||||
const string_alias = []u8;
|
||||
|
||||
const StructName = struct {};
|
||||
const StructName = struct {
|
||||
field: i32,
|
||||
};
|
||||
const StructAlias = StructName;
|
||||
|
||||
fn functionName(param_name: TypeName) void {
|
||||
@ -8231,7 +8233,9 @@ const xml_document =
|
||||
\\<document>
|
||||
\\</document>
|
||||
;
|
||||
const XmlParser = struct {};
|
||||
const XmlParser = struct {
|
||||
field: i32,
|
||||
};
|
||||
|
||||
// The initials BE (Big Endian) are just another word in Zig identifier names.
|
||||
fn readU32Be() u32 {}
|
||||
|
@ -47,7 +47,7 @@ pub const ZigCompiler = struct {
|
||||
|
||||
var lazy_init_targets = std.lazyInit(void);
|
||||
|
||||
fn init(loop: *event.Loop) !ZigCompiler {
|
||||
pub fn init(loop: *event.Loop) !ZigCompiler {
|
||||
lazy_init_targets.get() orelse {
|
||||
Target.initializeAll();
|
||||
lazy_init_targets.resolve();
|
||||
@ -533,7 +533,7 @@ pub const Compilation = struct {
|
||||
const basename = std.os.path.basename(root_src);
|
||||
|
||||
comp.root_package = try Package.create(comp.arena(), dirname, basename);
|
||||
comp.std_package = try Package.create(comp.arena(), comp.zig_std_dir, "index.zig");
|
||||
comp.std_package = try Package.create(comp.arena(), comp.zig_std_dir, "std.zig");
|
||||
try comp.root_package.add("std", comp.std_package);
|
||||
} else {
|
||||
comp.root_package = try Package.create(comp.arena(), ".", "");
|
||||
|
@ -11,7 +11,7 @@ pub fn testZigInstallPrefix(allocator: *mem.Allocator, test_path: []const u8) ![
|
||||
const test_zig_dir = try os.path.join(allocator, [][]const u8{ test_path, "lib", "zig" });
|
||||
errdefer allocator.free(test_zig_dir);
|
||||
|
||||
const test_index_file = try os.path.join(allocator, [][]const u8{ test_zig_dir, "std", "index.zig" });
|
||||
const test_index_file = try os.path.join(allocator, [][]const u8{ test_zig_dir, "std", "std.zig" });
|
||||
defer allocator.free(test_index_file);
|
||||
|
||||
var file = try os.File.openRead(test_index_file);
|
||||
|
@ -39,7 +39,6 @@ pub const Type = struct {
|
||||
Id.ErrorSet => @fieldParentPtr(ErrorSet, "base", base).destroy(comp),
|
||||
Id.Enum => @fieldParentPtr(Enum, "base", base).destroy(comp),
|
||||
Id.Union => @fieldParentPtr(Union, "base", base).destroy(comp),
|
||||
Id.Namespace => @fieldParentPtr(Namespace, "base", base).destroy(comp),
|
||||
Id.BoundFn => @fieldParentPtr(BoundFn, "base", base).destroy(comp),
|
||||
Id.ArgTuple => @fieldParentPtr(ArgTuple, "base", base).destroy(comp),
|
||||
Id.Opaque => @fieldParentPtr(Opaque, "base", base).destroy(comp),
|
||||
@ -73,7 +72,6 @@ pub const Type = struct {
|
||||
Id.ErrorSet => return @fieldParentPtr(ErrorSet, "base", base).getLlvmType(allocator, llvm_context),
|
||||
Id.Enum => return @fieldParentPtr(Enum, "base", base).getLlvmType(allocator, llvm_context),
|
||||
Id.Union => return @fieldParentPtr(Union, "base", base).getLlvmType(allocator, llvm_context),
|
||||
Id.Namespace => unreachable,
|
||||
Id.BoundFn => return @fieldParentPtr(BoundFn, "base", base).getLlvmType(allocator, llvm_context),
|
||||
Id.ArgTuple => unreachable,
|
||||
Id.Opaque => return @fieldParentPtr(Opaque, "base", base).getLlvmType(allocator, llvm_context),
|
||||
@ -89,7 +87,6 @@ pub const Type = struct {
|
||||
Id.ComptimeInt,
|
||||
Id.Undefined,
|
||||
Id.Null,
|
||||
Id.Namespace,
|
||||
Id.BoundFn,
|
||||
Id.ArgTuple,
|
||||
Id.Opaque,
|
||||
@ -123,7 +120,6 @@ pub const Type = struct {
|
||||
Id.ComptimeInt,
|
||||
Id.Undefined,
|
||||
Id.Null,
|
||||
Id.Namespace,
|
||||
Id.BoundFn,
|
||||
Id.ArgTuple,
|
||||
Id.Opaque,
|
||||
@ -1020,14 +1016,6 @@ pub const Type = struct {
|
||||
}
|
||||
};
|
||||
|
||||
pub const Namespace = struct {
|
||||
base: Type,
|
||||
|
||||
pub fn destroy(self: *Namespace, comp: *Compilation) void {
|
||||
comp.gpa().destroy(self);
|
||||
}
|
||||
};
|
||||
|
||||
pub const BoundFn = struct {
|
||||
base: Type,
|
||||
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include "libc_installation.hpp"
|
||||
|
||||
struct AstNode;
|
||||
struct ImportTableEntry;
|
||||
struct ZigFn;
|
||||
struct Scope;
|
||||
struct ScopeBlock;
|
||||
@ -317,7 +316,6 @@ struct ConstExprValue {
|
||||
ConstUnionValue x_union;
|
||||
ConstArrayValue x_array;
|
||||
ConstPtrValue x_ptr;
|
||||
ImportTableEntry *x_import;
|
||||
ConstArgTuple x_arg_tuple;
|
||||
|
||||
// populated if special == ConstValSpecialRuntime
|
||||
@ -369,10 +367,8 @@ struct Tld {
|
||||
VisibMod visib_mod;
|
||||
AstNode *source_node;
|
||||
|
||||
ImportTableEntry *import;
|
||||
ZigType *import;
|
||||
Scope *parent_scope;
|
||||
// set this flag temporarily to detect infinite loops
|
||||
bool dep_loop_flag;
|
||||
TldResolution resolution;
|
||||
};
|
||||
|
||||
@ -382,6 +378,7 @@ struct TldVar {
|
||||
ZigVar *var;
|
||||
Buf *extern_lib_name;
|
||||
Buf *section_name;
|
||||
bool analyzing_type; // flag to detect dependency loops
|
||||
};
|
||||
|
||||
struct TldFn {
|
||||
@ -700,7 +697,7 @@ struct AstNodeUse {
|
||||
AstNode *expr;
|
||||
|
||||
TldResolution resolution;
|
||||
ConstExprValue *value;
|
||||
ConstExprValue *using_namespace_value;
|
||||
};
|
||||
|
||||
struct AstNodeIfBoolExpr {
|
||||
@ -937,7 +934,7 @@ struct AstNode {
|
||||
enum NodeType type;
|
||||
size_t line;
|
||||
size_t column;
|
||||
ImportTableEntry *owner;
|
||||
ZigType *owner;
|
||||
union {
|
||||
AstNodeFnDef fn_def;
|
||||
AstNodeFnProto fn_proto;
|
||||
@ -1075,12 +1072,32 @@ enum ResolveStatus {
|
||||
ResolveStatusSizeKnown,
|
||||
};
|
||||
|
||||
struct ZigPackage {
|
||||
Buf root_src_dir;
|
||||
Buf root_src_path; // relative to root_src_dir
|
||||
Buf pkg_path; // a.b.c.d which follows the package dependency chain from the root package
|
||||
|
||||
// reminder: hash tables must be initialized before use
|
||||
HashMap<Buf *, ZigPackage *, buf_hash, buf_eql_buf> package_table;
|
||||
};
|
||||
|
||||
// Stuff that only applies to a struct which is the implicit root struct of a file
|
||||
struct RootStruct {
|
||||
ZigPackage *package;
|
||||
Buf *path; // relative to root_package->root_src_dir
|
||||
ZigList<size_t> *line_offsets;
|
||||
Buf *source_code;
|
||||
AstNode *c_import_node;
|
||||
ZigLLVMDIFile *di_file;
|
||||
};
|
||||
|
||||
struct ZigTypeStruct {
|
||||
AstNode *decl_node;
|
||||
TypeStructField *fields;
|
||||
ScopeDecls *decls_scope;
|
||||
uint64_t size_bytes;
|
||||
HashMap<Buf *, TypeStructField *, buf_hash, buf_eql_buf> fields_by_name;
|
||||
RootStruct *root_struct;
|
||||
|
||||
uint32_t src_field_count;
|
||||
uint32_t gen_field_count;
|
||||
@ -1232,7 +1249,6 @@ enum ZigTypeId {
|
||||
ZigTypeIdEnum,
|
||||
ZigTypeIdUnion,
|
||||
ZigTypeIdFn,
|
||||
ZigTypeIdNamespace,
|
||||
ZigTypeIdBoundFn,
|
||||
ZigTypeIdArgTuple,
|
||||
ZigTypeIdOpaque,
|
||||
@ -1246,6 +1262,10 @@ enum OnePossibleValue {
|
||||
OnePossibleValueYes,
|
||||
};
|
||||
|
||||
struct ZigTypeOpaque {
|
||||
Buf *bare_name;
|
||||
};
|
||||
|
||||
struct ZigType {
|
||||
ZigTypeId id;
|
||||
Buf name;
|
||||
@ -1268,6 +1288,7 @@ struct ZigType {
|
||||
ZigTypeBoundFn bound_fn;
|
||||
ZigTypePromise promise;
|
||||
ZigTypeVector vector;
|
||||
ZigTypeOpaque opaque;
|
||||
} data;
|
||||
|
||||
// use these fields to make sure we don't duplicate type table entries for the same type
|
||||
@ -1285,29 +1306,6 @@ struct ZigType {
|
||||
bool gen_h_loop_flag;
|
||||
};
|
||||
|
||||
struct PackageTableEntry {
|
||||
Buf root_src_dir;
|
||||
Buf root_src_path; // relative to root_src_dir
|
||||
|
||||
// reminder: hash tables must be initialized before use
|
||||
HashMap<Buf *, PackageTableEntry *, buf_hash, buf_eql_buf> package_table;
|
||||
};
|
||||
|
||||
struct ImportTableEntry {
|
||||
AstNode *root;
|
||||
Buf *path; // relative to root_package->root_src_dir
|
||||
PackageTableEntry *package;
|
||||
ZigLLVMDIFile *di_file;
|
||||
Buf *source_code;
|
||||
ZigList<size_t> *line_offsets;
|
||||
ScopeDecls *decls_scope;
|
||||
AstNode *c_import_node;
|
||||
bool any_imports_failed;
|
||||
bool scanned;
|
||||
|
||||
ZigList<AstNode *> use_decls;
|
||||
};
|
||||
|
||||
enum FnAnalState {
|
||||
FnAnalStateReady,
|
||||
FnAnalStateProbing,
|
||||
@ -1670,7 +1668,7 @@ struct CodeGen {
|
||||
LLVMValueRef return_err_fn;
|
||||
|
||||
// reminder: hash tables must be initialized before use
|
||||
HashMap<Buf *, ImportTableEntry *, buf_hash, buf_eql_buf> import_table;
|
||||
HashMap<Buf *, ZigType *, buf_hash, buf_eql_buf> import_table;
|
||||
HashMap<Buf *, BuiltinFnEntry *, buf_hash, buf_eql_buf> builtin_fn_table;
|
||||
HashMap<Buf *, ZigType *, buf_hash, buf_eql_buf> primitive_type_table;
|
||||
HashMap<TypeId, ZigType *, type_id_hash, type_id_eql> type_table;
|
||||
@ -1684,8 +1682,6 @@ struct CodeGen {
|
||||
HashMap<Buf *, ConstExprValue *, buf_hash, buf_eql_buf> string_literals_table;
|
||||
HashMap<const ZigType *, ConstExprValue *, type_ptr_hash, type_ptr_eql> type_info_cache;
|
||||
|
||||
ZigList<ImportTableEntry *> import_queue;
|
||||
size_t import_queue_index;
|
||||
ZigList<Tld *> resolve_queue;
|
||||
size_t resolve_queue_index;
|
||||
ZigList<AstNode *> use_queue;
|
||||
@ -1699,14 +1695,14 @@ struct CodeGen {
|
||||
ZigList<ErrorTableEntry *> errors_by_index;
|
||||
size_t largest_err_name_len;
|
||||
|
||||
PackageTableEntry *std_package;
|
||||
PackageTableEntry *panic_package;
|
||||
PackageTableEntry *test_runner_package;
|
||||
PackageTableEntry *compile_var_package;
|
||||
ImportTableEntry *compile_var_import;
|
||||
ImportTableEntry *root_import;
|
||||
ImportTableEntry *bootstrap_import;
|
||||
ImportTableEntry *test_runner_import;
|
||||
ZigPackage *std_package;
|
||||
ZigPackage *panic_package;
|
||||
ZigPackage *test_runner_package;
|
||||
ZigPackage *compile_var_package;
|
||||
ZigType *compile_var_import;
|
||||
ZigType *root_import;
|
||||
ZigType *bootstrap_import;
|
||||
ZigType *test_runner_import;
|
||||
|
||||
struct {
|
||||
ZigType *entry_bool;
|
||||
@ -1731,7 +1727,6 @@ struct CodeGen {
|
||||
ZigType *entry_unreachable;
|
||||
ZigType *entry_type;
|
||||
ZigType *entry_invalid;
|
||||
ZigType *entry_namespace;
|
||||
ZigType *entry_block;
|
||||
ZigType *entry_num_lit_int;
|
||||
ZigType *entry_num_lit_float;
|
||||
@ -1851,7 +1846,7 @@ struct CodeGen {
|
||||
Buf *root_out_name;
|
||||
Buf *test_filter;
|
||||
Buf *test_name_prefix;
|
||||
PackageTableEntry *root_package;
|
||||
ZigPackage *root_package;
|
||||
Buf *zig_lib_dir;
|
||||
Buf *zig_std_dir;
|
||||
|
||||
@ -1945,13 +1940,17 @@ struct ScopeDecls {
|
||||
Scope base;
|
||||
|
||||
HashMap<Buf *, Tld *, buf_hash, buf_eql_buf> decl_table;
|
||||
bool safety_off;
|
||||
ZigList<AstNode *> use_decls;
|
||||
AstNode *safety_set_node;
|
||||
bool fast_math_on;
|
||||
AstNode *fast_math_set_node;
|
||||
ImportTableEntry *import;
|
||||
ZigType *import;
|
||||
// If this is a scope from a container, this is the type entry, otherwise null
|
||||
ZigType *container_type;
|
||||
Buf *bare_name;
|
||||
|
||||
bool safety_off;
|
||||
bool fast_math_on;
|
||||
bool any_imports_failed;
|
||||
};
|
||||
|
||||
// This scope comes from a block expression in user code.
|
||||
@ -3463,7 +3462,8 @@ static const size_t err_union_err_index = 0;
|
||||
static const size_t err_union_payload_index = 1;
|
||||
|
||||
// TODO call graph analysis to find out what this number needs to be for every function
|
||||
static const size_t stack_trace_ptr_count = 30;
|
||||
// MUST BE A POWER OF TWO.
|
||||
static const size_t stack_trace_ptr_count = 32;
|
||||
|
||||
// these belong to the async function
|
||||
#define RETURN_ADDRESSES_FIELD_NAME "return_addresses"
|
||||
@ -3476,6 +3476,8 @@ static const size_t stack_trace_ptr_count = 30;
|
||||
#define ERR_RET_TRACE_PTR_FIELD_NAME "err_ret_trace_ptr"
|
||||
#define RESULT_PTR_FIELD_NAME "result_ptr"
|
||||
|
||||
#define NAMESPACE_SEP_CHAR '.'
|
||||
#define NAMESPACE_SEP_STR "."
|
||||
|
||||
enum FloatMode {
|
||||
FloatModeStrict,
|
||||
@ -3507,7 +3509,7 @@ struct FnWalkTypes {
|
||||
};
|
||||
|
||||
struct FnWalkVars {
|
||||
ImportTableEntry *import;
|
||||
ZigType *import;
|
||||
LLVMValueRef llvm_fn;
|
||||
ZigFn *fn;
|
||||
ZigVar *var;
|
||||
|
531
src/analyze.cpp
531
src/analyze.cpp
File diff suppressed because it is too large
Load Diff
@ -12,8 +12,9 @@
|
||||
|
||||
void semantic_analyze(CodeGen *g);
|
||||
ErrorMsg *add_node_error(CodeGen *g, AstNode *node, Buf *msg);
|
||||
ErrorMsg *add_token_error(CodeGen *g, ImportTableEntry *owner, Token *token, Buf *msg);
|
||||
ErrorMsg *add_token_error(CodeGen *g, ZigType *owner, Token *token, Buf *msg);
|
||||
ErrorMsg *add_error_note(CodeGen *g, ErrorMsg *parent_msg, AstNode *node, Buf *msg);
|
||||
void emit_error_notes_for_ref_stack(CodeGen *g, ErrorMsg *msg);
|
||||
ZigType *new_type_table_entry(ZigTypeId id);
|
||||
ZigType *get_pointer_to_type(CodeGen *g, ZigType *child_type, bool is_const);
|
||||
ZigType *get_pointer_to_type_extra(CodeGen *g, ZigType *child_type, bool is_const,
|
||||
@ -29,11 +30,13 @@ ZigType *get_optional_type(CodeGen *g, ZigType *child_type);
|
||||
ZigType *get_array_type(CodeGen *g, ZigType *child_type, uint64_t array_size);
|
||||
ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type);
|
||||
ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind,
|
||||
AstNode *decl_node, const char *name, ContainerLayout layout);
|
||||
AstNode *decl_node, const char *full_name, Buf *bare_name, ContainerLayout layout);
|
||||
ZigType *get_root_container_type(CodeGen *g, const char *full_name, Buf *bare_name,
|
||||
RootStruct *root_struct);
|
||||
ZigType *get_smallest_unsigned_int_type(CodeGen *g, uint64_t x);
|
||||
ZigType *get_error_union_type(CodeGen *g, ZigType *err_set_type, ZigType *payload_type);
|
||||
ZigType *get_bound_fn_type(CodeGen *g, ZigFn *fn_entry);
|
||||
ZigType *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const char *name);
|
||||
ZigType *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const char *full_name, Buf *bare_name);
|
||||
ZigType *get_struct_type(CodeGen *g, const char *type_name, const char *field_names[],
|
||||
ZigType *field_types[], size_t field_count);
|
||||
ZigType *get_promise_type(CodeGen *g, ZigType *result_type);
|
||||
@ -46,13 +49,19 @@ bool type_allowed_in_extern(CodeGen *g, ZigType *type_entry);
|
||||
bool ptr_allows_addr_zero(ZigType *ptr_type);
|
||||
bool type_is_nonnull_ptr(ZigType *type);
|
||||
|
||||
ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *abs_full_path, Buf *source_code);
|
||||
|
||||
enum SourceKind {
|
||||
SourceKindRoot,
|
||||
SourceKindPkgMain,
|
||||
SourceKindNonRoot,
|
||||
};
|
||||
ZigType *add_source_file(CodeGen *g, ZigPackage *package, Buf *abs_full_path, Buf *source_code,
|
||||
SourceKind source_kind);
|
||||
|
||||
ZigVar *find_variable(CodeGen *g, Scope *orig_context, Buf *name, ScopeFnDef **crossed_fndef_scope);
|
||||
Tld *find_decl(CodeGen *g, Scope *scope, Buf *name);
|
||||
void resolve_top_level_decl(CodeGen *g, Tld *tld, bool pointer_only, AstNode *source_node);
|
||||
bool type_is_codegen_pointer(ZigType *type);
|
||||
Tld *find_container_decl(CodeGen *g, ScopeDecls *decls_scope, Buf *name);
|
||||
void resolve_top_level_decl(CodeGen *g, Tld *tld, AstNode *source_node);
|
||||
bool type_is_non_optional_pointer(ZigType *type);
|
||||
|
||||
ZigType *get_src_ptr_type(ZigType *type);
|
||||
ZigType *get_codegen_ptr_type(ZigType *type);
|
||||
@ -77,11 +86,11 @@ bool is_array_ref(ZigType *type_entry);
|
||||
bool is_container_ref(ZigType *type_entry);
|
||||
bool is_valid_vector_elem_type(ZigType *elem_type);
|
||||
void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node);
|
||||
void scan_import(CodeGen *g, ImportTableEntry *import);
|
||||
void preview_use_decl(CodeGen *g, AstNode *node);
|
||||
void resolve_use_decl(CodeGen *g, AstNode *node);
|
||||
ZigFn *scope_fn_entry(Scope *scope);
|
||||
ImportTableEntry *get_scope_import(Scope *scope);
|
||||
ZigPackage *scope_package(Scope *scope);
|
||||
ZigType *get_scope_import(Scope *scope);
|
||||
void init_tld(Tld *tld, TldId id, Buf *name, VisibMod visib_mod, AstNode *source_node, Scope *parent_scope);
|
||||
ZigVar *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf *name,
|
||||
bool is_const, ConstExprValue *init_value, Tld *src_tld, ZigType *var_type);
|
||||
@ -109,7 +118,6 @@ ScopeCImport *create_cimport_scope(CodeGen *g, AstNode *node, Scope *parent);
|
||||
ScopeLoop *create_loop_scope(CodeGen *g, AstNode *node, Scope *parent);
|
||||
ScopeSuspend *create_suspend_scope(CodeGen *g, AstNode *node, Scope *parent);
|
||||
ScopeFnDef *create_fndef_scope(CodeGen *g, AstNode *node, Scope *parent, ZigFn *fn_entry);
|
||||
ScopeDecls *create_decls_scope(CodeGen *g, AstNode *node, Scope *parent, ZigType *container_type, ImportTableEntry *import);
|
||||
Scope *create_comptime_scope(CodeGen *g, AstNode *node, Scope *parent);
|
||||
Scope *create_coro_prelude_scope(CodeGen *g, AstNode *node, Scope *parent);
|
||||
Scope *create_runtime_scope(CodeGen *g, AstNode *node, Scope *parent, IrInstruction *is_comptime);
|
||||
@ -186,7 +194,7 @@ LinkLib *add_link_lib(CodeGen *codegen, Buf *lib);
|
||||
|
||||
uint32_t get_abi_alignment(CodeGen *g, ZigType *type_entry);
|
||||
ZigType *get_align_amt_type(CodeGen *g);
|
||||
PackageTableEntry *new_anonymous_package(void);
|
||||
ZigPackage *new_anonymous_package(void);
|
||||
|
||||
Buf *const_value_to_buffer(ConstExprValue *const_val);
|
||||
void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, Buf *symbol_name, GlobalLinkageId linkage, bool ccc);
|
||||
@ -232,4 +240,6 @@ Error ensure_const_val_repr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_no
|
||||
ConstExprValue *const_val, ZigType *wanted_type);
|
||||
|
||||
void typecheck_panic_fn(CodeGen *g, TldFn *tld_fn, ZigFn *panic_fn);
|
||||
Buf *type_bare_name(ZigType *t);
|
||||
Buf *type_h_name(ZigType *t);
|
||||
#endif
|
||||
|
@ -59,7 +59,7 @@ static inline void buf_deinit(Buf *buf) {
|
||||
static inline void buf_init_from_mem(Buf *buf, const char *ptr, size_t len) {
|
||||
assert(len != SIZE_MAX);
|
||||
buf->list.resize(len + 1);
|
||||
safe_memcpy(buf_ptr(buf), ptr, len);
|
||||
memcpy(buf_ptr(buf), ptr, len);
|
||||
buf->list.at(buf_len(buf)) = 0;
|
||||
}
|
||||
|
||||
@ -98,7 +98,7 @@ static inline Buf *buf_slice(Buf *in_buf, size_t start, size_t end) {
|
||||
assert(end <= buf_len(in_buf));
|
||||
Buf *out_buf = allocate<Buf>(1);
|
||||
out_buf->list.resize(end - start + 1);
|
||||
safe_memcpy(buf_ptr(out_buf), buf_ptr(in_buf) + start, end - start);
|
||||
memcpy(buf_ptr(out_buf), buf_ptr(in_buf) + start, end - start);
|
||||
out_buf->list.at(buf_len(out_buf)) = 0;
|
||||
return out_buf;
|
||||
}
|
||||
@ -108,7 +108,7 @@ static inline void buf_append_mem(Buf *buf, const char *mem, size_t mem_len) {
|
||||
assert(mem_len != SIZE_MAX);
|
||||
size_t old_len = buf_len(buf);
|
||||
buf_resize(buf, old_len + mem_len);
|
||||
safe_memcpy(buf_ptr(buf) + old_len, mem, mem_len);
|
||||
memcpy(buf_ptr(buf) + old_len, mem, mem_len);
|
||||
buf->list.at(buf_len(buf)) = 0;
|
||||
}
|
||||
|
||||
|
212
src/codegen.cpp
212
src/codegen.cpp
@ -48,16 +48,17 @@ static void init_darwin_native(CodeGen *g) {
|
||||
}
|
||||
}
|
||||
|
||||
static PackageTableEntry *new_package(const char *root_src_dir, const char *root_src_path) {
|
||||
PackageTableEntry *entry = allocate<PackageTableEntry>(1);
|
||||
static ZigPackage *new_package(const char *root_src_dir, const char *root_src_path, const char *pkg_path) {
|
||||
ZigPackage *entry = allocate<ZigPackage>(1);
|
||||
entry->package_table.init(4);
|
||||
buf_init_from_str(&entry->root_src_dir, root_src_dir);
|
||||
buf_init_from_str(&entry->root_src_path, root_src_path);
|
||||
buf_init_from_str(&entry->pkg_path, pkg_path);
|
||||
return entry;
|
||||
}
|
||||
|
||||
PackageTableEntry *new_anonymous_package(void) {
|
||||
return new_package("", "");
|
||||
ZigPackage *new_anonymous_package() {
|
||||
return new_package("", "", "");
|
||||
}
|
||||
|
||||
static const char *symbols_that_llvm_depends_on[] = {
|
||||
@ -87,8 +88,8 @@ static const char *symbols_that_llvm_depends_on[] = {
|
||||
// TODO probably all of compiler-rt needs to go here
|
||||
};
|
||||
|
||||
CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out_type, BuildMode build_mode,
|
||||
Buf *zig_lib_dir, Buf *override_std_dir, ZigLibCInstallation *libc)
|
||||
CodeGen *codegen_create(Buf *main_pkg_path, Buf *root_src_path, const ZigTarget *target,
|
||||
OutType out_type, BuildMode build_mode, Buf *zig_lib_dir, Buf *override_std_dir, ZigLibCInstallation *libc)
|
||||
{
|
||||
CodeGen *g = allocate<CodeGen>(1);
|
||||
|
||||
@ -132,20 +133,39 @@ CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out
|
||||
}
|
||||
|
||||
if (root_src_path) {
|
||||
Buf *src_basename = buf_alloc();
|
||||
Buf *src_dir = buf_alloc();
|
||||
os_path_split(root_src_path, src_dir, src_basename);
|
||||
Buf *root_pkg_path;
|
||||
Buf *rel_root_src_path;
|
||||
if (main_pkg_path == nullptr) {
|
||||
Buf *src_basename = buf_alloc();
|
||||
Buf *src_dir = buf_alloc();
|
||||
os_path_split(root_src_path, src_dir, src_basename);
|
||||
|
||||
if (buf_len(src_basename) == 0) {
|
||||
fprintf(stderr, "Invalid root source path: %s\n", buf_ptr(root_src_path));
|
||||
exit(1);
|
||||
if (buf_len(src_basename) == 0) {
|
||||
fprintf(stderr, "Invalid root source path: %s\n", buf_ptr(root_src_path));
|
||||
exit(1);
|
||||
}
|
||||
root_pkg_path = src_dir;
|
||||
rel_root_src_path = src_basename;
|
||||
} else {
|
||||
Buf resolved_root_src_path = os_path_resolve(&root_src_path, 1);
|
||||
Buf resolved_main_pkg_path = os_path_resolve(&main_pkg_path, 1);
|
||||
|
||||
if (!buf_starts_with_buf(&resolved_root_src_path, &resolved_main_pkg_path)) {
|
||||
fprintf(stderr, "Root source path '%s' outside main package path '%s'",
|
||||
buf_ptr(root_src_path), buf_ptr(main_pkg_path));
|
||||
exit(1);
|
||||
}
|
||||
root_pkg_path = main_pkg_path;
|
||||
rel_root_src_path = buf_create_from_mem(
|
||||
buf_ptr(&resolved_root_src_path) + buf_len(&resolved_main_pkg_path) + 1,
|
||||
buf_len(&resolved_root_src_path) - buf_len(&resolved_main_pkg_path) - 1);
|
||||
}
|
||||
|
||||
g->root_package = new_package(buf_ptr(src_dir), buf_ptr(src_basename));
|
||||
g->std_package = new_package(buf_ptr(g->zig_std_dir), "index.zig");
|
||||
g->root_package = new_package(buf_ptr(root_pkg_path), buf_ptr(rel_root_src_path), "");
|
||||
g->std_package = new_package(buf_ptr(g->zig_std_dir), "std.zig", "std");
|
||||
g->root_package->package_table.put(buf_create_from_str("std"), g->std_package);
|
||||
} else {
|
||||
g->root_package = new_package(".", "");
|
||||
g->root_package = new_package(".", "", "");
|
||||
}
|
||||
|
||||
g->zig_std_special_dir = buf_alloc();
|
||||
@ -621,7 +641,7 @@ static ZigLLVMDIScope *get_di_scope(CodeGen *g, Scope *scope) {
|
||||
if (scope->di_scope)
|
||||
return scope->di_scope;
|
||||
|
||||
ImportTableEntry *import = get_scope_import(scope);
|
||||
ZigType *import = get_scope_import(scope);
|
||||
switch (scope->id) {
|
||||
case ScopeIdCImport:
|
||||
zig_unreachable();
|
||||
@ -644,7 +664,7 @@ static ZigLLVMDIScope *get_di_scope(CodeGen *g, Scope *scope) {
|
||||
assert(fn_di_scope != nullptr);
|
||||
ZigLLVMDISubprogram *subprogram = ZigLLVMCreateFunction(g->dbuilder,
|
||||
fn_di_scope, buf_ptr(&fn_table_entry->symbol_name), "",
|
||||
import->di_file, line_number,
|
||||
import->data.structure.root_struct->di_file, line_number,
|
||||
fn_table_entry->type_entry->data.fn.raw_di_type, is_internal_linkage,
|
||||
is_definition, scope_line, flags, is_optimized, nullptr);
|
||||
|
||||
@ -658,7 +678,7 @@ static ZigLLVMDIScope *get_di_scope(CodeGen *g, Scope *scope) {
|
||||
assert(decls_scope->container_type);
|
||||
scope->di_scope = ZigLLVMTypeToScope(decls_scope->container_type->di_type);
|
||||
} else {
|
||||
scope->di_scope = ZigLLVMFileToScope(import->di_file);
|
||||
scope->di_scope = ZigLLVMFileToScope(import->data.structure.root_struct->di_file);
|
||||
}
|
||||
return scope->di_scope;
|
||||
case ScopeIdBlock:
|
||||
@ -668,7 +688,7 @@ static ZigLLVMDIScope *get_di_scope(CodeGen *g, Scope *scope) {
|
||||
assert(scope->parent);
|
||||
ZigLLVMDILexicalBlock *di_block = ZigLLVMCreateLexicalBlock(g->dbuilder,
|
||||
get_di_scope(g, scope->parent),
|
||||
import->di_file,
|
||||
import->data.structure.root_struct->di_file,
|
||||
(unsigned)scope->source_node->line + 1,
|
||||
(unsigned)scope->source_node->column + 1);
|
||||
scope->di_scope = ZigLLVMLexicalBlockToScope(di_block);
|
||||
@ -1236,7 +1256,7 @@ static LLVMValueRef get_add_error_return_trace_addr_fn(CodeGen *g) {
|
||||
|
||||
LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->type_ref;
|
||||
|
||||
// stack_trace.instruction_addresses[stack_trace.index % stack_trace.instruction_addresses.len] = return_address;
|
||||
// stack_trace.instruction_addresses[stack_trace.index & (stack_trace.instruction_addresses.len - 1)] = return_address;
|
||||
|
||||
LLVMValueRef err_ret_trace_ptr = LLVMGetParam(fn_val, 0);
|
||||
LLVMValueRef address_value = LLVMGetParam(fn_val, 1);
|
||||
@ -1254,9 +1274,10 @@ static LLVMValueRef get_add_error_return_trace_addr_fn(CodeGen *g) {
|
||||
|
||||
LLVMValueRef len_value = gen_load_untyped(g, len_field_ptr, 0, false, "");
|
||||
LLVMValueRef index_val = gen_load_untyped(g, index_field_ptr, 0, false, "");
|
||||
LLVMValueRef modded_val = LLVMBuildURem(g->builder, index_val, len_value, "");
|
||||
LLVMValueRef len_val_minus_one = LLVMBuildSub(g->builder, len_value, LLVMConstInt(usize_type_ref, 1, false), "");
|
||||
LLVMValueRef masked_val = LLVMBuildAnd(g->builder, index_val, len_val_minus_one, "");
|
||||
LLVMValueRef address_indices[] = {
|
||||
modded_val,
|
||||
masked_val,
|
||||
};
|
||||
|
||||
LLVMValueRef ptr_value = gen_load_untyped(g, ptr_field_ptr, 0, false, "");
|
||||
@ -2196,7 +2217,7 @@ var_ok:
|
||||
if (dest_ty != nullptr && var->decl_node) {
|
||||
// arg index + 1 because the 0 index is return value
|
||||
var->di_loc_var = ZigLLVMCreateParameterVariable(g->dbuilder, get_di_scope(g, var->parent_scope),
|
||||
buf_ptr(&var->name), fn_walk->data.vars.import->di_file,
|
||||
buf_ptr(&var->name), fn_walk->data.vars.import->data.structure.root_struct->di_file,
|
||||
(unsigned)(var->decl_node->line + 1),
|
||||
dest_ty->di_type, !g->strip_debug_symbols, 0, di_arg_index + 1);
|
||||
}
|
||||
@ -3938,7 +3959,7 @@ static LLVMValueRef gen_non_null_bit(CodeGen *g, ZigType *maybe_type, LLVMValueR
|
||||
if (child_type->zero_bits) {
|
||||
return maybe_handle;
|
||||
} else {
|
||||
bool is_scalar = type_is_codegen_pointer(child_type) || child_type->id == ZigTypeIdErrorSet;
|
||||
bool is_scalar = type_is_non_optional_pointer(child_type) || child_type->id == ZigTypeIdErrorSet;
|
||||
if (is_scalar) {
|
||||
return LLVMBuildICmp(g->builder, LLVMIntNE, maybe_handle, LLVMConstNull(maybe_type->type_ref), "");
|
||||
} else {
|
||||
@ -3978,7 +3999,7 @@ static LLVMValueRef ir_render_optional_unwrap_ptr(CodeGen *g, IrExecutable *exec
|
||||
if (child_type->zero_bits) {
|
||||
return nullptr;
|
||||
} else {
|
||||
bool is_scalar = type_is_codegen_pointer(child_type) || child_type->id == ZigTypeIdErrorSet;
|
||||
bool is_scalar = type_is_non_optional_pointer(child_type) || child_type->id == ZigTypeIdErrorSet;
|
||||
if (is_scalar) {
|
||||
return maybe_ptr;
|
||||
} else {
|
||||
@ -4549,7 +4570,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst
|
||||
|
||||
return tmp_struct_ptr;
|
||||
} else if (array_type->id == ZigTypeIdPointer) {
|
||||
assert(array_type->data.pointer.ptr_len == PtrLenUnknown);
|
||||
assert(array_type->data.pointer.ptr_len != PtrLenSingle);
|
||||
LLVMValueRef start_val = ir_llvm_value(g, instruction->start);
|
||||
LLVMValueRef end_val = ir_llvm_value(g, instruction->end);
|
||||
|
||||
@ -4640,7 +4661,8 @@ static LLVMValueRef ir_render_return_address(CodeGen *g, IrExecutable *executabl
|
||||
IrInstructionReturnAddress *instruction)
|
||||
{
|
||||
LLVMValueRef zero = LLVMConstNull(g->builtin_types.entry_i32->type_ref);
|
||||
return LLVMBuildCall(g->builder, get_return_address_fn_val(g), &zero, 1, "");
|
||||
LLVMValueRef ptr_val = LLVMBuildCall(g->builder, get_return_address_fn_val(g), &zero, 1, "");
|
||||
return LLVMBuildPtrToInt(g->builder, ptr_val, g->builtin_types.entry_usize->type_ref, "");
|
||||
}
|
||||
|
||||
static LLVMValueRef get_frame_address_fn_val(CodeGen *g) {
|
||||
@ -4661,7 +4683,8 @@ static LLVMValueRef ir_render_frame_address(CodeGen *g, IrExecutable *executable
|
||||
IrInstructionFrameAddress *instruction)
|
||||
{
|
||||
LLVMValueRef zero = LLVMConstNull(g->builtin_types.entry_i32->type_ref);
|
||||
return LLVMBuildCall(g->builder, get_frame_address_fn_val(g), &zero, 1, "");
|
||||
LLVMValueRef ptr_val = LLVMBuildCall(g->builder, get_frame_address_fn_val(g), &zero, 1, "");
|
||||
return LLVMBuildPtrToInt(g->builder, ptr_val, g->builtin_types.entry_usize->type_ref, "");
|
||||
}
|
||||
|
||||
static LLVMValueRef get_handle_fn_val(CodeGen *g) {
|
||||
@ -4839,7 +4862,7 @@ static LLVMValueRef ir_render_maybe_wrap(CodeGen *g, IrExecutable *executable, I
|
||||
}
|
||||
|
||||
LLVMValueRef payload_val = ir_llvm_value(g, instruction->value);
|
||||
if (type_is_codegen_pointer(child_type) || child_type->id == ZigTypeIdErrorSet) {
|
||||
if (type_is_non_optional_pointer(child_type) || child_type->id == ZigTypeIdErrorSet) {
|
||||
return payload_val;
|
||||
}
|
||||
|
||||
@ -5800,7 +5823,6 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con
|
||||
case ZigTypeIdNull:
|
||||
case ZigTypeIdErrorUnion:
|
||||
case ZigTypeIdErrorSet:
|
||||
case ZigTypeIdNamespace:
|
||||
case ZigTypeIdBoundFn:
|
||||
case ZigTypeIdArgTuple:
|
||||
case ZigTypeIdVoid:
|
||||
@ -6077,9 +6099,9 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
|
||||
case ZigTypeIdOptional:
|
||||
{
|
||||
ZigType *child_type = type_entry->data.maybe.child_type;
|
||||
if (child_type->zero_bits) {
|
||||
if (!type_has_bits(child_type)) {
|
||||
return LLVMConstInt(LLVMInt1Type(), const_val->data.x_optional ? 1 : 0, false);
|
||||
} else if (type_is_codegen_pointer(child_type)) {
|
||||
} else if (get_codegen_ptr_type(type_entry) != nullptr) {
|
||||
return gen_const_val_ptr(g, const_val, name);
|
||||
} else if (child_type->id == ZigTypeIdErrorSet) {
|
||||
return gen_const_val_err_set(g, const_val, name);
|
||||
@ -6400,7 +6422,6 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
|
||||
case ZigTypeIdComptimeInt:
|
||||
case ZigTypeIdUndefined:
|
||||
case ZigTypeIdNull:
|
||||
case ZigTypeIdNamespace:
|
||||
case ZigTypeIdBoundFn:
|
||||
case ZigTypeIdArgTuple:
|
||||
case ZigTypeIdOpaque:
|
||||
@ -6506,12 +6527,12 @@ static void gen_global_var(CodeGen *g, ZigVar *var, LLVMValueRef init_val,
|
||||
assert(var->gen_is_const);
|
||||
assert(type_entry);
|
||||
|
||||
ImportTableEntry *import = get_scope_import(var->parent_scope);
|
||||
ZigType *import = get_scope_import(var->parent_scope);
|
||||
assert(import);
|
||||
|
||||
bool is_local_to_unit = true;
|
||||
ZigLLVMCreateGlobalVariable(g->dbuilder, get_di_scope(g, var->parent_scope), buf_ptr(&var->name),
|
||||
buf_ptr(&var->name), import->di_file,
|
||||
buf_ptr(&var->name), import->data.structure.root_struct->di_file,
|
||||
(unsigned)(var->decl_node->line + 1),
|
||||
type_entry->di_type, is_local_to_unit);
|
||||
|
||||
@ -6767,7 +6788,7 @@ static void do_code_gen(CodeGen *g) {
|
||||
*slot = build_alloca(g, slot_type, "", alignment_bytes);
|
||||
}
|
||||
|
||||
ImportTableEntry *import = get_scope_import(&fn_table_entry->fndef_scope->base);
|
||||
ZigType *import = get_scope_import(&fn_table_entry->fndef_scope->base);
|
||||
|
||||
unsigned gen_i_init = want_first_arg_sret(g, fn_type_id) ? 1 : 0;
|
||||
|
||||
@ -6799,7 +6820,7 @@ static void do_code_gen(CodeGen *g) {
|
||||
var->value_ref = build_alloca(g, var->var_type, buf_ptr(&var->name), var->align_bytes);
|
||||
|
||||
var->di_loc_var = ZigLLVMCreateAutoVariable(g->dbuilder, get_di_scope(g, var->parent_scope),
|
||||
buf_ptr(&var->name), import->di_file, (unsigned)(var->decl_node->line + 1),
|
||||
buf_ptr(&var->name), import->data.structure.root_struct->di_file, (unsigned)(var->decl_node->line + 1),
|
||||
var->var_type->di_type, !g->strip_debug_symbols, 0);
|
||||
|
||||
} else if (is_c_abi) {
|
||||
@ -6823,7 +6844,7 @@ static void do_code_gen(CodeGen *g) {
|
||||
}
|
||||
if (var->decl_node) {
|
||||
var->di_loc_var = ZigLLVMCreateParameterVariable(g->dbuilder, get_di_scope(g, var->parent_scope),
|
||||
buf_ptr(&var->name), import->di_file,
|
||||
buf_ptr(&var->name), import->data.structure.root_struct->di_file,
|
||||
(unsigned)(var->decl_node->line + 1),
|
||||
gen_type->di_type, !g->strip_debug_symbols, 0, (unsigned)(var->gen_arg_index + 1));
|
||||
}
|
||||
@ -6971,12 +6992,6 @@ static void define_builtin_types(CodeGen *g) {
|
||||
entry->zero_bits = true;
|
||||
g->builtin_types.entry_invalid = entry;
|
||||
}
|
||||
{
|
||||
ZigType *entry = new_type_table_entry(ZigTypeIdNamespace);
|
||||
buf_init_from_str(&entry->name, "(namespace)");
|
||||
entry->zero_bits = true;
|
||||
g->builtin_types.entry_namespace = entry;
|
||||
}
|
||||
{
|
||||
ZigType *entry = new_type_table_entry(ZigTypeIdComptimeFloat);
|
||||
buf_init_from_str(&entry->name, "comptime_float");
|
||||
@ -7130,7 +7145,8 @@ static void define_builtin_types(CodeGen *g) {
|
||||
g->builtin_types.entry_i64 = get_int_type(g, true, 64);
|
||||
|
||||
{
|
||||
g->builtin_types.entry_c_void = get_opaque_type(g, nullptr, nullptr, "c_void");
|
||||
g->builtin_types.entry_c_void = get_opaque_type(g, nullptr, nullptr, "c_void",
|
||||
buf_create_from_str("c_void"));
|
||||
g->primitive_type_table.put(&g->builtin_types.entry_c_void->name, g->builtin_types.entry_c_void);
|
||||
}
|
||||
|
||||
@ -7470,7 +7486,6 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
|
||||
" Enum: Enum,\n"
|
||||
" Union: Union,\n"
|
||||
" Fn: Fn,\n"
|
||||
" Namespace: void,\n"
|
||||
" BoundFn: Fn,\n"
|
||||
" ArgTuple: void,\n"
|
||||
" Opaque: void,\n"
|
||||
@ -7479,18 +7494,18 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
|
||||
"\n\n"
|
||||
" pub const Int = struct {\n"
|
||||
" is_signed: bool,\n"
|
||||
" bits: u8,\n"
|
||||
" bits: comptime_int,\n"
|
||||
" };\n"
|
||||
"\n"
|
||||
" pub const Float = struct {\n"
|
||||
" bits: u8,\n"
|
||||
" bits: comptime_int,\n"
|
||||
" };\n"
|
||||
"\n"
|
||||
" pub const Pointer = struct {\n"
|
||||
" size: Size,\n"
|
||||
" is_const: bool,\n"
|
||||
" is_volatile: bool,\n"
|
||||
" alignment: u32,\n"
|
||||
" alignment: comptime_int,\n"
|
||||
" child: type,\n"
|
||||
"\n"
|
||||
" pub const Size = enum {\n"
|
||||
@ -7502,7 +7517,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
|
||||
" };\n"
|
||||
"\n"
|
||||
" pub const Array = struct {\n"
|
||||
" len: usize,\n"
|
||||
" len: comptime_int,\n"
|
||||
" child: type,\n"
|
||||
" };\n"
|
||||
"\n"
|
||||
@ -7514,7 +7529,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
|
||||
"\n"
|
||||
" pub const StructField = struct {\n"
|
||||
" name: []const u8,\n"
|
||||
" offset: ?usize,\n"
|
||||
" offset: ?comptime_int,\n"
|
||||
" field_type: type,\n"
|
||||
" };\n"
|
||||
"\n"
|
||||
@ -7535,7 +7550,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
|
||||
"\n"
|
||||
" pub const Error = struct {\n"
|
||||
" name: []const u8,\n"
|
||||
" value: usize,\n"
|
||||
" value: comptime_int,\n"
|
||||
" };\n"
|
||||
"\n"
|
||||
" pub const ErrorSet = struct {\n"
|
||||
@ -7544,7 +7559,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
|
||||
"\n"
|
||||
" pub const EnumField = struct {\n"
|
||||
" name: []const u8,\n"
|
||||
" value: usize,\n"
|
||||
" value: comptime_int,\n"
|
||||
" };\n"
|
||||
"\n"
|
||||
" pub const Enum = struct {\n"
|
||||
@ -7596,7 +7611,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
|
||||
" };\n"
|
||||
"\n"
|
||||
" pub const Vector = struct {\n"
|
||||
" len: u32,\n"
|
||||
" len: comptime_int,\n"
|
||||
" child: type,\n"
|
||||
" };\n"
|
||||
"\n"
|
||||
@ -7751,12 +7766,12 @@ static Error define_builtin_compile_vars(CodeGen *g) {
|
||||
|
||||
assert(g->root_package);
|
||||
assert(g->std_package);
|
||||
g->compile_var_package = new_package(buf_ptr(this_dir), builtin_zig_basename);
|
||||
g->compile_var_package = new_package(buf_ptr(this_dir), builtin_zig_basename, "builtin");
|
||||
g->root_package->package_table.put(buf_create_from_str("builtin"), g->compile_var_package);
|
||||
g->std_package->package_table.put(buf_create_from_str("builtin"), g->compile_var_package);
|
||||
g->std_package->package_table.put(buf_create_from_str("std"), g->std_package);
|
||||
g->compile_var_import = add_source_file(g, g->compile_var_package, builtin_zig_path, contents);
|
||||
scan_import(g, g->compile_var_import);
|
||||
g->compile_var_import = add_source_file(g, g->compile_var_package, builtin_zig_path, contents,
|
||||
SourceKindPkgMain);
|
||||
|
||||
return ErrorNone;
|
||||
}
|
||||
@ -7948,17 +7963,20 @@ void codegen_translate_c(CodeGen *g, Buf *full_path) {
|
||||
Buf *src_dirname = buf_alloc();
|
||||
os_path_split(full_path, src_dirname, src_basename);
|
||||
|
||||
ImportTableEntry *import = allocate<ImportTableEntry>(1);
|
||||
import->source_code = nullptr;
|
||||
import->path = full_path;
|
||||
g->root_import = import;
|
||||
import->decls_scope = create_decls_scope(g, nullptr, nullptr, nullptr, import);
|
||||
Buf noextname = BUF_INIT;
|
||||
os_path_extname(src_basename, &noextname, nullptr);
|
||||
|
||||
detect_libc(g);
|
||||
|
||||
init(g);
|
||||
|
||||
import->di_file = ZigLLVMCreateFile(g->dbuilder, buf_ptr(src_basename), buf_ptr(src_dirname));
|
||||
RootStruct *root_struct = allocate<RootStruct>(1);
|
||||
root_struct->source_code = nullptr;
|
||||
root_struct->path = full_path;
|
||||
root_struct->di_file = ZigLLVMCreateFile(g->dbuilder, buf_ptr(src_basename), buf_ptr(src_dirname));
|
||||
|
||||
ZigType *import = get_root_container_type(g, buf_ptr(&noextname), &noextname, root_struct);
|
||||
g->root_import = import;
|
||||
|
||||
ZigList<ErrorMsg *> errors = {0};
|
||||
Error err = parse_h_file(import, &errors, buf_ptr(full_path), g, nullptr);
|
||||
@ -7977,7 +7995,7 @@ void codegen_translate_c(CodeGen *g, Buf *full_path) {
|
||||
}
|
||||
}
|
||||
|
||||
static ImportTableEntry *add_special_code(CodeGen *g, PackageTableEntry *package, const char *basename) {
|
||||
static ZigType *add_special_code(CodeGen *g, ZigPackage *package, const char *basename) {
|
||||
Buf *code_basename = buf_create_from_str(basename);
|
||||
Buf path_to_code_src = BUF_INIT;
|
||||
os_path_join(g->zig_std_special_dir, code_basename, &path_to_code_src);
|
||||
@ -7991,21 +8009,21 @@ static ImportTableEntry *add_special_code(CodeGen *g, PackageTableEntry *package
|
||||
zig_panic("unable to open '%s': %s\n", buf_ptr(&path_to_code_src), err_str(err));
|
||||
}
|
||||
|
||||
return add_source_file(g, package, resolved_path, import_code);
|
||||
return add_source_file(g, package, resolved_path, import_code, SourceKindPkgMain);
|
||||
}
|
||||
|
||||
static PackageTableEntry *create_bootstrap_pkg(CodeGen *g, PackageTableEntry *pkg_with_main) {
|
||||
PackageTableEntry *package = codegen_create_package(g, buf_ptr(g->zig_std_special_dir), "bootstrap.zig");
|
||||
static ZigPackage *create_bootstrap_pkg(CodeGen *g, ZigPackage *pkg_with_main) {
|
||||
ZigPackage *package = codegen_create_package(g, buf_ptr(g->zig_std_special_dir), "bootstrap.zig", "std.special");
|
||||
package->package_table.put(buf_create_from_str("@root"), pkg_with_main);
|
||||
return package;
|
||||
}
|
||||
|
||||
static PackageTableEntry *create_test_runner_pkg(CodeGen *g) {
|
||||
return codegen_create_package(g, buf_ptr(g->zig_std_special_dir), "test_runner.zig");
|
||||
static ZigPackage *create_test_runner_pkg(CodeGen *g) {
|
||||
return codegen_create_package(g, buf_ptr(g->zig_std_special_dir), "test_runner.zig", "std.special");
|
||||
}
|
||||
|
||||
static PackageTableEntry *create_panic_pkg(CodeGen *g) {
|
||||
return codegen_create_package(g, buf_ptr(g->zig_std_special_dir), "panic.zig");
|
||||
static ZigPackage *create_panic_pkg(CodeGen *g) {
|
||||
return codegen_create_package(g, buf_ptr(g->zig_std_special_dir), "panic.zig", "std.special");
|
||||
}
|
||||
|
||||
static void create_test_compile_var_and_add_test_runner(CodeGen *g) {
|
||||
@ -8089,24 +8107,24 @@ static void gen_root_source(CodeGen *g) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
g->root_import = add_source_file(g, g->root_package, resolved_path, source_code);
|
||||
ZigType *root_import_alias = add_source_file(g, g->root_package, resolved_path, source_code, SourceKindRoot);
|
||||
assert(root_import_alias == g->root_import);
|
||||
|
||||
assert(g->root_out_name);
|
||||
assert(g->out_type != OutTypeUnknown);
|
||||
|
||||
{
|
||||
// Zig has lazy top level definitions. Here we semantically analyze the panic function.
|
||||
ImportTableEntry *import_with_panic;
|
||||
ZigType *import_with_panic;
|
||||
if (g->have_pub_panic) {
|
||||
import_with_panic = g->root_import;
|
||||
} else {
|
||||
g->panic_package = create_panic_pkg(g);
|
||||
import_with_panic = add_special_code(g, g->panic_package, "panic.zig");
|
||||
}
|
||||
scan_import(g, import_with_panic);
|
||||
Tld *panic_tld = find_decl(g, &import_with_panic->decls_scope->base, buf_create_from_str("panic"));
|
||||
Tld *panic_tld = find_decl(g, &get_container_scope(import_with_panic)->base, buf_create_from_str("panic"));
|
||||
assert(panic_tld != nullptr);
|
||||
resolve_top_level_decl(g, panic_tld, false, nullptr);
|
||||
resolve_top_level_decl(g, panic_tld, nullptr);
|
||||
}
|
||||
|
||||
|
||||
@ -8358,7 +8376,6 @@ static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, ZigType *type_e
|
||||
case ZigTypeIdComptimeInt:
|
||||
case ZigTypeIdUndefined:
|
||||
case ZigTypeIdNull:
|
||||
case ZigTypeIdNamespace:
|
||||
case ZigTypeIdBoundFn:
|
||||
case ZigTypeIdArgTuple:
|
||||
case ZigTypeIdErrorUnion:
|
||||
@ -8496,7 +8513,7 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu
|
||||
if (child_type->zero_bits) {
|
||||
buf_init_from_str(out_buf, "bool");
|
||||
return;
|
||||
} else if (type_is_codegen_pointer(child_type)) {
|
||||
} else if (type_is_non_optional_pointer(child_type)) {
|
||||
return get_c_type(g, gen_h, child_type, out_buf);
|
||||
} else {
|
||||
zig_unreachable();
|
||||
@ -8506,19 +8523,19 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu
|
||||
case ZigTypeIdOpaque:
|
||||
{
|
||||
buf_init_from_str(out_buf, "struct ");
|
||||
buf_append_buf(out_buf, &type_entry->name);
|
||||
buf_append_buf(out_buf, type_h_name(type_entry));
|
||||
return;
|
||||
}
|
||||
case ZigTypeIdUnion:
|
||||
{
|
||||
buf_init_from_str(out_buf, "union ");
|
||||
buf_append_buf(out_buf, &type_entry->name);
|
||||
buf_append_buf(out_buf, type_h_name(type_entry));
|
||||
return;
|
||||
}
|
||||
case ZigTypeIdEnum:
|
||||
{
|
||||
buf_init_from_str(out_buf, "enum ");
|
||||
buf_append_buf(out_buf, &type_entry->name);
|
||||
buf_append_buf(out_buf, type_h_name(type_entry));
|
||||
return;
|
||||
}
|
||||
case ZigTypeIdArray:
|
||||
@ -8541,7 +8558,6 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu
|
||||
case ZigTypeIdInvalid:
|
||||
case ZigTypeIdMetaType:
|
||||
case ZigTypeIdBoundFn:
|
||||
case ZigTypeIdNamespace:
|
||||
case ZigTypeIdComptimeFloat:
|
||||
case ZigTypeIdComptimeInt:
|
||||
case ZigTypeIdUndefined:
|
||||
@ -8614,10 +8630,17 @@ static void gen_h_file(CodeGen *g) {
|
||||
Buf return_type_c = BUF_INIT;
|
||||
get_c_type(g, gen_h, fn_type_id->return_type, &return_type_c);
|
||||
|
||||
Buf *symbol_name;
|
||||
if (fn_table_entry->export_list.length == 0) {
|
||||
symbol_name = &fn_table_entry->symbol_name;
|
||||
} else {
|
||||
FnExport *fn_export = &fn_table_entry->export_list.items[0];
|
||||
symbol_name = &fn_export->name;
|
||||
}
|
||||
buf_appendf(&h_buf, "%s %s %s(",
|
||||
buf_ptr(export_macro),
|
||||
buf_ptr(&return_type_c),
|
||||
buf_ptr(&fn_table_entry->symbol_name));
|
||||
buf_ptr(symbol_name));
|
||||
|
||||
Buf param_type_c = BUF_INIT;
|
||||
if (fn_type_id->param_count > 0) {
|
||||
@ -8693,7 +8716,6 @@ static void gen_h_file(CodeGen *g) {
|
||||
case ZigTypeIdNull:
|
||||
case ZigTypeIdErrorUnion:
|
||||
case ZigTypeIdErrorSet:
|
||||
case ZigTypeIdNamespace:
|
||||
case ZigTypeIdBoundFn:
|
||||
case ZigTypeIdArgTuple:
|
||||
case ZigTypeIdOptional:
|
||||
@ -8703,7 +8725,7 @@ static void gen_h_file(CodeGen *g) {
|
||||
zig_unreachable();
|
||||
case ZigTypeIdEnum:
|
||||
if (type_entry->data.enumeration.layout == ContainerLayoutExtern) {
|
||||
fprintf(out_h, "enum %s {\n", buf_ptr(&type_entry->name));
|
||||
fprintf(out_h, "enum %s {\n", buf_ptr(type_h_name(type_entry)));
|
||||
for (uint32_t field_i = 0; field_i < type_entry->data.enumeration.src_field_count; field_i += 1) {
|
||||
TypeEnumField *enum_field = &type_entry->data.enumeration.fields[field_i];
|
||||
Buf *value_buf = buf_alloc();
|
||||
@ -8716,12 +8738,12 @@ static void gen_h_file(CodeGen *g) {
|
||||
}
|
||||
fprintf(out_h, "};\n\n");
|
||||
} else {
|
||||
fprintf(out_h, "enum %s;\n", buf_ptr(&type_entry->name));
|
||||
fprintf(out_h, "enum %s;\n", buf_ptr(type_h_name(type_entry)));
|
||||
}
|
||||
break;
|
||||
case ZigTypeIdStruct:
|
||||
if (type_entry->data.structure.layout == ContainerLayoutExtern) {
|
||||
fprintf(out_h, "struct %s {\n", buf_ptr(&type_entry->name));
|
||||
fprintf(out_h, "struct %s {\n", buf_ptr(type_h_name(type_entry)));
|
||||
for (uint32_t field_i = 0; field_i < type_entry->data.structure.src_field_count; field_i += 1) {
|
||||
TypeStructField *struct_field = &type_entry->data.structure.fields[field_i];
|
||||
|
||||
@ -8739,12 +8761,12 @@ static void gen_h_file(CodeGen *g) {
|
||||
}
|
||||
fprintf(out_h, "};\n\n");
|
||||
} else {
|
||||
fprintf(out_h, "struct %s;\n", buf_ptr(&type_entry->name));
|
||||
fprintf(out_h, "struct %s;\n", buf_ptr(type_h_name(type_entry)));
|
||||
}
|
||||
break;
|
||||
case ZigTypeIdUnion:
|
||||
if (type_entry->data.unionation.layout == ContainerLayoutExtern) {
|
||||
fprintf(out_h, "union %s {\n", buf_ptr(&type_entry->name));
|
||||
fprintf(out_h, "union %s {\n", buf_ptr(type_h_name(type_entry)));
|
||||
for (uint32_t field_i = 0; field_i < type_entry->data.unionation.src_field_count; field_i += 1) {
|
||||
TypeUnionField *union_field = &type_entry->data.unionation.fields[field_i];
|
||||
|
||||
@ -8754,11 +8776,11 @@ static void gen_h_file(CodeGen *g) {
|
||||
}
|
||||
fprintf(out_h, "};\n\n");
|
||||
} else {
|
||||
fprintf(out_h, "union %s;\n", buf_ptr(&type_entry->name));
|
||||
fprintf(out_h, "union %s;\n", buf_ptr(type_h_name(type_entry)));
|
||||
}
|
||||
break;
|
||||
case ZigTypeIdOpaque:
|
||||
fprintf(out_h, "struct %s;\n\n", buf_ptr(&type_entry->name));
|
||||
fprintf(out_h, "struct %s;\n\n", buf_ptr(type_h_name(type_entry)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -8792,7 +8814,7 @@ void codegen_add_time_event(CodeGen *g, const char *name) {
|
||||
g->timing_events.append({os_get_time(), name});
|
||||
}
|
||||
|
||||
static void add_cache_pkg(CodeGen *g, CacheHash *ch, PackageTableEntry *pkg) {
|
||||
static void add_cache_pkg(CodeGen *g, CacheHash *ch, ZigPackage *pkg) {
|
||||
if (buf_len(&pkg->root_src_path) == 0)
|
||||
return;
|
||||
|
||||
@ -9046,9 +9068,11 @@ void codegen_build_and_link(CodeGen *g) {
|
||||
codegen_add_time_event(g, "Done");
|
||||
}
|
||||
|
||||
PackageTableEntry *codegen_create_package(CodeGen *g, const char *root_src_dir, const char *root_src_path) {
|
||||
ZigPackage *codegen_create_package(CodeGen *g, const char *root_src_dir, const char *root_src_path,
|
||||
const char *pkg_path)
|
||||
{
|
||||
init(g);
|
||||
PackageTableEntry *pkg = new_package(root_src_dir, root_src_path);
|
||||
ZigPackage *pkg = new_package(root_src_dir, root_src_path, pkg_path);
|
||||
if (g->std_package != nullptr) {
|
||||
assert(g->compile_var_package != nullptr);
|
||||
pkg->package_table.put(buf_create_from_str("std"), g->std_package);
|
||||
|
@ -15,8 +15,8 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out_type, BuildMode build_mode,
|
||||
Buf *zig_lib_dir, Buf *override_std_dir, ZigLibCInstallation *libc);
|
||||
CodeGen *codegen_create(Buf *main_pkg_path, Buf *root_src_path, const ZigTarget *target,
|
||||
OutType out_type, BuildMode build_mode, Buf *zig_lib_dir, Buf *override_std_dir, ZigLibCInstallation *libc);
|
||||
|
||||
void codegen_set_clang_argv(CodeGen *codegen, const char **args, size_t len);
|
||||
void codegen_set_llvm_argv(CodeGen *codegen, const char **args, size_t len);
|
||||
@ -48,7 +48,8 @@ void codegen_print_timing_report(CodeGen *g, FILE *f);
|
||||
void codegen_link(CodeGen *g);
|
||||
void codegen_build_and_link(CodeGen *g);
|
||||
|
||||
PackageTableEntry *codegen_create_package(CodeGen *g, const char *root_src_dir, const char *root_src_path);
|
||||
ZigPackage *codegen_create_package(CodeGen *g, const char *root_src_dir, const char *root_src_path,
|
||||
const char *pkg_path);
|
||||
void codegen_add_assembly(CodeGen *g, Buf *path);
|
||||
void codegen_add_object(CodeGen *g, Buf *object_path);
|
||||
|
||||
|
@ -78,8 +78,8 @@ static bool test_zig_install_prefix(Buf *test_path, Buf *out_zig_lib_dir) {
|
||||
Buf std_buf = BUF_INIT;
|
||||
buf_init_from_str(&std_buf, "std");
|
||||
|
||||
Buf index_zig_buf = BUF_INIT;
|
||||
buf_init_from_str(&index_zig_buf, "index.zig");
|
||||
Buf std_zig_buf = BUF_INIT;
|
||||
buf_init_from_str(&std_zig_buf, "std.zig");
|
||||
|
||||
Buf test_lib_dir = BUF_INIT;
|
||||
Buf test_zig_dir = BUF_INIT;
|
||||
@ -89,7 +89,7 @@ static bool test_zig_install_prefix(Buf *test_path, Buf *out_zig_lib_dir) {
|
||||
os_path_join(test_path, &lib_buf, &test_lib_dir);
|
||||
os_path_join(&test_lib_dir, &zig_buf, &test_zig_dir);
|
||||
os_path_join(&test_zig_dir, &std_buf, &test_std_dir);
|
||||
os_path_join(&test_std_dir, &index_zig_buf, &test_index_file);
|
||||
os_path_join(&test_std_dir, &std_zig_buf, &test_index_file);
|
||||
|
||||
int err;
|
||||
bool exists;
|
||||
|
292
src/ir.cpp
292
src/ir.cpp
@ -258,7 +258,6 @@ static bool types_have_same_zig_comptime_repr(ZigType *a, ZigType *b) {
|
||||
case ZigTypeIdPointer:
|
||||
case ZigTypeIdUndefined:
|
||||
case ZigTypeIdNull:
|
||||
case ZigTypeIdNamespace:
|
||||
case ZigTypeIdBoundFn:
|
||||
case ZigTypeIdErrorSet:
|
||||
case ZigTypeIdOpaque:
|
||||
@ -1123,11 +1122,11 @@ static IrInstruction *ir_create_const_fn(IrBuilder *irb, Scope *scope, AstNode *
|
||||
return &const_instruction->base;
|
||||
}
|
||||
|
||||
static IrInstruction *ir_build_const_import(IrBuilder *irb, Scope *scope, AstNode *source_node, ImportTableEntry *import) {
|
||||
static IrInstruction *ir_build_const_import(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigType *import) {
|
||||
IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
|
||||
const_instruction->base.value.type = irb->codegen->builtin_types.entry_namespace;
|
||||
const_instruction->base.value.type = irb->codegen->builtin_types.entry_type;
|
||||
const_instruction->base.value.special = ConstValSpecialStatic;
|
||||
const_instruction->base.value.data.x_import = import;
|
||||
const_instruction->base.value.data.x_type = import;
|
||||
return &const_instruction->base;
|
||||
}
|
||||
|
||||
@ -3824,7 +3823,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
|
||||
if (tld)
|
||||
return ir_build_decl_ref(irb, scope, node, tld, lval);
|
||||
|
||||
if (node->owner->any_imports_failed) {
|
||||
if (get_container_scope(node->owner)->any_imports_failed) {
|
||||
// skip the error message since we had a failing import in this file
|
||||
// if an import breaks we don't need redundant undeclared identifier errors
|
||||
return irb->codegen->invalid_instruction;
|
||||
@ -6609,20 +6608,32 @@ static bool render_instance_name_recursive(CodeGen *codegen, Buf *name, Scope *o
|
||||
return true;
|
||||
}
|
||||
|
||||
static Buf *get_anon_type_name(CodeGen *codegen, IrExecutable *exec, const char *kind_name, AstNode *source_node) {
|
||||
static Buf *get_anon_type_name(CodeGen *codegen, IrExecutable *exec, const char *kind_name,
|
||||
Scope *scope, AstNode *source_node, Buf *out_bare_name)
|
||||
{
|
||||
if (exec->name) {
|
||||
return exec->name;
|
||||
ZigType *import = get_scope_import(scope);
|
||||
Buf *namespace_name = buf_create_from_buf(&import->name);
|
||||
if (buf_len(namespace_name) != 0) buf_append_char(namespace_name, NAMESPACE_SEP_CHAR);
|
||||
buf_append_buf(namespace_name, exec->name);
|
||||
buf_init_from_buf(out_bare_name, exec->name);
|
||||
return namespace_name;
|
||||
} else if (exec->name_fn != nullptr) {
|
||||
Buf *name = buf_alloc();
|
||||
buf_append_buf(name, &exec->name_fn->symbol_name);
|
||||
buf_appendf(name, "(");
|
||||
render_instance_name_recursive(codegen, name, &exec->name_fn->fndef_scope->base, exec->begin_scope);
|
||||
buf_appendf(name, ")");
|
||||
buf_init_from_buf(out_bare_name, name);
|
||||
return name;
|
||||
} else {
|
||||
//Note: C-imports do not have valid location information
|
||||
return buf_sprintf("(anonymous %s at %s:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ")", kind_name,
|
||||
(source_node->owner->path != nullptr) ? buf_ptr(source_node->owner->path) : "(null)", source_node->line + 1, source_node->column + 1);
|
||||
ZigType *import = get_scope_import(scope);
|
||||
Buf *namespace_name = buf_create_from_buf(&import->name);
|
||||
if (buf_len(namespace_name) != 0) buf_append_char(namespace_name, NAMESPACE_SEP_CHAR);
|
||||
buf_appendf(namespace_name, "%s:%" ZIG_PRI_usize ":%" ZIG_PRI_usize, kind_name,
|
||||
source_node->line + 1, source_node->column + 1);
|
||||
buf_init_from_buf(out_bare_name, namespace_name);
|
||||
return namespace_name;
|
||||
}
|
||||
}
|
||||
|
||||
@ -6630,24 +6641,23 @@ static IrInstruction *ir_gen_container_decl(IrBuilder *irb, Scope *parent_scope,
|
||||
assert(node->type == NodeTypeContainerDecl);
|
||||
|
||||
ContainerKind kind = node->data.container_decl.kind;
|
||||
Buf *name = get_anon_type_name(irb->codegen, irb->exec, container_string(kind), node);
|
||||
|
||||
VisibMod visib_mod = VisibModPub;
|
||||
TldContainer *tld_container = allocate<TldContainer>(1);
|
||||
init_tld(&tld_container->base, TldIdContainer, name, visib_mod, node, parent_scope);
|
||||
Buf *bare_name = buf_alloc();
|
||||
Buf *name = get_anon_type_name(irb->codegen, irb->exec, container_string(kind), parent_scope, node, bare_name);
|
||||
|
||||
ContainerLayout layout = node->data.container_decl.layout;
|
||||
ZigType *container_type = get_partial_container_type(irb->codegen, parent_scope,
|
||||
kind, node, buf_ptr(name), layout);
|
||||
kind, node, buf_ptr(name), bare_name, layout);
|
||||
ScopeDecls *child_scope = get_container_scope(container_type);
|
||||
|
||||
tld_container->type_entry = container_type;
|
||||
tld_container->decls_scope = child_scope;
|
||||
|
||||
for (size_t i = 0; i < node->data.container_decl.decls.length; i += 1) {
|
||||
AstNode *child_node = node->data.container_decl.decls.at(i);
|
||||
scan_decls(irb->codegen, child_scope, child_node);
|
||||
}
|
||||
|
||||
TldContainer *tld_container = allocate<TldContainer>(1);
|
||||
init_tld(&tld_container->base, TldIdContainer, bare_name, VisibModPub, node, parent_scope);
|
||||
tld_container->type_entry = container_type;
|
||||
tld_container->decls_scope = child_scope;
|
||||
irb->codegen->resolve_queue.append(&tld_container->base);
|
||||
|
||||
// Add this to the list to mark as invalid if analyzing this exec fails.
|
||||
@ -6732,7 +6742,8 @@ static IrInstruction *ir_gen_err_set_decl(IrBuilder *irb, Scope *parent_scope, A
|
||||
|
||||
uint32_t err_count = node->data.err_set_decl.decls.length;
|
||||
|
||||
Buf *type_name = get_anon_type_name(irb->codegen, irb->exec, "error set", node);
|
||||
Buf bare_name = BUF_INIT;
|
||||
Buf *type_name = get_anon_type_name(irb->codegen, irb->exec, "error", parent_scope, node, &bare_name);
|
||||
ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet);
|
||||
buf_init_from_buf(&err_set_type->name, type_name);
|
||||
err_set_type->data.error_set.err_count = err_count;
|
||||
@ -12065,7 +12076,6 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
|
||||
case ZigTypeIdErrorSet:
|
||||
case ZigTypeIdFn:
|
||||
case ZigTypeIdOpaque:
|
||||
case ZigTypeIdNamespace:
|
||||
case ZigTypeIdBoundFn:
|
||||
case ZigTypeIdArgTuple:
|
||||
case ZigTypeIdPromise:
|
||||
@ -13407,7 +13417,6 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
|
||||
case ZigTypeIdOptional:
|
||||
case ZigTypeIdErrorUnion:
|
||||
case ZigTypeIdErrorSet:
|
||||
case ZigTypeIdNamespace:
|
||||
case ZigTypeIdBoundFn:
|
||||
case ZigTypeIdArgTuple:
|
||||
case ZigTypeIdOpaque:
|
||||
@ -13432,7 +13441,6 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
|
||||
case ZigTypeIdErrorSet:
|
||||
case ZigTypeIdVector:
|
||||
zig_panic("TODO export const value of type %s", buf_ptr(&target->value.type->name));
|
||||
case ZigTypeIdNamespace:
|
||||
case ZigTypeIdBoundFn:
|
||||
case ZigTypeIdArgTuple:
|
||||
case ZigTypeIdOpaque:
|
||||
@ -14616,7 +14624,6 @@ static IrInstruction *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op_
|
||||
case ZigTypeIdEnum:
|
||||
case ZigTypeIdUnion:
|
||||
case ZigTypeIdFn:
|
||||
case ZigTypeIdNamespace:
|
||||
case ZigTypeIdBoundFn:
|
||||
case ZigTypeIdArgTuple:
|
||||
case ZigTypeIdPromise:
|
||||
@ -15368,7 +15375,7 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira,
|
||||
auto entry = container_scope->decl_table.maybe_get(field_name);
|
||||
Tld *tld = entry ? entry->value : nullptr;
|
||||
if (tld && tld->id == TldIdFn) {
|
||||
resolve_top_level_decl(ira->codegen, tld, false, source_instr->source_node);
|
||||
resolve_top_level_decl(ira->codegen, tld, source_instr->source_node);
|
||||
if (tld->resolution == TldResolutionInvalid)
|
||||
return ira->codegen->invalid_instruction;
|
||||
TldFn *tld_fn = (TldFn *)tld;
|
||||
@ -15557,8 +15564,7 @@ static void add_link_lib_symbol(IrAnalyze *ira, Buf *lib_name, Buf *symbol_name,
|
||||
|
||||
|
||||
static IrInstruction *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_instruction, Tld *tld) {
|
||||
bool pointer_only = false;
|
||||
resolve_top_level_decl(ira->codegen, tld, pointer_only, source_instruction->source_node);
|
||||
resolve_top_level_decl(ira->codegen, tld, source_instruction->source_node);
|
||||
if (tld->resolution == TldResolutionInvalid)
|
||||
return ira->codegen->invalid_instruction;
|
||||
|
||||
@ -15735,12 +15741,17 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
|
||||
}
|
||||
}
|
||||
ScopeDecls *container_scope = get_container_scope(child_type);
|
||||
if (container_scope != nullptr) {
|
||||
auto entry = container_scope->decl_table.maybe_get(field_name);
|
||||
Tld *tld = entry ? entry->value : nullptr;
|
||||
if (tld) {
|
||||
return ir_analyze_decl_ref(ira, &field_ptr_instruction->base, tld);
|
||||
Tld *tld = find_container_decl(ira->codegen, container_scope, field_name);
|
||||
if (tld) {
|
||||
if (tld->visib_mod == VisibModPrivate &&
|
||||
tld->import != get_scope_import(field_ptr_instruction->base.scope))
|
||||
{
|
||||
ErrorMsg *msg = ir_add_error(ira, &field_ptr_instruction->base,
|
||||
buf_sprintf("'%s' is private", buf_ptr(field_name)));
|
||||
add_error_note(ira->codegen, msg, tld->source_node, buf_sprintf("declared here"));
|
||||
return ira->codegen->invalid_instruction;
|
||||
}
|
||||
return ir_analyze_decl_ref(ira, &field_ptr_instruction->base, tld);
|
||||
}
|
||||
if (child_type->id == ZigTypeIdUnion &&
|
||||
(child_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr ||
|
||||
@ -15758,9 +15769,11 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
|
||||
ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
|
||||
}
|
||||
}
|
||||
const char *container_name = (child_type == ira->codegen->root_import) ?
|
||||
"root source file" : buf_ptr(buf_sprintf("container '%s'", buf_ptr(&child_type->name)));
|
||||
ir_add_error(ira, &field_ptr_instruction->base,
|
||||
buf_sprintf("container '%s' has no member called '%s'",
|
||||
buf_ptr(&child_type->name), buf_ptr(field_name)));
|
||||
buf_sprintf("%s has no member called '%s'",
|
||||
container_name, buf_ptr(field_name)));
|
||||
return ira->codegen->invalid_instruction;
|
||||
} else if (child_type->id == ZigTypeIdErrorSet) {
|
||||
ErrorTableEntry *err_entry;
|
||||
@ -15971,37 +15984,6 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
|
||||
buf_sprintf("type '%s' does not support field access", buf_ptr(&child_type->name)));
|
||||
return ira->codegen->invalid_instruction;
|
||||
}
|
||||
} else if (container_type->id == ZigTypeIdNamespace) {
|
||||
assert(container_ptr->value.type->id == ZigTypeIdPointer);
|
||||
ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);
|
||||
if (!container_ptr_val)
|
||||
return ira->codegen->invalid_instruction;
|
||||
|
||||
ConstExprValue *namespace_val = const_ptr_pointee(ira, ira->codegen, container_ptr_val,
|
||||
field_ptr_instruction->base.source_node);
|
||||
if (namespace_val == nullptr)
|
||||
return ira->codegen->invalid_instruction;
|
||||
assert(namespace_val->special == ConstValSpecialStatic);
|
||||
|
||||
ImportTableEntry *namespace_import = namespace_val->data.x_import;
|
||||
|
||||
Tld *tld = find_decl(ira->codegen, &namespace_import->decls_scope->base, field_name);
|
||||
if (tld) {
|
||||
if (tld->visib_mod == VisibModPrivate &&
|
||||
tld->import != source_node->owner)
|
||||
{
|
||||
ErrorMsg *msg = ir_add_error_node(ira, source_node,
|
||||
buf_sprintf("'%s' is private", buf_ptr(field_name)));
|
||||
add_error_note(ira->codegen, msg, tld->source_node, buf_sprintf("declared here"));
|
||||
return ira->codegen->invalid_instruction;
|
||||
}
|
||||
return ir_analyze_decl_ref(ira, &field_ptr_instruction->base, tld);
|
||||
} else {
|
||||
const char *import_name = namespace_import->path ? buf_ptr(namespace_import->path) : "(C import)";
|
||||
ir_add_error_node(ira, source_node,
|
||||
buf_sprintf("no member named '%s' in '%s'", buf_ptr(field_name), import_name));
|
||||
return ira->codegen->invalid_instruction;
|
||||
}
|
||||
} else {
|
||||
ir_add_error_node(ira, field_ptr_instruction->base.source_node,
|
||||
buf_sprintf("type '%s' does not support field access", buf_ptr(&container_type->name)));
|
||||
@ -16281,7 +16263,6 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira,
|
||||
case ZigTypeIdEnum:
|
||||
case ZigTypeIdUnion:
|
||||
case ZigTypeIdFn:
|
||||
case ZigTypeIdNamespace:
|
||||
case ZigTypeIdBoundFn:
|
||||
case ZigTypeIdPromise:
|
||||
case ZigTypeIdVector:
|
||||
@ -16402,7 +16383,6 @@ static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira,
|
||||
case ZigTypeIdEnum:
|
||||
case ZigTypeIdUnion:
|
||||
case ZigTypeIdFn:
|
||||
case ZigTypeIdNamespace:
|
||||
case ZigTypeIdBoundFn:
|
||||
case ZigTypeIdPromise:
|
||||
case ZigTypeIdVector:
|
||||
@ -16452,7 +16432,6 @@ static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira,
|
||||
case ZigTypeIdComptimeInt:
|
||||
case ZigTypeIdBoundFn:
|
||||
case ZigTypeIdMetaType:
|
||||
case ZigTypeIdNamespace:
|
||||
case ZigTypeIdArgTuple:
|
||||
case ZigTypeIdOpaque:
|
||||
ir_add_error_node(ira, size_of_instruction->base.source_node,
|
||||
@ -16860,7 +16839,6 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,
|
||||
case ZigTypeIdPointer:
|
||||
case ZigTypeIdPromise:
|
||||
case ZigTypeIdFn:
|
||||
case ZigTypeIdNamespace:
|
||||
case ZigTypeIdErrorSet: {
|
||||
if (pointee_val) {
|
||||
IrInstruction *result = ir_const(ira, &switch_target_instruction->base, nullptr);
|
||||
@ -17009,25 +16987,29 @@ static IrInstruction *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructio
|
||||
return ira->codegen->invalid_instruction;
|
||||
|
||||
AstNode *source_node = import_instruction->base.source_node;
|
||||
ImportTableEntry *import = source_node->owner;
|
||||
ZigType *import = source_node->owner;
|
||||
|
||||
Buf *import_target_path;
|
||||
Buf *search_dir;
|
||||
assert(import->package);
|
||||
PackageTableEntry *target_package;
|
||||
auto package_entry = import->package->package_table.maybe_get(import_target_str);
|
||||
assert(import->data.structure.root_struct->package);
|
||||
ZigPackage *target_package;
|
||||
auto package_entry = import->data.structure.root_struct->package->package_table.maybe_get(import_target_str);
|
||||
SourceKind source_kind;
|
||||
if (package_entry) {
|
||||
target_package = package_entry->value;
|
||||
import_target_path = &target_package->root_src_path;
|
||||
search_dir = &target_package->root_src_dir;
|
||||
source_kind = SourceKindPkgMain;
|
||||
} else {
|
||||
// try it as a filename
|
||||
target_package = import->package;
|
||||
target_package = import->data.structure.root_struct->package;
|
||||
import_target_path = import_target_str;
|
||||
|
||||
// search relative to importing file
|
||||
search_dir = buf_alloc();
|
||||
os_path_dirname(import->path, search_dir);
|
||||
os_path_dirname(import->data.structure.root_struct->path, search_dir);
|
||||
|
||||
source_kind = SourceKindNonRoot;
|
||||
}
|
||||
|
||||
Buf full_path = BUF_INIT;
|
||||
@ -17041,10 +17023,19 @@ static IrInstruction *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructio
|
||||
|
||||
auto import_entry = ira->codegen->import_table.maybe_get(resolved_path);
|
||||
if (import_entry) {
|
||||
IrInstruction *result = ir_const(ira, &import_instruction->base,
|
||||
ira->codegen->builtin_types.entry_namespace);
|
||||
result->value.data.x_import = import_entry->value;
|
||||
return result;
|
||||
return ir_const_type(ira, &import_instruction->base, import_entry->value);
|
||||
}
|
||||
|
||||
if (source_kind == SourceKindNonRoot) {
|
||||
ZigPackage *cur_scope_pkg = scope_package(import_instruction->base.scope);
|
||||
Buf *pkg_root_src_dir = &cur_scope_pkg->root_src_dir;
|
||||
Buf resolved_root_src_dir = os_path_resolve(&pkg_root_src_dir, 1);
|
||||
if (!buf_starts_with_buf(resolved_path, &resolved_root_src_dir)) {
|
||||
ir_add_error_node(ira, source_node,
|
||||
buf_sprintf("import of file outside package path: '%s'",
|
||||
buf_ptr(import_target_path)));
|
||||
return ira->codegen->invalid_instruction;
|
||||
}
|
||||
}
|
||||
|
||||
if ((err = file_fetch(ira->codegen, resolved_path, import_code))) {
|
||||
@ -17059,13 +17050,9 @@ static IrInstruction *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructio
|
||||
}
|
||||
}
|
||||
|
||||
ImportTableEntry *target_import = add_source_file(ira->codegen, target_package, resolved_path, import_code);
|
||||
ZigType *target_import = add_source_file(ira->codegen, target_package, resolved_path, import_code, source_kind);
|
||||
|
||||
scan_import(ira->codegen, target_import);
|
||||
|
||||
IrInstruction *result = ir_const(ira, &import_instruction->base, ira->codegen->builtin_types.entry_namespace);
|
||||
result->value.data.x_import = target_import;
|
||||
return result;
|
||||
return ir_const_type(ira, &import_instruction->base, target_import);
|
||||
}
|
||||
|
||||
static IrInstruction *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstructionRef *ref_instruction) {
|
||||
@ -17398,17 +17385,7 @@ static IrInstruction *ir_analyze_instruction_compile_err(IrAnalyze *ira,
|
||||
return ira->codegen->invalid_instruction;
|
||||
|
||||
ErrorMsg *msg = ir_add_error(ira, &instruction->base, msg_buf);
|
||||
size_t i = ira->codegen->tld_ref_source_node_stack.length;
|
||||
for (;;) {
|
||||
if (i == 0)
|
||||
break;
|
||||
i -= 1;
|
||||
AstNode *source_node = ira->codegen->tld_ref_source_node_stack.at(i);
|
||||
if (source_node) {
|
||||
add_error_note(ira->codegen, msg, source_node,
|
||||
buf_sprintf("referenced here"));
|
||||
}
|
||||
}
|
||||
emit_error_notes_for_ref_stack(ira->codegen, msg);
|
||||
|
||||
return ira->codegen->invalid_instruction;
|
||||
}
|
||||
@ -17665,6 +17642,12 @@ static IrInstruction *ir_analyze_instruction_bit_offset_of(IrAnalyze *ira,
|
||||
return ir_const_unsigned(ira, &instruction->base, bit_offset);
|
||||
}
|
||||
|
||||
static IrInstruction *ir_error_dependency_loop(IrAnalyze *ira, IrInstruction *source_instr) {
|
||||
ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("dependency loop detected"));
|
||||
emit_error_notes_for_ref_stack(ira->codegen, msg);
|
||||
return ira->codegen->invalid_instruction;
|
||||
}
|
||||
|
||||
static void ensure_field_index(ZigType *type, const char *field_name, size_t index) {
|
||||
Buf *field_name_buf;
|
||||
|
||||
@ -17711,7 +17694,9 @@ static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, Zig
|
||||
return var->const_value->data.x_type;
|
||||
}
|
||||
|
||||
static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, ScopeDecls *decls_scope) {
|
||||
static Error ir_make_type_info_defs(IrAnalyze *ira, IrInstruction *source_instr, ConstExprValue *out_val,
|
||||
ScopeDecls *decls_scope)
|
||||
{
|
||||
Error err;
|
||||
ZigType *type_info_definition_type = ir_type_info_get_type(ira, "Definition", nullptr);
|
||||
if ((err = ensure_complete_type(ira->codegen, type_info_definition_type)))
|
||||
@ -17741,7 +17726,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco
|
||||
while ((curr_entry = decl_it.next()) != nullptr) {
|
||||
// If the definition is unresolved, force it to be resolved again.
|
||||
if (curr_entry->value->resolution == TldResolutionUnresolved) {
|
||||
resolve_top_level_decl(ira->codegen, curr_entry->value, false, curr_entry->value->source_node);
|
||||
resolve_top_level_decl(ira->codegen, curr_entry->value, curr_entry->value->source_node);
|
||||
if (curr_entry->value->resolution != TldResolutionOk) {
|
||||
return ErrorSemanticAnalyzeFail;
|
||||
}
|
||||
@ -17831,6 +17816,11 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco
|
||||
ZigFn *fn_entry = ((TldFn *)curr_entry->value)->fn_entry;
|
||||
assert(!fn_entry->is_test);
|
||||
|
||||
if (fn_entry->type_entry == nullptr) {
|
||||
ir_error_dependency_loop(ira, source_instr);
|
||||
return ErrorSemanticAnalyzeFail;
|
||||
}
|
||||
|
||||
AstNodeFnProto *fn_node = (AstNodeFnProto *)(fn_entry->proto_node);
|
||||
|
||||
ConstExprValue *fn_def_val = create_const_vals(1);
|
||||
@ -18007,7 +17997,7 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_ty
|
||||
// alignment: u32
|
||||
ensure_field_index(result->type, "alignment", 3);
|
||||
fields[3].special = ConstValSpecialStatic;
|
||||
fields[3].type = get_int_type(ira->codegen, false, 29);
|
||||
fields[3].type = ira->codegen->builtin_types.entry_num_lit_int;
|
||||
bigint_init_unsigned(&fields[3].data.x_bigint, get_ptr_align(ira->codegen, attrs_type));
|
||||
// child: type
|
||||
ensure_field_index(result->type, "child", 4);
|
||||
@ -18026,7 +18016,7 @@ static void make_enum_field_val(IrAnalyze *ira, ConstExprValue *enum_field_val,
|
||||
|
||||
ConstExprValue *inner_fields = create_const_vals(2);
|
||||
inner_fields[1].special = ConstValSpecialStatic;
|
||||
inner_fields[1].type = ira->codegen->builtin_types.entry_usize;
|
||||
inner_fields[1].type = ira->codegen->builtin_types.entry_num_lit_int;
|
||||
|
||||
ConstExprValue *name = create_const_str_lit(ira->codegen, enum_field->name);
|
||||
init_const_slice(ira->codegen, &inner_fields[0], name, 0, buf_len(enum_field->name), true);
|
||||
@ -18036,7 +18026,9 @@ static void make_enum_field_val(IrAnalyze *ira, ConstExprValue *enum_field_val,
|
||||
enum_field_val->data.x_struct.fields = inner_fields;
|
||||
}
|
||||
|
||||
static Error ir_make_type_info_value(IrAnalyze *ira, AstNode *source_node, ZigType *type_entry, ConstExprValue **out) {
|
||||
static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr, ZigType *type_entry,
|
||||
ConstExprValue **out)
|
||||
{
|
||||
Error err;
|
||||
assert(type_entry != nullptr);
|
||||
assert(!type_is_invalid(type_entry));
|
||||
@ -18056,7 +18048,6 @@ static Error ir_make_type_info_value(IrAnalyze *ira, AstNode *source_node, ZigTy
|
||||
case ZigTypeIdComptimeInt:
|
||||
case ZigTypeIdUndefined:
|
||||
case ZigTypeIdNull:
|
||||
case ZigTypeIdNamespace:
|
||||
case ZigTypeIdArgTuple:
|
||||
case ZigTypeIdOpaque:
|
||||
*out = nullptr;
|
||||
@ -18089,7 +18080,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, AstNode *source_node, ZigTy
|
||||
// bits: u8
|
||||
ensure_field_index(result->type, "bits", 1);
|
||||
fields[1].special = ConstValSpecialStatic;
|
||||
fields[1].type = ira->codegen->builtin_types.entry_u8;
|
||||
fields[1].type = ira->codegen->builtin_types.entry_num_lit_int;
|
||||
bigint_init_unsigned(&fields[1].data.x_bigint, type_entry->data.integral.bit_count);
|
||||
|
||||
break;
|
||||
@ -18106,7 +18097,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, AstNode *source_node, ZigTy
|
||||
// bits: u8
|
||||
ensure_field_index(result->type, "bits", 0);
|
||||
fields[0].special = ConstValSpecialStatic;
|
||||
fields[0].type = ira->codegen->builtin_types.entry_u8;
|
||||
fields[0].type = ira->codegen->builtin_types.entry_num_lit_int;
|
||||
bigint_init_unsigned(&fields->data.x_bigint, type_entry->data.floating.bit_count);
|
||||
|
||||
break;
|
||||
@ -18130,7 +18121,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, AstNode *source_node, ZigTy
|
||||
// len: usize
|
||||
ensure_field_index(result->type, "len", 0);
|
||||
fields[0].special = ConstValSpecialStatic;
|
||||
fields[0].type = ira->codegen->builtin_types.entry_usize;
|
||||
fields[0].type = ira->codegen->builtin_types.entry_num_lit_int;
|
||||
bigint_init_unsigned(&fields[0].data.x_bigint, type_entry->data.array.len);
|
||||
// child: type
|
||||
ensure_field_index(result->type, "child", 1);
|
||||
@ -18151,7 +18142,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, AstNode *source_node, ZigTy
|
||||
// len: usize
|
||||
ensure_field_index(result->type, "len", 0);
|
||||
fields[0].special = ConstValSpecialStatic;
|
||||
fields[0].type = ira->codegen->builtin_types.entry_u32;
|
||||
fields[0].type = ira->codegen->builtin_types.entry_num_lit_int;
|
||||
bigint_init_unsigned(&fields[0].data.x_bigint, type_entry->data.vector.len);
|
||||
// child: type
|
||||
ensure_field_index(result->type, "child", 1);
|
||||
@ -18248,8 +18239,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, AstNode *source_node, ZigTy
|
||||
}
|
||||
// defs: []TypeInfo.Definition
|
||||
ensure_field_index(result->type, "defs", 3);
|
||||
if ((err = ir_make_type_info_defs(ira, &fields[3], type_entry->data.enumeration.decls_scope)))
|
||||
if ((err = ir_make_type_info_defs(ira, source_instr, &fields[3],
|
||||
type_entry->data.enumeration.decls_scope)))
|
||||
{
|
||||
return err;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
@ -18266,11 +18260,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, AstNode *source_node, ZigTy
|
||||
ensure_field_index(result->type, "errors", 0);
|
||||
|
||||
ZigType *type_info_error_type = ir_type_info_get_type(ira, "Error", nullptr);
|
||||
if (!resolve_inferred_error_set(ira->codegen, type_entry, source_node)) {
|
||||
if (!resolve_inferred_error_set(ira->codegen, type_entry, source_instr->source_node)) {
|
||||
return ErrorSemanticAnalyzeFail;
|
||||
}
|
||||
if (type_is_global_error_set(type_entry)) {
|
||||
ir_add_error_node(ira, source_node,
|
||||
ir_add_error(ira, source_instr,
|
||||
buf_sprintf("TODO: compiler bug: implement @typeInfo support for anyerror. https://github.com/ziglang/zig/issues/1936"));
|
||||
return ErrorSemanticAnalyzeFail;
|
||||
}
|
||||
@ -18292,7 +18286,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, AstNode *source_node, ZigTy
|
||||
|
||||
ConstExprValue *inner_fields = create_const_vals(2);
|
||||
inner_fields[1].special = ConstValSpecialStatic;
|
||||
inner_fields[1].type = ira->codegen->builtin_types.entry_usize;
|
||||
inner_fields[1].type = ira->codegen->builtin_types.entry_num_lit_int;
|
||||
|
||||
ConstExprValue *name = nullptr;
|
||||
if (error->cached_error_name_val != nullptr)
|
||||
@ -18412,8 +18406,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, AstNode *source_node, ZigTy
|
||||
}
|
||||
// defs: []TypeInfo.Definition
|
||||
ensure_field_index(result->type, "defs", 3);
|
||||
if ((err = ir_make_type_info_defs(ira, &fields[3], type_entry->data.unionation.decls_scope)))
|
||||
if ((err = ir_make_type_info_defs(ira, source_instr, &fields[3],
|
||||
type_entry->data.unionation.decls_scope)))
|
||||
{
|
||||
return err;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
@ -18461,7 +18458,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, AstNode *source_node, ZigTy
|
||||
|
||||
ConstExprValue *inner_fields = create_const_vals(3);
|
||||
inner_fields[1].special = ConstValSpecialStatic;
|
||||
inner_fields[1].type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_usize);
|
||||
inner_fields[1].type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_num_lit_int);
|
||||
|
||||
if (!type_has_bits(struct_field->type_entry)) {
|
||||
inner_fields[1].data.x_optional = nullptr;
|
||||
@ -18487,8 +18484,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, AstNode *source_node, ZigTy
|
||||
}
|
||||
// defs: []TypeInfo.Definition
|
||||
ensure_field_index(result->type, "defs", 2);
|
||||
if ((err = ir_make_type_info_defs(ira, &fields[2], type_entry->data.structure.decls_scope)))
|
||||
if ((err = ir_make_type_info_defs(ira, source_instr, &fields[2],
|
||||
type_entry->data.structure.decls_scope)))
|
||||
{
|
||||
return err;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
@ -18600,7 +18600,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, AstNode *source_node, ZigTy
|
||||
{
|
||||
ZigType *fn_type = type_entry->data.bound_fn.fn_type;
|
||||
assert(fn_type->id == ZigTypeIdFn);
|
||||
if ((err = ir_make_type_info_value(ira, source_node, fn_type, &result)))
|
||||
if ((err = ir_make_type_info_value(ira, source_instr, fn_type, &result)))
|
||||
return err;
|
||||
|
||||
break;
|
||||
@ -18625,7 +18625,7 @@ static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira,
|
||||
ZigType *result_type = ir_type_info_get_type(ira, nullptr, nullptr);
|
||||
|
||||
ConstExprValue *payload;
|
||||
if ((err = ir_make_type_info_value(ira, instruction->base.source_node, type_entry, &payload)))
|
||||
if ((err = ir_make_type_info_value(ira, &instruction->base, type_entry, &payload)))
|
||||
return ira->codegen->invalid_instruction;
|
||||
|
||||
IrInstruction *result = ir_const(ira, &instruction->base, result_type);
|
||||
@ -18680,7 +18680,7 @@ static IrInstruction *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstruc
|
||||
return ira->codegen->invalid_instruction;
|
||||
|
||||
if (!type_entry->cached_const_name_val) {
|
||||
type_entry->cached_const_name_val = create_const_str_lit(ira->codegen, &type_entry->name);
|
||||
type_entry->cached_const_name_val = create_const_str_lit(ira->codegen, type_bare_name(type_entry));
|
||||
}
|
||||
IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
|
||||
copy_const_val(&result->value, type_entry->cached_const_name_val, true);
|
||||
@ -18702,14 +18702,21 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
|
||||
if (type_is_invalid(cimport_result->type))
|
||||
return ira->codegen->invalid_instruction;
|
||||
|
||||
ImportTableEntry *child_import = allocate<ImportTableEntry>(1);
|
||||
child_import->decls_scope = create_decls_scope(ira->codegen, node, nullptr, nullptr, child_import);
|
||||
child_import->c_import_node = node;
|
||||
child_import->package = new_anonymous_package();
|
||||
child_import->package->package_table.put(buf_create_from_str("builtin"), ira->codegen->compile_var_package);
|
||||
child_import->package->package_table.put(buf_create_from_str("std"), ira->codegen->std_package);
|
||||
child_import->di_file = ZigLLVMCreateFile(ira->codegen->dbuilder,
|
||||
ZigPackage *cur_scope_pkg = scope_package(instruction->base.scope);
|
||||
Buf *namespace_name = buf_sprintf("%s.cimport:%" ZIG_PRI_usize ":%" ZIG_PRI_usize,
|
||||
buf_ptr(&cur_scope_pkg->pkg_path), node->line + 1, node->column + 1);
|
||||
|
||||
RootStruct *root_struct = allocate<RootStruct>(1);
|
||||
root_struct->package = new_anonymous_package();
|
||||
root_struct->package->package_table.put(buf_create_from_str("builtin"), ira->codegen->compile_var_package);
|
||||
root_struct->package->package_table.put(buf_create_from_str("std"), ira->codegen->std_package);
|
||||
root_struct->c_import_node = node;
|
||||
// TODO create namespace_name file in zig-cache instead of /tmp and use it
|
||||
// for this DIFile
|
||||
root_struct->di_file = ZigLLVMCreateFile(ira->codegen->dbuilder,
|
||||
buf_ptr(buf_create_from_str("cimport.h")), buf_ptr(buf_create_from_str(".")));
|
||||
ZigType *child_import = get_root_container_type(ira->codegen, buf_ptr(namespace_name),
|
||||
namespace_name, root_struct);
|
||||
|
||||
ZigList<ErrorMsg *> errors = {0};
|
||||
|
||||
@ -18738,14 +18745,12 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
|
||||
if (ira->codegen->verbose_cimport) {
|
||||
fprintf(stderr, "\nC imports:\n");
|
||||
fprintf(stderr, "-----------\n");
|
||||
ast_render(ira->codegen, stderr, child_import->root, 4);
|
||||
ast_render(ira->codegen, stderr, child_import->data.structure.decl_node, 4);
|
||||
}
|
||||
|
||||
scan_decls(ira->codegen, child_import->decls_scope, child_import->root);
|
||||
scan_decls(ira->codegen, get_container_scope(child_import), child_import->data.structure.decl_node);
|
||||
|
||||
IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_namespace);
|
||||
result->value.data.x_import = child_import;
|
||||
return result;
|
||||
return ir_const_type(ira, &instruction->base, child_import);
|
||||
}
|
||||
|
||||
static IrInstruction *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstructionCInclude *instruction) {
|
||||
@ -18819,10 +18824,10 @@ static IrInstruction *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstru
|
||||
if (!rel_file_path)
|
||||
return ira->codegen->invalid_instruction;
|
||||
|
||||
ImportTableEntry *import = get_scope_import(instruction->base.scope);
|
||||
ZigType *import = get_scope_import(instruction->base.scope);
|
||||
// figure out absolute path to resource
|
||||
Buf source_dir_path = BUF_INIT;
|
||||
os_path_dirname(import->path, &source_dir_path);
|
||||
os_path_dirname(import->data.structure.root_struct->path, &source_dir_path);
|
||||
|
||||
Buf *resolve_paths[] = {
|
||||
&source_dir_path,
|
||||
@ -19752,6 +19757,9 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
|
||||
return ira->codegen->invalid_instruction;
|
||||
}
|
||||
} else {
|
||||
if (array_type->data.pointer.ptr_len == PtrLenC) {
|
||||
array_type = adjust_ptr_len(ira->codegen, array_type, PtrLenUnknown);
|
||||
}
|
||||
return_type = get_slice_type(ira->codegen, array_type);
|
||||
if (!end) {
|
||||
ir_add_error(ira, &instruction->base, buf_sprintf("slice of pointer must include end value"));
|
||||
@ -20137,18 +20145,14 @@ static IrInstruction *ir_analyze_instruction_breakpoint(IrAnalyze *ira, IrInstru
|
||||
static IrInstruction *ir_analyze_instruction_return_address(IrAnalyze *ira, IrInstructionReturnAddress *instruction) {
|
||||
IrInstruction *result = ir_build_return_address(&ira->new_irb,
|
||||
instruction->base.scope, instruction->base.source_node);
|
||||
ZigType *u8 = ira->codegen->builtin_types.entry_u8;
|
||||
ZigType *u8_ptr_const = get_pointer_to_type(ira->codegen, u8, true);
|
||||
result->value.type = u8_ptr_const;
|
||||
result->value.type = ira->codegen->builtin_types.entry_usize;
|
||||
return result;
|
||||
}
|
||||
|
||||
static IrInstruction *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrInstructionFrameAddress *instruction) {
|
||||
IrInstruction *result = ir_build_frame_address(&ira->new_irb,
|
||||
instruction->base.scope, instruction->base.source_node);
|
||||
ZigType *u8 = ira->codegen->builtin_types.entry_u8;
|
||||
ZigType *u8_ptr_const = get_pointer_to_type(ira->codegen, u8, true);
|
||||
result->value.type = u8_ptr_const;
|
||||
result->value.type = ira->codegen->builtin_types.entry_usize;
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -20179,7 +20183,6 @@ static IrInstruction *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruct
|
||||
case ZigTypeIdComptimeInt:
|
||||
case ZigTypeIdUndefined:
|
||||
case ZigTypeIdNull:
|
||||
case ZigTypeIdNamespace:
|
||||
case ZigTypeIdBoundFn:
|
||||
case ZigTypeIdArgTuple:
|
||||
case ZigTypeIdVoid:
|
||||
@ -21025,7 +21028,6 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
|
||||
case ZigTypeIdOpaque:
|
||||
case ZigTypeIdBoundFn:
|
||||
case ZigTypeIdArgTuple:
|
||||
case ZigTypeIdNamespace:
|
||||
case ZigTypeIdUnreachable:
|
||||
case ZigTypeIdComptimeFloat:
|
||||
case ZigTypeIdComptimeInt:
|
||||
@ -21185,7 +21187,6 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
|
||||
case ZigTypeIdOpaque:
|
||||
case ZigTypeIdBoundFn:
|
||||
case ZigTypeIdArgTuple:
|
||||
case ZigTypeIdNamespace:
|
||||
case ZigTypeIdUnreachable:
|
||||
case ZigTypeIdComptimeFloat:
|
||||
case ZigTypeIdComptimeInt:
|
||||
@ -21343,7 +21344,6 @@ static bool type_can_bit_cast(ZigType *t) {
|
||||
case ZigTypeIdOpaque:
|
||||
case ZigTypeIdBoundFn:
|
||||
case ZigTypeIdArgTuple:
|
||||
case ZigTypeIdNamespace:
|
||||
case ZigTypeIdUnreachable:
|
||||
case ZigTypeIdComptimeFloat:
|
||||
case ZigTypeIdComptimeInt:
|
||||
@ -21516,7 +21516,7 @@ static IrInstruction *ir_analyze_instruction_decl_ref(IrAnalyze *ira,
|
||||
Tld *tld = instruction->tld;
|
||||
LVal lval = instruction->lval;
|
||||
|
||||
resolve_top_level_decl(ira->codegen, tld, lval == LValPtr, instruction->base.source_node);
|
||||
resolve_top_level_decl(ira->codegen, tld, instruction->base.source_node);
|
||||
if (tld->resolution == TldResolutionInvalid)
|
||||
return ira->codegen->invalid_instruction;
|
||||
|
||||
@ -21528,6 +21528,10 @@ static IrInstruction *ir_analyze_instruction_decl_ref(IrAnalyze *ira,
|
||||
TldVar *tld_var = (TldVar *)tld;
|
||||
ZigVar *var = tld_var->var;
|
||||
|
||||
if (var == nullptr) {
|
||||
return ir_error_dependency_loop(ira, &instruction->base);
|
||||
}
|
||||
|
||||
IrInstruction *var_ptr = ir_get_var_ptr(ira, &instruction->base, var);
|
||||
if (type_is_invalid(var_ptr->value.type))
|
||||
return ira->codegen->invalid_instruction;
|
||||
@ -21664,9 +21668,11 @@ static IrInstruction *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstru
|
||||
}
|
||||
|
||||
static IrInstruction *ir_analyze_instruction_opaque_type(IrAnalyze *ira, IrInstructionOpaqueType *instruction) {
|
||||
Buf *name = get_anon_type_name(ira->codegen, ira->new_irb.exec, "opaque", instruction->base.source_node);
|
||||
Buf *bare_name = buf_alloc();
|
||||
Buf *full_name = get_anon_type_name(ira->codegen, ira->new_irb.exec, "opaque",
|
||||
instruction->base.scope, instruction->base.source_node, bare_name);
|
||||
ZigType *result_type = get_opaque_type(ira->codegen, instruction->base.scope, instruction->base.source_node,
|
||||
buf_ptr(name));
|
||||
buf_ptr(full_name), bare_name);
|
||||
return ir_const_type(ira, &instruction->base, result_type);
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ static Buf *build_a_raw(CodeGen *parent_gen, const char *aname, Buf *full_path)
|
||||
child_out_type = OutTypeObj;
|
||||
}
|
||||
|
||||
CodeGen *child_gen = codegen_create(full_path, parent_gen->zig_target, child_out_type,
|
||||
CodeGen *child_gen = codegen_create(nullptr, full_path, parent_gen->zig_target, child_out_type,
|
||||
parent_gen->build_mode, parent_gen->zig_lib_dir, parent_gen->zig_std_dir,
|
||||
parent_gen->libc);
|
||||
|
||||
@ -87,10 +87,8 @@ static Buf *build_a(CodeGen *parent_gen, const char *aname) {
|
||||
}
|
||||
|
||||
static Buf *build_compiler_rt(CodeGen *parent_gen) {
|
||||
Buf *dir_path = buf_alloc();
|
||||
os_path_join(parent_gen->zig_std_special_dir, buf_create_from_str("compiler_rt"), dir_path);
|
||||
Buf *full_path = buf_alloc();
|
||||
os_path_join(dir_path, buf_create_from_str("index.zig"), full_path);
|
||||
os_path_join(parent_gen->zig_std_special_dir, buf_create_from_str("compiler_rt.zig"), full_path);
|
||||
|
||||
return build_a_raw(parent_gen, "compiler_rt", full_path);
|
||||
}
|
||||
|
34
src/main.cpp
34
src/main.cpp
@ -63,6 +63,7 @@ static int print_full_usage(const char *arg0, FILE *file, int return_code) {
|
||||
" --output-lib [file] override import library path\n"
|
||||
" --pkg-begin [name] [path] make pkg available to import and push current pkg\n"
|
||||
" --pkg-end pop current pkg\n"
|
||||
" --main-pkg-path set the directory of the root package\n"
|
||||
" --release-fast build with optimizations on and safety off\n"
|
||||
" --release-safe build with optimizations on and safety on\n"
|
||||
" --release-small build with size optimizations on and safety off\n"
|
||||
@ -215,7 +216,7 @@ struct CliPkg {
|
||||
CliPkg *parent;
|
||||
};
|
||||
|
||||
static void add_package(CodeGen *g, CliPkg *cli_pkg, PackageTableEntry *pkg) {
|
||||
static void add_package(CodeGen *g, CliPkg *cli_pkg, ZigPackage *pkg) {
|
||||
for (size_t i = 0; i < cli_pkg->children.length; i += 1) {
|
||||
CliPkg *child_cli_pkg = cli_pkg->children.at(i);
|
||||
|
||||
@ -223,10 +224,11 @@ static void add_package(CodeGen *g, CliPkg *cli_pkg, PackageTableEntry *pkg) {
|
||||
Buf *basename = buf_alloc();
|
||||
os_path_split(buf_create_from_str(child_cli_pkg->path), dirname, basename);
|
||||
|
||||
PackageTableEntry *child_pkg = codegen_create_package(g, buf_ptr(dirname), buf_ptr(basename));
|
||||
ZigPackage *child_pkg = codegen_create_package(g, buf_ptr(dirname), buf_ptr(basename),
|
||||
buf_ptr(buf_sprintf("%s.%s", buf_ptr(&pkg->pkg_path), child_cli_pkg->name)));
|
||||
auto entry = pkg->package_table.put_unique(buf_create_from_str(child_cli_pkg->name), child_pkg);
|
||||
if (entry) {
|
||||
PackageTableEntry *existing_pkg = entry->value;
|
||||
ZigPackage *existing_pkg = entry->value;
|
||||
Buf *full_path = buf_alloc();
|
||||
os_path_join(&existing_pkg->root_src_dir, &existing_pkg->root_src_path, full_path);
|
||||
fprintf(stderr, "Unable to add package '%s'->'%s': already exists as '%s'\n",
|
||||
@ -437,6 +439,7 @@ int main(int argc, char **argv) {
|
||||
TargetSubsystem subsystem = TargetSubsystemAuto;
|
||||
bool is_single_threaded = false;
|
||||
Buf *override_std_dir = nullptr;
|
||||
Buf *main_pkg_path = nullptr;
|
||||
ValgrindSupport valgrind_support = ValgrindSupportAuto;
|
||||
|
||||
if (argc >= 2 && strcmp(argv[1], "build") == 0) {
|
||||
@ -475,8 +478,8 @@ int main(int argc, char **argv) {
|
||||
|
||||
ZigTarget target;
|
||||
get_native_target(&target);
|
||||
CodeGen *g = codegen_create(build_runner_path, &target, OutTypeExe, BuildModeDebug, get_zig_lib_dir(),
|
||||
override_std_dir, nullptr);
|
||||
CodeGen *g = codegen_create(main_pkg_path, build_runner_path, &target, OutTypeExe,
|
||||
BuildModeDebug, get_zig_lib_dir(), override_std_dir, nullptr);
|
||||
g->valgrind_support = valgrind_support;
|
||||
g->enable_time_report = timing_info;
|
||||
buf_init_from_str(&g->cache_dir, cache_dir ? cache_dir : default_zig_cache_name);
|
||||
@ -543,8 +546,8 @@ int main(int argc, char **argv) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
PackageTableEntry *build_pkg = codegen_create_package(g, buf_ptr(&build_file_dirname),
|
||||
buf_ptr(&build_file_basename));
|
||||
ZigPackage *build_pkg = codegen_create_package(g, buf_ptr(&build_file_dirname),
|
||||
buf_ptr(&build_file_basename), "std.special");
|
||||
g->root_package->package_table.put(buf_create_from_str("@build"), build_pkg);
|
||||
g->enable_cache = get_cache_opt(enable_cache, true);
|
||||
codegen_build_and_link(g);
|
||||
@ -566,8 +569,8 @@ int main(int argc, char **argv) {
|
||||
get_native_target(&target);
|
||||
Buf *fmt_runner_path = buf_alloc();
|
||||
os_path_join(get_zig_special_dir(), buf_create_from_str("fmt_runner.zig"), fmt_runner_path);
|
||||
CodeGen *g = codegen_create(fmt_runner_path, &target, OutTypeExe, BuildModeDebug, get_zig_lib_dir(),
|
||||
nullptr, nullptr);
|
||||
CodeGen *g = codegen_create(main_pkg_path, fmt_runner_path, &target, OutTypeExe,
|
||||
BuildModeDebug, get_zig_lib_dir(), nullptr, nullptr);
|
||||
buf_init_from_str(&g->cache_dir, cache_dir ? cache_dir : default_zig_cache_name);
|
||||
g->valgrind_support = valgrind_support;
|
||||
g->is_single_threaded = true;
|
||||
@ -728,6 +731,8 @@ int main(int argc, char **argv) {
|
||||
llvm_argv.append(argv[i]);
|
||||
} else if (strcmp(arg, "--override-std-dir") == 0) {
|
||||
override_std_dir = buf_create_from_str(argv[i]);
|
||||
} else if (strcmp(arg, "--main-pkg-path") == 0) {
|
||||
main_pkg_path = buf_create_from_str(argv[i]);
|
||||
} else if (strcmp(arg, "--library-path") == 0 || strcmp(arg, "-L") == 0) {
|
||||
lib_dirs.append(argv[i]);
|
||||
} else if (strcmp(arg, "--library") == 0) {
|
||||
@ -907,8 +912,8 @@ int main(int argc, char **argv) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
case CmdBuiltin: {
|
||||
CodeGen *g = codegen_create(nullptr, &target, out_type, build_mode, get_zig_lib_dir(), override_std_dir,
|
||||
nullptr);
|
||||
CodeGen *g = codegen_create(main_pkg_path, nullptr, &target,
|
||||
out_type, build_mode, get_zig_lib_dir(), override_std_dir, nullptr);
|
||||
g->valgrind_support = valgrind_support;
|
||||
g->is_single_threaded = is_single_threaded;
|
||||
Buf *builtin_source = codegen_generate_builtin_source(g);
|
||||
@ -1011,8 +1016,8 @@ int main(int argc, char **argv) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
CodeGen *g = codegen_create(zig_root_source_file, &target, out_type, build_mode, get_zig_lib_dir(),
|
||||
override_std_dir, libc);
|
||||
CodeGen *g = codegen_create(main_pkg_path, zig_root_source_file, &target, out_type, build_mode,
|
||||
get_zig_lib_dir(), override_std_dir, libc);
|
||||
g->valgrind_support = valgrind_support;
|
||||
g->subsystem = subsystem;
|
||||
|
||||
@ -1095,7 +1100,6 @@ int main(int argc, char **argv) {
|
||||
if (out_file_lib != nullptr && out_type == OutTypeLib && !is_static)
|
||||
codegen_set_output_lib_path(g, buf_create_from_str(out_file_lib));
|
||||
|
||||
|
||||
add_package(g, cur_pkg, g->root_package);
|
||||
|
||||
if (cmd == CmdBuild || cmd == CmdRun || cmd == CmdTest) {
|
||||
@ -1145,7 +1149,7 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
} else if (cmd == CmdTranslateC) {
|
||||
codegen_translate_c(g, in_file_buf);
|
||||
ast_render(g, stdout, g->root_import->root, 4);
|
||||
ast_render(g, stdout, g->root_import->data.structure.decl_node, 4);
|
||||
if (timing_info)
|
||||
codegen_print_timing_report(g, stdout);
|
||||
return EXIT_SUCCESS;
|
||||
|
@ -264,7 +264,7 @@ void os_path_join(Buf *dirname, Buf *basename, Buf *out_full_path) {
|
||||
buf_append_buf(out_full_path, basename);
|
||||
}
|
||||
|
||||
int os_path_real(Buf *rel_path, Buf *out_abs_path) {
|
||||
Error os_path_real(Buf *rel_path, Buf *out_abs_path) {
|
||||
#if defined(ZIG_OS_WINDOWS)
|
||||
buf_resize(out_abs_path, 4096);
|
||||
if (_fullpath(buf_ptr(out_abs_path), buf_ptr(rel_path), buf_len(out_abs_path)) == nullptr) {
|
||||
|
@ -96,7 +96,7 @@ void os_path_dirname(Buf *full_path, Buf *out_dirname);
|
||||
void os_path_split(Buf *full_path, Buf *out_dirname, Buf *out_basename);
|
||||
void os_path_extname(Buf *full_path, Buf *out_basename, Buf *out_extname);
|
||||
void os_path_join(Buf *dirname, Buf *basename, Buf *out_full_path);
|
||||
int os_path_real(Buf *rel_path, Buf *out_abs_path);
|
||||
Error os_path_real(Buf *rel_path, Buf *out_abs_path);
|
||||
Buf os_path_resolve(Buf **paths_ptr, size_t paths_len);
|
||||
bool os_path_is_absolute(Buf *path);
|
||||
|
||||
|
@ -18,7 +18,7 @@ struct ParseContext {
|
||||
Buf *buf;
|
||||
size_t current_token;
|
||||
ZigList<Token> *tokens;
|
||||
ImportTableEntry *owner;
|
||||
ZigType *owner;
|
||||
ErrColor err_color;
|
||||
};
|
||||
|
||||
@ -130,8 +130,10 @@ static void ast_error(ParseContext *pc, Token *token, const char *format, ...) {
|
||||
va_end(ap);
|
||||
|
||||
|
||||
ErrorMsg *err = err_msg_create_with_line(pc->owner->path, token->start_line, token->start_column,
|
||||
pc->owner->source_code, pc->owner->line_offsets, msg);
|
||||
ErrorMsg *err = err_msg_create_with_line(pc->owner->data.structure.root_struct->path,
|
||||
token->start_line, token->start_column,
|
||||
pc->owner->data.structure.root_struct->source_code,
|
||||
pc->owner->data.structure.root_struct->line_offsets, msg);
|
||||
err->line_start = token->start_line;
|
||||
err->column_start = token->start_column;
|
||||
|
||||
@ -148,8 +150,10 @@ static void ast_asm_error(ParseContext *pc, AstNode *node, size_t offset, const
|
||||
Buf *msg = buf_vprintf(format, ap);
|
||||
va_end(ap);
|
||||
|
||||
ErrorMsg *err = err_msg_create_with_line(pc->owner->path, node->line, node->column,
|
||||
pc->owner->source_code, pc->owner->line_offsets, msg);
|
||||
ErrorMsg *err = err_msg_create_with_line(pc->owner->data.structure.root_struct->path,
|
||||
node->line, node->column,
|
||||
pc->owner->data.structure.root_struct->source_code,
|
||||
pc->owner->data.structure.root_struct->line_offsets, msg);
|
||||
|
||||
print_err_msg(err, pc->err_color);
|
||||
exit(EXIT_FAILURE);
|
||||
@ -570,9 +574,7 @@ static void ast_parse_asm_template(ParseContext *pc, AstNode *node) {
|
||||
}
|
||||
}
|
||||
|
||||
AstNode *ast_parse(Buf *buf, ZigList<Token> *tokens, ImportTableEntry *owner,
|
||||
ErrColor err_color)
|
||||
{
|
||||
AstNode *ast_parse(Buf *buf, ZigList<Token> *tokens, ZigType *owner, ErrColor err_color) {
|
||||
ParseContext pc = {};
|
||||
pc.err_color = err_color;
|
||||
pc.owner = owner;
|
||||
|
@ -16,7 +16,7 @@ ATTRIBUTE_PRINTF(2, 3)
|
||||
void ast_token_error(Token *token, const char *format, ...);
|
||||
|
||||
|
||||
AstNode * ast_parse(Buf *buf, ZigList<Token> *tokens, ImportTableEntry *owner, ErrColor err_color);
|
||||
AstNode * ast_parse(Buf *buf, ZigList<Token> *tokens, ZigType *owner, ErrColor err_color);
|
||||
|
||||
void ast_print(AstNode *node, int indent);
|
||||
|
||||
|
@ -676,15 +676,15 @@ Error target_parse_triple(ZigTarget *target, const char *triple) {
|
||||
if (!opt_archsub.is_some)
|
||||
return ErrorMissingArchitecture;
|
||||
|
||||
if (!opt_os.is_some)
|
||||
return ErrorMissingOperatingSystem;
|
||||
|
||||
if ((err = target_parse_archsub(&target->arch, &target->sub_arch,
|
||||
(char*)opt_archsub.value.ptr, opt_archsub.value.len)))
|
||||
{
|
||||
return err;
|
||||
}
|
||||
|
||||
if (!opt_os.is_some)
|
||||
return ErrorMissingOperatingSystem;
|
||||
|
||||
if ((err = target_parse_os(&target->os, (char*)opt_os.value.ptr, opt_os.value.len))) {
|
||||
return err;
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ struct TransScopeWhile {
|
||||
};
|
||||
|
||||
struct Context {
|
||||
ImportTableEntry *import;
|
||||
ZigType *import;
|
||||
ZigList<ErrorMsg *> *errors;
|
||||
VisibMod visib_mod;
|
||||
bool want_export;
|
||||
@ -4779,7 +4779,7 @@ static void process_preprocessor_entities(Context *c, ZigClangASTUnit *zunit) {
|
||||
}
|
||||
}
|
||||
|
||||
Error parse_h_buf(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, Buf *source,
|
||||
Error parse_h_buf(ZigType *import, ZigList<ErrorMsg *> *errors, Buf *source,
|
||||
CodeGen *codegen, AstNode *source_node)
|
||||
{
|
||||
Error err;
|
||||
@ -4795,7 +4795,7 @@ Error parse_h_buf(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, Buf *so
|
||||
return err;
|
||||
}
|
||||
|
||||
Error parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const char *target_file,
|
||||
Error parse_h_file(ZigType *import, ZigList<ErrorMsg *> *errors, const char *target_file,
|
||||
CodeGen *codegen, AstNode *source_node)
|
||||
{
|
||||
Context context = {0};
|
||||
@ -5005,7 +5005,8 @@ Error parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const
|
||||
render_macros(c);
|
||||
render_aliases(c);
|
||||
|
||||
import->root = c->root;
|
||||
import->data.structure.decl_node = c->root;
|
||||
import->data.structure.decls_scope->base.source_node = c->root;
|
||||
|
||||
return ErrorNone;
|
||||
}
|
||||
|
@ -11,10 +11,10 @@
|
||||
|
||||
#include "all_types.hpp"
|
||||
|
||||
Error parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const char *target_file,
|
||||
Error parse_h_file(ZigType *import, ZigList<ErrorMsg *> *errors, const char *target_file,
|
||||
CodeGen *codegen, AstNode *source_node);
|
||||
|
||||
Error parse_h_buf(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, Buf *source,
|
||||
Error parse_h_buf(ZigType *import, ZigList<ErrorMsg *> *errors, Buf *source,
|
||||
CodeGen *codegen, AstNode *source_node);
|
||||
|
||||
#endif
|
||||
|
12
src/util.hpp
12
src/util.hpp
@ -93,18 +93,6 @@ ATTRIBUTE_RETURNS_NOALIAS static inline T *allocate(size_t count) {
|
||||
return ptr;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static inline void safe_memcpy(T *dest, const T *src, size_t count) {
|
||||
#ifdef NDEBUG
|
||||
memcpy(dest, src, count * sizeof(T));
|
||||
#else
|
||||
// manually assign every elment to trigger compile error for non-copyable structs
|
||||
for (size_t i = 0; i < count; i += 1) {
|
||||
dest[i] = src[i];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static inline T *reallocate(T *old, size_t old_count, size_t new_count) {
|
||||
T *ptr = reallocate_nonzero(old, old_count, new_count);
|
||||
|
@ -1,4 +1,4 @@
|
||||
const std = @import("index.zig");
|
||||
const std = @import("std.zig");
|
||||
const debug = std.debug;
|
||||
const assert = debug.assert;
|
||||
const testing = std.testing;
|
||||
@ -406,6 +406,6 @@ const Item = struct {
|
||||
|
||||
test "std.ArrayList: ArrayList(T) of struct T" {
|
||||
var root = Item{ .integer = 1, .sub_items = ArrayList(Item).init(debug.global_allocator) };
|
||||
try root.sub_items.append( Item{ .integer = 42, .sub_items = ArrayList(Item).init(debug.global_allocator) } );
|
||||
try root.sub_items.append(Item{ .integer = 42, .sub_items = ArrayList(Item).init(debug.global_allocator) });
|
||||
testing.expect(root.sub_items.items[0].integer == 42);
|
||||
}
|
||||
|
9
std/atomic.zig
Normal file
9
std/atomic.zig
Normal file
@ -0,0 +1,9 @@
|
||||
pub const Stack = @import("atomic/stack.zig").Stack;
|
||||
pub const Queue = @import("atomic/queue.zig").Queue;
|
||||
pub const Int = @import("atomic/int.zig").Int;
|
||||
|
||||
test "std.atomic" {
|
||||
_ = @import("atomic/stack.zig");
|
||||
_ = @import("atomic/queue.zig");
|
||||
_ = @import("atomic/int.zig");
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
pub const Stack = @import("stack.zig").Stack;
|
||||
pub const Queue = @import("queue.zig").Queue;
|
||||
pub const Int = @import("int.zig").Int;
|
||||
|
||||
test "std.atomic" {
|
||||
_ = @import("stack.zig");
|
||||
_ = @import("queue.zig");
|
||||
_ = @import("int.zig");
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
const std = @import("../index.zig");
|
||||
const std = @import("../std.zig");
|
||||
const builtin = @import("builtin");
|
||||
const AtomicOrder = builtin.AtomicOrder;
|
||||
const AtomicRmwOp = builtin.AtomicRmwOp;
|
||||
|
@ -68,7 +68,7 @@ pub fn Stack(comptime T: type) type {
|
||||
};
|
||||
}
|
||||
|
||||
const std = @import("../index.zig");
|
||||
const std = @import("../std.zig");
|
||||
const Context = struct {
|
||||
allocator: *std.mem.Allocator,
|
||||
stack: *Stack(i32),
|
||||
|
@ -1,4 +1,4 @@
|
||||
const std = @import("index.zig");
|
||||
const std = @import("std.zig");
|
||||
const assert = std.debug.assert;
|
||||
const testing = std.testing;
|
||||
const mem = std.mem;
|
||||
|
@ -1,4 +1,4 @@
|
||||
const std = @import("index.zig");
|
||||
const std = @import("std.zig");
|
||||
const HashMap = std.HashMap;
|
||||
const mem = std.mem;
|
||||
const Allocator = mem.Allocator;
|
||||
|
@ -1,4 +1,4 @@
|
||||
const std = @import("index.zig");
|
||||
const std = @import("std.zig");
|
||||
const HashMap = @import("hash_map.zig").HashMap;
|
||||
const mem = @import("mem.zig");
|
||||
const Allocator = mem.Allocator;
|
||||
|
@ -1,4 +1,4 @@
|
||||
const std = @import("index.zig");
|
||||
const std = @import("std.zig");
|
||||
const debug = std.debug;
|
||||
const mem = std.mem;
|
||||
const Allocator = mem.Allocator;
|
||||
|
@ -1,4 +1,4 @@
|
||||
const std = @import("index.zig");
|
||||
const std = @import("std.zig");
|
||||
const builtin = @import("builtin");
|
||||
const io = std.io;
|
||||
const mem = std.mem;
|
||||
@ -859,6 +859,7 @@ pub const LibExeObjStep = struct {
|
||||
verbose_cc: bool,
|
||||
c_std: Builder.CStd,
|
||||
override_std_dir: ?[]const u8,
|
||||
main_pkg_path: ?[]const u8,
|
||||
exec_cmd_args: ?[]const ?[]const u8,
|
||||
name_prefix: []const u8,
|
||||
filter: ?[]const u8,
|
||||
@ -950,6 +951,7 @@ pub const LibExeObjStep = struct {
|
||||
.c_std = Builder.CStd.C99,
|
||||
.system_linker_hack = false,
|
||||
.override_std_dir = null,
|
||||
.main_pkg_path = null,
|
||||
.exec_cmd_args = null,
|
||||
.name_prefix = "",
|
||||
.filter = null,
|
||||
@ -1098,6 +1100,10 @@ pub const LibExeObjStep = struct {
|
||||
self.override_std_dir = dir_path;
|
||||
}
|
||||
|
||||
pub fn setMainPkgPath(self: *LibExeObjStep, dir_path: []const u8) void {
|
||||
self.main_pkg_path = dir_path;
|
||||
}
|
||||
|
||||
pub fn setOutputPath(self: *LibExeObjStep, file_path: []const u8) void {
|
||||
self.output_path = file_path;
|
||||
|
||||
@ -1320,7 +1326,7 @@ pub const LibExeObjStep = struct {
|
||||
zig_args.append("--ver-patch") catch unreachable;
|
||||
zig_args.append(builder.fmt("{}", self.version.patch)) catch unreachable;
|
||||
}
|
||||
if ((self.kind == Kind.Exe or self.kind == Kind.Test) and self.static) {
|
||||
if (self.static) {
|
||||
zig_args.append("--static") catch unreachable;
|
||||
}
|
||||
|
||||
@ -1424,6 +1430,11 @@ pub const LibExeObjStep = struct {
|
||||
try zig_args.append(builder.pathFromRoot(dir));
|
||||
}
|
||||
|
||||
if (self.main_pkg_path) |dir| {
|
||||
try zig_args.append("--main-pkg-path");
|
||||
try zig_args.append(builder.pathFromRoot(dir));
|
||||
}
|
||||
|
||||
try builder.spawnChild(zig_args.toSliceConst());
|
||||
|
||||
if (self.kind == Kind.Lib and !self.static and self.target.wantSharedLibSymLinks()) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
const std = @import("../index.zig");
|
||||
const std = @import("../std.zig");
|
||||
const build = @import("../build.zig");
|
||||
const Step = build.Step;
|
||||
const Builder = build.Builder;
|
||||
|
@ -2,14 +2,14 @@ const builtin = @import("builtin");
|
||||
const Os = builtin.Os;
|
||||
|
||||
pub use switch (builtin.os) {
|
||||
Os.linux => @import("linux.zig"),
|
||||
Os.windows => @import("windows.zig"),
|
||||
Os.macosx, Os.ios => @import("darwin.zig"),
|
||||
Os.freebsd => @import("freebsd.zig"),
|
||||
Os.netbsd => @import("netbsd.zig"),
|
||||
Os.linux => @import("c/linux.zig"),
|
||||
Os.windows => @import("c/windows.zig"),
|
||||
Os.macosx, Os.ios => @import("c/darwin.zig"),
|
||||
Os.freebsd => @import("c/freebsd.zig"),
|
||||
Os.netbsd => @import("c/netbsd.zig"),
|
||||
else => empty_import,
|
||||
};
|
||||
const empty_import = @import("../empty.zig");
|
||||
const empty_import = @import("empty.zig");
|
||||
|
||||
// TODO https://github.com/ziglang/zig/issues/265 on this whole file
|
||||
|
@ -163,7 +163,7 @@ pub const Kevent = extern struct {
|
||||
// sys/types.h on macos uses #pragma pack(4) so these checks are
|
||||
// to make sure the struct is laid out the same. These values were
|
||||
// produced from C code using the offsetof macro.
|
||||
const std = @import("../index.zig");
|
||||
const std = @import("../std.zig");
|
||||
const assert = std.debug.assert;
|
||||
|
||||
comptime {
|
||||
|
@ -1,5 +1,5 @@
|
||||
const builtin = @import("builtin");
|
||||
const std = @import("index.zig");
|
||||
const std = @import("std.zig");
|
||||
const io = std.io;
|
||||
const mem = std.mem;
|
||||
const os = std.os;
|
||||
|
45
std/crypto.zig
Normal file
45
std/crypto.zig
Normal file
@ -0,0 +1,45 @@
|
||||
pub const Md5 = @import("crypto/md5.zig").Md5;
|
||||
pub const Sha1 = @import("crypto/sha1.zig").Sha1;
|
||||
|
||||
const sha2 = @import("crypto/sha2.zig");
|
||||
pub const Sha224 = sha2.Sha224;
|
||||
pub const Sha256 = sha2.Sha256;
|
||||
pub const Sha384 = sha2.Sha384;
|
||||
pub const Sha512 = sha2.Sha512;
|
||||
|
||||
const sha3 = @import("crypto/sha3.zig");
|
||||
pub const Sha3_224 = sha3.Sha3_224;
|
||||
pub const Sha3_256 = sha3.Sha3_256;
|
||||
pub const Sha3_384 = sha3.Sha3_384;
|
||||
pub const Sha3_512 = sha3.Sha3_512;
|
||||
|
||||
const blake2 = @import("crypto/blake2.zig");
|
||||
pub const Blake2s224 = blake2.Blake2s224;
|
||||
pub const Blake2s256 = blake2.Blake2s256;
|
||||
pub const Blake2b384 = blake2.Blake2b384;
|
||||
pub const Blake2b512 = blake2.Blake2b512;
|
||||
|
||||
const hmac = @import("crypto/hmac.zig");
|
||||
pub const HmacMd5 = hmac.HmacMd5;
|
||||
pub const HmacSha1 = hmac.HmacSha1;
|
||||
pub const HmacSha256 = hmac.HmacSha256;
|
||||
pub const HmacBlake2s256 = hmac.HmacBlake2s256;
|
||||
|
||||
const import_chaCha20 = @import("crypto/chacha20.zig");
|
||||
pub const chaCha20IETF = import_chaCha20.chaCha20IETF;
|
||||
pub const chaCha20With64BitNonce = import_chaCha20.chaCha20With64BitNonce;
|
||||
|
||||
pub const Poly1305 = @import("crypto/poly1305.zig").Poly1305;
|
||||
pub const X25519 = @import("crypto/x25519.zig").X25519;
|
||||
|
||||
test "crypto" {
|
||||
_ = @import("crypto/blake2.zig");
|
||||
_ = @import("crypto/chacha20.zig");
|
||||
_ = @import("crypto/hmac.zig");
|
||||
_ = @import("crypto/md5.zig");
|
||||
_ = @import("crypto/poly1305.zig");
|
||||
_ = @import("crypto/sha1.zig");
|
||||
_ = @import("crypto/sha2.zig");
|
||||
_ = @import("crypto/sha3.zig");
|
||||
_ = @import("crypto/x25519.zig");
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
const mem = @import("../mem.zig");
|
||||
const math = @import("../math/index.zig");
|
||||
const math = @import("../math.zig");
|
||||
const endian = @import("../endian.zig");
|
||||
const debug = @import("../debug/index.zig");
|
||||
const debug = @import("../debug.zig");
|
||||
const builtin = @import("builtin");
|
||||
const htest = @import("test.zig");
|
||||
|
||||
@ -34,8 +34,8 @@ pub const Blake2s256 = Blake2s(256);
|
||||
fn Blake2s(comptime out_len: usize) type {
|
||||
return struct {
|
||||
const Self = @This();
|
||||
const block_length = 64;
|
||||
const digest_length = out_len / 8;
|
||||
pub const block_length = 64;
|
||||
pub const digest_length = out_len / 8;
|
||||
|
||||
const iv = [8]u32{
|
||||
0x6A09E667,
|
||||
|
@ -1,6 +1,6 @@
|
||||
// Based on public domain Supercop by Daniel J. Bernstein
|
||||
|
||||
const std = @import("../index.zig");
|
||||
const std = @import("../std.zig");
|
||||
const mem = std.mem;
|
||||
const endian = std.endian;
|
||||
const assert = std.debug.assert;
|
||||
|
@ -1,4 +1,4 @@
|
||||
const std = @import("../index.zig");
|
||||
const std = @import("../std.zig");
|
||||
const crypto = std.crypto;
|
||||
const debug = std.debug;
|
||||
const mem = std.mem;
|
||||
|
@ -1,45 +0,0 @@
|
||||
pub const Md5 = @import("md5.zig").Md5;
|
||||
pub const Sha1 = @import("sha1.zig").Sha1;
|
||||
|
||||
const sha2 = @import("sha2.zig");
|
||||
pub const Sha224 = sha2.Sha224;
|
||||
pub const Sha256 = sha2.Sha256;
|
||||
pub const Sha384 = sha2.Sha384;
|
||||
pub const Sha512 = sha2.Sha512;
|
||||
|
||||
const sha3 = @import("sha3.zig");
|
||||
pub const Sha3_224 = sha3.Sha3_224;
|
||||
pub const Sha3_256 = sha3.Sha3_256;
|
||||
pub const Sha3_384 = sha3.Sha3_384;
|
||||
pub const Sha3_512 = sha3.Sha3_512;
|
||||
|
||||
const blake2 = @import("blake2.zig");
|
||||
pub const Blake2s224 = blake2.Blake2s224;
|
||||
pub const Blake2s256 = blake2.Blake2s256;
|
||||
pub const Blake2b384 = blake2.Blake2b384;
|
||||
pub const Blake2b512 = blake2.Blake2b512;
|
||||
|
||||
const hmac = @import("hmac.zig");
|
||||
pub const HmacMd5 = hmac.HmacMd5;
|
||||
pub const HmacSha1 = hmac.HmacSha1;
|
||||
pub const HmacSha256 = hmac.HmacSha256;
|
||||
pub const HmacBlake2s256 = hmac.HmacBlake2s256;
|
||||
|
||||
const import_chaCha20 = @import("chacha20.zig");
|
||||
pub const chaCha20IETF = import_chaCha20.chaCha20IETF;
|
||||
pub const chaCha20With64BitNonce = import_chaCha20.chaCha20With64BitNonce;
|
||||
|
||||
pub const Poly1305 = @import("poly1305.zig").Poly1305;
|
||||
pub const X25519 = @import("x25519.zig").X25519;
|
||||
|
||||
test "crypto" {
|
||||
_ = @import("blake2.zig");
|
||||
_ = @import("chacha20.zig");
|
||||
_ = @import("hmac.zig");
|
||||
_ = @import("md5.zig");
|
||||
_ = @import("poly1305.zig");
|
||||
_ = @import("sha1.zig");
|
||||
_ = @import("sha2.zig");
|
||||
_ = @import("sha3.zig");
|
||||
_ = @import("x25519.zig");
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
const mem = @import("../mem.zig");
|
||||
const math = @import("../math/index.zig");
|
||||
const math = @import("../math.zig");
|
||||
const endian = @import("../endian.zig");
|
||||
const builtin = @import("builtin");
|
||||
const debug = @import("../debug/index.zig");
|
||||
const fmt = @import("../fmt/index.zig");
|
||||
const debug = @import("../debug.zig");
|
||||
const fmt = @import("../fmt.zig");
|
||||
|
||||
const RoundParam = struct {
|
||||
a: usize,
|
||||
@ -29,8 +29,8 @@ fn Rp(a: usize, b: usize, c: usize, d: usize, k: usize, s: u32, t: u32) RoundPar
|
||||
|
||||
pub const Md5 = struct {
|
||||
const Self = @This();
|
||||
const block_length = 64;
|
||||
const digest_length = 16;
|
||||
pub const block_length = 64;
|
||||
pub const digest_length = 16;
|
||||
|
||||
s: [4]u32,
|
||||
// Streaming Cache
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// https://monocypher.org/
|
||||
|
||||
const std = @import("../index.zig");
|
||||
const std = @import("../std.zig");
|
||||
const builtin = @import("builtin");
|
||||
|
||||
const Endian = builtin.Endian;
|
||||
|
@ -1,7 +1,7 @@
|
||||
const mem = @import("../mem.zig");
|
||||
const math = @import("../math/index.zig");
|
||||
const math = @import("../math.zig");
|
||||
const endian = @import("../endian.zig");
|
||||
const debug = @import("../debug/index.zig");
|
||||
const debug = @import("../debug.zig");
|
||||
const builtin = @import("builtin");
|
||||
|
||||
const RoundParam = struct {
|
||||
@ -26,8 +26,8 @@ fn Rp(a: usize, b: usize, c: usize, d: usize, e: usize, i: u32) RoundParam {
|
||||
|
||||
pub const Sha1 = struct {
|
||||
const Self = @This();
|
||||
const block_length = 64;
|
||||
const digest_length = 20;
|
||||
pub const block_length = 64;
|
||||
pub const digest_length = 20;
|
||||
|
||||
s: [5]u32,
|
||||
// Streaming Cache
|
||||
|
@ -1,7 +1,7 @@
|
||||
const mem = @import("../mem.zig");
|
||||
const math = @import("../math/index.zig");
|
||||
const math = @import("../math.zig");
|
||||
const endian = @import("../endian.zig");
|
||||
const debug = @import("../debug/index.zig");
|
||||
const debug = @import("../debug.zig");
|
||||
const builtin = @import("builtin");
|
||||
const htest = @import("test.zig");
|
||||
|
||||
@ -78,8 +78,8 @@ pub const Sha256 = Sha2_32(Sha256Params);
|
||||
fn Sha2_32(comptime params: Sha2Params32) type {
|
||||
return struct {
|
||||
const Self = @This();
|
||||
const block_length = 64;
|
||||
const digest_length = params.out_len / 8;
|
||||
pub const block_length = 64;
|
||||
pub const digest_length = params.out_len / 8;
|
||||
|
||||
s: [8]u32,
|
||||
// Streaming Cache
|
||||
|
@ -1,7 +1,7 @@
|
||||
const mem = @import("../mem.zig");
|
||||
const math = @import("../math/index.zig");
|
||||
const math = @import("../math.zig");
|
||||
const endian = @import("../endian.zig");
|
||||
const debug = @import("../debug/index.zig");
|
||||
const debug = @import("../debug.zig");
|
||||
const builtin = @import("builtin");
|
||||
const htest = @import("test.zig");
|
||||
|
||||
@ -13,8 +13,8 @@ pub const Sha3_512 = Keccak(512, 0x06);
|
||||
fn Keccak(comptime bits: usize, comptime delim: u8) type {
|
||||
return struct {
|
||||
const Self = @This();
|
||||
const block_length = 200;
|
||||
const digest_length = bits / 8;
|
||||
pub const block_length = 200;
|
||||
pub const digest_length = bits / 8;
|
||||
|
||||
s: [200]u8,
|
||||
offset: usize,
|
||||
|
@ -1,4 +1,4 @@
|
||||
const std = @import("../index.zig");
|
||||
const std = @import("../std.zig");
|
||||
const testing = std.testing;
|
||||
const mem = std.mem;
|
||||
const fmt = std.fmt;
|
||||
|
@ -2,7 +2,7 @@ const builtin = @import("builtin");
|
||||
const std = @import("std");
|
||||
const time = std.os.time;
|
||||
const Timer = time.Timer;
|
||||
const crypto = @import("index.zig");
|
||||
const crypto = @import("../crypto.zig");
|
||||
|
||||
const KiB = 1024;
|
||||
const MiB = 1024 * KiB;
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// https://monocypher.org/
|
||||
|
||||
const std = @import("../index.zig");
|
||||
const std = @import("../std.zig");
|
||||
const builtin = @import("builtin");
|
||||
const fmt = std.fmt;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
const std = @import("index.zig");
|
||||
const std = @import("std.zig");
|
||||
const builtin = @import("builtin");
|
||||
const debug = std.debug;
|
||||
const mem = std.mem;
|
||||
|
@ -1,4 +1,4 @@
|
||||
const std = @import("../index.zig");
|
||||
const std = @import("std.zig");
|
||||
const math = std.math;
|
||||
const mem = std.mem;
|
||||
const io = std.io;
|
||||
@ -13,7 +13,7 @@ const ArrayList = std.ArrayList;
|
||||
const builtin = @import("builtin");
|
||||
const maxInt = std.math.maxInt;
|
||||
|
||||
pub const FailingAllocator = @import("failing_allocator.zig").FailingAllocator;
|
||||
pub const FailingAllocator = @import("debug/failing_allocator.zig").FailingAllocator;
|
||||
pub const failing_allocator = &FailingAllocator.init(global_allocator, 0).allocator;
|
||||
|
||||
pub const runtime_safety = switch (builtin.mode) {
|
||||
@ -171,7 +171,7 @@ pub fn assert(ok: bool) void {
|
||||
|
||||
pub fn panic(comptime format: []const u8, args: ...) noreturn {
|
||||
@setCold(true);
|
||||
const first_trace_addr = @ptrToInt(@returnAddress());
|
||||
const first_trace_addr = @returnAddress();
|
||||
panicExtra(null, first_trace_addr, format, args);
|
||||
}
|
||||
|
||||
@ -232,7 +232,7 @@ pub const StackIterator = struct {
|
||||
pub fn init(first_addr: ?usize) StackIterator {
|
||||
return StackIterator{
|
||||
.first_addr = first_addr,
|
||||
.fp = @ptrToInt(@frameAddress()),
|
||||
.fp = @frameAddress(),
|
||||
};
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
const std = @import("../index.zig");
|
||||
const std = @import("../std.zig");
|
||||
const mem = std.mem;
|
||||
|
||||
/// Allocator that fails after N allocations, useful for making sure out of
|
||||
|
@ -1,7 +1,7 @@
|
||||
const builtin = @import("builtin");
|
||||
const Os = builtin.Os;
|
||||
|
||||
const std = @import("index.zig");
|
||||
const std = @import("std.zig");
|
||||
const mem = std.mem;
|
||||
const cstr = std.cstr;
|
||||
const os = std.os;
|
||||
|
@ -1,5 +1,5 @@
|
||||
const builtin = @import("builtin");
|
||||
const std = @import("index.zig");
|
||||
const std = @import("std.zig");
|
||||
const io = std.io;
|
||||
const os = std.os;
|
||||
const math = std.math;
|
||||
|
@ -1,4 +1,4 @@
|
||||
const std = @import("../index.zig");
|
||||
const std = @import("../std.zig");
|
||||
const builtin = @import("builtin");
|
||||
const assert = std.debug.assert;
|
||||
const testing = std.testing;
|
||||
|
@ -1,5 +1,5 @@
|
||||
const builtin = @import("builtin");
|
||||
const std = @import("../index.zig");
|
||||
const std = @import("../std.zig");
|
||||
const event = std.event;
|
||||
const assert = std.debug.assert;
|
||||
const testing = std.testing;
|
||||
@ -404,11 +404,7 @@ pub async fn openPosix(
|
||||
|
||||
pub async fn openRead(loop: *Loop, path: []const u8) os.File.OpenError!os.FileHandle {
|
||||
switch (builtin.os) {
|
||||
builtin.Os.macosx,
|
||||
builtin.Os.linux,
|
||||
builtin.Os.freebsd,
|
||||
builtin.Os.netbsd
|
||||
=> {
|
||||
builtin.Os.macosx, builtin.Os.linux, builtin.Os.freebsd, builtin.Os.netbsd => {
|
||||
const flags = posix.O_LARGEFILE | posix.O_RDONLY | posix.O_CLOEXEC;
|
||||
return await (async openPosix(loop, path, flags, os.File.default_mode) catch unreachable);
|
||||
},
|
||||
@ -876,10 +872,7 @@ pub fn Watch(comptime V: type) type {
|
||||
|
||||
pub async fn addFile(self: *Self, file_path: []const u8, value: V) !?V {
|
||||
switch (builtin.os) {
|
||||
builtin.Os.macosx,
|
||||
builtin.Os.freebsd,
|
||||
builtin.Os.netbsd
|
||||
=> return await (async addFileKEvent(self, file_path, value) catch unreachable),
|
||||
builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => return await (async addFileKEvent(self, file_path, value) catch unreachable),
|
||||
builtin.Os.linux => return await (async addFileLinux(self, file_path, value) catch unreachable),
|
||||
builtin.Os.windows => return await (async addFileWindows(self, file_path, value) catch unreachable),
|
||||
else => @compileError("Unsupported OS"),
|
||||
|
@ -1,4 +1,4 @@
|
||||
const std = @import("../index.zig");
|
||||
const std = @import("../std.zig");
|
||||
const assert = std.debug.assert;
|
||||
const testing = std.testing;
|
||||
const builtin = @import("builtin");
|
||||
|
@ -1,4 +1,4 @@
|
||||
const std = @import("../index.zig");
|
||||
const std = @import("../std.zig");
|
||||
const builtin = @import("builtin");
|
||||
const Lock = std.event.Lock;
|
||||
const Loop = std.event.Loop;
|
||||
|
@ -1,4 +1,4 @@
|
||||
const std = @import("../index.zig");
|
||||
const std = @import("../std.zig");
|
||||
const builtin = @import("builtin");
|
||||
const Allocator = std.mem.Allocator;
|
||||
const assert = std.debug.assert;
|
||||
|
@ -1,4 +1,4 @@
|
||||
const std = @import("../index.zig");
|
||||
const std = @import("../std.zig");
|
||||
const builtin = @import("builtin");
|
||||
const assert = std.debug.assert;
|
||||
const testing = std.testing;
|
||||
|
@ -1,4 +1,4 @@
|
||||
const std = @import("../index.zig");
|
||||
const std = @import("../std.zig");
|
||||
const Lock = std.event.Lock;
|
||||
const Loop = std.event.Loop;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
const std = @import("../index.zig");
|
||||
const std = @import("../std.zig");
|
||||
const builtin = @import("builtin");
|
||||
const assert = std.debug.assert;
|
||||
const testing = std.testing;
|
||||
|
@ -1,4 +1,4 @@
|
||||
const std = @import("../index.zig");
|
||||
const std = @import("../std.zig");
|
||||
const builtin = @import("builtin");
|
||||
const testing = std.testing;
|
||||
const event = std.event;
|
||||
|
@ -1,4 +1,4 @@
|
||||
const std = @import("../index.zig");
|
||||
const std = @import("../std.zig");
|
||||
const builtin = @import("builtin");
|
||||
const assert = std.debug.assert;
|
||||
const testing = std.testing;
|
||||
|
@ -1,4 +1,4 @@
|
||||
const std = @import("../index.zig");
|
||||
const std = @import("../std.zig");
|
||||
const RwLock = std.event.RwLock;
|
||||
const Loop = std.event.Loop;
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
const std = @import("../index.zig");
|
||||
const std = @import("std.zig");
|
||||
const math = std.math;
|
||||
const debug = std.debug;
|
||||
const assert = debug.assert;
|
||||
const testing = std.testing;
|
||||
const mem = std.mem;
|
||||
const builtin = @import("builtin");
|
||||
const errol = @import("errol/index.zig");
|
||||
const errol = @import("fmt/errol.zig");
|
||||
const lossyCast = std.math.lossyCast;
|
||||
|
||||
const max_int_digits = 65;
|
||||
@ -858,10 +858,10 @@ test "fmt.parseUnsigned" {
|
||||
testing.expectError(error.Overflow, parseUnsigned(u2, "4", 16));
|
||||
}
|
||||
|
||||
pub const parseFloat = @import("parse_float.zig").parseFloat;
|
||||
pub const parseFloat = @import("fmt/parse_float.zig").parseFloat;
|
||||
|
||||
test "fmt.parseFloat" {
|
||||
_ = @import("parse_float.zig");
|
||||
_ = @import("fmt/parse_float.zig");
|
||||
}
|
||||
|
||||
pub fn charToDigit(c: u8, radix: u8) (error{InvalidCharacter}!u8) {
|
@ -1,8 +1,8 @@
|
||||
const std = @import("../../index.zig");
|
||||
const enum3 = @import("enum3.zig").enum3;
|
||||
const enum3_data = @import("enum3.zig").enum3_data;
|
||||
const lookup_table = @import("lookup.zig").lookup_table;
|
||||
const HP = @import("lookup.zig").HP;
|
||||
const std = @import("../std.zig");
|
||||
const enum3 = @import("errol/enum3.zig").enum3;
|
||||
const enum3_data = @import("errol/enum3.zig").enum3_data;
|
||||
const lookup_table = @import("errol/lookup.zig").lookup_table;
|
||||
const HP = @import("errol/lookup.zig").HP;
|
||||
const math = std.math;
|
||||
const mem = std.mem;
|
||||
const assert = std.debug.assert;
|
@ -29,7 +29,7 @@
|
||||
// - Only supports round-to-zero
|
||||
// - Does not handle denormals
|
||||
|
||||
const std = @import("../index.zig");
|
||||
const std = @import("../std.zig");
|
||||
|
||||
const max_digits = 25;
|
||||
|
||||
|
@ -1,22 +1,22 @@
|
||||
const adler = @import("adler.zig");
|
||||
const adler = @import("hash/adler.zig");
|
||||
pub const Adler32 = adler.Adler32;
|
||||
|
||||
// pub for polynomials + generic crc32 construction
|
||||
pub const crc = @import("crc.zig");
|
||||
pub const crc = @import("hash/crc.zig");
|
||||
pub const Crc32 = crc.Crc32;
|
||||
|
||||
const fnv = @import("fnv.zig");
|
||||
const fnv = @import("hash/fnv.zig");
|
||||
pub const Fnv1a_32 = fnv.Fnv1a_32;
|
||||
pub const Fnv1a_64 = fnv.Fnv1a_64;
|
||||
pub const Fnv1a_128 = fnv.Fnv1a_128;
|
||||
|
||||
const siphash = @import("siphash.zig");
|
||||
const siphash = @import("hash/siphash.zig");
|
||||
pub const SipHash64 = siphash.SipHash64;
|
||||
pub const SipHash128 = siphash.SipHash128;
|
||||
|
||||
test "hash" {
|
||||
_ = @import("adler.zig");
|
||||
_ = @import("crc.zig");
|
||||
_ = @import("fnv.zig");
|
||||
_ = @import("siphash.zig");
|
||||
_ = @import("hash/adler.zig");
|
||||
_ = @import("hash/crc.zig");
|
||||
_ = @import("hash/fnv.zig");
|
||||
_ = @import("hash/siphash.zig");
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
// https://tools.ietf.org/html/rfc1950#section-9
|
||||
// https://github.com/madler/zlib/blob/master/adler32.c
|
||||
|
||||
const std = @import("../index.zig");
|
||||
const std = @import("../std.zig");
|
||||
const testing = std.testing;
|
||||
|
||||
pub const Adler32 = struct {
|
||||
|
@ -5,7 +5,7 @@
|
||||
// - Crc32SmallWithPoly uses only 64 bytes of memory but is slower. Be aware that this is
|
||||
// still moderately fast just slow relative to the slicing approach.
|
||||
|
||||
const std = @import("../index.zig");
|
||||
const std = @import("../std.zig");
|
||||
const debug = std.debug;
|
||||
const testing = std.testing;
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
//
|
||||
// https://tools.ietf.org/html/draft-eastlake-fnv-14
|
||||
|
||||
const std = @import("../index.zig");
|
||||
const std = @import("../std.zig");
|
||||
const testing = std.testing;
|
||||
|
||||
pub const Fnv1a_32 = Fnv1a(u32, 0x01000193, 0x811c9dc5);
|
||||
|
@ -5,7 +5,7 @@
|
||||
//
|
||||
// https://131002.net/siphash/
|
||||
|
||||
const std = @import("../index.zig");
|
||||
const std = @import("../std.zig");
|
||||
const assert = std.debug.assert;
|
||||
const testing = std.testing;
|
||||
const math = std.math;
|
||||
|
@ -1,4 +1,4 @@
|
||||
const std = @import("index.zig");
|
||||
const std = @import("std.zig");
|
||||
const debug = std.debug;
|
||||
const assert = debug.assert;
|
||||
const testing = std.testing;
|
||||
@ -486,7 +486,6 @@ pub fn autoHash(key: var, comptime rng: *std.rand.Random, comptime HashInt: type
|
||||
builtin.TypeId.ErrorSet => return autoHash(@errorToInt(key), rng),
|
||||
builtin.TypeId.Promise, builtin.TypeId.Fn => return autoHash(@ptrToInt(key), rng),
|
||||
|
||||
builtin.TypeId.Namespace,
|
||||
builtin.TypeId.BoundFn,
|
||||
builtin.TypeId.ComptimeFloat,
|
||||
builtin.TypeId.ComptimeInt,
|
||||
@ -532,7 +531,6 @@ pub fn autoEql(a: var, b: @typeOf(a)) bool {
|
||||
builtin.TypeId.Float,
|
||||
builtin.TypeId.ComptimeFloat,
|
||||
builtin.TypeId.ComptimeInt,
|
||||
builtin.TypeId.Namespace,
|
||||
builtin.TypeId.Promise,
|
||||
builtin.TypeId.Enum,
|
||||
builtin.TypeId.BoundFn,
|
||||
|
@ -1,4 +1,4 @@
|
||||
const std = @import("index.zig");
|
||||
const std = @import("std.zig");
|
||||
const debug = std.debug;
|
||||
const assert = debug.assert;
|
||||
const testing = std.testing;
|
||||
|
@ -1,4 +1,4 @@
|
||||
const std = @import("index.zig");
|
||||
const std = @import("std.zig");
|
||||
const builtin = @import("builtin");
|
||||
const Os = builtin.Os;
|
||||
const c = std.c;
|
||||
|
@ -1,4 +1,4 @@
|
||||
const std = @import("../index.zig");
|
||||
const std = @import("../std.zig");
|
||||
const InStream = std.io.InStream;
|
||||
|
||||
pub fn SeekableStream(comptime SeekErrorType: type, comptime GetSeekPosErrorType: type) type {
|
||||
|
@ -1,4 +1,4 @@
|
||||
const std = @import("index.zig");
|
||||
const std = @import("std.zig");
|
||||
const io = std.io;
|
||||
const meta = std.meta;
|
||||
const trait = std.trait;
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// https://tools.ietf.org/html/rfc8259
|
||||
|
||||
const std = @import("index.zig");
|
||||
const std = @import("std.zig");
|
||||
const debug = std.debug;
|
||||
const testing = std.testing;
|
||||
const mem = std.mem;
|
||||
|
@ -3,7 +3,7 @@
|
||||
// Tests are taken from https://github.com/nst/JSONTestSuite
|
||||
// Read also http://seriot.ch/parsing_json.php for a good overview.
|
||||
|
||||
const std = @import("index.zig");
|
||||
const std = @import("std.zig");
|
||||
|
||||
fn ok(comptime s: []const u8) void {
|
||||
std.testing.expect(std.json.validate(s));
|
||||
|
@ -1,4 +1,4 @@
|
||||
const std = @import("index.zig");
|
||||
const std = @import("std.zig");
|
||||
const builtin = @import("builtin");
|
||||
const assert = std.debug.assert;
|
||||
const testing = std.testing;
|
||||
|
@ -1,4 +1,4 @@
|
||||
const std = @import("index.zig");
|
||||
const std = @import("std.zig");
|
||||
const debug = std.debug;
|
||||
const assert = debug.assert;
|
||||
const testing = std.testing;
|
||||
|
@ -1,5 +1,5 @@
|
||||
const builtin = @import("builtin");
|
||||
const std = @import("../index.zig");
|
||||
const std = @import("std.zig");
|
||||
const TypeId = builtin.TypeId;
|
||||
const assert = std.debug.assert;
|
||||
const testing = std.testing;
|
||||
@ -57,9 +57,9 @@ pub const nan_f128 = @bitCast(f128, nan_u128);
|
||||
pub const inf_u128 = u128(0x7fff0000000000000000000000000000);
|
||||
pub const inf_f128 = @bitCast(f128, inf_u128);
|
||||
|
||||
pub const nan = @import("nan.zig").nan;
|
||||
pub const snan = @import("nan.zig").snan;
|
||||
pub const inf = @import("inf.zig").inf;
|
||||
pub const nan = @import("math/nan.zig").nan;
|
||||
pub const snan = @import("math/nan.zig").snan;
|
||||
pub const inf = @import("math/inf.zig").inf;
|
||||
|
||||
pub fn approxEq(comptime T: type, x: T, y: T, epsilon: T) bool {
|
||||
assert(@typeId(T) == TypeId.Float);
|
||||
@ -111,109 +111,109 @@ pub fn raiseDivByZero() void {
|
||||
// Raise INEXACT fpu exception
|
||||
}
|
||||
|
||||
pub const isNan = @import("isnan.zig").isNan;
|
||||
pub const isSignalNan = @import("isnan.zig").isSignalNan;
|
||||
pub const fabs = @import("fabs.zig").fabs;
|
||||
pub const ceil = @import("ceil.zig").ceil;
|
||||
pub const floor = @import("floor.zig").floor;
|
||||
pub const trunc = @import("trunc.zig").trunc;
|
||||
pub const round = @import("round.zig").round;
|
||||
pub const frexp = @import("frexp.zig").frexp;
|
||||
pub const frexp32_result = @import("frexp.zig").frexp32_result;
|
||||
pub const frexp64_result = @import("frexp.zig").frexp64_result;
|
||||
pub const modf = @import("modf.zig").modf;
|
||||
pub const modf32_result = @import("modf.zig").modf32_result;
|
||||
pub const modf64_result = @import("modf.zig").modf64_result;
|
||||
pub const copysign = @import("copysign.zig").copysign;
|
||||
pub const isFinite = @import("isfinite.zig").isFinite;
|
||||
pub const isInf = @import("isinf.zig").isInf;
|
||||
pub const isPositiveInf = @import("isinf.zig").isPositiveInf;
|
||||
pub const isNegativeInf = @import("isinf.zig").isNegativeInf;
|
||||
pub const isNormal = @import("isnormal.zig").isNormal;
|
||||
pub const signbit = @import("signbit.zig").signbit;
|
||||
pub const scalbn = @import("scalbn.zig").scalbn;
|
||||
pub const pow = @import("pow.zig").pow;
|
||||
pub const powi = @import("powi.zig").powi;
|
||||
pub const sqrt = @import("sqrt.zig").sqrt;
|
||||
pub const cbrt = @import("cbrt.zig").cbrt;
|
||||
pub const acos = @import("acos.zig").acos;
|
||||
pub const asin = @import("asin.zig").asin;
|
||||
pub const atan = @import("atan.zig").atan;
|
||||
pub const atan2 = @import("atan2.zig").atan2;
|
||||
pub const hypot = @import("hypot.zig").hypot;
|
||||
pub const exp = @import("exp.zig").exp;
|
||||
pub const exp2 = @import("exp2.zig").exp2;
|
||||
pub const expm1 = @import("expm1.zig").expm1;
|
||||
pub const ilogb = @import("ilogb.zig").ilogb;
|
||||
pub const ln = @import("ln.zig").ln;
|
||||
pub const log = @import("log.zig").log;
|
||||
pub const log2 = @import("log2.zig").log2;
|
||||
pub const log10 = @import("log10.zig").log10;
|
||||
pub const log1p = @import("log1p.zig").log1p;
|
||||
pub const fma = @import("fma.zig").fma;
|
||||
pub const asinh = @import("asinh.zig").asinh;
|
||||
pub const acosh = @import("acosh.zig").acosh;
|
||||
pub const atanh = @import("atanh.zig").atanh;
|
||||
pub const sinh = @import("sinh.zig").sinh;
|
||||
pub const cosh = @import("cosh.zig").cosh;
|
||||
pub const tanh = @import("tanh.zig").tanh;
|
||||
pub const cos = @import("cos.zig").cos;
|
||||
pub const sin = @import("sin.zig").sin;
|
||||
pub const tan = @import("tan.zig").tan;
|
||||
pub const isNan = @import("math/isnan.zig").isNan;
|
||||
pub const isSignalNan = @import("math/isnan.zig").isSignalNan;
|
||||
pub const fabs = @import("math/fabs.zig").fabs;
|
||||
pub const ceil = @import("math/ceil.zig").ceil;
|
||||
pub const floor = @import("math/floor.zig").floor;
|
||||
pub const trunc = @import("math/trunc.zig").trunc;
|
||||
pub const round = @import("math/round.zig").round;
|
||||
pub const frexp = @import("math/frexp.zig").frexp;
|
||||
pub const frexp32_result = @import("math/frexp.zig").frexp32_result;
|
||||
pub const frexp64_result = @import("math/frexp.zig").frexp64_result;
|
||||
pub const modf = @import("math/modf.zig").modf;
|
||||
pub const modf32_result = @import("math/modf.zig").modf32_result;
|
||||
pub const modf64_result = @import("math/modf.zig").modf64_result;
|
||||
pub const copysign = @import("math/copysign.zig").copysign;
|
||||
pub const isFinite = @import("math/isfinite.zig").isFinite;
|
||||
pub const isInf = @import("math/isinf.zig").isInf;
|
||||
pub const isPositiveInf = @import("math/isinf.zig").isPositiveInf;
|
||||
pub const isNegativeInf = @import("math/isinf.zig").isNegativeInf;
|
||||
pub const isNormal = @import("math/isnormal.zig").isNormal;
|
||||
pub const signbit = @import("math/signbit.zig").signbit;
|
||||
pub const scalbn = @import("math/scalbn.zig").scalbn;
|
||||
pub const pow = @import("math/pow.zig").pow;
|
||||
pub const powi = @import("math/powi.zig").powi;
|
||||
pub const sqrt = @import("math/sqrt.zig").sqrt;
|
||||
pub const cbrt = @import("math/cbrt.zig").cbrt;
|
||||
pub const acos = @import("math/acos.zig").acos;
|
||||
pub const asin = @import("math/asin.zig").asin;
|
||||
pub const atan = @import("math/atan.zig").atan;
|
||||
pub const atan2 = @import("math/atan2.zig").atan2;
|
||||
pub const hypot = @import("math/hypot.zig").hypot;
|
||||
pub const exp = @import("math/exp.zig").exp;
|
||||
pub const exp2 = @import("math/exp2.zig").exp2;
|
||||
pub const expm1 = @import("math/expm1.zig").expm1;
|
||||
pub const ilogb = @import("math/ilogb.zig").ilogb;
|
||||
pub const ln = @import("math/ln.zig").ln;
|
||||
pub const log = @import("math/log.zig").log;
|
||||
pub const log2 = @import("math/log2.zig").log2;
|
||||
pub const log10 = @import("math/log10.zig").log10;
|
||||
pub const log1p = @import("math/log1p.zig").log1p;
|
||||
pub const fma = @import("math/fma.zig").fma;
|
||||
pub const asinh = @import("math/asinh.zig").asinh;
|
||||
pub const acosh = @import("math/acosh.zig").acosh;
|
||||
pub const atanh = @import("math/atanh.zig").atanh;
|
||||
pub const sinh = @import("math/sinh.zig").sinh;
|
||||
pub const cosh = @import("math/cosh.zig").cosh;
|
||||
pub const tanh = @import("math/tanh.zig").tanh;
|
||||
pub const cos = @import("math/cos.zig").cos;
|
||||
pub const sin = @import("math/sin.zig").sin;
|
||||
pub const tan = @import("math/tan.zig").tan;
|
||||
|
||||
pub const complex = @import("complex/index.zig");
|
||||
pub const complex = @import("math/complex.zig");
|
||||
pub const Complex = complex.Complex;
|
||||
|
||||
pub const big = @import("big/index.zig");
|
||||
pub const big = @import("math/big.zig");
|
||||
|
||||
test "math" {
|
||||
_ = @import("nan.zig");
|
||||
_ = @import("isnan.zig");
|
||||
_ = @import("fabs.zig");
|
||||
_ = @import("ceil.zig");
|
||||
_ = @import("floor.zig");
|
||||
_ = @import("trunc.zig");
|
||||
_ = @import("round.zig");
|
||||
_ = @import("frexp.zig");
|
||||
_ = @import("modf.zig");
|
||||
_ = @import("copysign.zig");
|
||||
_ = @import("isfinite.zig");
|
||||
_ = @import("isinf.zig");
|
||||
_ = @import("isnormal.zig");
|
||||
_ = @import("signbit.zig");
|
||||
_ = @import("scalbn.zig");
|
||||
_ = @import("pow.zig");
|
||||
_ = @import("powi.zig");
|
||||
_ = @import("sqrt.zig");
|
||||
_ = @import("cbrt.zig");
|
||||
_ = @import("acos.zig");
|
||||
_ = @import("asin.zig");
|
||||
_ = @import("atan.zig");
|
||||
_ = @import("atan2.zig");
|
||||
_ = @import("hypot.zig");
|
||||
_ = @import("exp.zig");
|
||||
_ = @import("exp2.zig");
|
||||
_ = @import("expm1.zig");
|
||||
_ = @import("ilogb.zig");
|
||||
_ = @import("ln.zig");
|
||||
_ = @import("log.zig");
|
||||
_ = @import("log2.zig");
|
||||
_ = @import("log10.zig");
|
||||
_ = @import("log1p.zig");
|
||||
_ = @import("fma.zig");
|
||||
_ = @import("asinh.zig");
|
||||
_ = @import("acosh.zig");
|
||||
_ = @import("atanh.zig");
|
||||
_ = @import("sinh.zig");
|
||||
_ = @import("cosh.zig");
|
||||
_ = @import("tanh.zig");
|
||||
_ = @import("sin.zig");
|
||||
_ = @import("cos.zig");
|
||||
_ = @import("tan.zig");
|
||||
_ = @import("math/nan.zig");
|
||||
_ = @import("math/isnan.zig");
|
||||
_ = @import("math/fabs.zig");
|
||||
_ = @import("math/ceil.zig");
|
||||
_ = @import("math/floor.zig");
|
||||
_ = @import("math/trunc.zig");
|
||||
_ = @import("math/round.zig");
|
||||
_ = @import("math/frexp.zig");
|
||||
_ = @import("math/modf.zig");
|
||||
_ = @import("math/copysign.zig");
|
||||
_ = @import("math/isfinite.zig");
|
||||
_ = @import("math/isinf.zig");
|
||||
_ = @import("math/isnormal.zig");
|
||||
_ = @import("math/signbit.zig");
|
||||
_ = @import("math/scalbn.zig");
|
||||
_ = @import("math/pow.zig");
|
||||
_ = @import("math/powi.zig");
|
||||
_ = @import("math/sqrt.zig");
|
||||
_ = @import("math/cbrt.zig");
|
||||
_ = @import("math/acos.zig");
|
||||
_ = @import("math/asin.zig");
|
||||
_ = @import("math/atan.zig");
|
||||
_ = @import("math/atan2.zig");
|
||||
_ = @import("math/hypot.zig");
|
||||
_ = @import("math/exp.zig");
|
||||
_ = @import("math/exp2.zig");
|
||||
_ = @import("math/expm1.zig");
|
||||
_ = @import("math/ilogb.zig");
|
||||
_ = @import("math/ln.zig");
|
||||
_ = @import("math/log.zig");
|
||||
_ = @import("math/log2.zig");
|
||||
_ = @import("math/log10.zig");
|
||||
_ = @import("math/log1p.zig");
|
||||
_ = @import("math/fma.zig");
|
||||
_ = @import("math/asinh.zig");
|
||||
_ = @import("math/acosh.zig");
|
||||
_ = @import("math/atanh.zig");
|
||||
_ = @import("math/sinh.zig");
|
||||
_ = @import("math/cosh.zig");
|
||||
_ = @import("math/tanh.zig");
|
||||
_ = @import("math/sin.zig");
|
||||
_ = @import("math/cos.zig");
|
||||
_ = @import("math/tan.zig");
|
||||
|
||||
_ = @import("complex/index.zig");
|
||||
_ = @import("math/complex.zig");
|
||||
|
||||
_ = @import("big/index.zig");
|
||||
_ = @import("math/big.zig");
|
||||
}
|
||||
|
||||
pub fn floatMantissaBits(comptime T: type) comptime_int {
|
||||
@ -738,14 +738,14 @@ test "math.f64_min" {
|
||||
|
||||
pub fn maxInt(comptime T: type) comptime_int {
|
||||
const info = @typeInfo(T);
|
||||
const bit_count = comptime_int(info.Int.bits); // TODO #1683
|
||||
const bit_count = info.Int.bits;
|
||||
if (bit_count == 0) return 0;
|
||||
return (1 << (bit_count - @boolToInt(info.Int.is_signed))) - 1;
|
||||
}
|
||||
|
||||
pub fn minInt(comptime T: type) comptime_int {
|
||||
const info = @typeInfo(T);
|
||||
const bit_count = comptime_int(info.Int.bits); // TODO #1683
|
||||
const bit_count = info.Int.bits;
|
||||
if (!info.Int.is_signed) return 0;
|
||||
if (bit_count == 0) return 0;
|
||||
return -(1 << (bit_count - 1));
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// - acos(x) = nan if x < -1 or x > 1
|
||||
|
||||
const std = @import("../index.zig");
|
||||
const std = @import("../std.zig");
|
||||
const math = std.math;
|
||||
const expect = std.testing.expect;
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
// - acosh(nan) = nan
|
||||
|
||||
const builtin = @import("builtin");
|
||||
const std = @import("../index.zig");
|
||||
const std = @import("../std.zig");
|
||||
const math = std.math;
|
||||
const expect = std.testing.expect;
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
// - asin(+-0) = +-0
|
||||
// - asin(x) = nan if x < -1 or x > 1
|
||||
|
||||
const std = @import("../index.zig");
|
||||
const std = @import("../std.zig");
|
||||
const math = std.math;
|
||||
const expect = std.testing.expect;
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
// - asinh(+-inf) = +-inf
|
||||
// - asinh(nan) = nan
|
||||
|
||||
const std = @import("../index.zig");
|
||||
const std = @import("../std.zig");
|
||||
const math = std.math;
|
||||
const expect = std.testing.expect;
|
||||
const maxInt = std.math.maxInt;
|
||||
|
@ -3,7 +3,7 @@
|
||||
// - atan(+-0) = +-0
|
||||
// - atan(+-inf) = +-pi/2
|
||||
|
||||
const std = @import("../index.zig");
|
||||
const std = @import("../std.zig");
|
||||
const math = std.math;
|
||||
const expect = std.testing.expect;
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
// atan2(+inf, x) = +pi/2
|
||||
// atan2(-inf, x) = -pi/2
|
||||
|
||||
const std = @import("../index.zig");
|
||||
const std = @import("../std.zig");
|
||||
const math = std.math;
|
||||
const expect = std.testing.expect;
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
// - atanh(x) = nan if |x| > 1 with signal
|
||||
// - atanh(nan) = nan
|
||||
|
||||
const std = @import("../index.zig");
|
||||
const std = @import("../std.zig");
|
||||
const math = std.math;
|
||||
const expect = std.testing.expect;
|
||||
const maxInt = std.math.maxInt;
|
||||
|
5
std/math/big.zig
Normal file
5
std/math/big.zig
Normal file
@ -0,0 +1,5 @@
|
||||
pub use @import("big/int.zig");
|
||||
|
||||
test "math.big" {
|
||||
_ = @import("big/int.zig");
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
pub use @import("int.zig");
|
||||
|
||||
test "math.big" {
|
||||
_ = @import("int.zig");
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
const std = @import("../../index.zig");
|
||||
const std = @import("../../std.zig");
|
||||
const builtin = @import("builtin");
|
||||
const debug = std.debug;
|
||||
const testing = std.testing;
|
||||
|
@ -4,7 +4,7 @@
|
||||
// - cbrt(+-inf) = +-inf
|
||||
// - cbrt(nan) = nan
|
||||
|
||||
const std = @import("../index.zig");
|
||||
const std = @import("../std.zig");
|
||||
const math = std.math;
|
||||
const expect = std.testing.expect;
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
// - ceil(nan) = nan
|
||||
|
||||
const builtin = @import("builtin");
|
||||
const std = @import("../index.zig");
|
||||
const std = @import("../std.zig");
|
||||
const math = std.math;
|
||||
const expect = std.testing.expect;
|
||||
|
||||
|
@ -1,27 +1,27 @@
|
||||
const std = @import("../../index.zig");
|
||||
const std = @import("../std.zig");
|
||||
const testing = std.testing;
|
||||
const math = std.math;
|
||||
|
||||
pub const abs = @import("abs.zig").abs;
|
||||
pub const acosh = @import("acosh.zig").acosh;
|
||||
pub const acos = @import("acos.zig").acos;
|
||||
pub const arg = @import("arg.zig").arg;
|
||||
pub const asinh = @import("asinh.zig").asinh;
|
||||
pub const asin = @import("asin.zig").asin;
|
||||
pub const atanh = @import("atanh.zig").atanh;
|
||||
pub const atan = @import("atan.zig").atan;
|
||||
pub const conj = @import("conj.zig").conj;
|
||||
pub const cosh = @import("cosh.zig").cosh;
|
||||
pub const cos = @import("cos.zig").cos;
|
||||
pub const exp = @import("exp.zig").exp;
|
||||
pub const log = @import("log.zig").log;
|
||||
pub const pow = @import("pow.zig").pow;
|
||||
pub const proj = @import("proj.zig").proj;
|
||||
pub const sinh = @import("sinh.zig").sinh;
|
||||
pub const sin = @import("sin.zig").sin;
|
||||
pub const sqrt = @import("sqrt.zig").sqrt;
|
||||
pub const tanh = @import("tanh.zig").tanh;
|
||||
pub const tan = @import("tan.zig").tan;
|
||||
pub const abs = @import("complex/abs.zig").abs;
|
||||
pub const acosh = @import("complex/acosh.zig").acosh;
|
||||
pub const acos = @import("complex/acos.zig").acos;
|
||||
pub const arg = @import("complex/arg.zig").arg;
|
||||
pub const asinh = @import("complex/asinh.zig").asinh;
|
||||
pub const asin = @import("complex/asin.zig").asin;
|
||||
pub const atanh = @import("complex/atanh.zig").atanh;
|
||||
pub const atan = @import("complex/atan.zig").atan;
|
||||
pub const conj = @import("complex/conj.zig").conj;
|
||||
pub const cosh = @import("complex/cosh.zig").cosh;
|
||||
pub const cos = @import("complex/cos.zig").cos;
|
||||
pub const exp = @import("complex/exp.zig").exp;
|
||||
pub const log = @import("complex/log.zig").log;
|
||||
pub const pow = @import("complex/pow.zig").pow;
|
||||
pub const proj = @import("complex/proj.zig").proj;
|
||||
pub const sinh = @import("complex/sinh.zig").sinh;
|
||||
pub const sin = @import("complex/sin.zig").sin;
|
||||
pub const sqrt = @import("complex/sqrt.zig").sqrt;
|
||||
pub const tanh = @import("complex/tanh.zig").tanh;
|
||||
pub const tan = @import("complex/tan.zig").tan;
|
||||
|
||||
pub fn Complex(comptime T: type) type {
|
||||
return struct {
|
||||
@ -148,24 +148,24 @@ test "complex.magnitude" {
|
||||
}
|
||||
|
||||
test "complex.cmath" {
|
||||
_ = @import("abs.zig");
|
||||
_ = @import("acosh.zig");
|
||||
_ = @import("acos.zig");
|
||||
_ = @import("arg.zig");
|
||||
_ = @import("asinh.zig");
|
||||
_ = @import("asin.zig");
|
||||
_ = @import("atanh.zig");
|
||||
_ = @import("atan.zig");
|
||||
_ = @import("conj.zig");
|
||||
_ = @import("cosh.zig");
|
||||
_ = @import("cos.zig");
|
||||
_ = @import("exp.zig");
|
||||
_ = @import("log.zig");
|
||||
_ = @import("pow.zig");
|
||||
_ = @import("proj.zig");
|
||||
_ = @import("sinh.zig");
|
||||
_ = @import("sin.zig");
|
||||
_ = @import("sqrt.zig");
|
||||
_ = @import("tanh.zig");
|
||||
_ = @import("tan.zig");
|
||||
_ = @import("complex/abs.zig");
|
||||
_ = @import("complex/acosh.zig");
|
||||
_ = @import("complex/acos.zig");
|
||||
_ = @import("complex/arg.zig");
|
||||
_ = @import("complex/asinh.zig");
|
||||
_ = @import("complex/asin.zig");
|
||||
_ = @import("complex/atanh.zig");
|
||||
_ = @import("complex/atan.zig");
|
||||
_ = @import("complex/conj.zig");
|
||||
_ = @import("complex/cosh.zig");
|
||||
_ = @import("complex/cos.zig");
|
||||
_ = @import("complex/exp.zig");
|
||||
_ = @import("complex/log.zig");
|
||||
_ = @import("complex/pow.zig");
|
||||
_ = @import("complex/proj.zig");
|
||||
_ = @import("complex/sinh.zig");
|
||||
_ = @import("complex/sin.zig");
|
||||
_ = @import("complex/sqrt.zig");
|
||||
_ = @import("complex/tanh.zig");
|
||||
_ = @import("complex/tan.zig");
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
const std = @import("../../index.zig");
|
||||
const std = @import("../../std.zig");
|
||||
const testing = std.testing;
|
||||
const math = std.math;
|
||||
const cmath = math.complex;
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user