![]() |
Toy 1.1.6
The Toy programming language is an imperative bytecode-intermediate embedded scripting language
|
@???@ More...
#include <stdbool.h>#include "toy_common.h"#include "toy_refstring.h"#include "toy_reffunction.h"Go to the source code of this file.
Data Structures | |
| struct | Toy_Literal |
Macros | |
| #define | TOY_IS_NULL(value) ((value).type == TOY_LITERAL_NULL) |
| #define | TOY_IS_BOOLEAN(value) ((value).type == TOY_LITERAL_BOOLEAN) |
| #define | TOY_IS_INTEGER(value) ((value).type == TOY_LITERAL_INTEGER) |
| #define | TOY_IS_FLOAT(value) ((value).type == TOY_LITERAL_FLOAT) |
| #define | TOY_IS_STRING(value) ((value).type == TOY_LITERAL_STRING) |
| #define | TOY_IS_ARRAY(value) ((value).type == TOY_LITERAL_ARRAY) |
| #define | TOY_IS_DICTIONARY(value) ((value).type == TOY_LITERAL_DICTIONARY) |
| #define | TOY_IS_FUNCTION(value) ((value).type == TOY_LITERAL_FUNCTION) |
| #define | TOY_IS_FUNCTION_NATIVE(value) ((value).type == TOY_LITERAL_FUNCTION_NATIVE) |
| #define | TOY_IS_FUNCTION_HOOK(value) ((value).type == TOY_LITERAL_FUNCTION_HOOK) |
| #define | TOY_IS_IDENTIFIER(value) ((value).type == TOY_LITERAL_IDENTIFIER) |
| #define | TOY_IS_TYPE(value) ((value).type == TOY_LITERAL_TYPE) |
| #define | TOY_IS_OPAQUE(value) ((value).type == TOY_LITERAL_OPAQUE) |
| #define | TOY_AS_BOOLEAN(value) ((value).as.boolean) |
| #define | TOY_AS_INTEGER(value) ((value).as.integer) |
| #define | TOY_AS_FLOAT(value) ((value).as.number) |
| #define | TOY_AS_STRING(value) ((value).as.string.ptr) |
| #define | TOY_AS_ARRAY(value) ((Toy_LiteralArray*)((value).as.array)) |
| #define | TOY_AS_DICTIONARY(value) ((Toy_LiteralDictionary*)((value).as.dictionary)) |
| #define | TOY_AS_FUNCTION(value) ((value).as.function) |
| #define | TOY_AS_FUNCTION_NATIVE(value) ((value).as.function.inner.native) |
| #define | TOY_AS_FUNCTION_HOOK(value) ((value).as.function.inner.hook) |
| #define | TOY_AS_IDENTIFIER(value) ((value).as.identifier.ptr) |
| #define | TOY_AS_TYPE(value) ((value).as.type) |
| #define | TOY_AS_OPAQUE(value) ((value).as.opaque.ptr) |
| #define | TOY_TO_NULL_LITERAL ((Toy_Literal){{ .integer = 0 }, TOY_LITERAL_NULL}) |
| #define | TOY_TO_BOOLEAN_LITERAL(value) ((Toy_Literal){{ .boolean = value }, TOY_LITERAL_BOOLEAN}) |
| #define | TOY_TO_INTEGER_LITERAL(value) ((Toy_Literal){{ .integer = value }, TOY_LITERAL_INTEGER}) |
| #define | TOY_TO_FLOAT_LITERAL(value) ((Toy_Literal){{ .number = value }, TOY_LITERAL_FLOAT}) |
| #define | TOY_TO_STRING_LITERAL(value) ((Toy_Literal){{ .string = { .ptr = value }},TOY_LITERAL_STRING}) |
| #define | TOY_TO_ARRAY_LITERAL(value) ((Toy_Literal){{ .array = value }, TOY_LITERAL_ARRAY}) |
| #define | TOY_TO_DICTIONARY_LITERAL(value) ((Toy_Literal){{ .dictionary = value }, TOY_LITERAL_DICTIONARY}) |
| #define | TOY_TO_FUNCTION_LITERAL(value) ((Toy_Literal){{ .function = { .inner = { .ptr = value }, .scope = NULL }}, TOY_LITERAL_FUNCTION}) |
| #define | TOY_TO_FUNCTION_NATIVE_LITERAL(value) ((Toy_Literal){{ .function = { .inner = { .native = value }, .scope = NULL }}, TOY_LITERAL_FUNCTION_NATIVE}) |
| #define | TOY_TO_FUNCTION_HOOK_LITERAL(value) ((Toy_Literal){{ .function = { .inner = { .hook = value }, .scope = NULL }}, TOY_LITERAL_FUNCTION_HOOK}) |
| #define | TOY_TO_IDENTIFIER_LITERAL(value) Toy_private_toIdentifierLiteral(value) |
| #define | TOY_TO_TYPE_LITERAL(value, c) ((Toy_Literal){{ .type = { .typeOf = value, .constant = c, .subtypes = NULL, .capacity = 0, .count = 0 }}, TOY_LITERAL_TYPE}) |
| #define | TOY_TO_OPAQUE_LITERAL(value, t) ((Toy_Literal){{ .opaque = { .ptr = value, .tag = t }}, TOY_LITERAL_OPAQUE}) |
| #define | TOY_IS_INDEX_BLANK(value) ((value).type == TOY_LITERAL_INDEX_BLANK) |
| #define | TOY_TO_INDEX_BLANK_LITERAL ((Toy_Literal){{ .integer = 0 }, TOY_LITERAL_INDEX_BLANK}) |
| #define | TOY_IS_TRUTHY(x) Toy_private_isTruthy(x) |
| #define | TOY_AS_FUNCTION_BYTECODE_LENGTH(lit) (Toy_lengthRefFunction((lit).inner.ptr)) |
| #define | TOY_MAX_STRING_LENGTH 4096 |
| #define | TOY_HASH_I(lit) ((lit).as.identifier.hash) |
| #define | TOY_TYPE_PUSH_SUBTYPE(lit, subtype) Toy_private_typePushSubtype(lit, subtype) |
| #define | TOY_GET_OPAQUE_TAG(o) o.as.opaque.tag |
Typedefs | |
| typedef int(* | Toy_NativeFn) (struct Toy_Interpreter *interpreter, struct Toy_LiteralArray *arguments) |
| @???@ | |
| typedef int(* | Toy_HookFn) (struct Toy_Interpreter *interpreter, struct Toy_Literal identifier, struct Toy_Literal alias) |
| @???@ | |
| typedef void(* | Toy_PrintFn) (const char *) |
| @???@ | |
| typedef struct Toy_Literal | Toy_Literal |
| @???@ | |
Functions | |
| TOY_API void | Toy_freeLiteral (Toy_Literal literal) |
| @???@ | |
| TOY_API bool | Toy_private_isTruthy (Toy_Literal x) |
| @???@ | |
| TOY_API Toy_Literal | Toy_private_toIdentifierLiteral (Toy_RefString *ptr) |
| @???@ | |
| TOY_API Toy_Literal * | Toy_private_typePushSubtype (Toy_Literal *lit, Toy_Literal subtype) |
| @???@ | |
| TOY_API Toy_Literal | Toy_copyLiteral (Toy_Literal original) |
| Returns a copy of the given literal. Literals should never be copied without this function, as it handles a lot of internal memory allocations. | |
| TOY_API bool | Toy_literalsAreEqual (Toy_Literal lhs, Toy_Literal rhs) |
| Checks to see if two given literals are equal. When an integer and a float are compared, the integer is cooerced into a float for the duration of the call. Arrays and dictionaries are equal only if their keys and values all equal. Likewise, types only equal if all subtypes are equal, in order. Functions and opaques are never equal to anything, while values with the type TOY_LITERAL_ANY are always equal. | |
| TOY_API int | Toy_hashLiteral (Toy_Literal lit) |
| Finds the hash of a literal, for various purposes. Different hashing algorithms are used for different types, and some types can't be hashed at all. Types that can't be hashed: | |
| TOY_API void | Toy_printLiteral (Toy_Literal literal) |
| Wraps a call to Toy_printLiteralCustom, with a printf-stdout wrapper as printFn. | |
| TOY_API void | Toy_printLiteralCustom (Toy_Literal literal, Toy_PrintFn) |
| Passes the string representation of literal to printFn. This function is not thread safe - due to the loopy and recursive nature of printing compound values, this function uses some globally persistent variables. | |
@???@
| #define TOY_AS_ARRAY | ( | value | ) | ((Toy_LiteralArray*)((value).as.array)) |
@???@
| #define TOY_AS_BOOLEAN | ( | value | ) | ((value).as.boolean) |
@???@
| #define TOY_AS_DICTIONARY | ( | value | ) | ((Toy_LiteralDictionary*)((value).as.dictionary)) |
@???@
| #define TOY_AS_FLOAT | ( | value | ) | ((value).as.number) |
@???@
| #define TOY_AS_FUNCTION | ( | value | ) | ((value).as.function) |
@???@
| #define TOY_AS_FUNCTION_BYTECODE_LENGTH | ( | lit | ) | (Toy_lengthRefFunction((lit).inner.ptr)) |
@???@
| #define TOY_AS_FUNCTION_HOOK | ( | value | ) | ((value).as.function.inner.hook) |
@???@
| #define TOY_AS_FUNCTION_NATIVE | ( | value | ) | ((value).as.function.inner.native) |
@???@
| #define TOY_AS_IDENTIFIER | ( | value | ) | ((value).as.identifier.ptr) |
@???@
| #define TOY_AS_INTEGER | ( | value | ) | ((value).as.integer) |
@???@
| #define TOY_AS_OPAQUE | ( | value | ) | ((value).as.opaque.ptr) |
@???@
| #define TOY_AS_STRING | ( | value | ) | ((value).as.string.ptr) |
@???@
| #define TOY_AS_TYPE | ( | value | ) | ((value).as.type) |
@???@
| #define TOY_GET_OPAQUE_TAG | ( | o | ) | o.as.opaque.tag |
@???@
| #define TOY_HASH_I | ( | lit | ) | ((lit).as.identifier.hash) |
@???@
| #define TOY_IS_ARRAY | ( | value | ) | ((value).type == TOY_LITERAL_ARRAY) |
@???@
| #define TOY_IS_BOOLEAN | ( | value | ) | ((value).type == TOY_LITERAL_BOOLEAN) |
@???@
| #define TOY_IS_DICTIONARY | ( | value | ) | ((value).type == TOY_LITERAL_DICTIONARY) |
@???@
| #define TOY_IS_FLOAT | ( | value | ) | ((value).type == TOY_LITERAL_FLOAT) |
@???@
| #define TOY_IS_FUNCTION | ( | value | ) | ((value).type == TOY_LITERAL_FUNCTION) |
@???@
| #define TOY_IS_FUNCTION_HOOK | ( | value | ) | ((value).type == TOY_LITERAL_FUNCTION_HOOK) |
@???@
| #define TOY_IS_FUNCTION_NATIVE | ( | value | ) | ((value).type == TOY_LITERAL_FUNCTION_NATIVE) |
@???@
| #define TOY_IS_IDENTIFIER | ( | value | ) | ((value).type == TOY_LITERAL_IDENTIFIER) |
@???@
| #define TOY_IS_INDEX_BLANK | ( | value | ) | ((value).type == TOY_LITERAL_INDEX_BLANK) |
@???@
| #define TOY_IS_INTEGER | ( | value | ) | ((value).type == TOY_LITERAL_INTEGER) |
@???@
| #define TOY_IS_NULL | ( | value | ) | ((value).type == TOY_LITERAL_NULL) |
@???@
| #define TOY_IS_OPAQUE | ( | value | ) | ((value).type == TOY_LITERAL_OPAQUE) |
@???@
| #define TOY_IS_STRING | ( | value | ) | ((value).type == TOY_LITERAL_STRING) |
@???@
| #define TOY_IS_TRUTHY | ( | x | ) | Toy_private_isTruthy(x) |
@???@
| #define TOY_IS_TYPE | ( | value | ) | ((value).type == TOY_LITERAL_TYPE) |
@???@
| #define TOY_MAX_STRING_LENGTH 4096 |
@???@
| #define TOY_TO_ARRAY_LITERAL | ( | value | ) | ((Toy_Literal){{ .array = value }, TOY_LITERAL_ARRAY}) |
@???@
| #define TOY_TO_BOOLEAN_LITERAL | ( | value | ) | ((Toy_Literal){{ .boolean = value }, TOY_LITERAL_BOOLEAN}) |
@???@
| #define TOY_TO_DICTIONARY_LITERAL | ( | value | ) | ((Toy_Literal){{ .dictionary = value }, TOY_LITERAL_DICTIONARY}) |
@???@
| #define TOY_TO_FLOAT_LITERAL | ( | value | ) | ((Toy_Literal){{ .number = value }, TOY_LITERAL_FLOAT}) |
@???@
| #define TOY_TO_FUNCTION_HOOK_LITERAL | ( | value | ) | ((Toy_Literal){{ .function = { .inner = { .hook = value }, .scope = NULL }}, TOY_LITERAL_FUNCTION_HOOK}) |
@???@
| #define TOY_TO_FUNCTION_LITERAL | ( | value | ) | ((Toy_Literal){{ .function = { .inner = { .ptr = value }, .scope = NULL }}, TOY_LITERAL_FUNCTION}) |
@???@
| #define TOY_TO_FUNCTION_NATIVE_LITERAL | ( | value | ) | ((Toy_Literal){{ .function = { .inner = { .native = value }, .scope = NULL }}, TOY_LITERAL_FUNCTION_NATIVE}) |
@???@
| #define TOY_TO_IDENTIFIER_LITERAL | ( | value | ) | Toy_private_toIdentifierLiteral(value) |
@???@
| #define TOY_TO_INDEX_BLANK_LITERAL ((Toy_Literal){{ .integer = 0 }, TOY_LITERAL_INDEX_BLANK}) |
@???@
| #define TOY_TO_INTEGER_LITERAL | ( | value | ) | ((Toy_Literal){{ .integer = value }, TOY_LITERAL_INTEGER}) |
@???@
| #define TOY_TO_NULL_LITERAL ((Toy_Literal){{ .integer = 0 }, TOY_LITERAL_NULL}) |
@???@
| #define TOY_TO_OPAQUE_LITERAL | ( | value, | |
| t | |||
| ) | ((Toy_Literal){{ .opaque = { .ptr = value, .tag = t }}, TOY_LITERAL_OPAQUE}) |
@???@
| #define TOY_TO_STRING_LITERAL | ( | value | ) | ((Toy_Literal){{ .string = { .ptr = value }},TOY_LITERAL_STRING}) |
@???@
| #define TOY_TO_TYPE_LITERAL | ( | value, | |
| c | |||
| ) | ((Toy_Literal){{ .type = { .typeOf = value, .constant = c, .subtypes = NULL, .capacity = 0, .count = 0 }}, TOY_LITERAL_TYPE}) |
@???@
| #define TOY_TYPE_PUSH_SUBTYPE | ( | lit, | |
| subtype | |||
| ) | Toy_private_typePushSubtype(lit, subtype) |
@???@
| int(* Toy_HookFn)(struct Toy_Interpreter *interpreter, struct Toy_Literal identifier, struct Toy_Literal alias) |
@???@
| interpreter | |
| identifier | |
| alias |
@???@
| int(* Toy_NativeFn)(struct Toy_Interpreter *interpreter, struct Toy_LiteralArray *arguments) |
@???@
| interpreter | |
| arguments |
| void(* Toy_PrintFn)(const char *) |
@???@
| enum Toy_LiteralType |
@???@
| Toy_Literal Toy_copyLiteral | ( | Toy_Literal | original | ) |
Returns a copy of the given literal. Literals should never be copied without this function, as it handles a lot of internal memory allocations.
| original |
| void Toy_freeLiteral | ( | Toy_Literal | literal | ) |
@???@
| literal |
| int Toy_hashLiteral | ( | Toy_Literal | lit | ) |
Finds the hash of a literal, for various purposes. Different hashing algorithms are used for different types, and some types can't be hashed at all. Types that can't be hashed:
| lit |
| bool Toy_literalsAreEqual | ( | Toy_Literal | lhs, |
| Toy_Literal | rhs | ||
| ) |
Checks to see if two given literals are equal. When an integer and a float are compared, the integer is cooerced into a float for the duration of the call. Arrays and dictionaries are equal only if their keys and values all equal. Likewise, types only equal if all subtypes are equal, in order. Functions and opaques are never equal to anything, while values with the type TOY_LITERAL_ANY are always equal.
| lhs | |
| rhs |
| void Toy_printLiteral | ( | Toy_Literal | literal | ) |
Wraps a call to Toy_printLiteralCustom, with a printf-stdout wrapper as printFn.
| literal |
| void Toy_printLiteralCustom | ( | Toy_Literal | literal, |
| Toy_PrintFn | |||
| ) |
Passes the string representation of literal to printFn. This function is not thread safe - due to the loopy and recursive nature of printing compound values, this function uses some globally persistent variables.
| literal | |
| Toy_PrintFn |
| bool Toy_private_isTruthy | ( | Toy_Literal | x | ) |
@???@
| x |
| Toy_Literal Toy_private_toIdentifierLiteral | ( | Toy_RefString * | ptr | ) |
@???@
| ptr |
| Toy_Literal * Toy_private_typePushSubtype | ( | Toy_Literal * | lit, |
| Toy_Literal | subtype | ||
| ) |
@???@
| lit | |
| subtype |