From 266c664fd9023c24a1bea8a09ae2f1fa125412fc Mon Sep 17 00:00:00 2001 From: Rene Rivera Date: Tue, 22 Mar 2022 23:02:51 -0400 Subject: [PATCH] Remove public function STACK access. In preparation to clean up the Jam function global stack move the definition of the STACK and related functions inside the function.cpp source file only. --- .vscode/launch.json | 30 +++++++++--------------------- src/engine/command.cpp | 4 ++-- src/engine/compile.cpp | 2 +- src/engine/function.cpp | 21 ++++++++++++++------- src/engine/function.h | 10 ++-------- src/engine/parse.cpp | 3 ++- 6 files changed, 30 insertions(+), 40 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 227e0c62d..0d86d5075 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -5,25 +5,13 @@ "version": "0.2.0", "configurations": [ { - "name": "(lldb) Launch", + "name": "(gdb) Launch", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}/src/engine/b2", - "args": ["-sBOOST_BUILD_PATH=${workspaceFolder}", "toolset=clang"], - "stopAtEntry": true, - "cwd": "${workspaceFolder}/test", - "environment": [], - "externalConsole": true, - "MIMode": "lldb" - }, - { - "name": "(gdb) Launch: example/hello", - "type": "cppdbg", - "request": "launch", - "program": "${workspaceFolder}/.build/clang-linux-10.0.0/debug/cxxstd-11-iso/b2", - "args": ["-n", "toolset=clang"], + "program": "${workspaceFolder}/.build/gcc-11/debug/cxxstd-11-iso/b2", + "args": ["-na"], "stopAtEntry": false, - "cwd": "${workspaceFolder}/example/hello", + "cwd": "${workspaceFolder}", "environment": [], "externalConsole": false, "MIMode": "gdb", @@ -36,13 +24,13 @@ ] }, { - "name": "(gdb) Launch: home/tmp/prebuild", + "name": "(gdb) Launch: ASAN", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}/.build/gcc-10.1.0/debug/cxxstd-11-iso/b2", - "args": ["-n","-sBOOST_BUILD_PATH=/home/grafik/Sync/DevRoots/B2/mainline/test/..","debug","release","-j1","-d2","toolset=gcc"], + "program": "${workspaceFolder}/.build/gcc-11/debug/address-sanitizer-on/cxxstd-11-iso/b2", + "args": ["-na", "toolset=gcc"], "stopAtEntry": false, - "cwd": "/home/grafik/tmp/prebuilt-1", + "cwd": "${workspaceFolder}", "environment": [], "externalConsole": false, "MIMode": "gdb", @@ -53,6 +41,6 @@ "ignoreFailures": true } ] - }, + } ] } \ No newline at end of file diff --git a/src/engine/command.cpp b/src/engine/command.cpp index 75837d49d..bd308b842 100644 --- a/src/engine/command.cpp +++ b/src/engine/command.cpp @@ -5,6 +5,7 @@ */ /* This file is ALSO: + * Copyright 2022 René Ferdinand Rivera Morell * Copyright 2001-2004 David Abrahams. * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE.txt or https://www.bfgroup.xyz/b2/LICENSE.txt) @@ -83,8 +84,7 @@ CMD * cmd_new( RULE * rule, LIST * targets, LIST * sources, LIST * shell ) lol_init( frame->args ); lol_add( frame->args, list_copy( targets ) ); lol_add( frame->args, list_copy( sources ) ); - function_run_actions( rule->actions->command, frame, stack_global(), - cmd->buf ); + function_run_actions( rule->actions->command, frame, cmd->buf ); frame_free( frame ); return cmd; diff --git a/src/engine/compile.cpp b/src/engine/compile.cpp index daeb3d2f9..b16826905 100644 --- a/src/engine/compile.cpp +++ b/src/engine/compile.cpp @@ -146,7 +146,7 @@ LIST * evaluate_rule( RULE * rule, OBJECT * rulename, FRAME * frame ) if ( rule->procedure ) { auto function = b2::jam::make_unique_bare_jptr( rule->procedure, function_refer, function_free ); - result = function_run( function.get(), frame, stack_global() ); + result = function_run( function.get(), frame ); } if ( DEBUG_PROFILE && rule->procedure ) diff --git a/src/engine/function.cpp b/src/engine/function.cpp index 2db31cfae..2437b1334 100644 --- a/src/engine/function.cpp +++ b/src/engine/function.cpp @@ -1,6 +1,6 @@ /* + * Copyright 2016-2022 Rene Rivera * Copyright 2011 Steven Watanabe - * Copyright 2016 Rene Rivera * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE.txt or copy at * https://www.bfgroup.xyz/b2/LICENSE.txt) @@ -222,6 +222,13 @@ static LIST * call_python_function( PYTHON_FUNCTION *, FRAME * ); #endif +typedef struct _stack STACK; +typedef STACK* stack_ptr; + +STACK * stack_global( void ); +void stack_push( STACK * s, LIST * l ); +LIST * stack_pop( STACK * s ); + struct _stack { void * data; @@ -4003,12 +4010,11 @@ static_assert( static_assert( sizeof(LIST *) <= sizeof(void *), "sizeof(LIST *) <= sizeof(void *)" ); static_assert( sizeof(char *) <= sizeof(void *), "sizeof(char *) <= sizeof(void *)" ); -void function_run_actions( FUNCTION * function, FRAME * frame, STACK * s, - string * out ) +void function_run_actions( FUNCTION * function, FRAME * frame, string * out ) { - *(string * *)stack_allocate( s, sizeof( string * ) ) = out; - list_free( function_run( function, frame, s ) ); - stack_deallocate( s, sizeof( string * ) ); + *(string * *)stack_allocate( stack_global(), sizeof( string * ) ) = out; + list_free( function_run( function, frame ) ); + stack_deallocate( stack_global(), sizeof( string * ) ); } // Result is either the filename or contents depending on: @@ -4162,8 +4168,9 @@ LIST * function_execute_write_file( * especially careful about stack push/pop. */ -LIST * function_run( FUNCTION * function_, FRAME * frame, STACK * s ) +LIST * function_run( FUNCTION * function_, FRAME * frame ) { + STACK * s = stack_global(); JAM_FUNCTION * function; instruction * code; LIST * l; diff --git a/src/engine/function.h b/src/engine/function.h index afa0277bb..6c5564a25 100644 --- a/src/engine/function.h +++ b/src/engine/function.h @@ -16,14 +16,8 @@ #include "jam_strings.h" typedef struct _function FUNCTION; -typedef struct _stack STACK; typedef FUNCTION* function_ptr; -typedef STACK* stack_ptr; - -STACK * stack_global( void ); -void stack_push( STACK * s, LIST * l ); -LIST * stack_pop( STACK * s ); FUNCTION * function_compile( PARSE * parse ); FUNCTION * function_builtin( LIST * ( * func )( FRAME * frame, int32_t flags ), int32_t flags, const char * * args ); @@ -32,10 +26,10 @@ void function_free( FUNCTION * ); OBJECT * function_rulename( FUNCTION * ); void function_set_rulename( FUNCTION *, OBJECT * ); void function_location( FUNCTION *, OBJECT * *, int32_t * ); -LIST * function_run( FUNCTION * function, FRAME * frame, STACK * s ); +LIST * function_run( FUNCTION * function, FRAME * frame ); FUNCTION * function_compile_actions( const char * actions, OBJECT * file, int32_t line ); -void function_run_actions( FUNCTION * function, FRAME * frame, STACK * s, string * out ); +void function_run_actions( FUNCTION * function, FRAME * frame, string * out ); FUNCTION * function_bind_variables( FUNCTION * f, module_t * module, int32_t * counter ); FUNCTION * function_unbind_variables( FUNCTION * f ); diff --git a/src/engine/parse.cpp b/src/engine/parse.cpp index d1588ab75..0df2e541c 100644 --- a/src/engine/parse.cpp +++ b/src/engine/parse.cpp @@ -5,6 +5,7 @@ */ /* This file is ALSO: + * Copyright 2022 René Ferdinand Rivera Morell * Copyright 2001-2004 David Abrahams. * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE.txt or https://www.bfgroup.xyz/b2/LICENSE.txt) @@ -52,7 +53,7 @@ static void parse_impl( FRAME * frame ) /* Run the parse tree. */ auto func = b2::jam::make_unique_bare_jptr( function_compile( p ), function_free ); parse_free( p ); - list_free( function_run( func.get(), frame, stack_global() ) ); + list_free( function_run( func.get(), frame ) ); } yyfdone();