aboutsummaryrefslogtreecommitdiff
path: root/builtins
diff options
context:
space:
mode:
Diffstat (limited to 'builtins')
-rw-r--r--builtins/nextline.c108
-rw-r--r--builtins/nextline.h31
-rw-r--r--builtins/path.c10
-rw-r--r--builtins/tomo.h1
4 files changed, 5 insertions, 145 deletions
diff --git a/builtins/nextline.c b/builtins/nextline.c
deleted file mode 100644
index b7928939..00000000
--- a/builtins/nextline.c
+++ /dev/null
@@ -1,108 +0,0 @@
-// An enum used for iterating over lines in a file
-// Most of the code here was generated by compiling:
-// enum NextLine(Done, Next(line:Text))
-
-#include <stdbool.h>
-#include <stdint.h>
-
-#include "siphash.h"
-#include "datatypes.h"
-#include "nextline.h"
-#include "text.h"
-#include "util.h"
-
-static Text_t NextLine$Next$as_text(NextLine$Next_t *obj, bool use_color)
-{
- if (!obj)
- return Text("Next");
- return Text$concat(use_color ? Text("\x1b[0;1mNext\x1b[m(") : Text("Next("), Text("line="),
- Text$as_text((Text_t[1]){obj->$line}, use_color, &Text$info), Text(")"));
-}
-
-public inline NextLine_t NextLine$tagged$Next(Text_t $line)
-{
- return (NextLine_t) {
- .tag = NextLine$tag$Next,.$Next = { $line }
- };
-}
-
-static Text_t NextLine$as_text(NextLine_t *obj, bool use_color)
-{
- if (!obj)
- return Text("NextLine");
- switch (obj->tag) {
- case NextLine$tag$Done:
- return use_color ? Text("\x1b[36;1mNextLine.Done\x1b[m") : Text("NextLine.Done");
- case NextLine$tag$Next:
- return Text$concat(use_color ? Text("\x1b[36;1mNextLine.Next\x1b[m(") :
- Text("NextLine.Next("), Text("line="),
- Text$as_text((Text_t[1]){obj->$Next.$line}, use_color, &Text$info), Text(")"));
- default:
- return (Text_t) {
- .length = 0};
- }
-}
-
-static bool NextLine$equal(const NextLine_t *x, const NextLine_t *y,
- const TypeInfo *info)
-{
- (void) info;
- if (x->tag != y->tag)
- return false;
- switch (x->tag) {
- case NextLine$tag$Done:
- return false;
- case NextLine$tag$Next:
- return generic_equal(&x->$Next, &y->$Next, (&NextLine$Next));
- default:
- return 0;
- }
-}
-
-static int NextLine$compare(const NextLine_t *x, const NextLine_t *y,
- const TypeInfo *info)
-{
- (void) info;
- int diff = (int)x->tag - (int)y->tag;
- if (diff)
- return diff;
- switch (x->tag) {
- case NextLine$tag$Done:
- return 0;
- case NextLine$tag$Next:
- return generic_compare(&x->$Next, &y->$Next, (&NextLine$Next));
- default:
- return 0;
- }
-}
-
-static uint64_t NextLine$hash(const NextLine_t *obj, const TypeInfo *info)
-{
- (void) info;
- uint64_t hashes[2] = { (uint64_t) obj->tag, 0 };
- switch (obj->tag) {
- case NextLine$tag$Done:
- break;
- case NextLine$tag$Next:
- hashes[1] = generic_hash(&obj->$Next, (&NextLine$Next));
- break;
- default: break;
- }
- return siphash24((void *) &hashes, sizeof(hashes));
-}
-
-public const TypeInfo NextLine$Done = { 0, 0, {.tag = EmptyStructInfo,.EmptyStructInfo.name =
- "NextLine$Done" } };
-public const TypeInfo NextLine$Next = { 24, 8, {.tag = CustomInfo,.CustomInfo =
- {.as_text =
- (void *) NextLine$Next$as_text,.hash =
- (void *) Text$hash,.compare =
- (void *) Text$compare,.equal =
- (void *) Text$equal,} } };
-public const TypeInfo NextLine = { 32, 8, {.tag = CustomInfo,.CustomInfo =
- {.as_text = (void *) NextLine$as_text,.equal =
- (void *) NextLine$equal,.hash =
- (void *) NextLine$hash,.compare =
- (void *) NextLine$compare} } };
-
-// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
diff --git a/builtins/nextline.h b/builtins/nextline.h
deleted file mode 100644
index ce4c9fab..00000000
--- a/builtins/nextline.h
+++ /dev/null
@@ -1,31 +0,0 @@
-#pragma once
-
-#include "datatypes.h"
-#include "types.h"
-
-// An enum used for iterating over lines in a file
-// Most of the code here was generated by compiling:
-// enum NextLine(Done, Next(line:Text))
-
-typedef struct NextLine_s NextLine_t;
-typedef struct NextLine$Done_s NextLine$Done_t;
-#pragma GCC diagnostic ignored "-Wpedantic"
-struct NextLine$Done_s {
-};
-typedef struct NextLine$Next_s NextLine$Next_t;
-struct NextLine$Next_s {
- Text_t $line;
-};
-struct NextLine_s {
- enum { NextLine$tag$Done = 0, NextLine$tag$Next = 1 } tag;
- union {
- NextLine$Done_t $Done;
- NextLine$Next_t $Next;
- };
-};
-extern const TypeInfo NextLine;
-extern const TypeInfo NextLine$Done;
-extern const TypeInfo NextLine$Next;
-NextLine_t NextLine$tagged$Next(Text_t $line);
-
-// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
diff --git a/builtins/path.c b/builtins/path.c
index ab032927..8864b7de 100644
--- a/builtins/path.c
+++ b/builtins/path.c
@@ -16,7 +16,7 @@
#include "files.h"
#include "functions.h"
#include "integers.h"
-#include "nextline.h"
+#include "optionals.h"
#include "path.h"
#include "text.h"
#include "types.h"
@@ -433,16 +433,16 @@ static void _line_reader_cleanup(FILE **f)
}
}
-static NextLine_t _next_line(FILE **f)
+static Text_t _next_line(FILE **f)
{
- if (!f || !*f) return (NextLine_t){NextLine$tag$Done};
+ if (!f || !*f) return NULL_TEXT;
char *line = NULL;
size_t size = 0;
ssize_t len = getline(&line, &size, *f);
if (len <= 0) {
_line_reader_cleanup(f);
- return (NextLine_t){NextLine$tag$Done};
+ return NULL_TEXT;
}
while (len > 0 && (line[len-1] == '\r' || line[len-1] == '\n'))
@@ -453,7 +453,7 @@ static NextLine_t _next_line(FILE **f)
Text_t line_text = Text$format("%.*s", len, line);
free(line);
- return NextLine$tagged$Next(line_text);
+ return line_text;
}
public Closure_t Path$by_line(Path_t path)
diff --git a/builtins/tomo.h b/builtins/tomo.h
index 4a52da7c..9354ccab 100644
--- a/builtins/tomo.h
+++ b/builtins/tomo.h
@@ -17,7 +17,6 @@
#include "datatypes.h"
#include "functions.h"
#include "integers.h"
-#include "nextline.h"
#include "macros.h"
#include "memory.h"
#include "nums.h"