![]() | Fun 0.41.5 The programming language that makes You have fun |
Implements the Fun language parser that converts source code to bytecode. More...
#include "parser.h"#include "value.h"#include "vm.h"#include <ctype.h>#include <stdarg.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include "parser_utils.c"
Go to the source code of this file.
Data Structures | |
| struct | LocalEnv |
| struct | LoopCtx |
Macros | |
| #define | TYPE_META_STRING 10001 |
| Type metadata tag used for string enforcement in declared types. | |
| #define | TYPE_META_BOOLEAN 10002 |
| Type metadata tag used for boolean enforcement in declared types. | |
| #define | TYPE_META_NIL 10003 |
| Type metadata tag indicating explicit nil type. | |
| #define | TYPE_META_CLASS 10004 |
| Type metadata tag marking class/instance values. | |
| #define | TYPE_META_FLOAT 10005 |
| Type metadata tag marking floating point numbers. | |
| #define | TYPE_META_ARRAY 10006 |
| Type metadata tag marking array values. | |
| #define | MAP_TYPE_KIND(t) |
Typedefs | |
| typedef struct LoopCtx | LoopCtx |
Functions | |
| char * | preprocess_includes_with_path (const char *src, const char *current_path) |
| Preprocess includes with a known file path to improve span markers. | |
| Bytecode * | parse_file_to_bytecode (const char *path) |
| Parse a .fun source file and return compiled bytecode. | |
| Bytecode * | parse_string_to_bytecode (const char *source) |
| Parse a source string and return compiled bytecode. | |
| int | parser_last_error (char *msgBuf, unsigned long msgCap, int *outLine, int *outCol) |
| Retrieve the last parser/compiler error information, if any. | |
Implements the Fun language parser that converts source code to bytecode.
This file contains the main parsing logic for the Fun programming language. It handles converting .fun source files into executable bytecode for the VM.
Key Features:
Functions:
Error Handling:
Example: Bytecode *bc = parse_file_to_bytecode("example.fun"); if (bc) { vm_run(&vm, bc); bytecode_free(bc); }
Definition in file parser.c.
| #define MAP_TYPE_KIND | ( | t | ) |
| #define TYPE_META_ARRAY 10006 |
| #define TYPE_META_BOOLEAN 10002 |
| #define TYPE_META_CLASS 10004 |
| #define TYPE_META_FLOAT 10005 |
| #define TYPE_META_NIL 10003 |
| #define TYPE_META_STRING 10001 |
| typedef struct LoopCtx LoopCtx |
| Bytecode * parse_file_to_bytecode | ( | const char * | path | ) |
Parse a .fun source file and return compiled bytecode.
Parse a .fun source file and compile it into a bytecode chunk.
Reads the file, preprocesses includes (tracking original file paths), resets the global error state, and compiles to Bytecode while attaching source metadata (name, source_file).
| path | Filesystem path to the source file. |
Definition at line 7529 of file parser.c.


| Bytecode * parse_string_to_bytecode | ( | const char * | source | ) |
Parse a source string and return compiled bytecode.
Parse source from a provided string buffer (REPL/tests helper).
Suitable for REPL or tests. Performs include preprocessing with no base path, compiles, and attaches generic source metadata.
| source | NUL-terminated source code string. |
Definition at line 7714 of file parser.c.


| int parser_last_error | ( | char * | msgBuf, |
| unsigned long | msgCap, | ||
| int * | outLine, | ||
| int * | outCol ) |
Retrieve the last parser/compiler error information, if any.
Retrieve information about the last parser error, if any.
Copies the error message into msgBuf (truncated to msgCap-1), and returns the one-based line and column where available. If no error is pending, returns 0 and leaves outputs unchanged.
| msgBuf | Destination buffer for the error message (may be NULL). |
| msgCap | Capacity of msgBuf in bytes. |
| outLine | Optional out param for one-based line number. |
| outCol | Optional out param for one-based column number. |
Definition at line 7770 of file parser.c.

| extern |
Preprocess includes with a known file path to improve span markers.
Definition at line 973 of file parser_utils.c.

| int is_class[MAX_GLOBALS] |
| char* names[MAX_GLOBALS] |
| int types[MAX_GLOBALS] |