commit 3b4816b04acbf0d92306c410fae9bbc7c6de1241
parent 26df6419a8cec3a440ce6be518f93ee88919ea18
Author: Drew DeVault <sir@cmpwn.com>
Date: Tue, 2 Feb 2021 21:45:40 -0500
stdlib: add rt::memset
Diffstat:
M | main.ha | | | 29 | ++++++++++++++++++++++++++--- |
M | stdlib.mk | | | 36 | +++++++++++++++++++----------------- |
2 files changed, 45 insertions(+), 20 deletions(-)
diff --git a/main.ha b/main.ha
@@ -1,7 +1,30 @@
-use fmt;
+use io;
use os;
export fn main() void = {
- let x = 1337;
- fmt::fprintf(os::stdout, "x: {} {}\n", 1337, "hello");
+ if (len(os::args) == 1z) {
+ match (io::copy(os::stdout, os::stdin)) {
+ err: io::error => fatal(io::errstr(err)),
+ size => void,
+ };
+ return;
+ };
+
+ for (let i = 1z; i < len(os::args); i += 1z) {
+ let in: *io::stream = match (os::open(os::args[i], io::mode::RDONLY)) {
+ stream: *io::stream => stream,
+ err: io::error => fatal(io::errstr(err)),
+ };
+ defer io::close(in);
+
+ match (io::copy(os::stdout, in)) {
+ err: io::error => fatal(io::errstr(err)),
+ size => void,
+ };
+ };
+};
+
+@noreturn fn fatal(why: str) void = {
+ io::errorln(why);
+ os::exit(1);
};
diff --git a/stdlib.mk b/stdlib.mk
@@ -9,6 +9,7 @@ librt_srcs=$(STDLIB)/rt/$(PLATFORM)/abort.ha \
$(STDLIB)/rt/$(PLATFORM)/syscalls.ha \
$(STDLIB)/rt/$(PLATFORM)/segmalloc.ha \
$(STDLIB)/rt/memcpy.ha \
+ $(STDLIB)/rt/memset.ha \
$(STDLIB)/rt/malloc.ha
$(HARECACHE)/rt/rt.ssa: $(librt_srcs)
@@ -134,23 +135,6 @@ $(HARECACHE)/strings/strings.ssa: $(libstrings_srcs) $(libstrings_deps)
stdlib_strings=$(HARECACHE)/strings/strings.o
-# fmt
-libfmt_srcs=\
- $(STDLIB)/fmt/fmt.ha
-
-libfmt_deps=$(stdlib_rt) \
- $(stdlib_io) \
- $(stdlib_strconv) \
- $(stdlib_strings) \
- $(stdlib_types)
-
-$(HARECACHE)/fmt/fmt.ssa: $(libfmt_srcs) $(libfmt_deps)
- @printf 'HAREC \t$@\n'
- @mkdir -p $(HARECACHE)/fmt
- @$(HAREC) -o $@ -Nfmt -t$(HARECACHE)/fmt/fmt.td $(libfmt_srcs)
-
-stdlib_fmt=$(HARECACHE)/fmt/fmt.o
-
# os
libos_srcs=\
$(STDLIB)/os/$(PLATFORM)/environ.ha \
@@ -170,3 +154,21 @@ $(HARECACHE)/os/os.ssa: $(libos_srcs) $(libos_deps)
@$(HAREC) -o $@ -Nos -t$(HARECACHE)/os/os.td $(libos_srcs)
stdlib_os=$(HARECACHE)/os/os.o
+
+# fmt
+libfmt_srcs=\
+ $(STDLIB)/fmt/fmt.ha
+
+libfmt_deps=$(stdlib_rt) \
+ $(stdlib_io) \
+ $(stdlib_os) \
+ $(stdlib_strconv) \
+ $(stdlib_strings) \
+ $(stdlib_types)
+
+$(HARECACHE)/fmt/fmt.ssa: $(libfmt_srcs) $(libfmt_deps)
+ @printf 'HAREC \t$@\n'
+ @mkdir -p $(HARECACHE)/fmt
+ @$(HAREC) -o $@ -Nfmt -t$(HARECACHE)/fmt/fmt.td $(libfmt_srcs)
+
+stdlib_fmt=$(HARECACHE)/fmt/fmt.o