mirror of
https://github.com/Ed94/gencpp.git
synced 2024-12-22 07:44:45 -08:00
Readme updates, Updated tests to use args macro more.
This commit is contained in:
parent
b17c094cd2
commit
128b0e17fe
26
Readme.md
26
Readme.md
@ -84,14 +84,14 @@ Example using each construction interface:
|
||||
```cpp
|
||||
Code t_uw = def_type( name(uw) );
|
||||
Code t_allocator = def_type( name(allocator) );
|
||||
Code t_string_cosnt = def_type( name(char), def_specifiers( ESpecifier::Const, ESpecifier::Ptr ) );
|
||||
Code t_string_const = def_type( name(char), def_specifiers( args( ESpecifier::Const, ESpecifier::Ptr ) ));
|
||||
|
||||
Code header;
|
||||
{
|
||||
Code num = def_variable( t_uw, name(Num) );
|
||||
Code cap = def_variable( t_uw, name(Capacity) );
|
||||
Code mem_alloc = def_variable( t_allocator, name(Allocator) );
|
||||
Code body = def_struct_body( num, cap, mem_alloc );
|
||||
Code body = def_struct_body( args( num, cap, mem_alloc ) );
|
||||
|
||||
header = def_struct( name(ArrayHeader), __, __, body );
|
||||
}
|
||||
@ -111,8 +111,6 @@ Code header = parse_struct( code(
|
||||
|
||||
```
|
||||
|
||||
Parse will automatically generate any types that have not been used previously.
|
||||
|
||||
### Untyped
|
||||
|
||||
```cpp
|
||||
@ -127,7 +125,8 @@ Code header = untyped_str( code(
|
||||
```
|
||||
|
||||
`name` is a helper macro for providing a string literal with its size, intended for the name paraemter of functions.
|
||||
`code` is a helper macro for providing a string literal with its size, but intended for code string parameters.
|
||||
`code` is a helper macro for providing a string literal with its size, but intended for code string parameters.
|
||||
`args` is a helper macro for providing the number of arguments to varadic constructors.
|
||||
|
||||
All three constrcuton interfaces will generate the following C code:
|
||||
|
||||
@ -152,7 +151,6 @@ The other one in the gen directory within test is the metaprogram's build specif
|
||||
Both of them build the same source file: `test.cpp`. The only differences are that gen needs a different relative path to the include directories and defines the macro definition: `gen_time`.
|
||||
|
||||
This method is setup where all the metaprogram's code are the within the same files as the regular program's code.
|
||||
If in your use case, you decide to have exclusive separation or partial separation of the metaprogam's code from the program's code files, then your build configuration would need to change to reflect that (specifically the sources).
|
||||
|
||||
## Outline
|
||||
|
||||
@ -176,9 +174,9 @@ Keywords kept from "Modern C++":
|
||||
When it comes to expressions:
|
||||
|
||||
**There is no support for validating expressions.**
|
||||
**The reason:** Its difficult to parse with not much of a benefit from doing so.
|
||||
**The reason:** Its difficult to parse without enough benefits.
|
||||
Most of the time, the critical complex metaprogramming conundrums are producing the frame of abstractions around the expressions (which this library provides constructors to help validate, you can skip that process by using the untyped constructors).
|
||||
Its not very much a priority to add such a level of complexity to the library when there isn't a high reward or need for it.
|
||||
Its not a priority to add such a level of complexity to the library when there isn't a high reward or need for it.
|
||||
Especially when the priority is to keep this library small and easy to grasp for what it is.
|
||||
|
||||
When it comes to templates:
|
||||
@ -201,7 +199,7 @@ Use at your own mental peril...
|
||||
As mentioned in [Usage](#usage), the user is provided Code objects by calling the constructor's functions to generate them or find existing matches.
|
||||
|
||||
The AST is managed by the library and provided the user via its interface.
|
||||
However, the user may specificy memory configuration.
|
||||
However, the user may specifiy memory configuration.
|
||||
|
||||
Data layout of AST struct:
|
||||
|
||||
@ -225,7 +223,8 @@ u8 _Align_Pad[3];
|
||||
|
||||
*`CodeT` is a typedef for `ECode::Type` which has an underlying type of `u32`*
|
||||
*`OperatorT` is a typedef for `EOperator::Type` which has an underlying type of `u32`*
|
||||
*`StringCahced` is a typedef for `char const*` to denote it is an interned string*
|
||||
*`StringCahced` is a typedef for `String const`, to denote it is an interned string*
|
||||
*`String` is the dynamically allocated string type for the library.
|
||||
|
||||
AST widths are setup to be AST_POD_Size.
|
||||
The width dictates how much the static array can hold before it must give way to using an allocated array:
|
||||
@ -248,9 +247,6 @@ uw ArrS_Cap =
|
||||
|
||||
*Ex: If the AST_POD_Size is 256 the capacity of the static array is 27.*
|
||||
|
||||
ASTs can be set to readonly by calling Code's lock() member function.
|
||||
Adding comments is always available even if the AST is set to readonly.
|
||||
|
||||
Data Notes:
|
||||
|
||||
* The allocator definitions used are exposed to the user incase they want to dictate memory usage
|
||||
@ -280,7 +276,7 @@ Otherwise the library is free of any templates.
|
||||
### Upfront Construction
|
||||
|
||||
All component ASTs must be previously constructed, and provided on creation of the code AST.
|
||||
The construction will fail and return InvalidCode otherwise.
|
||||
The construction will fail and return Code::Invalid otherwise.
|
||||
|
||||
Interface :``
|
||||
|
||||
@ -479,6 +475,8 @@ The following are provided predefined by the library as they are commonly used:
|
||||
* `t_bool`
|
||||
* `t_char`
|
||||
* `t_wchar_t`
|
||||
* `t_class`
|
||||
* `t_typename`
|
||||
|
||||
Optionally the following may be defined if `GEN_DEFINE_LIBRARY_CODE_CONSTANTS` is defined
|
||||
|
||||
|
@ -3052,30 +3052,27 @@ namespace gen
|
||||
, ModuleFlag mflags = ModuleFlag::None );
|
||||
|
||||
Code def_class_body ( s32 num, ... );
|
||||
Code def_enum_body ( s32 num, ... );
|
||||
Code def_export_body ( s32 num, ... );
|
||||
Code def_extern_link_body( s32 num, ... );
|
||||
Code def_function_body ( s32 num, ... );
|
||||
Code def_global_body ( s32 num, ... );
|
||||
Code def_namespace_body ( s32 num, ... );
|
||||
Code def_params ( s32 num, ... );
|
||||
Code def_specifiers ( s32 num, ... );
|
||||
Code def_struct_body ( s32 num, ... );
|
||||
Code def_union_body ( s32 num, ... );
|
||||
Code def_class_body ( s32 num, Code* codes );
|
||||
Code def_enum_body ( s32 num, ... );
|
||||
Code def_enum_body ( s32 num, Code* codes );
|
||||
Code def_export_body ( s32 num, ... );
|
||||
Code def_export_body ( s32 num, Code* codes);
|
||||
Code def_extern_link_body( s32 num, ... );
|
||||
Code def_extern_link_body( s32 num, Code* codes );
|
||||
Code def_function_body ( s32 num, ... );
|
||||
Code def_function_body ( s32 num, Code* codes );
|
||||
Code def_global_body ( s32 num, ... );
|
||||
Code def_global_body ( s32 num, Code* codes );
|
||||
Code def_namespace_body ( s32 num, ... );
|
||||
Code def_namespace_body ( s32 num, Code* codes );
|
||||
Code def_params ( s32 num, ... );
|
||||
Code def_params ( s32 num, Code* params );
|
||||
Code def_specifiers ( s32 num, ... );
|
||||
Code def_specifiers ( s32 num, SpecifierT* specs );
|
||||
Code def_struct_body ( s32 num, ... );
|
||||
Code def_struct_body ( s32 num, Code* codes );
|
||||
Code def_union_body ( s32 num, ... );
|
||||
Code def_union_body ( s32 num, Code* codes );
|
||||
|
||||
// Use this to manually populate the entries on demand (will not be checked for validity).
|
||||
Code def_empty_body( CodeT body_type );
|
||||
# pragma endregion Upfront
|
||||
|
||||
# pragma region Parsing
|
||||
|
@ -9,18 +9,19 @@ Code gen__array_base()
|
||||
{
|
||||
Code t_allocator_info = def_type( name(AllocatorInfo) );
|
||||
|
||||
Code header = def_struct( name(ArrayHeader), def_struct_body( 3
|
||||
, def_variable( t_allocator_info, name(Allocator) )
|
||||
Code header = def_struct( name(ArrayHeader),
|
||||
def_struct_body( args(
|
||||
def_variable( t_allocator_info, name(Allocator) )
|
||||
, def_variable( t_uw, name(Capacity) )
|
||||
, def_variable( t_uw, name(Num) )
|
||||
));
|
||||
)));
|
||||
|
||||
Code grow_formula = def_function( name(array_grow_formula), def_param( t_uw, name(value)), t_uw
|
||||
, def_execution( code( return 2 * value * 8; ) )
|
||||
, def_specifiers( 2, ESpecifier::Static_Member, ESpecifier::Inline )
|
||||
, def_specifiers( args( ESpecifier::Static_Member, ESpecifier::Inline ) )
|
||||
);
|
||||
|
||||
return def_global_body( 2, header, grow_formula );
|
||||
return def_global_body( args( header, grow_formula ) );
|
||||
}
|
||||
|
||||
Code gen__array( StrC type )
|
||||
@ -71,10 +72,10 @@ Code gen__array( StrC type )
|
||||
|
||||
Code init_reserve;
|
||||
{
|
||||
Code params = def_params( 2
|
||||
, def_param( t_allocator_info, name(allocator) )
|
||||
Code params = def_params( args(
|
||||
def_param( t_allocator_info, name(allocator) )
|
||||
, def_param( t_sw, name(capacity) )
|
||||
);
|
||||
));
|
||||
|
||||
Code body = def_execution( code(
|
||||
Header* header = rcast( Header*, alloc( allocator, sizeof(Header) + sizeof(Type) ));
|
||||
@ -264,8 +265,8 @@ Code gen__array( StrC type )
|
||||
return Data;
|
||||
)));
|
||||
|
||||
Code body = def_struct_body( 20
|
||||
, using_header
|
||||
Code body = def_struct_body( args(
|
||||
using_header
|
||||
, using_type
|
||||
, ct_grow_formula
|
||||
|
||||
@ -289,7 +290,7 @@ Code gen__array( StrC type )
|
||||
, op_ptr
|
||||
|
||||
, data
|
||||
);
|
||||
));
|
||||
array = def_struct( name, body );
|
||||
}
|
||||
|
||||
|
@ -9,11 +9,12 @@ Code gen__buffer_base()
|
||||
{
|
||||
Code t_allocator_info = def_type( name(AllocatorInfo) );
|
||||
|
||||
Code header = def_struct( name(BufferHeader), def_struct_body( 3
|
||||
, def_variable( t_allocator_info, name(Backing) )
|
||||
Code header = def_struct( name(BufferHeader),
|
||||
def_struct_body( args(
|
||||
def_variable( t_allocator_info, name(Backing) )
|
||||
, def_variable( t_uw, name(Capacity) )
|
||||
, def_variable( t_uw, name(Num) )
|
||||
));
|
||||
)));
|
||||
|
||||
return def_global_body( 1, header );
|
||||
}
|
||||
@ -49,10 +50,10 @@ Code gen__buffer( StrC type, sw type_size )
|
||||
|
||||
Code init;
|
||||
{
|
||||
Code params = def_params( 2
|
||||
Code params = def_params( args(
|
||||
, def_param( t_allocator_info, name(allocator))
|
||||
, def_param( t_sw, name(capacity))
|
||||
);
|
||||
));
|
||||
|
||||
Code body = def_execution( code(
|
||||
Header* header = rcast( Header*, alloc( allocator, sizeof(Header) + capacity * sizeof(Type) ) );
|
||||
@ -72,10 +73,10 @@ Code gen__buffer( StrC type, sw type_size )
|
||||
|
||||
Code init_copy;
|
||||
{
|
||||
Code params = def_params( 2
|
||||
, def_param( t_allocator_info, name(allocator))
|
||||
Code params = def_params( args(
|
||||
def_param( t_allocator_info, name(allocator))
|
||||
, def_param( t_buffer_type, name(other))
|
||||
);
|
||||
));
|
||||
|
||||
init_copy = def_function( name(init), params, t_buffer_type
|
||||
, def_execution( code(
|
||||
@ -105,10 +106,10 @@ Code gen__buffer( StrC type, sw type_size )
|
||||
|
||||
Code appendv;
|
||||
{
|
||||
Code params = def_params( 2
|
||||
, def_param( t_type_ptr, name( values))
|
||||
Code params = def_params( args(
|
||||
def_param( t_type_ptr, name( values))
|
||||
, def_param( t_sw, name( num))
|
||||
);
|
||||
));
|
||||
|
||||
appendv = def_function( name(append), params, t_void
|
||||
, def_execution( code(
|
||||
@ -176,8 +177,8 @@ Code gen__buffer( StrC type, sw type_size )
|
||||
return Data;
|
||||
)));
|
||||
|
||||
buffer = def_struct( name, def_struct_body( 14
|
||||
, using_header
|
||||
buffer = def_struct( name, def_struct_body( args(
|
||||
using_header
|
||||
, using_type
|
||||
|
||||
, init
|
||||
@ -194,7 +195,7 @@ Code gen__buffer( StrC type, sw type_size )
|
||||
, op_type_ptr
|
||||
|
||||
, data
|
||||
));
|
||||
)));
|
||||
}
|
||||
|
||||
return buffer;
|
||||
|
@ -50,11 +50,11 @@ Code gen__hashtable( StrC type )
|
||||
StringCached ht_entry_name = get_cached_string({ len, name_str });
|
||||
|
||||
t_ht_entry = def_type( ht_entry_name );
|
||||
ht_entry = def_struct( ht_entry_name, def_struct_body( 3
|
||||
, def_variable( t_u64, name(Key))
|
||||
ht_entry = def_struct( ht_entry_name, def_struct_body( args(
|
||||
def_variable( t_u64, name(Key))
|
||||
, def_variable( t_sw, name(Next))
|
||||
, def_variable( t_type, name(Value))
|
||||
));
|
||||
)));
|
||||
|
||||
array_ht_entry = gen__array( ht_entry_name );
|
||||
t_array_ht_entry = def_type( array_ht_entry->Name );
|
||||
@ -102,7 +102,7 @@ Code gen__hashtable( StrC type )
|
||||
);
|
||||
Code body = def_execution( token_fmt( "type", (StrC)name, tmpl ) );
|
||||
|
||||
Code params = def_params( 2, def_param( t_allocator_info, name(allocator)), def_param( t_sw, name(num)));
|
||||
Code params = def_params( args( def_param( t_allocator_info, name(allocator)), def_param( t_sw, name(num))));
|
||||
|
||||
init_reserve = def_function( name(init_reserve), params, t_ht_type, body, spec_static_member );
|
||||
}
|
||||
@ -281,10 +281,10 @@ Code gen__hashtable( StrC type )
|
||||
|
||||
Code set;
|
||||
{
|
||||
Code params = def_params( 2
|
||||
, def_param( t_u64, name(key))
|
||||
Code params = def_params( args(
|
||||
def_param( t_u64, name(key))
|
||||
, def_param( t_type, name(value))
|
||||
);
|
||||
));
|
||||
|
||||
Code body = def_execution( code(
|
||||
sw idx;
|
||||
@ -372,7 +372,7 @@ Code gen__hashtable( StrC type )
|
||||
))
|
||||
);
|
||||
|
||||
hashtable = def_struct( name, def_struct_body( 25
|
||||
hashtable = def_struct( name, def_struct_body( args(
|
||||
, using_entry
|
||||
, using_array_entry
|
||||
, using_find_result
|
||||
@ -402,10 +402,10 @@ Code gen__hashtable( StrC type )
|
||||
, add_entry
|
||||
, find
|
||||
, full
|
||||
));
|
||||
)));
|
||||
}
|
||||
|
||||
return def_global_body( 3, ht_entry, array_ht_entry, hashtable );
|
||||
return def_global_body( args( ht_entry, array_ht_entry, hashtable ));
|
||||
}
|
||||
|
||||
struct GenHashTableRequest
|
||||
|
@ -45,10 +45,10 @@ Code gen__ring( StrC type )
|
||||
|
||||
Code init;
|
||||
{
|
||||
Code params = def_params( 2
|
||||
Code params = def_params( args(
|
||||
, def_param( t_allocator_info, name(allocator) )
|
||||
, def_param( t_uw, name(max_size) )
|
||||
);
|
||||
));
|
||||
|
||||
char const* tmpl = stringize(
|
||||
<type> result = { 0 };
|
||||
@ -129,7 +129,7 @@ Code gen__ring( StrC type )
|
||||
))
|
||||
);
|
||||
|
||||
ring = def_struct( name, def_struct_body( 14,
|
||||
ring = def_struct( name, def_struct_body( args(
|
||||
using_type,
|
||||
|
||||
init,
|
||||
@ -147,7 +147,7 @@ Code gen__ring( StrC type )
|
||||
head,
|
||||
tail,
|
||||
buffer
|
||||
));
|
||||
)));
|
||||
}
|
||||
|
||||
return ring;
|
||||
|
@ -218,10 +218,10 @@ u32 gen_sanity()
|
||||
, def_comment( txt_StrC("Empty function body") )
|
||||
);
|
||||
|
||||
Code params = def_params( 2
|
||||
, def_param( t_u8, name(a) )
|
||||
Code params = def_params( args(
|
||||
def_param( t_u8, name(a) )
|
||||
, def_param( t_u8, name(b) )
|
||||
);
|
||||
));
|
||||
|
||||
def = def_function( name(test_function_wparams), params, __, body );
|
||||
|
||||
|
@ -1,4 +1,7 @@
|
||||
#include "Bloat.cpp"
|
||||
#ifdef gen_time
|
||||
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
||||
#define GEN_FEATURE_PARSING
|
||||
#include "gen.cpp"
|
||||
#include "Upfront\Array.Upfront.hpp"
|
||||
#include "Upfront\Buffer.Upfront.hpp"
|
||||
#include "Upfront\HashTable.Upfront.hpp"
|
||||
@ -6,8 +9,6 @@
|
||||
#include "Upfront\Sanity.Upfront.hpp"
|
||||
|
||||
|
||||
#ifdef gen_time
|
||||
#include "gen.cpp"
|
||||
|
||||
using namespace gen;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user