Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vm: implement case string in bytecode #1148

Merged
merged 4 commits into from
Jan 30, 2024

Conversation

zerbina
Copy link
Collaborator

@zerbina zerbina commented Jan 30, 2024

Summary

Remove the dedicated string slice-list matching support from the VM
and replace it with an in-bytecode implementation. This gives more
control to the code generator and removes the last internal usage of
cnstString , preparing for the latter's removal.

Details

An of branch of a case matching over a string is now translated
into a sequence of LdConst + EqStr + TJmp (one per label),
replicating the behaviour previously implemented by the Branch
opcode.

While the bytecode implementation is a bit slower and also results in
slightly larger VM executables, having less high-level string operations
in the VM makes it easier to evolve.

The string slice-list matching is removed from the Branch opcode
implementation, and cnstSliceListStr together with all its usages is
removed.

Use a sequence of `EqStr` + `opcTJmp` pairs for implementing `case`
statements with a selector of type string.

This is less efficient (especially due to `LdConst` still creating a
copy) and increases code size, but it removes a user of "simple" string
constants (which are going to be removed eventually).
It's obsolete now that a manual comparison chain is used.
It's not used anywhere anymore.
@zerbina zerbina added compiler/vm Embedded virtual machine simplification Removal of the old, unused, unnecessary or un/under-specified language features. labels Jan 30, 2024
Copy link
Collaborator

@saem saem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropping the specialization saves us a bit of code, as well.

@saem
Copy link
Collaborator

saem commented Jan 30, 2024

/merge

Copy link

Merge requested by: @saem

Contents after the first section break of the PR description has been removed and preserved below:


Notes for Reviewers

@chore-runner chore-runner bot added this pull request to the merge queue Jan 30, 2024
Merged via the queue into nim-works:devel with commit 2897e4e Jan 30, 2024
19 checks passed
@zerbina zerbina deleted the vm-no-string-case-support branch February 3, 2024 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/vm Embedded virtual machine simplification Removal of the old, unused, unnecessary or un/under-specified language features.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants