mirror of
https://github.com/zekexiao/pocketlang.git
synced 2025-02-06 12:46:53 +08:00
79 lines
2.7 KiB
C
79 lines
2.7 KiB
C
|
/*
|
||
|
* Copyright (c) 2020-2021 Thakee Nathees
|
||
|
* Distributed Under The MIT License
|
||
|
*/
|
||
|
|
||
|
#ifndef PK_INTERNAL
|
||
|
#define PK_INTERNAL
|
||
|
|
||
|
#include "include/pocketlang.h"
|
||
|
|
||
|
#include "pk_common.h"
|
||
|
|
||
|
// Commonly used c standard headers across the sources. Don't include any
|
||
|
// headers that are specific to a single source here, instead include them in
|
||
|
// their source files explicitly (can not be implicitly included by another
|
||
|
// header). And don't include any C standard headers in any of the pocketlang
|
||
|
// headers.
|
||
|
#include <assert.h>
|
||
|
#include <errno.h>
|
||
|
#include <float.h>
|
||
|
#include <stdarg.h>
|
||
|
#include <stdbool.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
|
||
|
// __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS are a workaround to
|
||
|
// allow C++ programs to use stdint.h macros specified in the C99
|
||
|
// standard that aren't in the C++ standard.
|
||
|
#define __STDC_LIMIT_MACROS
|
||
|
#include <stdint.h>
|
||
|
|
||
|
/*****************************************************************************/
|
||
|
/* INTERNAL CONFIGURATIONS */
|
||
|
/*****************************************************************************/
|
||
|
|
||
|
// Set this to dump compiled opcodes of each functions.
|
||
|
#define DEBUG_DUMP_COMPILED_CODE 0
|
||
|
|
||
|
// Set this to dump stack frame before executing the next instruction.
|
||
|
#define DEBUG_DUMP_CALL_STACK 0
|
||
|
|
||
|
// Nan-Tagging could be disable for debugging/portability purposes. See "var.h"
|
||
|
// header for more information on Nan-tagging.
|
||
|
#define VAR_NAN_TAGGING 1
|
||
|
|
||
|
// The maximum number of argument a pocketlang function supported to call. This
|
||
|
// value is arbitrary and feel free to change it. (Just used this limit for an
|
||
|
// internal buffer to store values before calling a new fiber).
|
||
|
#define MAX_ARGC 32
|
||
|
|
||
|
// The factor by which a buffer will grow when it's capacity reached.
|
||
|
#define GROW_FACTOR 2
|
||
|
|
||
|
// The initial minimum capacity of a buffer to allocate.
|
||
|
#define MIN_CAPACITY 8
|
||
|
|
||
|
/*****************************************************************************/
|
||
|
/* ALLOCATION MACROS */
|
||
|
/*****************************************************************************/
|
||
|
|
||
|
// Allocate object of [type] using the vmRealloc function.
|
||
|
#define ALLOCATE(vm, type) \
|
||
|
((type*)vmRealloc(vm, NULL, 0, sizeof(type)))
|
||
|
|
||
|
// Allocate object of [type] which has a dynamic tail array of type [tail_type]
|
||
|
// with [count] entries.
|
||
|
#define ALLOCATE_DYNAMIC(vm, type, count, tail_type) \
|
||
|
((type*)vmRealloc(vm, NULL, 0, sizeof(type) + sizeof(tail_type) * (count)))
|
||
|
|
||
|
// Allocate [count] amount of object of [type] array.
|
||
|
#define ALLOCATE_ARRAY(vm, type, count) \
|
||
|
((type*)vmRealloc(vm, NULL, 0, sizeof(type) * (count)))
|
||
|
|
||
|
// Deallocate a pointer allocated by vmRealloc before.
|
||
|
#define DEALLOCATE(vm, pointer) \
|
||
|
vmRealloc(vm, pointer, 0, 0)
|
||
|
|
||
|
#endif // PK_INTERNAL
|