Skip to content
This repository has been archived by the owner on Jun 27, 2022. It is now read-only.

[Lang Enhancement Proposal] Use alloca() and implement stack-based variable storage for small values #68

Open
Luna-Klatzer opened this issue Nov 23, 2021 · 0 comments
Assignees
Labels
enhancement New feature or request language Core language issue, change or idea

Comments

@Luna-Klatzer
Copy link
Member

Luna-Klatzer commented Nov 23, 2021

Affected area by change:

  • Language Syntax: no
  • Language Library (Parac Base Library): yes
  • Compiler: yes
  • Pre-Processor: no
  • Documentation: yes

Short Introduction and Summary
Currently, the implementation of memory is handled through datatypes which are allocated purely on the heap, as they use void* PblMalloc(size_t), though for better optimisations the allocations should happen preferably on the stack, and if possible with stack overflow checking, to avoid undefined behaviour.

Is your request related to a problem? Please describe.
At the moment, the allocation of memory is rather inefficient, as even small data-types are allocated on the stack, causing slow-downs, which could be easily fixed with additional implementation of something like void* PblAlloca(size_t).

Describe the solution you'd like

  • Implement a generic function in pbl-mem.h with the following signature void* PblAlloca(size_t).
  • Additional macros called PBL_ALLOCA_DECLARATION and PBL_ALLOCA_DEFINITION, which should use PblAlloca()
  • Rename PBL_ALLOC_DEFINITION to PBL_MALLOC_DEFINITION, PBL_ALLOC_DECLARATION to PBL_MALLOC_DECLARATION and PBL_ALLOC_ARRAY_DEFINITION to PBL_MALLOC_ARRAY_DEFINITION for clearer signalisation that the heap is used.

Describe alternatives you've considered
Perhaps revert to the old usage of actual finished types, though this would create issues with the current pointer implementations, so re-creating the stack usage is preferable.

Additional context

@Luna-Klatzer Luna-Klatzer added enhancement New feature or request dev labels Nov 23, 2021
@Luna-Klatzer Luna-Klatzer added this to the Road to Hello World milestone Nov 23, 2021
@Luna-Klatzer Luna-Klatzer self-assigned this Nov 23, 2021
@Luna-Klatzer Luna-Klatzer added language Core language issue, change or idea and removed dev labels Apr 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request language Core language issue, change or idea
Projects
None yet
Development

No branches or pull requests

1 participant