Commit graph

21 commits

Author SHA1 Message Date
906ae3eac4 Make main slightly more sophisticated
The main apfl program can now take a script file name as an argument to
evaluate instead of stdin. In that case, the whole script is read at once
and there are no `>` / `...` prompts then. The tokenizer and parser are
still accessible but are now behind the `-T` / `-P` flags.
2023-03-07 23:05:09 +01:00
e0881c558c strings+io: Make chars unsigned 2023-02-13 22:31:18 +01:00
55c95f99ad Rename format => io_writer
To make it clearer that this can be used for writing binary data too.
2023-02-10 21:48:31 +01:00
bd19f689b9 Add backtraces to errors 2023-01-28 21:44:56 +01:00
5e9ac36a39 Get rid of fatal errors and report allocation error directly 2023-01-13 22:54:06 +01:00
5b4ac67de9 Make APFL_ERR_INPUT_ERROR non fatal
For two reasons:

- We'll later want apfl code to load other apfl code. If an IO error
  happens in that case, we don't want that to be a fatal error, only a
  regular error that can be catched in apfl (once we have something like
  `try`).
- I want to get rid of fatal errors as a generic category completely.
  Instead the error reporting functions themselves should tell you the type
  of error directly, if it was something fatal.
2022-12-08 22:10:18 +01:00
4ecfeabded main+playground: Don't print nil values in repl
This makes the output of `print` in the repl nicer :)
2022-10-30 22:51:51 +01:00
fa4ed7bf83 Abstract away stdout
Instead of using stdout directly, we're now using a configurable
apfl_format_writer.
2022-10-30 21:21:40 +01:00
b033983d52 main: Make eval the default mode 2022-07-15 21:57:35 +02:00
8d947244c9 Implement exceptions-like error handling
Most functzions will no longer return an enum apfl_result, but will raise
an error that bubbles up.
2022-06-26 16:06:14 +02:00
09f7df79bb apfl_debug_print_val: Use format writer abstraction 2022-06-05 22:06:33 +02:00
d1b2ba7a53 Use formatter for printing values 2022-04-22 23:13:01 +02:00
a4fd3acfac Use formatter for expr printing 2022-04-22 22:52:53 +02:00
0f6f136873 Push formatted parser error on stack during evaluation
This way we can see the parse errors again in evaluation mode

Not fully fleshed out yet: We simply use apfl_debug_print_val to dump the
top of the stack (the formatted error) to stderr but don't nicely handle
if there is nothing on the stack (apfl_debug_print_val will print a rather
cryptic "stack index invalid" error). Also the whole dance we need to do to
put the formatted error onto the stack feels rather awkward (there should
probably a function for this) and we also should probably try to push an
error description on the stack in case this moving-string-to-stack business
fails.

Now "only" all other errors need to be put on the stack as a string :)
2022-04-21 22:55:11 +02:00
9ce5c20736 No longer evaluate exprs directly 2022-04-21 21:17:17 +02:00
b7c88635d9 Redo source reader interface
The callback and the opaque data are now grouped together in a struct
instead of being passed individually into the tokenizer.

This also exposes the string source reader struct and therefore removes
the need of heap allocating it. Neat!
2022-04-15 22:35:36 +02:00
ebf3fc89ff Introduce allocator abstraction
We now no longer call malloc/free/... directly, but use an allocator object
that is passed around.

This was mainly done as a preparation for a garbage collector: The
collector will need to know, how much memory we're using, introducing the
collector abstraction will allow the GC to hook into the memory allocation
and observe the memory usage.

This has other potential applications:

- We could now be embedded into applications that can't use the libc
  allocator.
- There could be an allocator that limits the total amount of used memory,
  e.g. for sandboxing purposes.
- In our tests we could use this to simulate out of memory conditions
  (implement an allocator that fails at the n-th allocation, increase n by
  one and restart the test until there are no more faked OOM conditions).

The function signature of the allocator is basically exactly the same as
the one Lua uses.
2022-02-08 22:53:13 +01:00
21efc85dba Convert to Lua-style stack API
Only for evaluating expressions for now and right now the only exposed
operation is to debug print a value on the stack, this obviously needs to
be expanded.

I've done this for two reasons:

1. A Lua-style stack API is much nicer to work with than to manually manage
   refcounts.
2. We'll soon need a more sophisticated garbage collector (if you even want
   to count the refcounting as garbage collection). For this, the GC will
   need root objects to start tracing for live objects, the stack will be
   one of these roots.
2022-01-20 22:45:09 +01:00
b2c252fbc2 main.c: Add repl mode switching
You can now choose, if you want to play around with the tokenizer, parser
or evaluator in the repl.
2022-01-02 17:22:22 +01:00
c288c333ca Continue work on parser
Seems that we can parse most things now :). Assignments don't work yet,
thoug. Also we're currently leaking memory pretty badly.
2021-12-15 21:47:17 +01:00
d094ed7bd5 Initial commit 2021-12-15 21:47:17 +01:00