Skip to content

Conversation

@asarhaddon
Copy link
Contributor

  • Define MalType as a pointer type, instead of an alias for a struct. It is now possible to declare it constant.
  • Use macros to avoid lots of code duplication.
  • Avoid redundant tests when possible.
  • Avoid implicit signed/unsigned conversions.
  • Use the const modifier whenever possible.
  • Move private forward declarations from .h to .c, and forward declarations on the top of the .c.

Makefile:
enable more warnings avoid recompiling each .o for each step fix .PHONY usage

core.c:
Link mal_list/vector/hash_map directly to make_*. Move mal_readline from stepA (reallocate with GC).

      • /: exactly two arguments. =: without memory allocation, stop comparing functions and closures. Stop assuming that nil contains a valid list(first/rest/get). throw: the argument should never be an exception. vec: refuse maps. seq: fix allocation of single character-strings.

core.h:
Represent the namespace as a static array instead of a linked list.

list:

  • Avoid reversals, either by modifying the last link or simply by inserting elements in the right order,
  • Avoid void*, the benefit of genericity here is small compared to the benefits of type checking.
  • Store a pointer to nil as default metadata, instead of NULL.

env:

  • Implement with binary trees. This is easy for a mutable structure, and helps a lot the performance of accessing REPL keys.
  • move repeated calls to env_set to steps.

maps:

  • Check type of map keys.
  • Remove the confusing in-place mutations.

printer:
Replace most string allocations with idiomatic printf-style specifiers.

reader:
Rewrite without intermediate tokenizer. Propagate more errors. Merge list/vector/hasmap handling.

run:
does not need bash.

steps:

  • reduce diff between steps.
  • Add an env_apply helper, reducing duplication.
  • Merge regularise_parameters into eval_fnstar (propagating errors was a burden compared to the benefit).
  • Use the same function for eval_vector, eval_hashmap and apply arguments. Return an error directly, not a list containing an error.
  • Rewrite quasiquote, fixing some misplaced unquotes.
  • Clarify return value of TCO helpers.
  • Report errors during startup.

types:

  • Try to merge type selection and value extraction, for concision and safety.
  • In the union, use one name per type (mal_string/keyword/symbol were confused in several places anyway).
  • Represent atoms as a double pointer, and macros with a type.
  • Prefer enums to macros.
  • Represent function parameters as a static array instead of a linked list.

* Define MalType as a pointer type, instead of an alias for a struct.
  It is now possible to declare it constant.
* Use macros to avoid lots of code duplication.
* Avoid redundant tests when possible.
* Avoid implicit signed/unsigned conversions.
* Use the const modifier whenever possible.
* Move private forward declarations from .h to .c,
  and forward declarations on the top of the .c.

Makefile:
  enable more warnings
  avoid recompiling each .o for each step
  fix .PHONY usage

core.c:
  Link mal_list/vector/hash_map directly to make_*.
  Move mal_readline from stepA (reallocate with GC).
  + - * /: exactly two arguments.
  =: without memory allocation, stop comparing functions and closures.
  Stop assuming that nil contains a valid list(first/rest/get).
  throw: the argument should never be an exception.
  vec: refuse maps.
  seq: fix allocation of single character-strings.

core.h:
  Represent the namespace as a static array instead of a linked list.

list:
* Avoid reversals, either by modifying the last link or simply by
  inserting elements in the right order,
* Avoid void*, the benefit of genericity here is small compared to
  the benefits of type checking.
* Store a pointer to nil as default metadata, instead of NULL.

env:
* Implement with binary trees.  This is easy for a mutable structure,
  and helps a lot the performance of accessing REPL keys.
* move repeated calls to env_set to steps.

maps:
* Check type of map keys.
* Remove the confusing in-place mutations.

printer:
  Replace most string allocations with idiomatic printf-style
  specifiers.

reader:
  Rewrite without intermediate tokenizer.
  Propagate more errors.
  Merge list/vector/hasmap handling.

run:
  does not need bash.

steps:
 * reduce diff between steps.
 * Add an env_apply helper, reducing duplication.
 * Merge regularise_parameters into eval_fnstar (propagating errors
   was a burden compared to the benefit).
 * Use the same function for eval_vector, eval_hashmap and apply arguments.
   Return an error directly, not a list containing an error.
 * Rewrite quasiquote, fixing some misplaced unquotes.
 * Clarify return value of TCO helpers.
 * Report errors during startup.

types:
* Try to merge type selection and value extraction, for concision and safety.
* In the union, use one name per type (mal_string/keyword/symbol were
  confused in several places anyway).
* Represent atoms as a double pointer, and macros with a type.
* Prefer enums to macros.
* Represent function parameters as a static array instead of a linked list.
@asarhaddon
Copy link
Contributor Author

Reducing the allocations has no visible effect on performances. On the other hand, the change of implementation for the REPL environment multiplies the performance score by 4.

@kanaka kanaka merged commit 62d1ed3 into kanaka:master Aug 1, 2025
4 checks passed
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