1515#include "ps_parse_declaration.h"
1616#include "ps_parse_executable.h"
1717#include "ps_parse_expression.h"
18+ #include "ps_parse_statement.h"
1819#include "ps_parse_type.h"
1920#include "ps_procedures.h"
2021#include "ps_signature.h"
@@ -459,20 +460,25 @@ bool ps_parse_procedure_or_function_declaration(ps_compiler *compiler, ps_ast_bl
459460}
460461
461462bool ps_parse_procedure_or_function_call_user (ps_compiler * compiler , ps_ast_block * block , ps_ast_call * * call ,
462- ps_symbol * executable , ps_value * result_value )
463+ ps_symbol * executable )
463464{
464465 PARSE_BEGIN ("PROCEDURE_OR_FUNCTION_CALL" , "" )
466+ (void )start_line ;
467+ (void )start_column ;
465468
466469 uint16_t line = 0 ;
467470 uint16_t column = 0 ;
468- bool has_environment = false;
469471 ps_symbol * result_symbol = NULL ;
470472 ps_identifier result_identifier = "RESULT" ;
473+ ps_value * result_value = NULL ;
474+
475+ if (executable -> kind != PS_SYMBOL_KIND_PROCEDURE && executable -> kind != PS_SYMBOL_KIND_FUNCTION )
476+ RETURN_ERROR (PS_ERROR_UNEXPECTED_TOKEN )
471477
472478 // Enter environment for procedure or function
473- has_environment = ps_compiler_enter_environment (compiler , executable -> name );
474- if (!has_environment )
475- TRACE_ERROR ("ENTER_ENVIRONMENT" )
479+ // has_environment = ps_compiler_enter_environment(compiler, executable->name);
480+ // if (!has_environment)
481+ // TRACE_ERROR("ENTER_ENVIRONMENT")
476482 // Parse actual parameters
477483 if (lexer -> current_token .type == PS_TOKEN_LEFT_PARENTHESIS )
478484 {
@@ -502,16 +508,14 @@ bool ps_parse_procedure_or_function_call_user(ps_compiler *compiler, ps_ast_bloc
502508 else if (executable -> kind == PS_SYMBOL_KIND_FUNCTION )
503509 {
504510 // Function have a return value
505- result_value -> type = executable -> value -> data .x -> block -> signature -> result_type ;
506- result_value -> data .v = NULL ;
507- result_value -> allocated = false;
511+ result_value =
512+ ps_value_alloc (executable -> value -> data .x -> block -> signature -> result_type , (ps_value_data ){.h = 0 });
513+ if (result_value == NULL )
514+ GOTO_CLEANUP (PS_ERROR_OUT_OF_MEMORY )
508515 result_symbol = ps_symbol_alloc (PS_SYMBOL_KIND_VARIABLE , result_identifier , result_value );
509516 if (result_symbol == NULL )
510- {
511- compiler -> error = PS_ERROR_OUT_OF_MEMORY ;
512- goto cleanup ;
513- }
514- if (!ps_environment_add_symbol (ps_compiler_get_environment (compiler ), result_symbol ))
517+ GOTO_CLEANUP (PS_ERROR_OUT_OF_MEMORY )
518+ if (!ps_compiler_add_symbol (compiler , block , result_symbol ))
515519 {
516520 ps_symbol_free (result_symbol );
517521 compiler -> error = PS_ERROR_OUT_OF_MEMORY ;
@@ -520,6 +524,9 @@ bool ps_parse_procedure_or_function_call_user(ps_compiler *compiler, ps_ast_bloc
520524 }
521525
522526 // TODO build AST node for CALL
527+ * call = ps_ast_create_call (line , column ,
528+ executable -> kind == PS_SYMBOL_KIND_PROCEDURE ? PS_AST_PROCEDURE : PS_AST_FUNCTION ,
529+ executable , 0 , NULL , NULL , NULL );
523530
524531cleanup :
525532 if (compiler -> error != PS_ERROR_NONE )
@@ -537,24 +544,26 @@ bool ps_parse_procedure_or_function_call(ps_compiler *compiler, ps_ast_block *bl
537544 ps_symbol * executable )
538545{
539546 PARSE_BEGIN ("PROCEDURE_OR_FUNCTION_CALL" , "" )
547+ (void )start_line ;
548+ (void )start_column ;
540549
541550 if (executable == & ps_system_procedure_write || executable == & ps_system_procedure_writeln )
542551 {
543552 // Write or WriteLn
544- if (!ps_parse_write_or_writeln (compiler , block , executable == & ps_system_procedure_writeln ))
553+ if (!ps_parse_write_or_writeln (compiler , block , call , executable == & ps_system_procedure_writeln ))
545554 TRACE_ERROR ("WRITE[LN]" );
546555 }
547556 else if (executable == & ps_system_procedure_read || executable == & ps_system_procedure_readln )
548557 {
549558 compiler -> error = PS_ERROR_NOT_IMPLEMENTED ;
550- if (!ps_parse_read_or_readln (compiler , block , executable == & ps_system_procedure_readln ))
559+ if (!ps_parse_read_or_readln (compiler , block , call , executable == & ps_system_procedure_readln ))
551560 TRACE_ERROR ("READ[LN]" );
552561 }
553562 else if (executable == & ps_system_procedure_randomize )
554563 {
555564 // Randomize
556- if (! ps_procedure_randomize ( compiler , NULL ))
557- TRACE_ERROR ( "RANDOMIZE" );
565+ ps_compiler_set_message ( compiler , "TODO: call RANDOMIZE" , executable -> name );
566+ RETURN_ERROR ( PS_ERROR_NOT_IMPLEMENTED )
558567 }
559568 else if (executable -> system )
560569 {
@@ -563,7 +572,7 @@ bool ps_parse_procedure_or_function_call(ps_compiler *compiler, ps_ast_block *bl
563572 RETURN_ERROR (PS_ERROR_NOT_IMPLEMENTED )
564573 }
565574 // User defined procedure or function call
566- else if (!ps_parse_procedure_or_function_call_user (compiler , block , call , executable , result_value ))
575+ else if (!ps_parse_procedure_or_function_call_user (compiler , block , call , executable ))
567576 TRACE_ERROR ("USER" );
568577
569578 PARSE_END ("OK" )
0 commit comments