Test now runs generated code, swtiched math test to use polyorphism from cpp.

Now need to make that array test...
This commit is contained in:
Edward R. Gonzalez 2023-04-02 12:25:08 -04:00
parent 5e26d53a12
commit 340f466f24
7 changed files with 39 additions and 41 deletions

View File

@ -3,7 +3,7 @@
An attempt at simple staged metaprogramming for c/c++. An attempt at simple staged metaprogramming for c/c++.
This project is not minimum feature complete yet. This project is not minimum feature complete yet.
Version 1 will have a most of c and a subset of c++ features available to it. Version 1 will have c and a subset of c++ features available to it.
## How it works ## How it works

View File

@ -1,5 +1,4 @@
#include "Bloat.hpp" #include "Bloat.hpp"
#define gen_time
#include "gen.hpp" #include "gen.hpp"
#ifdef gen_time #ifdef gen_time

View File

@ -98,23 +98,29 @@ Pop-Location
# Build the program depending on generated files. # Build the program depending on generated files.
# if ( -not( Test-Path $path_test_build ) ) if ( -not( Test-Path $path_test_build ) )
# { {
# $args_meson = @() $args_meson = @()
# $args_meson += "setup" $args_meson += "setup"
# $args_meson += $path_test_build $args_meson += $path_test_build
# Push-Location $path_test Push-Location $path_test
# & meson $args_meson & meson $args_meson
# Pop-Location Pop-Location
# } }
# $args_ninja = @() $args_ninja = @()
# $args_ninja += "-C" $args_ninja += "-C"
# $args_ninja += $path_test_build $args_ninja += $path_test_build
# Push-Location $path_root Push-Location $path_root
# ninja $args_ninja ninja $args_ninja
# Pop-Location Pop-Location
$testcpp = Join-Path $path_test_build testcpp.exe
Push-Location $path_test
& $testcpp
Pop-Location
# endregion Test Build # endregion Test Build
# } # }

View File

@ -1,24 +1,24 @@
inline inline
u8 square_u8(u8 value) u8 square(u8 value)
{ {
return value * value return value * value;
} }
inline inline
u16 square_u16(u16 value) u16 square(u16 value)
{ {
return value * value return value * value;
} }
inline inline
u32 square_u32(u32 value) u32 square(u32 value)
{ {
return value * value return value * value;
} }
inline inline
u64 square_u64(u64 value) u64 square(u64 value)
{ {
return value * value return value * value;
} }

View File

@ -1,6 +1,5 @@
#pragma once #pragma once
#define gen_time
#include "Bloat.hpp" #include "Bloat.hpp"
#include "gen.hpp" #include "gen.hpp"
@ -23,10 +22,10 @@
{ {
Code integral_type = make_type( type ); Code integral_type = make_type( type );
string name = string_sprintf( g_allocator, (char*)sprintf_buf, ZPL_PRINTF_MAXLEN, "square_%s", type ); string name = string_sprintf( g_allocator, (char*)sprintf_buf, ZPL_PRINTF_MAXLEN, "square", type );
Code specifiers = make_specifiers( 1, Specifier::Inline ); Code specifiers = make_specifiers( 1, Specifier::Inline );
Code params = make_parameters( 1, "value", integral_type ); Code params = make_parameters( 1, "value", integral_type );
Code ret_stmt = make_fmt( "\treturn value * value" ); Code ret_stmt = make_fmt( "\treturn value * value;" );
Code result = make_function( name, Code result = make_function( name,
specifiers, specifiers,
@ -64,11 +63,4 @@
#include "math.gen.hpp" #include "math.gen.hpp"
#undef square #undef square
#define sym_square( Type_, Value_ ) square_#Type_( Value_ )
template<class type>
type square( type value )
[
sym_square( type, value );
]
#endif #endif

View File

@ -4,14 +4,15 @@ project( 'test', 'c', 'cpp', default_options : ['buildtype=debug'] )
includes = include_directories( includes = include_directories(
[ [
'../project' './gen',
, '../thirdparty' '../project',
'../thirdparty'
]) ])
# get_sources = files('./get_sources.ps1') # get_sources = files('./get_sources.ps1')
# sources = files(run_command('powershell', get_sources, check: true).stdout().strip().split('\n')) # sources = files(run_command('powershell', get_sources, check: true).stdout().strip().split('\n'))
sources = [ 'math.hpp' ] sources = [ 'test.cpp' ]
if get_option('buildtype').startswith('debug') if get_option('buildtype').startswith('debug')
@ -19,4 +20,4 @@ if get_option('buildtype').startswith('debug')
endif endif
executable( '', sources, include_directories : includes ) executable( 'testcpp', sources, include_directories : includes )

View File

@ -25,7 +25,7 @@ int gen_main()
int main() int main()
{ {
u32 result = square(5); u32 result = square( 5U );
zpl_printf("TEST RESULT: %d", result); zpl_printf("TEST RESULT: %d", result);
} }