Commit graph

20 commits

Author SHA1 Message Date
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
db0fb2aee4 expr: Make body objects refcounted
We'll soon need this, once we implement function definitions
2022-01-22 17:16:28 +01:00
d81bef9184 parser/tokenizer: Save textual data as refcounted strings
This avoids creating refcounted strings during evaluation and makes it
easier to use the same parsed string in multiple places (should be
useful once we implement functions).
2022-01-18 21:18:27 +01:00
ce37113f93 Fix some missing allocation checks / length checks 2022-01-15 21:51:40 +01:00
ae45aeebe2 parser+expr: Handle blank identifier (_) 2022-01-08 23:20:29 +01:00
50cd2c18d2 expr+parser: Restrict what an assignable can be
If you assign into a member access (`foo.bar = baz` or `foo@bar = baz`), it
is no longer permitted that the LHS of the at/dot is an arbitrary
assignable. It now must be a variable, at or dot. This disallows some silly
constructs (e.g. `[foo]@bar = baz`), increases the similarity to function
parameters and should make writing the evaluation code for these more easy.
2022-01-08 23:06:22 +01:00
4eea93ff97 Improve AST representation of expansion in assignables / parameters
The previous representation didn't properly model the fact that an
assignable / parameter can only be expanded, if it's a list element. This
now better models this. Other than being more correct, this should also
make evaluating these a bit easier.

While I was at it, I also improved the error message for multiple
expansions on the same level and added tests for these.
2022-01-07 23:08:25 +01:00
7903686fe7 Parser: Fix not setting error when -> is missing in dictionaries 2022-01-05 21:50:50 +01:00
80ad5c979d resizable: Replace grow_cap function
This replaces the grow_cap function with the ensure_cap family of
functions, as they actually do what you want: You'll likely not want to
blindly increase the capacity of a growable, but you want to make sure that
the capacity is large enough to hold the elements you're about to insert.
2022-01-02 17:16:32 +01:00
f685214abe Add apfl_string_eq macro
It's easy to forget the `== 0` after the apfl_string_cmp() call, so let's
add a macro that does the job for us.
2022-01-02 16:51:19 +01:00
74e43e61ce Parser: Clean up more things and make sure to not deinit uninitialized data 2021-12-19 00:28:35 +01:00
0995739ca8 Parser: Do a better job at cleaning up temporary allocations
-fsanitize=memory no longer finds any memory leak in the parser test suite.
We don't yet test error cases, but still pretty good :).
2021-12-18 21:42:48 +01:00
d312500a5b parser: Remove useless result var in parse_fragment
Was always PF_OK
2021-12-18 21:39:09 +01:00
54f27e448c Parser: Skip inner bracket separators after every list element
Forgot that here.
2021-12-18 16:12:21 +01:00
fd24623c27 parser: Set the position of a call to the open parenthesis 2021-12-17 21:07:12 +01:00
e79945a398 Continue work on parser
- Simplify return types: Many functions that returned
  `enum parse_fragment_result` only ever returned PF_OK or PF_ERROR.
  Changing these functions to return bool simplifies things a lot. This
  also helped in identifying some places where I didn't handle all
  parse_fragment_result values properly.
- More cleaning up
- Allow linebreaks inside parenthesis
2021-12-16 22:09:59 +01:00
d853ba40ad parser: Fix parsing assignments 2021-12-16 22:09:59 +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
09d51b9080 Parser: Make the parser object own the token
This simplifies the code a bit, since the methods now don't have to deinit
the token themselves any more.
2021-12-15 21:47:17 +01:00
d094ed7bd5 Initial commit 2021-12-15 21:47:17 +01:00