Commit graph

29 commits

Author SHA1 Message Date
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
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
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
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
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
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
2666c0f148 Implement bytecode (de)serialization 2023-03-07 21:40:07 +01:00
86e148554d Add quine 2023-03-03 22:25:38 +01:00
b026494891 alloc: Guard against multiplication overflow 2023-02-14 22:04:10 +01:00
76cf60d20f Enable building as shared library 2023-02-10 21:48:31 +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
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
3bbd0e79a1 Implement predicates
This implements the last remaining feature of the language syntax! :)

The implementation of this was delightfully simple, since all the heavy
lifting is done by already implemented functions.
2022-11-19 23:26:59 +01:00
3d7bef187c Matchers: Don't return twice when value to capture is missing
We called return_from_matcher once inside
matcher_evaluate_capturing_instruction and outside of it. That way we
returned not to the parent call stack entry but to the grandparent.
2022-11-19 23:26:59 +01:00
20c2880f4c Implement assigning into dictionaries
It's now possible to assign to a key of a dictionary and even to a nested
key path.

This patch changes the way matchers work a bit:
First, a function call stack frame now has a stack of matchers that are
manipulateable instead of a single matcher.
Second, the matcher is now in charge of setting the matched values to the
variables (previously the caller of the matcher needed to extract the
matched values and assign them itself). This change simplifies code
generation, especially for chained assignments and dictionary key paths.

This removes the last usage of APFL_ERR_NOT_IMPLEMENTED :)
2022-11-19 23:26:52 +01:00
7c5465d266 Add a test for chained assignments 2022-11-19 21:27:08 +01:00
0682b5464d Add test for == function 2022-11-08 22:03:05 +01:00
97d79754dd Implement while 2022-11-08 22:03:05 +01:00
18ae382414 Add test for if 2022-10-31 15:50:51 +01:00
0836b8c97c Implement global functions not, len and type 2022-10-31 15:29:01 +01:00
154cc42740 globals: Fix math operations returning argument list on single arg 2022-10-30 23:08:41 +01:00
39578c9478 Add more functional tests 2022-10-30 23:07:53 +01:00
b7015e7b13 Implement a simple test runner for functional tests 2022-10-30 22:51:51 +01:00
3aabadbf6d Switch to CMake 2022-09-16 23:04:20 +02:00