Commit Graph

132 Commits

Author SHA1 Message Date
Aryadev Chavali
21254e77bf tag: INT_MAX/INT_MIN are now i64 by default 2026-02-11 10:29:57 +00:00
Aryadev Chavali
e772b06ae5 main: rearrange code and setup prototypes 2026-02-11 10:29:57 +00:00
Aryadev Chavali
eca46069f8 main: print out expressions from reading 2026-02-11 10:29:57 +00:00
Aryadev Chavali
c2f1835b4c main: factor out the stream init code into its own function 2026-02-11 10:29:57 +00:00
Aryadev Chavali
93a52db7cc alisp.org: add TODO about reader macros 2026-02-11 10:29:57 +00:00
Aryadev Chavali
d88bc2baeb alisp.org: mark some TODOs 2026-02-11 10:29:57 +00:00
Aryadev Chavali
2dc0c6080e reader: deal with quotes
This is currently implemented as a parse-time primitive.  Scheme
doesn't seem to have reader macros (which is INSANE) but Common Lisp
does.  We'll need to add a TODO about this.
2026-02-11 10:29:57 +00:00
Aryadev Chavali
8e81e6f762 reader: at every iteration of read_all, skip comments and whitespace 2026-02-11 10:29:57 +00:00
Aryadev Chavali
a49492b27f stream: clean up 2026-02-11 10:29:57 +00:00
Aryadev Chavali
8b2fe97fc2 lisp: sys_cost for memory footprint 2026-02-11 10:29:57 +00:00
Aryadev Chavali
ff512986f8 symtable: sym_table_cost
Useful for figuring out the rough memory footprint (actually utilised)
by the symbol table.
2026-02-11 10:29:57 +00:00
Aryadev Chavali
47f33cb969 tag: make function inputs constant 2026-02-11 10:29:57 +00:00
Aryadev Chavali
39e5b76f8b lisp: lisp_print 2026-02-11 10:29:57 +00:00
Aryadev Chavali
b91e79933b symtable: refactor for SV changes and propagate 2026-02-11 10:29:57 +00:00
Aryadev Chavali
3e7734037c sv: rearrange sv_substr and sv_truncate 2026-02-11 10:29:57 +00:00
Aryadev Chavali
9f3bb57972 sv: major refactor
- Internal data pointer is read only by default => any uses that
  require use of the pointer itself (freeing, mutating) must perform a
  cast.

- refactor tests to use some new sv macros and functions, and clean
  them up.

- slight cleanup of sv.c
2026-02-11 10:29:57 +00:00
Aryadev Chavali
b646ae3f7e sv: fix sv_substr
Issue I came up with when looking at the code, based on
sv_chop_right's impl.  Why do we keep this function around again?
2026-02-11 10:29:57 +00:00
Aryadev Chavali
818d4da850 sv: SV_AUTO macro (for literal strings/literal byte arrays really). 2026-02-11 10:29:57 +00:00
Aryadev Chavali
daa1d3d565 lisp: add and implement lisp_free_rec
May be useful for testing.
2026-02-11 10:29:57 +00:00
Aryadev Chavali
b7fc5170b0 reader: implement read_sym and read_list
To be tested properly.
2026-02-11 10:29:57 +00:00
Aryadev Chavali
d02174ea8b Makefile: add reader to units to compile 2026-02-11 10:29:57 +00:00
Aryadev Chavali
7ef6905d7a main: fit reader into main. 2026-02-11 10:29:57 +00:00
Aryadev Chavali
c12f4b2d2c reader: some work done on basic API 2026-02-11 10:29:57 +00:00
Aryadev Chavali
b8d0ee2c7f .dir-locals: added compile-command for testing
When I'm writing unit test code, it's nicer to compile with full logs
by default.
2026-02-09 09:57:46 +00:00
Aryadev Chavali
fe727d75e4 remove breaks after return in switch-case 2026-02-09 09:57:04 +00:00
Aryadev Chavali
06a4eafbb9 stream: optimise stream_substr_abs, stream_till, stream_while
In the base cases of STRINGS and FILES, these functions should be very
quick (operating on stuff in memory), and amortized for pipes.
2026-02-09 09:57:04 +00:00
Aryadev Chavali
fc5a6eb8fb stream: refactor stream_seek_forward for changes in FILE API 2026-02-09 09:57:04 +00:00
Aryadev Chavali
5c7fb0fabd stream: stream_stop -> stream_free 2026-02-09 09:57:04 +00:00
Aryadev Chavali
f164427b47 stream: stream_reset
We can reuse the same stream by resetting it.  We don't delete the
cached data.
2026-02-09 09:57:04 +00:00
Aryadev Chavali
2238f348e1 stream: stream_line_col includes current position in computation 2026-02-09 09:57:04 +00:00
Aryadev Chavali
f56a59ff7a stream: STREAM_TYPE_FILE will now read file upfront
No more having to chunk read - if ~stream_init_file~ is used, the
constructor slurps the entire file into the cache.  This pays up front
for a bunch of checks essentially.

