Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ziglang/zig
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 3f658879740e
Choose a base ref
...
head repository: ziglang/zig
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2a8160e80fc0
Choose a head ref
  • 5 commits
  • 39 files changed
  • 1 contributor

Commits on Dec 18, 2017

  1. wip export rewrite

    andrewrk committed Dec 18, 2017
    Copy the full SHA
    1fdebc1 View commit details

Commits on Dec 19, 2017

  1. Copy the full SHA
    c627f9e View commit details
  2. export keyword works again

    andrewrk committed Dec 19, 2017
    Copy the full SHA
    27ba4f0 View commit details
  3. bring back code that uses export and fix tests

    partial revert of 1fdebc1
    andrewrk committed Dec 19, 2017
    Copy the full SHA
    9d9201c View commit details
  4. Merge branch 'export-rewrite'

    introduces the `@export` builtin function which can be used
    in a comptime block to conditionally export a function.
    
    it also allows creation of aliases.
    
    previous export syntax is still allowed.
    
    closes #462
    closes #420
    andrewrk committed Dec 19, 2017
    Copy the full SHA
    2a8160e View commit details
24 changes: 15 additions & 9 deletions doc/langref.html.in
Original file line number Diff line number Diff line change
@@ -136,6 +136,7 @@
<li><a href="#builtin-divFloor">@divFloor</a></li>
<li><a href="#builtin-divTrunc">@divTrunc</a></li>
<li><a href="#builtin-embedFile">@embedFile</a></li>
<li><a href="#builtin-export">@export</a></li>
<li><a href="#builtin-tagName">@tagName</a></li>
<li><a href="#builtin-EnumTagType">@EnumTagType</a></li>
<li><a href="#builtin-errorName">@errorName</a></li>
@@ -4368,6 +4369,11 @@ test.zig:6:2: error: found compile log statement
<ul>
<li><a href="#builtin-import">@import</a></li>
</ul>
<h3 id="builtin-export">@export</h3>
<pre><code class="zig">@export(comptime name: []const u8, target: var, linkage: builtin.GlobalLinkage) -&gt; []const u8</code></pre>
<p>
Creates a symbol in the output object file.
</p>
<h3 id="builtin-tagName">@tagName</h3>
<pre><code class="zig">@tagName(value: var) -&gt; []const u8</code></pre>
<p>
@@ -5815,13 +5821,15 @@ TopLevelItem = ErrorValueDecl | CompTimeExpression(Block) | TopLevelDecl | TestD

TestDecl = "test" String Block

TopLevelDecl = option(VisibleMod) (FnDef | ExternDecl | GlobalVarDecl | UseDecl)
TopLevelDecl = option("pub") (FnDef | ExternDecl | GlobalVarDecl | UseDecl)

ErrorValueDecl = "error" Symbol ";"

GlobalVarDecl = VariableDeclaration ";"
GlobalVarDecl = option("export") VariableDeclaration ";"

VariableDeclaration = option("comptime") ("var" | "const") Symbol option(":" TypeExpr) option("align" "(" Expression ")") "=" Expression
LocalVarDecl = option("comptime") VariableDeclaration

VariableDeclaration = ("var" | "const") Symbol option(":" TypeExpr) option("align" "(" Expression ")") option("section" "(" Expression ")") "=" Expression

ContainerMember = (ContainerField | FnDef | GlobalVarDecl)

@@ -5831,19 +5839,17 @@ UseDecl = "use" Expression ";"

ExternDecl = "extern" option(String) (FnProto | VariableDeclaration) ";"

FnProto = option("coldcc" | "nakedcc" | "stdcallcc") "fn" option(Symbol) ParamDeclList option("align" "(" Expression ")") option("-&gt;" TypeExpr)

VisibleMod = "pub" | "export"
FnProto = option("coldcc" | "nakedcc" | "stdcallcc" | "extern") "fn" option(Symbol) ParamDeclList option("align" "(" Expression ")") option("section" "(" Expression ")") option("-&gt;" TypeExpr)

FnDef = option("inline" | "extern") FnProto Block
FnDef = option("inline" | "export") FnProto Block

ParamDeclList = "(" list(ParamDecl, ",") ")"

ParamDecl = option("noalias" | "comptime") option(Symbol ":") (TypeExpr | "...")

Block = "{" many(Statement) option(Expression) "}"

Statement = Label | VariableDeclaration ";" | Defer(Block) | Defer(Expression) ";" | BlockExpression(Block) | Expression ";" | ";"
Statement = Label | LocalVarDecl ";" | Defer(Block) | Defer(Expression) ";" | BlockExpression(Block) | Expression ";" | ";"

Label = Symbol ":"

@@ -5949,7 +5955,7 @@ StructLiteralField = "." Symbol "=" Expression

PrefixOp = "!" | "-" | "~" | "*" | ("&amp;" option("align" "(" Expression option(":" Integer ":" Integer) ")" ) option("const") option("volatile")) | "?" | "%" | "%%" | "??" | "-%"

PrimaryExpression = Integer | Float | String | CharLiteral | KeywordLiteral | GroupedExpression | GotoExpression | BlockExpression(BlockOrExpression) | Symbol | ("@" Symbol FnCallExpression) | ArrayType | (option("extern") FnProto) | AsmExpression | ("error" "." Symbol) | ContainerDecl
PrimaryExpression = Integer | Float | String | CharLiteral | KeywordLiteral | GroupedExpression | GotoExpression | BlockExpression(BlockOrExpression) | Symbol | ("@" Symbol FnCallExpression) | ArrayType | FnProto | AsmExpression | ("error" "." Symbol) | ContainerDecl

