-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ae2ac34
commit 4081b63
Showing
14 changed files
with
837 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
//* algorithm | ||
//* min_ | ||
//* Gets two integer values and returns the minimum one. | ||
func ^.min_(a #I, b #I) -> #I | ||
if (a < b) a else b | ||
//* max_ | ||
//* Gets two integer values and returns the maximum one. | ||
func ^.max_(a #I, b #I) -> #I | ||
if (a < b) b else a |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
include altlib."posix.al" | ||
|
||
//* cassert | ||
|
||
//* assert_ | ||
//* Gets one integer value and stop execution with return code `3`, if the value is `0`. | ||
func ^.assert_(x #I) -> #V { | ||
eval if (not x) { eval posix_exit(3) } | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
#include <stdio.h> | ||
#include <posix.h> | ||
#include <stdbool.h> | ||
#include <string.h> | ||
|
||
const char *sections[1024]; | ||
const char *subsections[1024][1024]; | ||
|
||
void parse(int section_id, char *filename, int fd) { | ||
int file = posix_open(filename, 0, 0); | ||
int subsection_id = 1; | ||
|
||
bool global_header = true; | ||
bool local_header = true; | ||
bool code = false; | ||
|
||
while (true) { | ||
char buffer[4096]; | ||
int len = 0; | ||
bool bad = true; | ||
int backtick = 0; | ||
while (posix_read(file, buffer + len, 1)) { | ||
if (buffer[len] == '\n') { | ||
bad = false; | ||
break; | ||
} | ||
if (buffer[len] == '<' && code) { | ||
_strcpy(buffer + len, "<"); | ||
len += 2; | ||
} | ||
if (buffer[len] == '>' && code) { | ||
_strcpy(buffer + len, ">"); | ||
len += 2; | ||
} | ||
if (buffer[len] == '`' && !code) { | ||
if (backtick == 0) { | ||
_strcpy(buffer + len, "<code>"); | ||
len += 5; | ||
} | ||
else { | ||
_strcpy(buffer + len, "</code>"); | ||
len += 6; | ||
} | ||
backtick = 1 - backtick; | ||
} | ||
len++; | ||
} | ||
if (bad) break; | ||
buffer[len] = '\0'; | ||
char *line = buffer; | ||
|
||
if (!_strncmp(line, "//*", 3) && _strlen(line) >= 4) { | ||
if (code) { | ||
_fputs(fd, "</code></pre>\n"); | ||
code = false; | ||
} | ||
line += 4; | ||
if (global_header) { | ||
_fputsi(fd, "<h2 id=\"", section_id, "\">"); | ||
_fputs2(fd, line, "</h2>\n"); | ||
sections[section_id] = _strdup(line); | ||
global_header = false; | ||
} | ||
else if (local_header) { | ||
_fputsi(fd, "<h3 id=\"", section_id, "."); | ||
_fputi(fd, subsection_id); | ||
_fputs3(fd, "\">", line, "</h3>\n"); | ||
subsections[section_id][subsection_id] = _strdup(line); | ||
subsection_id++; | ||
local_header = false; | ||
} | ||
else { | ||
_fputs2(fd, line, "\n"); | ||
} | ||
} | ||
else { | ||
if (!code && _strlen(line) && !global_header) { | ||
_fputs(fd, "<pre><code>"); | ||
code = true; | ||
local_header = true; | ||
} | ||
if (code) { | ||
_fputs2(fd, line, "\n"); | ||
} | ||
} | ||
} | ||
if (code) { | ||
_fputs(fd, "</code></pre>\n"); | ||
code = false; | ||
} | ||
posix_close(file); | ||
} | ||
|
||
int main(int argc, char **argv) { | ||
int fd_contents[2]; | ||
posix_pipe(fd_contents); | ||
for (int i = 1; i < argc; i++) { | ||
parse(i, argv[i], fd_contents[1]); | ||
} | ||
posix_close(fd_contents[1]); | ||
char *str = read_file_descriptor(fd_contents[0]); | ||
posix_close(fd_contents[0]); | ||
|
||
int out = STDOUT; | ||
|
||
_fputs(out, "<body>\n"); | ||
_fputs(out, "<header><h1>Altlib Reference</h1></header>\n"); | ||
_fputs(out, "<div id=\"navigation\"><nav>\n"); | ||
_fputs(out, "<h2>Table of Contents</h2>\n"); | ||
_fputs(out, "<ul>"); | ||
for (int i = 1; i < 1024; i++) { | ||
if (!sections[i]) break; | ||
_fputsi(out, "<li><a href=\"#", i, "\">"); | ||
_fputs2(out, sections[i], "</a>\n"); | ||
_fputs(out, "<ul>\n"); | ||
for (int j = 1; j < 1024; j++) { | ||
if (!subsections[i][j]) break; | ||
_fputsi(out, "<li><a href=\"#", i, "."); | ||
_fputi(out, j); | ||
_fputs3(out, "\">", subsections[i][j], "</a></li>\n"); | ||
} | ||
_fputs(out, "</ul></li>\n"); | ||
} | ||
_fputs(out, "</ul></nav></div>\n"); | ||
|
||
_fputs(out, "<div id=\"contents-wrapper\"><main id=\"contents\">\n"); | ||
_fputs(out, str); | ||
_fputs(out, "</main></div></body></html>\n"); | ||
|
||
return 0; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<!DOCTYPE html> | ||
|
||
<html> | ||
<head> | ||
<meta http-equip="Context-Type" context="text/html"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta name="color-scheme" content="light dark"> | ||
<title>Altlib Reference</title> | ||
<style> | ||
:root{ | ||
--nav-width: 26em; | ||
--nav-margin-l: 1em; | ||
} | ||
body{ | ||
font-family: system-ui, -apple-system, Roboto, "Segoe UI", sans-serif; | ||
margin: 0; | ||
line-height: 1.5; | ||
} | ||
|
||
#contents { | ||
max-width: 60em; | ||
margin: auto; | ||
padding: 0 1em; | ||
} | ||
#navigation { | ||
padding: 0 1em; | ||
} | ||
|
||
@media screen and (min-width: 1025px) { | ||
header { | ||
margin-left: calc(var(--nav-width) + var(--nav-margin-l)); | ||
} | ||
header h1 { | ||
margin: auto; | ||
max-width: 30em; | ||
} | ||
#navigation { | ||
overflow: auto; | ||
width: var(--nav-width); | ||
height: 100vh; | ||
position: fixed; | ||
top:0; | ||
left:0; | ||
bottom:0; | ||
padding: unset; | ||
margin-left: var(--nav-margin-l); | ||
} | ||
#navigation nav ul { | ||
padding-left: 1em; | ||
} | ||
#contents-wrapper { | ||
margin-left: calc(var(--nav-width) + var(--nav-margin-l)); | ||
} | ||
} | ||
|
||
code { | ||
background: #f8f8f8; | ||
border: 1px dotted silver; | ||
padding-left: 0.3em; | ||
padding-right: 0.3em; | ||
} | ||
pre > code { | ||
display: block; | ||
overflow: auto; | ||
padding: 0.5em; | ||
border: 1px solid #eee; | ||
line-height: normal; | ||
} | ||
</style> | ||
</head> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,9 @@ | ||
//* memory | ||
|
||
//* _memcpy | ||
//* Copies the data of length `sz` bytes from `src` pointer to `dest` pointer. | ||
proto ._memcpy(dest #1I, src #1I, sz #I) -> #1I | ||
|
||
//* _memset | ||
//* Sets the data of length `count` bytes to `dest` pointer with value `ch`. Important: only the lowest byte in `ch` argument is used. | ||
proto ._memset(dest #1I, ch #I, count #I) -> #1I |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
//* stdlib | ||
//* todo | ||
proto ._malloc(sz #I) -> #1I | ||
proto ._free(ptr #1I) -> #V | ||
|
Oops, something went wrong.