Functions are working, tests incomplete

This required a massive cross-cutting rework to the scope system,
multiple subtle bugfixes and relearning of the parser internals, but it
does appear that functions are working correctly.

A few caveats: for now, parameters are always constant, regardless of
type, return values can't be specified, and some script tests have been
written.

Most importantly, a key feature is working: closures.
This commit is contained in:
2026-04-12 11:47:26 +10:00
parent b0d9c15d33
commit c0c03a4110
18 changed files with 158 additions and 92 deletions

View File

@@ -2,6 +2,7 @@
#include "toy_common.h"
#include "toy_bucket.h"
#include "toy_scope.h"
typedef enum Toy_FunctionType {
TOY_FUNCTION_CUSTOM,
@@ -11,6 +12,7 @@ typedef enum Toy_FunctionType {
typedef struct Toy_FunctionBytecode {
Toy_FunctionType type;
unsigned char* code;
Toy_Scope* parentScope;
} Toy_FunctionBytecode;
typedef struct Toy_FunctionNative {
@@ -24,4 +26,6 @@ typedef union Toy_Function_t {
Toy_FunctionNative native;
} Toy_Function;
TOY_API Toy_Function* Toy_createFunctionFromBytecode(Toy_Bucket** bucketHandle, unsigned char* bytecode);
TOY_API Toy_Function* Toy_createFunctionFromBytecode(Toy_Bucket** bucketHandle, unsigned char* bytecode, Toy_Scope* parentScope);
TOY_API void Toy_freeFunction(Toy_Function* fn);