mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
@@ -6,10 +6,7 @@
|
||||
|
||||
#include "toy_console_colors.h"
|
||||
|
||||
#include "toy_lexer.h"
|
||||
#include "toy_parser.h"
|
||||
#include "toy_compiler.h"
|
||||
#include "toy_interpreter.h"
|
||||
#include "toy.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
@@ -78,10 +78,10 @@ const unsigned char* Toy_compileString(const char* source, size_t* size) {
|
||||
Toy_initParser(&parser, &lexer);
|
||||
Toy_initCompiler(&compiler);
|
||||
|
||||
//run the parser until the end of the source
|
||||
//step 1 - run the parser until the end of the source
|
||||
Toy_ASTNode* node = Toy_scanParser(&parser);
|
||||
while(node != NULL) {
|
||||
//pack up and leave
|
||||
//on error, pack up and leave
|
||||
if (node->type == TOY_AST_NODE_ERROR) {
|
||||
Toy_freeASTNode(node);
|
||||
Toy_freeCompiler(&compiler);
|
||||
@@ -94,7 +94,7 @@ const unsigned char* Toy_compileString(const char* source, size_t* size) {
|
||||
node = Toy_scanParser(&parser);
|
||||
}
|
||||
|
||||
//get the bytecode dump
|
||||
//step 2 - get the bytecode dump
|
||||
const unsigned char* tb = Toy_collateCompiler(&compiler, size);
|
||||
|
||||
//cleanup
|
||||
|
||||
67
source/toy.h
Normal file
67
source/toy.h
Normal file
@@ -0,0 +1,67 @@
|
||||
#pragma once
|
||||
|
||||
/* toy.h - A Toy Programming Language
|
||||
|
||||
If you're looking how to use Toy directly, try https://toylang.com/
|
||||
Otherwise, these headers may help learn how Toy works internally.
|
||||
|
||||
*/
|
||||
|
||||
/* utilities - these define a bunch of useful macros based on platform.
|
||||
|
||||
The most important one is `TOY_API`, which highlights functions intended for the end user.
|
||||
|
||||
*/
|
||||
|
||||
#include "toy_common.h"
|
||||
#include "toy_console_colors.h"
|
||||
#include "toy_memory.h"
|
||||
|
||||
/* core pipeline - from source to execution
|
||||
|
||||
Each step is as follows:
|
||||
|
||||
source -> lexer -> token
|
||||
token -> parser -> AST
|
||||
AST -> compiler -> bytecode
|
||||
bytecode -> interpreter -> result
|
||||
|
||||
I should note that the parser -> compiler phase is actually made up of two steps - the write step
|
||||
and the collate step. See `Toy_compileString()` in `repl/repl_tools.c` for an example of how to compile
|
||||
properly.
|
||||
|
||||
*/
|
||||
|
||||
#include "toy_lexer.h"
|
||||
#include "toy_parser.h"
|
||||
#include "toy_compiler.h"
|
||||
#include "toy_interpreter.h"
|
||||
|
||||
/* building block structures - the basic units of operation
|
||||
|
||||
Literals represent any value within the language, including some internal ones that you never see.
|
||||
Literal Arrays are literally arrays within memory, and are the most heavily used structure in Toy.
|
||||
Literal Dictionaries are unordered key-value hashmaps, that use a running strategy for collisions.
|
||||
|
||||
*/
|
||||
|
||||
#include "toy_literal.h"
|
||||
#include "toy_literal_array.h"
|
||||
#include "toy_literal_dictionary.h"
|
||||
|
||||
/* other components - you probably won't use these directly, but they're a good learning opportunity.
|
||||
|
||||
`Toy_Scope` holds the variables of a specific scope within Toy - be it a script, a function, a block, etc.
|
||||
Scopes are also where the type system lives at runtime. They use identifier literals as keys, exclusively.
|
||||
|
||||
`Toy_RefString` is a utility class that wraps traditional C strings, making them less memory intensive and
|
||||
faster to copy and move. In reality, since strings are considered immutable, multiple variables can point
|
||||
to the same string to save memory, and you can just create a new one of these vars pointing to the original
|
||||
rather than copying entirely for a speed boost. This module has it's own memory allocator system that is
|
||||
plugged into the main memory allocator.
|
||||
|
||||
*/
|
||||
|
||||
#include "toy_scope.h"
|
||||
#include "toy_refstring.h"
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#define TOY_VERSION_MAJOR 1
|
||||
#define TOY_VERSION_MINOR 1
|
||||
#define TOY_VERSION_PATCH 1
|
||||
#define TOY_VERSION_PATCH 2
|
||||
#define TOY_VERSION_BUILD __DATE__ " " __TIME__
|
||||
|
||||
//platform/compiler-specific instructions
|
||||
|
||||
Reference in New Issue
Block a user