ArrayType : "[" option(Expression) "]" option("align" "(" Expression option(":" Integer ":" Integer) ")")) option("const") option("volatile") TypeExpr

57 changes: 28 additions & 29 deletions src/all_types.hpp
Original file line number Diff line number Diff line change
@@ -37,6 +37,7 @@ struct IrBasicBlock;
struct ScopeDecls;
struct ZigWindowsSDK;
struct Tld;
struct TldExport;

struct IrGotoItem {
AstNode *source_node;
@@ -272,7 +273,6 @@ enum ReturnKnowledge {
enum VisibMod {
VisibModPrivate,
VisibModPub,
VisibModExport,
};

enum GlobalLinkageId {
@@ -313,11 +313,8 @@ struct TldVar {
Tld base;

VariableTableEntry *var;
AstNode *set_global_section_node;
Buf *section_name;
AstNode *set_global_linkage_node;
GlobalLinkageId linkage;
Buf *extern_lib_name;
Buf *section_name;
};

struct TldFn {
@@ -425,13 +422,16 @@ struct AstNodeFnProto {
AstNode *return_type;
bool is_var_args;
bool is_extern;
bool is_export;
bool is_inline;
CallingConvention cc;
AstNode *fn_def_node;
// populated if this is an extern declaration
Buf *lib_name;
// populated if the "align A" is present
AstNode *align_expr;
// populated if the "section(S)" is present
AstNode *section_expr;
};

struct AstNodeFnDef {
@@ -480,15 +480,18 @@ struct AstNodeVariableDeclaration {
VisibMod visib_mod;
Buf *symbol;
bool is_const;
bool is_inline;
bool is_comptime;
bool is_export;
bool is_extern;
// one or both of type and expr will be non null
AstNode *type;
AstNode *expr;
// populated if this is an extern declaration
Buf *lib_name;
// populated if the "align A" is present
// populated if the "align(A)" is present
AstNode *align_expr;
// populated if the "section(S)" is present
AstNode *section_expr;
};

struct AstNodeErrorValueDecl {
@@ -1177,6 +1180,11 @@ enum FnInline {
FnInlineNever,
};

struct FnExport {
Buf name;
GlobalLinkageId linkage;
};

struct FnTableEntry {
LLVMValueRef llvm_value;
const char *llvm_name;
@@ -1204,12 +1212,11 @@ struct FnTableEntry {
ZigList<IrInstruction *> alloca_list;
ZigList<VariableTableEntry *> variable_list;

AstNode *set_global_section_node;
Buf *section_name;
AstNode *set_global_linkage_node;
GlobalLinkageId linkage;
AstNode *set_alignstack_node;
uint32_t alignstack_value;

ZigList<FnExport> export_list;
};

uint32_t fn_table_entry_hash(FnTableEntry*);
@@ -1258,8 +1265,6 @@ enum BuiltinFnId {
BuiltinFnIdSetFloatMode,
BuiltinFnIdTypeName,
BuiltinFnIdCanImplicitCast,
BuiltinFnIdSetGlobalSection,
BuiltinFnIdSetGlobalLinkage,
BuiltinFnIdPanic,
BuiltinFnIdPtrCast,
BuiltinFnIdBitCast,
@@ -1279,6 +1284,7 @@ enum BuiltinFnId {
BuiltinFnIdOpaqueType,
BuiltinFnIdSetAlignStack,
BuiltinFnIdArgType,
BuiltinFnIdExport,
};

struct BuiltinFnEntry {
@@ -1425,7 +1431,7 @@ struct CodeGen {
HashMap<GenericFnTypeId *, FnTableEntry *, generic_fn_type_id_hash, generic_fn_type_id_eql> generic_table;
HashMap<Scope *, IrInstruction *, fn_eval_hash, fn_eval_eql> memoized_fn_eval_table;
HashMap<ZigLLVMFnKey, LLVMValueRef, zig_llvm_fn_key_hash, zig_llvm_fn_key_eql> llvm_fn_table;
HashMap<Buf *, Tld *, buf_hash, buf_eql_buf> exported_symbol_names;
HashMap<Buf *, AstNode *, buf_hash, buf_eql_buf> exported_symbol_names;
HashMap<Buf *, Tld *, buf_hash, buf_eql_buf> external_prototypes;


@@ -1886,8 +1892,6 @@ enum IrInstructionId {
IrInstructionIdCheckStatementIsVoid,
IrInstructionIdTypeName,
IrInstructionIdCanImplicitCast,
IrInstructionIdSetGlobalSection,
IrInstructionIdSetGlobalLinkage,
IrInstructionIdDeclRef,
IrInstructionIdPanic,
IrInstructionIdTagName,
@@ -1901,6 +1905,7 @@ enum IrInstructionId {
IrInstructionIdOpaqueType,
IrInstructionIdSetAlignStack,
IrInstructionIdArgType,
IrInstructionIdExport,
};

struct IrInstruction {
@@ -2626,20 +2631,6 @@ struct IrInstructionCanImplicitCast {
IrInstruction *target_value;
};

struct IrInstructionSetGlobalSection {
IrInstruction base;

Tld *tld;
IrInstruction *value;
};

struct IrInstructionSetGlobalLinkage {
IrInstruction base;

Tld *tld;
IrInstruction *value;
};

struct IrInstructionDeclRef {
IrInstruction base;

@@ -2728,6 +2719,14 @@ struct IrInstructionArgType {
IrInstruction *arg_index;
};

struct IrInstructionExport {
IrInstruction base;

IrInstruction *name;
IrInstruction *linkage;
IrInstruction *target;
};

static const size_t slice_ptr_index = 0;
static const size_t slice_len_index = 1;

Loading