Commit graph

216 commits

Author SHA1 Message Date
267e5bc78d Examples: Add mandelbrot.apfl
It's a nice little benchmark. At the moment we need to manually call the
garbage collection, otherwise it eats too much memory and takes forever.
The goal is to be able to remove this call and it not wasting too much
memory.
2024-07-12 23:01:44 +02:00
ac130c2f77 Expose get-or-default as global 2024-05-23 23:41:38 +02:00
8ecbba5217 Grow resizables more than requested to avoid excessive alloocator calls 2024-01-14 16:29:55 +01:00
e5c4f32126 refactor 2023-11-24 21:57:57 +01:00
8d8fcdd64b Remove duplicated declaration 2023-11-23 21:34:10 +01:00
396c5ad866 gc: Tighter coupling to full context
We'll soon need the whole apfl_ctx in the garbage collector.
2023-11-23 21:30:51 +01:00
0361000e7c apflc: Use an apfl_ctx for compilation
We'll soon need the full apfl_ctx, where we previously only needed the
gc. apflc was the only place manually constructing a struct gc without
an apfl_ctx, so lets change that.
2023-11-23 21:03:40 +01:00
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
85bafd0ef9 globals: Add pipe, find-index and unwrap-nil 2023-11-06 23:21:46 +01:00
7e8a897f08 Fix typo 2023-10-26 21:32:17 +02:00
ddd39f19ef Implement global slice and splice functions
This also adds the apfl_list_splice() function for manipulating lists.
2023-10-26 21:31:27 +02:00
85d2c67404 More consistent variable naming in .apfl files
Use "C" for all modules that take a dict of builtins from C code
2023-10-26 21:31:27 +02:00
3bb47d6ad3 functional-test-runner: Check, if context could be created 2023-09-04 14:05:01 +02:00
387b4bfd99 tokenizer: Use same number parsing code as in tonumber 2023-09-04 14:04:40 +02:00
0209fe6a51 tokenizer: Use unsigned char 2023-09-03 16:36:10 +02:00
52ea737975 tokenizer: Manage last position automatically when unreading byte 2023-09-03 16:24:50 +02:00
1866963738 gc: Add blockstats 2023-07-22 22:30:07 +02:00
63d64b0778 Add regex module "re"
This uses the PCRE2 library to implement regexes in apfl
2023-07-03 23:53:09 +02:00
97f5986781 Implement tonumber 2023-07-03 23:52:49 +02:00
1650a8f8be Fix NDEBUG builds 2023-07-03 23:45:43 +02:00
159004c2e4 Parser: Fix destroying invalid data in nested pairs 2023-07-03 23:45:43 +02:00
35a3c808c4 Add code to debug errors when initialiting globals 2023-07-03 23:45:43 +02:00
4d01f20d6e Implement first try of a module system
Very much inspired by lua, as so often: The module system maintains a list
of searchers that will be called with the requested module name. They can
then return a loader function, which will then be called again with the
module name. That loader then returns the actual module, which is then
cached. We also add a goofy "foo" module in main.c to test this.
2023-07-03 23:45:43 +02:00
c07caa9aa2 Implement the registry and a agrv getter to test it
The registry is a global dictionary accessible from C that stores arbitrary
apfl values.
2023-03-31 21:31:07 +02:00
370fb89367 Add / rename functions for loading other sources 2023-03-30 20:51:30 +02:00
0e9f8ae0ee Implement global ++/-- functions 2023-03-29 22:36:38 +02:00
e31dc3d585 Add global raise function 2023-03-29 22:35:08 +02:00
fe7bda0f40 Add syntax files for sublime text 2023-03-23 23:44:54 +01:00
1cff056e53 Implement symbol values 2023-03-23 23:44:54 +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
8233e94ab3 gc: Speed up new_object by adding new blocks to the front of the list
This way we don't have to traverse the whole list to the very end every
time we want a new object.
2023-03-21 20:54:09 +01:00
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
2e7fefc7f7 Implement some string manipulation functions 2023-03-07 21:57:04 +01:00
1634b9439b Implement for / loop / [k]each loops 2023-03-07 21:40:07 +01:00
25c872f4ee Define globals in apfl itself
We're now first building a standalone bytecode compiler `apflc` that will
compile `globals.apfl` into bytecode and write it out as a C source file.
When initializing a new context, that embedded bytecode will then get
evaluated and the global scope will be populated from the dictionary
returned by that bytecode.
2023-03-07 21:40:07 +01:00
baef5914cd Fix hashing const string and gc string differently 2023-03-07 21:40:07 +01:00
2666c0f148 Implement bytecode (de)serialization 2023-03-07 21:40:07 +01:00
86e148554d Add quine 2023-03-03 22:25:38 +01:00
07655c31bd Make function's closure scope optional 2023-02-26 16:57:02 +01:00
4d840fd817 Allow NULL as subfunction matcher
This will match all arguments and discard them. This makes the bytecode
for simple functions easier and will make it easier to construct simple
function programmatically.
2023-02-25 23:19:45 +01:00
a4f7f0884d Make line and column size_t 2023-02-16 21:41:02 +01:00
f4841ff2cd Use stdnoreturn instead of our own APFL_NORETURN 2023-02-16 20:52:27 +01:00
b026494891 alloc: Guard against multiplication overflow 2023-02-14 22:04:10 +01:00
e0881c558c strings+io: Make chars unsigned 2023-02-13 22:31:18 +01:00
01dfec2e32 Make playground usable on mobile 2023-02-10 21:48:31 +01:00
0dd27b7046 parser: Use correct union member 2023-02-10 21:48:31 +01:00
76cf60d20f Enable building as shared library 2023-02-10 21:48:31 +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
0b44878fcd Remove TODO to allow const variable names
I made it possible for variable names to be const strings, only to discover
this actually used *more* heap memory instead of less. Also only very low
performance gains. So let's not do that and keep things a bit simpler.
2023-02-10 20:37:47 +01:00
09f5cef085 alloc: Fix passing wrong oldsize if oldsize==0 in verifying_alloc 2023-02-09 23:01:46 +01:00