This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# The main problem with building zig with zig are build system changes. | |
# Further I had problems using C test suite, so it seems to me that not all | |
# necessary configs are being reused within the build system. | |
# Therefore this script cross compiles Zig with Zig to track upstream. | |
# However stage2 does not work with this and fails with | |
# error: unknown command: -print-file-name=libstdc++.a | |
# The following command exited with error code 1: | |
# $HOME/dev/git/zig/zig-bootstrap/out/host/bin/zig -print-file-name=libstdc++.a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const math = @import("std").math; | |
const print = @import("std").debug.print; | |
fn printTestCases(comptime T: type, min_divided: T, max_divided: T) !void { | |
print("try test__negsi2({d}, {d});\n", .{ min_divided, max_divided }); | |
print("try test__negsi2({d}, {d});\n", .{ max_divided, min_divided }); | |
} | |
pub fn main() !void { | |
const ST = i128; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const math = @import("std").math; | |
const print = @import("std").debug.print; | |
// a < b => 0 | |
// a == b => 1 | |
// a > b => 2 | |
fn printTestCase(comptime T: type, a: T, b: T) !void { | |
var cmp: i32 = undefined; | |
if (a < b) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Configuration for zellij. | |
# In order to troubleshoot your configuration try using the following command: | |
# `zellij setup --check` | |
# It should show current config locations and features that are enabled. | |
# | |
# Mode | Switch | |
# normal | Normal | |
# resize | Resize | |
# pane | Pane |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Observation: only MIN has no abs | |
// 2s complement is ~x+1 | |
// 2s compl of MIN == MIN, since ~0b100..00 + 1 == 0b011..11 + 1 == 0b100..00 | |
// NOTE: 2s complement of 0 would overflow ~0x00..00 + 1 == 0xff..ff + 1 kaboom | |
// working version | |
fn absvXi_generic(comptime ST: type) fn (a: ST) callconv(.C) ST { | |
return struct { | |
fn f(a: ST) callconv(.C) ST { | |
var x = a; | |
if (x < 0) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const debug = @import("std").debug; | |
fn printRes(comptime ST: type, a: ST, b: ST) !void { | |
const UT = switch (ST) { | |
i2 => u2, | |
i32 => u32, | |
i64 => u64, | |
i128 => u128, | |
else => unreachable, | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <inttypes.h> | |
#include <stdint.h> | |
#include <stdio.h> | |
// yes, it breaks. Clearly Zig has better semantics, as it utilizes LLVM. | |
int32_t addv(int32_t a, int32_t b) | |
{ | |
uint32_t usum = (uint32_t)a + (uint32_t)b; | |
int32_t isum = (int32_t)usum; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <vector> | |
void print_vector(const std::vector<int> &pos, | |
const std::vector<std::string> &str) { | |
for (size_t i = 1; i < pos.size(); ++i) // offset: i:1..N | |
printf("%s\t", str[pos[i]].c_str()); // str:0..N-1 | |
printf("\n"); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
const char *donuts[] = {"iced", "jam", "plain", | |
"something completely different"}; | |
int pos[] = {0, 0, 0, 0}; | |
void printDonuts(int k) { | |
for (size_t i = 1; i < k + 1; i += 1) // offset: i:1..N, N=k+1 | |
printf("%s\t", donuts[pos[i]]); // str:0..N-1 | |
printf("\n"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
const process = std.process; | |
const stdout = std.io.getStdOut(); | |
//const log = std.log; | |
const usage: []const u8 = | |
\\Usage: bracket_count file1 file2 .. | |
; | |
pub fn main() !void { |