switching from zog to zpp as a submodule. make buildtype=release works

This commit is contained in:
Zander Thannhauser 2025-03-29 19:06:47 -05:00
parent b8cece0ee0
commit 9cf6edb5fb
17 changed files with 154 additions and 119 deletions

6
.gitmodules vendored Normal file
View file

@ -0,0 +1,6 @@
[submodule "submodules/zpp"]
path = submodules/zpp
url = ssh://git@gitea.pestctrl.io:2223/Zander/zpp.git
[submodule "extern/zpp"]
path = extern/zpp
url = ssh://git@gitea.pestctrl.io:2223/Zander/zpp.git

View file

@ -86,12 +86,14 @@ struct cmdln_flags* new_cmdln_flags(
break;
}
#ifndef RELEASE_BUILD
case 5: // --test-interactive-using-input-file
{
test_interactive_using_input_file = optarg;
break;
}
#endif
case 'c': // --command
{

1
extern/zpp vendored Submodule

@ -0,0 +1 @@
Subproject commit 89bb34256e6d876ecebd8d8ca1175a0388c3ddfc

View file

@ -1,7 +1,7 @@
#include "terminalcolors.h"
#include "bin/globals/terminalcolors.cpp-4.c"
#include "bin/e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
@ -15,13 +15,13 @@
struct colors terminalcolors = {
.precedences = {
#include "bin/globals/terminalcolors.cpp-18.c"
#include "bin/94850162c0dceac6c6f9558e763457a6e8ac75c569da6ba6c986030bd21d4b1f"
},
#include "bin/globals/terminalcolors.cpp-24.c"
#include "bin/6a7d755dd4b2ea24593a9d09a7cfd18ae05601661eb1ff5416e878a887508378"

View file

@ -1,7 +1,7 @@
#include "terminalcolors.h"
/*/ python
/*/
import colorsys;

View file

@ -33,9 +33,9 @@ include srclist.mk
.PRECIOUS: %.c
%.c: %.cpp zog.py | bin/
%.c: %.cpp ./extern/zpp/zpp | bin/
@echo "preprocessing ${<} ..."
@./zog.py -i $< --snippet-directory=bin -o $@
@./extern/zpp/zpp $< --snippet-directory=bin -o $@
${prefix}/%.o ${prefix}/%.d: %.c ${optionset} | ${prefix}/%/
@echo "compiling (${buildtype}) ${*}.c ..."

View file

@ -26,6 +26,7 @@
#include "struct.h"
#include "next.h"
#if 0
static const enum state {
s_error,
@ -136,6 +137,7 @@ static const enum state {
[s_reading_identifier]['0' ... '9'] = s_reading_identifier,
[s_reading_identifier][128] = s_reading_identifier,
};
#endif
void tokenizer_next(
struct tokenizer* this)

135
repl/main.c Normal file
View file

@ -0,0 +1,135 @@
#include <assert.h>
#include <debug.h>
#include "main.h"
void repl_main(void)
{
ENTER;
TODO;
// if we're actually connected to a terminal:
// set terminal options.
// otherwise, open the file we're pretending is a terminal.
// create input string
// which is an actual string that the history object has a reference to?
// create history:
// I think this is a list of strings?
// create terminal tokenizer
// create terminal buffer:
// which keeps track of what characters we want where (not nessarily \\
the entire height of the terminal, but certianly the entire width) \\
characters can have foreground color (and maybe boldness?).
// has a insert column and line. handles word-wrap.
// keeps track of what's on the screen and only edits as nessisary.
// starts with assuming we're only editing one line (full width), but \\
if the expression line gets too long or printing error messages \\
might push us beyond that, then --even if we cleared-- we would \\
need to consider the new editing height.
// this terminal buffer also keeps track of where the cursor should \\
be vs. where it is and will update that apprioately as well.
// loop:
// read next token
// somehow also check if the terminal resized. If it did:
// tell the terminal buffer.
// internally this will completely reset what's live.
// match token.kind:
// (almost) every case clears and redraws what we want the buffer \\
to contain.
// case up, down:
// selects history index?
// which selects the string we're editing?
// case left, right:
// just move cursor position, no clear needed.
// case 'a-zA-Z0-9', etc.:
// insert the letter into the string
// create parsing tokenizer
// parse the string
// all statements and expressions keep references to the \\
tokens.
// tell the statement to color tokens
// the tokenizer keeps references to all tokens too.
// clear the buffer
// set buffer insert position to 0, 0.
// maybe the prompt + line is longer than the terminal width.
// some maybe we word-wrap?
// draw the prompt line (either green or red)
// iterate through tokenizer's tokens:
// each token knows how many whitespace characters were \\
read since the previous one.
// print their text into the buffer with the token's color.
// the buffer will handle word-wrapping.
// some tokens don't have an expression or statement that \\
owns them.
// some part of the input text may not be part of a \\
token? like a comment?
// I think comments will need to be considered \\
tokens that the parser doesn't pick up. That way \\
it at least appears in the output line.
// case delete, backspace:
// remove the letter at location
// run through basically the same parsing logic as inserting \\
a character
// case enter:
// push a newline
// if line is not empty:
// evaluate statement
// which might print a value
// into the terminal buffer? or straight out?
// I think straight out.
// terminal buffer.clear(true-reset = True):
// true reset will clear what's "live" and the buffer, \\
and set the height back to 1.
// new string line
// new history entry
// redraw prompt.
// update buffer:
// compare (buffer of what we want vs. what's live)
TODO;
EXIT;
}

2
repl/main.h Normal file
View file

@ -0,0 +1,2 @@
void repl_main(void);

0
repl/tokenizer/free.c Normal file
View file

0
repl/tokenizer/free.h Normal file
View file

0
repl/tokenizer/new.c Normal file
View file

0
repl/tokenizer/new.h Normal file
View file

0
repl/tokenizer/next.c Normal file
View file

0
repl/tokenizer/next.h Normal file
View file

0
repl/tokenizer/struct.h Normal file
View file

113
zog.py
View file

@ -1,113 +0,0 @@
#!/usr/bin/env python3
import os;
import sys;
import io;
import argparse;
parser = argparse.ArgumentParser(prog = 'zog');
parser.add_argument('-i', '--input', required = True);
parser.add_argument('-o', '--output', required = True);
parser.add_argument('-s', '--snippet-directory', default = "/tmp/");
args = parser.parse_args(sys.argv[1:]);
input_file = args.input;
output_file = args.output;
snippet_directory = args.snippet_directory;
while input_file.startswith("./"):
input_file = input_file[2:];
while snippet_directory.startswith("./"):
snippet_directory = snippet_directory[2:];
while snippet_directory.endswith("/"):
snippet_directory = snippet_directory[:-1];
myglobals = dict();
istream = open(input_file, "r");
ostream = open(output_file, "w");
lines = istream.readlines();
i = 0;
n = len(lines);
while i < n:
if "/*/" in lines[i]:
indentation = lines[i].index("/*/");
start_index = i;
i += 1;
source = ""
while "/*/" not in lines[i]:
source += lines[i][indentation:];
i += 1;
end_index = i;
i += 1;
real_stdout = sys.stdout
sys.stdout = captured_stdout = io.StringIO()
eval(compile(source, "<zog-snippet>", "exec"), myglobals);
sys.stdout = real_stdout
outstring = captured_stdout.getvalue();
if outstring and outstring[-1] != "\n":
outstring += "\n"
temppath = f"{snippet_directory}/{input_file}-{start_index+1}.c";
tempdir = temppath[:temppath.rindex('/')];
os.makedirs(tempdir, exist_ok = True);
with open(temppath, "w") as stream:
for outline in outstring.split("\n"):
stream.write((" " * indentation) + outline + '\n');
ostream.write(f'#include "{temppath}"' + "\n");
ostream.write("\n" * (end_index - start_index));
else:
ostream.write(lines[i]);
i += 1;
istream.close();
ostream.close();