Commit graph

202 commits

Author SHA1 Message Date
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
3f6e1f14a9 Implement loading other scripts 2023-01-31 22:07:28 +01:00
607da73c62 Add functions for reading/writing files and introduce native objects 2023-01-29 16:46:00 +01:00
bd19f689b9 Add backtraces to errors 2023-01-28 21:44:56 +01:00
3cc2a83226 Add functions to get information about the call stack 2023-01-28 21:42:40 +01:00
1afec3c7a0 Add named functions
An `name = {}` assignment now sets the name of the function to `name`.
Also the globally defined functions are named too now.
2023-01-24 22:16:27 +01:00
dd580a1519 Improve a bunch of error messages 2023-01-24 21:30:05 +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
57cd32dfa5 Fix apfl_join_strings accessing invalid addresses
Previously we were getting a pointer into the value stack for the parts
list. However, that pointer would not necessarily be a valid pointer later
any more, as we're also manipulating the value stack.

This introduces the higher level API apfl_set_list_member_by_index to
modify a list and also adds an option for our test suite to run the tests
with valgrind --tool=memcheck. This should catch such errors in the future.
2022-11-29 23:13:10 +01:00
e4f2053ca6 Fix apfl_join_strings manipulating the parts list 2022-11-26 23:06:55 +01:00
0febf48401 Remove duplicated code 2022-11-20 21:57:12 +01:00
874638748b Make iterative runner not panic on OOM
The iterative runner used functions that could throw errors on OOM before
protecting itself using apfl_call_protected. An error at that point would
have resulted in calling the panic handler as a last resort.

This now introduces the apfl_do_protected function which allows running C
code protected without needing to wrap it in a cfunc value, thus removing
the need for the functions that could throw in the iterative runner.
2022-11-20 21:44:00 +01:00
e8a92a18b4 Implement functions for concatenating strings 2022-11-20 21:44:00 +01:00
f9878b43d8 Implement comparison operators 2022-11-20 13:47:38 +01:00