Commit graph

64 commits

Author SHA1 Message Date
cc79bab69f resizable: Implement splicing 2022-01-20 21:33:04 +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
c9a935b161 Support assigning into dictionaries
You can now set keys in dictionaries to a value. If a key in a key path is
missing, we automatically create an empty dictionary. Otherwise setting
deeply nested keys becomes annoying.
2022-01-15 23:09:24 +01:00
2684f1e61e Fix copying hashmaps
- len == 0 wasn't handled propery
- Incorrect source k/v address
- New object was never returned m(
2022-01-15 23:01:23 +01:00
ce37113f93 Fix some missing allocation checks / length checks 2022-01-15 21:51:40 +01:00
2162b8b580 Add a README
This roughly describes the syntax and semantics of the language
2022-01-14 23:25:57 +01:00
a14b490dfe Partially implement pattern matching assignments
We're still missing predicates (need to be able to call functions for that
one) and assignments into dictionaries. But we now can deconstruct a list
and check against constants.

So things like this work now:

	[1 foo ~bar [a b]] = [1 "Hello" 2 3 4 [5 6]]
	# foo is: "Hello"
	# bar is: [2 3 4]
	# a is: 5
	# b is: 6

Pretty cool :)
2022-01-14 23:25:57 +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
ac3af0baf1 apfl_ctx_destroy: Do nothing on NULL input 2022-01-08 22:09:43 +01:00
6439f4f8ce Tokenizer: Disallow ASCII control characters outside strings 2022-01-07 23:39:06 +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
e928f40da4 Implement simple variable support
We can now assign to variables and retrieve their values. Not all
assignables are implemented yet, but still pretty cool :).
2022-01-06 22:53:26 +01:00
bab1812cc9 Add tokenizer tests to check binary string handling 2022-01-06 22:50:44 +01:00
76f3c776a0 Add parser tests for function calls 2022-01-06 22:50:14 +01:00
96b1fecdcd Hashmap: Make copy callbacks return void
Since we're using refcounts, we don't really copy anything and no error can
occur. So let's make these callbacks return void to simplify things. This
also makes the return value false of the value getters unambiguous: It now
always means that the key was not present.
2022-01-05 21:54:37 +01:00
7903686fe7 Parser: Fix not setting error when -> is missing in dictionaries 2022-01-05 21:50:50 +01:00
721d2d2d21 Implement evaluating container member access 2022-01-05 00:25:41 +01:00
0384875ef3 values: Split lists into read-only lists and editable lists
This is analogous to dictionaries and ensures that no circular references
can be created when using the exported API in apfl.h.

This also changes apfl_value_copy into apfl_value_incref to better reflect
what it does and to reflect that it is no longer an operation that can
fail.
2022-01-04 23:11:38 +01:00
c98a4f4fe9 Remove apfl_function_response
Accidentally comitted that already
2022-01-04 21:56:52 +01:00
f3d0bbed17 Implement evaluating dictionary literals
We can now have dictionaries with keys and values of arbitrary types.
Very cool! :)
2022-01-04 21:51:44 +01:00
8b5d881ab9 Fix typos 2022-01-04 21:29:13 +01:00
00e19ce242 Hashmap demo: Fix hashing string
Not sure this ever worked...
2022-01-04 21:28:38 +01:00
eaa6b723bc Fix refcounted strings
Increasing the refcount (confusingly called copy before, fixed that too)
didn't work properly, as the object was copied and the refcount was only
updated in one of the copies.
2022-01-04 21:22:46 +01:00
27eaefaaaa value.c: Print empty list into single line 2022-01-02 21:23:41 +01:00
4cd95d32c5 eval.c: Handle errors during evaluating string constants 2022-01-02 21:20:08 +01:00
b29219af25 Make strings in apfl_value refcounted
This avoids copying the string every time we pass it around. Not too
important right now, but will become important onve we're able to evaluate
more complex expressions.
2022-01-02 17:55:44 +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
649607ce50 Start work on evaluating expressions
Right now we're only evaluating bool/nil/number/string/list literals, but
it's a start :).
2022-01-02 17:22:22 +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
eea7e8f840 strings: Add apfl_string_blank() and doucment apfl_string_copy()
It's really easy to accidentally pass an uninitialized string as dst into
the copy function, which will result in an free() call to an arbitrary
pointer. Maybe it's a better idea to not deinit the dst string before
copying? The documentation at least makes it more clear and the new
apfl_string_blank() function makes it easy to create an empty string.
2022-01-02 17:01:51 +01:00
92dc89d3ca Move {=>apfl_}print_indented out of expr.c
We'll soon need it elsewhere.
2022-01-02 16:53:26 +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
002894a960 Add a logo :) 2022-01-02 16:45:21 +01:00
74e43e61ce Parser: Clean up more things and make sure to not deinit uninitialized data 2021-12-19 00:28:35 +01:00
8d1eaf5d78 Add tests for some parsing errors 2021-12-19 00:27:34 +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
c74bd74bda Add another parser test 2021-12-18 17:06:17 +01:00
3759813ed9 Parser tests: Make LIST_* macros type safe
With the varargs approach that was used before, it was very easy to add a
list item of the wrong type, which would (hopefully) result in an assertion
violation, because va_arg() then read some senseless data.
2021-12-18 16:35:18 +01:00
5712d7f4ff Add more parser tests 2021-12-18 16:12:37 +01:00
54f27e448c Parser: Skip inner bracket separators after every list element
Forgot that here.
2021-12-18 16:12:21 +01:00
632687b47d Parser tests: Add helpers for creating consts 2021-12-18 16:11:23 +01:00
1ba891282e Parser test: Fix error message when encountering an error 2021-12-18 16:09:53 +01:00
bde841120a test.h: Make test functions static
This makes the compiler complain about a test that was not registered with
ADDTEST.
2021-12-18 16:09:03 +01:00
e3369d8a32 Add more parser tests 2021-12-17 21:08:03 +01:00
4908386435 expr: Also print position on variables and constants 2021-12-17 21:07:45 +01:00
fd24623c27 parser: Set the position of a call to the open parenthesis 2021-12-17 21:07:12 +01:00
3469623fee Add first parser test cases 2021-12-16 23:42:37 +01:00
10a99d0b1e expr: Fix silly bug in equality check 2021-12-16 23:42:11 +01:00