~stream_init_pipe~ should be used for chunked reading.
2026-02-09 09:57:04 +00:00
Aryadev Chavali
6a54c54bfb stream: a bit of tidying up 2026-02-09 09:57:04 +00:00
Aryadev Chavali
2855536bdd stream: a few further refactors due to new sv functions 2026-02-09 09:57:04 +00:00
Aryadev Chavali
8426f04734 sv: refactor to use sv_truncate 2026-02-09 09:57:04 +00:00
Aryadev Chavali
459f434e5d stream: bug fix on stream_while/stream_till (due to eda2711)
The new versions of stream_substr require exact sizes.
2026-02-09 09:57:04 +00:00
Aryadev Chavali
9ee8955908 stream: Refactor stream_substr and stream_substr_abs using stream_sv
Bit more elegant, and allows the caller code to focus on the task
rather than string management.
2026-02-09 09:57:04 +00:00
Aryadev Chavali
477abc9aa1 stream: stream_sv and stream_sv_abs
Just straight string views into the current stream content - obviously
may not be stable.  Helpful when analysing a non-moving stream.
2026-02-09 09:57:04 +00:00
oreodave
a6d3d861b7 sv: add a few more functions
* alisp.org: reset state of Unit tests to TODO

* alisp.org: take sv_t tasks out of the backlog and set to WIP

* sv: add prototypes for sv_chop_{left,right} and sv_substr

* sv: implement sv_chop_{left, right} and sv_substr

* sv: sv_till and sv_while

* sv: add sv_truncate

When you just want to decrease to a specific size, sv_chop_right is a
bit cumbersome.

* alisp.org: Update and adjust
2026-02-06 07:02:10 +00:00
oreodave
a65964e2f7 tests: refactor testing and implement a bunch of tests
* tests: split of symtable testing into its own suite

makes sense to be there, not in the lisp API

* tests: Added string view suite

sv_copy is the only function, but we may have others later.

* tests: Meaningful and pretty logging for tests

* tests: slight cleanliness

* tests: c23 allows you to inline stack allocated arrays in struct decls

* test: Added definition to make default testing less verbose

TEST_VERBOSE is a preprocesser directive which TEST is dependent on.
By default it is 0, in which case TEST simply fails if the condition
is not true.  Otherwise, a full log (as done previously) is made.

* Makefile: added mode flag for full logs

MODE=full will initialise a debug build with all logs, including test
logs.  Otherwise, MODE=debug just sets up standard debug build with
main logs but no testing logs.  MODE=release optimises and strips all
logs.

* tests: fix size of LISP_API_SUITE tests

* test_lisp_api: int_test -> smi_test, added smi_oob_test

* test_lisp_api: sym_test -> sym_fresh_test

* test_lisp_api: added sym_unique_test

* alisp.org: Added some tasks

* symtable: sym_table_cleanup -> sym_table_free

* lisp: split off lisp_free as it's own function

lisp_free will do a shallow clean of any object, freeing its
associated memory.  It won't recur through any containers, nor will it
freakout if you give it something that is constant (symbols, small
integers, NIL, etc).

* test_lisp_api: added sys_test

* test_stream: basic skeleton

* test_stream: implement stream_test_string

* test_stream: Enable only stream_test_string

* tests: enable STREAM_SUITE

* sv: fix possible runtime issue with NULL SV's in sv_copy

* alisp.org: add TODOs for all the tests required for streams

* tests: Better suite creation

While the previous method of in-lining a stack allocated array of
tests into the suite struct declaration was nice, we had to update
size manually.

This macro will allow us to just append new tests to the suite without
having to care for that.  It generates a uniquely named variable for
the test array, then uses that test array in the suite declaration.
Nice and easy.

* test: TEST_INIT macro as a prologue for any unit test

* main: Put all variable declarations at start of main to ensure decl

