Skip to content

Commit

Permalink
Refactor interpreter stack code to avoid duplicate macro expansion (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota authored Aug 14, 2024
1 parent 7cee884 commit 93ac143
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/compiler/crystal/interpreter/interpreter.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1000,16 +1000,16 @@ class Crystal::Repl::Interpreter
private macro stack_pop(t)
%aligned_size = align(sizeof({{t}}))
%value = uninitialized {{t}}
(stack - %aligned_size).copy_to(pointerof(%value).as(UInt8*), sizeof({{t}}))
(stack - %aligned_size).copy_to(pointerof(%value).as(UInt8*), sizeof(typeof(%value)))
stack_shrink_by(%aligned_size)
%value
end

private macro stack_push(value)
%temp = {{value}}
stack.copy_from(pointerof(%temp).as(UInt8*), sizeof(typeof({{value}})))
%size = sizeof(typeof(%temp))

%size = sizeof(typeof({{value}}))
stack.copy_from(pointerof(%temp).as(UInt8*), %size)
%aligned_size = align(%size)
stack += %size
stack_grow_by(%aligned_size - %size)
Expand Down

0 comments on commit 93ac143

Please sign in to comment.