Skip to content

Fix/calling convention#658

Merged
SuperFola merged 13 commits intodevfrom
fix/calling-convention
Mar 17, 2026
Merged

Fix/calling convention#658
SuperFola merged 13 commits intodevfrom
fix/calling-convention

Conversation

@SuperFola
Copy link
Member

@SuperFola SuperFola commented Mar 16, 2026

Description

Changes the calling convention so that in function calls, the function is evaluated first, then the arguments, in the order they appear.

This breaks a ton of things but it's worth it as everything will work the same way (operator currently evaluate from left to right, but ArkScript <= 4.4.0 evaluates function arguments from right to left, and the function to call last).

Some optimisations like CALL_SYMBOL and CALL_BUILTIN are a bit hard to add back, so we'll see if we can keep those.

Checklist

  • I have read the Contributor guide
  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated the documentation if needed (on https://github.com/ArkScript-lang/website, content/docs/)
  • I have added tests that prove my fix/feature is working
  • New and existing tests pass locally with my changes

…y the argument of push_return_address as hex
… function

Functions are compiled last to be near their CALL instruction,
so we need to compile the arguments first to have them registered
by the AST lowerer, and have the correct IDs
…d a GET_FIELD_AS_CLOSURE instruction to call closure fields
@github-actions
Copy link

github-actions bot commented Mar 16, 2026

Static analysis report

Lizard report

Listing only functions with cyclomatic complexity >= 15 or NLOC >= 100 or parameters >= 6.

Filename Start line:end line Function name Parameters NLOC CCN
src/arkreactor/VM/VM.cpp 407:2156 Ark::VM::safeRun 3 1471 288
src/arkreactor/Compiler/BytecodeReader.cpp 297:726 Ark::BytecodeReader::display 4 380 114
src/arkreactor/Compiler/Lowerer/ASTLowerer.cpp 210:314 Ark::internal::ASTLowerer::compileExpression 4 87 29
src/arkreactor/Compiler/Lowerer/ASTLowerer.cpp 348:425 Ark::internal::ASTLowerer::compileListInstruction 3 62 29
src/arkreactor/Compiler/Lowerer/ASTLowerer.cpp 818:937 Ark::internal::ASTLowerer::handleFunctionCall 3 89 26
src/arkreactor/VM/Value/Value.cpp 77:145 Ark::Value::toString 2 54 21
src/arkreactor/VM/VM.cpp 2310:2404 Ark::VM::backtrace 3 81 20
src/arkreactor/VM/Debugger.cpp 251:327 Ark::internal::Debugger::prompt 4 70 19
src/arkreactor/Compiler/Lowerer/ASTLowerer.cpp 764:816 Ark::internal::ASTLowerer::handleOperator 3 42 18
src/arkreactor/Compiler/Lowerer/ASTLowerer.cpp 105:127 Ark::internal::ASTLowerer::nodeProducesOutput 1 18 17
src/arkreactor/Compiler/Lowerer/ASTLowerer.cpp 492:570 Ark::internal::ASTLowerer::compileFunction 3 56 16
src/arkreactor/VM/VM.cpp 2168:2225 Ark::VM::throwArityError 4 47 15
src/arkreactor/Compiler/IntermediateRepresentation/IROptimizer.cpp 22:260 Ark::internal::IROptimizer::IROptimizer 1 219 14
Report about files you didn't modify in this PR
Filename Start line:end line Function name Parameters NLOC CCN
src/arkreactor/Compiler/Macros/Processor.cpp 259:628 Ark::internal::MacroProcessor::evaluate 3 338 114
src/arkreactor/Error/Diagnostics.cpp 45:192 Ark::Diagnostics::makeContext 4 109 44
src/arkscript/main.cpp 24:383 main 2 310 43
src/arkscript/JsonCompiler.cpp 27:276 JsonCompiler::_compile 1 214 38
src/arkreactor/Compiler/NameResolution/NameResolutionPass.cpp 162:267 Ark::internal::NameResolutionPass::visitKeyword 3 85 35
src/arkreactor/Builtins/Slice.cpp 21:93 Ark::internal::Builtins::slice 1 63 34
src/arkreactor/Compiler/AST/Parser.cpp 841:932 Ark::internal::Parser::string 1 88 32
src/arkreactor/Compiler/AST/Node.cpp 179:285 Ark::internal::Node::repr 0 90 30
src/arkreactor/Compiler/Macros/Processor.cpp 107:191 Ark::internal::MacroProcessor::processNode 3 63 28
src/arkreactor/Compiler/AST/Node.cpp 287:368 Ark::internal::Node::debugPrint 1 70 26
src/arkreactor/TypeChecker.cpp 149:236 Ark::types::generateError 6 75 25
src/arkreactor/TypeChecker.cpp 32:147 Ark::types::displayContract 6 102 24
src/arkreactor/Compiler/NameResolution/NameResolutionPass.cpp 56:160 Ark::internal::NameResolutionPass::visit 2 83 23
src/arkreactor/Compiler/AST/Parser.cpp 289:417 Ark::internal::Parser::import_ 1 98 23
include/utf8.hpp 138:184 utf8::isValid 1 44 21
src/arkreactor/Compiler/AST/Optimizer.cpp 35:85 Ark::internal::Optimizer::countAndPruneDeadCode 1 42 20
src/arkreactor/Compiler/NameResolution/StaticScope.cpp 68:109 Ark::internal::NamespaceScope::get 3 32 19
src/arkscript/Formatter.cpp 501:560 Formatter::formatCall 2 51 19
src/arkreactor/Builtins/String.cpp 46:112 fmt::formatter::parse 1 59 18
src/arkreactor/Compiler/AST/Optimizer.cpp 87:144 Ark::internal::Optimizer::pruneUnusedGlobalVariables 1 50 18
src/arkscript/Formatter.cpp 186:248 Formatter::format 3 59 18
src/arkreactor/Compiler/Macros/Executors/Function.cpp 16:89 Ark::internal::FunctionExecutor::applyMacro 2 56 17
include/Ark/Compiler/AST/Predicates.hpp 132:156 Ark::internal::IsSymbol::operator ( ) 1 24 16
src/arkscript/Formatter.cpp 298:339 Formatter::formatFunction 2 35 16
src/arkreactor/Compiler/Macros/Executors/Function.cpp 99:156 Ark::internal::FunctionExecutor::unify 5 50 15
src/arkreactor/Error/Diagnostics.cpp 194:211 Ark::Diagnostics::helper 7 17 2

CppCheck report

Filename Line Type Description
include/Ark/VM/VM.inl 258 style Variable 'maybe_value_ptr' can be declared as pointer to const
src/arkreactor/Compiler/BytecodeReader.cpp 478 style struct member 'Arg::kind' is never used.
src/arkreactor/Compiler/IntermediateRepresentation/IROptimizer.cpp 249 style Consider using std::transform algorithm instead of a raw loop.
src/arkreactor/Compiler/IntermediateRepresentation/IROptimizer.cpp 256 style Consider using std::transform algorithm instead of a raw loop.
src/arkreactor/VM/VM.cpp 281 error Iterators of different containers 'm_execution_contexts.emplace_back(std::make_unique())' and 'm_execution_contexts.front()' are used together.
Report files about files you didn't modify in this PR
Filename Line Type Description
src/arkreactor/Builtins/Bytecode.cpp 23 style Parameter 'vm' can be declared as pointer to const
src/arkreactor/Builtins/IO.cpp 165 style Consider using std::transform algorithm instead of a raw loop.
src/arkreactor/Compiler/NameResolution/ScopeResolver.cpp 134 style Consider using std::find_if algorithm instead of a raw loop.
include/Ark/VM/Value/Future.hpp 50 style Unused private function: 'Future::deleteSelfViaVM'
src/arkreactor/VM/Value/Future.cpp 23 performance Variable 'm_value' is assigned in constructor body. Consider performing initialization in initialization list.

@codspeed-hq
Copy link

codspeed-hq bot commented Mar 16, 2026

Merging this PR will degrade performance by 5.75%

❌ 5 (👁 5) regressed benchmarks
✅ 13 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
👁 fibonacci 28.7 ms 30.4 ms -5.75%
👁 ackermann 352.9 ms 356.7 ms -1.05%
👁 create_closure 4.8 ms 4.9 ms -1.96%
👁 binary_trees 4.8 s 4.9 s -2.05%
👁 quicksort 1.1 ms 1.2 ms -1.13%

Comparing fix/calling-convention (7a48276) with dev (704d407)

Open in CodSpeed

@github-actions
Copy link

github-actions bot commented Mar 16, 2026

Fuzzing report

/usr/local/bin/afl-whatsup status check tool for afl-fuzz by Michal Zalewski

Summary stats

    Fuzzers alive : 0
   Dead or remote : 1 (included in stats)
   Total run time : 5 minutes, 0 seconds
      Total execs : 41 thousands
 Cumulative speed : 138 execs/sec
    Pending items : 143 faves, 1262 total
 Coverage reached : 10.62%
    Crashes saved : 0
      Hangs saved : 0

Cycles without finds : 0
Time without finds : 0

[+] Captured 43596 tuples (map size 242003, highest value 255, total values 457969782) in '/dev/null'.
[+] A coverage of 43596 edges were achieved out of 242048 existing (18.01%) with 1272 input files.

@github-actions
Copy link

github-actions bot commented Mar 17, 2026

Super Instructions report

Super Instruction Uses in compiled code
CALL_SYMBOL 4126
LOAD_CONST_LOAD_CONST 2329
LOAD_CONST_STORE 1734
LOAD_CONST_SET_VAL 624
CALL_BUILTIN 564
INCREMENT_STORE 388
GET_FIELD_FROM_SYMBOL_INDEX 375
AT_SYM_SYM 353
CALL_BUILTIN_WITHOUT_RETURN_ADDRESS 311
CALL_SYMBOL_BY_INDEX 287
GET_FIELD_FROM_SYMBOL 263
STORE_LIST 245
APPEND_IN_PLACE_SYM 216
LT_LEN_SYM_JUMP_IF_FALSE 179
LT_SYM_JUMP_IF_FALSE 148
SET_VAL_FROM_INDEX 132
STORE_FROM_INDEX 101
STORE_LEN 99
EQ_SYM_INDEX_JUMP_IF_TRUE 96
SET_VAL_FROM 81
FUSED_MATH 63
DECREMENT_BY_INDEX 63
DECREMENT 59
AT_SYM_INDEX_SYM_INDEX 54
LT_CONST_JUMP_IF_TRUE 52
CALL_CURRENT_PAGE 51
GT_CONST_JUMP_IF_TRUE 34
AT_SYM_INDEX_CONST 34
DECREMENT_STORE 31
INCREMENT_BY_INDEX 31
EQ_CONST_JUMP_IF_TRUE 28
GT_CONST_JUMP_IF_FALSE 27
MUL_BY_INDEX 26
STORE_HEAD_BY_INDEX 24
STORE_TAIL_BY_INDEX 23
MUL_BY 23
CHECK_TYPE_OF_BY_INDEX 17
APPEND_IN_PLACE_SYM_INDEX 15
STORE_FROM 12
LT_CONST_JUMP_IF_FALSE 8
INCREMENT 7
NEQ_SYM_JUMP_IF_FALSE 4
SET_VAL_TAIL 4
STORE_HEAD 2
CHECK_TYPE_OF 2
NEQ_CONST_JUMP_IF_TRUE 2
GT_SYM_JUMP_IF_FALSE 1
SET_VAL_TAIL_BY_INDEX 1
SET_VAL_HEAD_BY_INDEX 1
MUL_SET_VAL 1
SET_VAL_HEAD 1
STORE_TAIL 1

@coveralls
Copy link

coveralls commented Mar 17, 2026

Pull Request Test Coverage Report for Build 23209154018

Details

  • 143 of 157 (91.08%) changed or added relevant lines in 8 files are covered.
  • 5 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.05%) to 93.659%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/arkreactor/Compiler/Lowerer/ASTLowerer.cpp 50 51 98.04%
src/arkreactor/VM/Debugger.cpp 3 4 75.0%
src/arkreactor/VM/Value/Value.cpp 0 1 0.0%
include/Ark/VM/VM.inl 29 31 93.55%
src/arkreactor/VM/VM.cpp 48 57 84.21%
Files with Coverage Reduction New Missed Lines %
src/arkreactor/VM/Debugger.cpp 1 89.84%
src/arkreactor/VM/VM.cpp 4 92.16%
Totals Coverage Status
Change from base Build 23052437195: -0.05%
Covered Lines: 9601
Relevant Lines: 10251

💛 - Coveralls

@SuperFola SuperFola marked this pull request as ready for review March 17, 2026 18:05
@SuperFola SuperFola merged commit 171b214 into dev Mar 17, 2026
33 checks passed
@SuperFola SuperFola deleted the fix/calling-convention branch March 17, 2026 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants