Skip to content

Commit

Permalink
remove var args from the language
Browse files Browse the repository at this point in the history
closes #208
  • Loading branch information
andrewrk committed Dec 9, 2019
1 parent f205d23 commit a3f6a58
Show file tree
Hide file tree
Showing 21 changed files with 2,049 additions and 2,820 deletions.
5 changes: 1 addition & 4 deletions doc/langref.html.in
Original file line number Diff line number Diff line change
Expand Up @@ -5862,7 +5862,7 @@ pub fn main() void {

{#code_begin|syntax#}
/// Calls print and then flushes the buffer.
pub fn printf(self: *OutStream, comptime format: []const u8, args: ...) anyerror!void {
pub fn printf(self: *OutStream, comptime format: []const u8, args: var) anyerror!void {
const State = enum {
Start,
OpenBrace,
Expand Down Expand Up @@ -8277,7 +8277,6 @@ test "integer truncation" {
<li>{#link|union#}</li>
<li>{#link|Functions#}</li>
<li>BoundFn</li>
<li>ArgTuple</li>
<li>{#link|struct#}</li>
</ul>
{#header_close#}
Expand Down Expand Up @@ -8310,7 +8309,6 @@ pub const TypeId = enum {
Fn,
Block,
BoundFn,
ArgTuple,
Opaque,
};
{#code_end#}
Expand Down Expand Up @@ -8343,7 +8341,6 @@ pub const TypeInfo = union(TypeId) {
Union: Union,
Fn: Fn,
BoundFn: Fn,
ArgTuple: void,
Opaque: void,
Promise: Promise,
Vector: Vector,
Expand Down
1 change: 0 additions & 1 deletion lib/std/builtin.zig
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ pub const TypeInfo = union(enum) {
Union: Union,
Fn: Fn,
BoundFn: Fn,
ArgTuple: void,
Opaque: void,
Frame: void,
AnyFrame: AnyFrame,
Expand Down
10 changes: 4 additions & 6 deletions lib/std/fmt.zig
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ pub fn format(
args: var,
) Errors!void {
const ArgSetType = @IntType(false, 32);
const args_fields = std.meta.fields(@typeOf(args));
const args_len = args_fields.len;
if (args_len > ArgSetType.bit_count) {
if (args.len > ArgSetType.bit_count) {
@compileError("32 arguments max are supported per format call");
}

Expand Down Expand Up @@ -160,14 +158,14 @@ pub fn format(
maybe_pos_arg.? += c - '0';
specifier_start = i + 1;

if (maybe_pos_arg.? >= args_len) {
if (maybe_pos_arg.? >= args.len) {
@compileError("Positional value refers to non-existent argument");
}
},
'}' => {
const arg_to_print = comptime nextArg(&used_pos_args, maybe_pos_arg, &next_arg);

if (arg_to_print >= args_len) {
if (arg_to_print >= args.len) {
@compileError("Too few arguments");
}

Expand Down Expand Up @@ -304,7 +302,7 @@ pub fn format(
used_pos_args |= 1 << i;
}

if (@popCount(ArgSetType, used_pos_args) != args_len) {
if (@popCount(ArgSetType, used_pos_args) != args.len) {
@compileError("Unused arguments");
}
if (state != State.Start) {
Expand Down
1 change: 0 additions & 1 deletion lib/std/hash/auto_hash.zig
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ pub fn hash(hasher: var, key: var, comptime strat: HashStrategy) void {
.NoReturn,
.Opaque,
.Undefined,
.ArgTuple,
.Void,
.Null,
.BoundFn,
Expand Down
2 changes: 1 addition & 1 deletion lib/std/special/docs/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,7 @@
// This is just for debugging purposes, not needed to function
var assertList = ["Type","Void","Bool","NoReturn","Int","Float","Pointer","Array","Struct",
"ComptimeFloat","ComptimeInt","Undefined","Null","Optional","ErrorUnion","ErrorSet","Enum",
"Union","Fn","BoundFn","ArgTuple","Opaque","Frame","AnyFrame","Vector","EnumLiteral"];
"Union","Fn","BoundFn","Opaque","Frame","AnyFrame","Vector","EnumLiteral"];
for (var i = 0; i < assertList.length; i += 1) {
if (map[assertList[i]] == null) throw new Error("No type kind '" + assertList[i] + "' found");
}
Expand Down
1 change: 0 additions & 1 deletion lib/std/testing.zig
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {
switch (@typeInfo(@typeOf(actual))) {
.NoReturn,
.BoundFn,
.ArgTuple,
.Opaque,
.Frame,
.AnyFrame,
Expand Down
12 changes: 0 additions & 12 deletions src-self-hosted/type.zig
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ pub const Type = struct {
.Enum => @fieldParentPtr(Enum, "base", base).destroy(comp),
.Union => @fieldParentPtr(Union, "base", base).destroy(comp),
.BoundFn => @fieldParentPtr(BoundFn, "base", base).destroy(comp),
.ArgTuple => @fieldParentPtr(ArgTuple, "base", base).destroy(comp),
.Opaque => @fieldParentPtr(Opaque, "base", base).destroy(comp),
.Frame => @fieldParentPtr(Frame, "base", base).destroy(comp),
.AnyFrame => @fieldParentPtr(AnyFrame, "base", base).destroy(comp),
Expand Down Expand Up @@ -76,7 +75,6 @@ pub const Type = struct {
.Enum => return @fieldParentPtr(Enum, "base", base).getLlvmType(allocator, llvm_context),
.Union => return @fieldParentPtr(Union, "base", base).getLlvmType(allocator, llvm_context),
.BoundFn => return @fieldParentPtr(BoundFn, "base", base).getLlvmType(allocator, llvm_context),
.ArgTuple => unreachable,
.Opaque => return @fieldParentPtr(Opaque, "base", base).getLlvmType(allocator, llvm_context),
.Frame => return @fieldParentPtr(Frame, "base", base).getLlvmType(allocator, llvm_context),
.AnyFrame => return @fieldParentPtr(AnyFrame, "base", base).getLlvmType(allocator, llvm_context),
Expand All @@ -93,7 +91,6 @@ pub const Type = struct {
.Undefined,
.Null,
.BoundFn,
.ArgTuple,
.Opaque,
=> unreachable,

Expand Down Expand Up @@ -128,7 +125,6 @@ pub const Type = struct {
.Undefined,
.Null,
.BoundFn,
.ArgTuple,
.Opaque,
=> unreachable,

Expand Down Expand Up @@ -1004,14 +1000,6 @@ pub const Type = struct {
}
};

pub const ArgTuple = struct {
base: Type,

pub fn destroy(self: *ArgTuple, comp: *Compilation) void {
comp.gpa().destroy(self);
}
};

pub const Opaque = struct {
base: Type,

Expand Down
2 changes: 0 additions & 2 deletions src/all_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1471,7 +1471,6 @@ enum ZigTypeId {
ZigTypeIdUnion,
ZigTypeIdFn,
ZigTypeIdBoundFn,
ZigTypeIdArgTuple,
ZigTypeIdOpaque,
ZigTypeIdFnFrame,
ZigTypeIdAnyFrame,
Expand Down Expand Up @@ -2039,7 +2038,6 @@ struct CodeGen {
ZigType *entry_null;
ZigType *entry_var;
ZigType *entry_global_error_set;
ZigType *entry_arg_tuple;
ZigType *entry_enum_literal;
ZigType *entry_any_frame;
} builtin_types;
Expand Down
Loading

0 comments on commit a3f6a58

Please sign in to comment.