There is a chance that /end/ is jumped to without the FILE pointer or
stream actually being declared.  This deals with that.

* stream: Make stream name a constant cstr

We don't deal with the memory for it anyway.

* stream: do not initialise file streams with a non-empty vector

Because of the not_inlined trick, a 0 initialised SBO vector is
completely valid to use if required.  Future /vec_ensure/'s will deal
with it appropriately.  So there's no need to initialise the vector
ahead of time like this.

* test_stream: implement stream_test_file

We might need to setup a prelude for initialising a file in the
filesystem for testing here - not only does stream_test_file need it,
but I see later tests requiring an equivalence check for files and
strings (variants of a stream).

* test_stream: setup prologue and epilogue as fake tests in the suite

Standard old test functions, but they don't call TEST_INIT or
TEST_PASSED.  They're placed at the start and at the end of the test
array.

Those macros just do printing anyway, so they're not necessary.

* tests: TEST_INIT -> TEST_START, TEST_PASSED -> TEST_END

* tests: TEST_START only logs if TEST_VERBOSE is enabled.

* test_lisp_api: "cons'" -> "conses"

* alisp.org: Mark off completed stream_test_file

* test_stream: implement stream_test_peek_next

* test_stream: randomise filename

Just to make sure it's not hardcoded or anything.

* test_stream: make filename bigger, and increase the random alphabet

* test: seed random number generator

* test_stream: don't write null terminator to mock file

* stream: stream_seek will do clamped movement if offset is invalid

If a forward/backward offset is too big, we'll clamp to the edges of
the file rather than failing completely.  We return the number of
bytes moved so callers can still validate, but the stream API can now
deal with these situations a bit more effectively.

* test_stream: implement stream_test_seek

* stream: ensure stream_stop resets the FILE pointer if STREAM_TYPE_FILE

* stream: stream_substr's call to stream_seek_forward refactored

Following stream_seek_forward's own refactor, where we get offsets
back instead of just a boolean, we should verify that offset.

* main: put stream_stop before FILE pointer close

As stream_stop requires a valid FILE pointer (fseek), we need to do it
before we close the pipe.

* test_vec: vec_test_substr -> vec_test_gen_substr

* test_stream: implement stream_test_substr

* alisp: add TODO for sv_t
2026-02-06 06:08:13 +00:00
Aryadev Chavali
40ef094b68 alisp.org: Remove notes and overview
Not needed with what we're doing currently.  I'll make proper
documentation when I'm done.
2026-02-05 04:35:54 +00:00
Aryadev Chavali
656226c050 alisp.org: make a backlog for tasks 2026-02-05 04:35:47 +00:00
Aryadev Chavali
edb2f5c5c8 dir-locals: run testing, then examples for default compile-command
By default we should test all our code for regressions.  I'm always
running the examples anyway to test new features, so we should have
that recipe run afterwards.

If a test fails, that's first priority to fix.

If an example fails, time to continue working.
2026-02-05 04:34:29 +00:00
Aryadev Chavali
118a25055c main: the beginnings of alisp.out
We've started composing the stuff we've made so far I/O wise,
initialising a stream based off user command line input.  We even
allow stdin!
2026-02-05 04:32:48 +00:00
Aryadev Chavali
e7d3bca4d7 stream: fix bug with stream_next; return the next character
It seems we'd return the previously peeked character when
stream_next'ing, when really we should be sending the updated
character.
2026-02-05 04:29:07 +00:00
Aryadev Chavali
10d6876de4 reader: implement read_err_to_cstr 2026-02-05 04:07:59 +00:00
Aryadev Chavali
75daad53ea reader: add a few more read errors and read_err_to_cstr 2026-02-05 04:06:27 +00:00
Aryadev Chavali
1e451c57e8 stream: stream_line_col: get the line/column of stream currently
Best part is that this should only use cached data, so no chunking
required.
2026-02-05 04:04:54 +00:00
Aryadev Chavali
d14f015c38 stream: use the nonexistent errors in stream_init_* 2026-02-05 04:04:54 +00:00
Aryadev Chavali
26e545a732 stream: Rearranged STREAM_ERR to be nonzero positive
I don't know why I was thinking about having valid positive values for
STREAM_ERR.  Doesn't make sense.
2026-02-05 04:04:54 +00:00
Aryadev Chavali
169a165cfc stream: added stream_err_to_cstr
Simple routine, not really much to explain here.
2026-02-05 04:04:54 +00:00