Commit graph

15 commits

Author SHA1 Message Date
aa6346eafa tokenizer: Add backtick delimited strings
This is useful when writing strings that contain a lot of backslashes,
e.g. in regular expressions.
2023-11-07 21:45:27 +01:00
6056e3a450 Implement pairs
Pairs are 2-tuples of values that are constructed and matched with the `::`
operator. They can also be matched with a `:` operator, the LHS is an
expression then, the pair will then only match, if the LHS matches the
result of that expression.

Pairs should be useful to do something similar what sum types / tagged
unions do in statically typed languages, e.g. you could write something
like:

    some := (symbol) # Somthing that creates a unique value
    filter-map := {
      _ [] -> []
      f [x ~xs] ->
        {
          some:y -> [y ~(filter-map f xs)]
          nil -> filter-map f xs
        } (f x)
    }
    filter-map {
      x?even -> some :: (* x 10)
      _ -> nil
    } some-list
2023-03-22 23:54:03 +01:00
2666c0f148 Implement bytecode (de)serialization 2023-03-07 21:40:07 +01:00
a4f7f0884d Make line and column size_t 2023-02-16 21:41:02 +01:00
e0881c558c strings+io: Make chars unsigned 2023-02-13 22:31:18 +01: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
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
6439f4f8ce Tokenizer: Disallow ASCII control characters outside strings 2022-01-07 23:39:06 +01:00
bab1812cc9 Add tokenizer tests to check binary string handling 2022-01-06 22:50:44 +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
84f127bfec Move must_alloc into test.h 2021-12-16 22:50:14 +01:00
025fd61abd Add apfl_string_source_reader
A useful source reader implementation to pass in a source saved as an
in-memory string into the tokenizer.

This replaces the string_src_reader in the tokenizer_test and is even a bit
more flexible, by allowing any aplf_string_view as the source.
2021-12-16 22:49:41 +01:00
c0e47b14e6 Add tokenizer test case
During development on the parser I got a "malloc(): corrupted top size"
error in the tokenizer when parsing `a=a`. I wrote this test to see if it
was really a problem with the tokenizer. It wasn't, lets keep the test
nontheless.
2021-12-16 22:09:59 +01:00
d094ed7bd5 Initial commit 2021-12-15 21:47:17 +01:00