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

Parser v2? #2

Open
Kroc opened this issue Feb 22, 2024 · 5 comments
Open

Parser v2? #2

Kroc opened this issue Feb 22, 2024 · 5 comments
Labels
enhancement New feature or request
Milestone

Comments

@Kroc
Copy link
Owner

Kroc commented Feb 22, 2024

It has occurred to me that another method of parsing would be to use a straight jump table from ASCII code to routine.
Since the order of tokens would no longer be enforced by code order (i.e. a value must follow a unary operator), there would instead be a "mode" variable that would describe the context for each routine arrived at. For example, if an operator is encountered but the mode says we're not in an expression, then we throw an error.

There are a number of cons:

  • The parsing flow is much harder to follow
  • One token is not connected to another by code flow meaning that register pressure may increase
  • A mode value needs to be persisted and this may be difficult to pin to a register (as above)
  • the ASCII jump table will take ~192-256 bytes

However there are some pros:

  • Less code is required to express parsing; may actually save bytes
  • Less code also means less code to port for other architectures, such as porting v80 to 6502 (v65?)
  • Less coupling of routines, easier to make improvements without knock-on effects
@Kroc Kroc added the enhancement New feature or request label Feb 22, 2024
@Kroc Kroc mentioned this issue Jun 8, 2024
7 tasks
@Kroc
Copy link
Owner Author

Kroc commented Jun 8, 2024

Had an idea: Writing to the code-segment could be done via a routine that has the current code-segment address in the LD instruction, avoiding having it pinned to IY if we have another need for it? This adds a call for writing to the code-segment, but most calls will be eliminated with the move to a char jump-table. This would depend upon IX/IY being better used for something else that requires the offset capability (heap records?)

@Kroc
Copy link
Owner Author

Kroc commented Jun 13, 2024

I would like to have a fast path for numbers that avoids the full expression parser, but we can't know if a number is alone or part of an expression ahead of time as we must look for the operator that follows.

There are two approaches to this we could follow:

  1. Read the value and if an operator follows, start the expression with the initial value provided beforehand
  2. Require all expressions using operators to use parenthesis, i.e. ($1+ $2) so that the presence of an operator may be known beforehand

@Kroc Kroc mentioned this issue Jul 1, 2024
2 tasks
@Kroc Kroc added this to the v2.x milestone Jul 2, 2024
@Kroc
Copy link
Owner Author

Kroc commented Jul 12, 2024

The nightmare of eZ80's (#12) prefix splurge means looking at a potential replacement instruction parser. When I began writing the instruction parser one idea I toyed with was a prefix-based list where the first byte/nybble specifies how many chars are shared with the previous entry, and the instructions are all listed alphabetically, dictionary like. I couldn't be sure it would save enough space, so I went with the tree but I need to make a working version of the list to see if it would help with eZ80 encoding.

@Kroc
Copy link
Owner Author

Kroc commented Sep 13, 2024

After a couple of months, the results are in:

- #size_of_opcodes      $0F35 (ISA1)
                        $0FAA (ISA2)
- #size_of_parseISA     $0050
- #size_of_parseISA2    $0084

Cycles:
- v1:   139,215,546
- v2:   109,007,184

The new instruction parser is marginally larger (there's still room for optimisation) but, save for yet-unseen bugs, is also faster! I didn't expect this, but I'll take the win after all that work; this will make adding new ISAs much easier on everybody

@Kroc
Copy link
Owner Author

Kroc commented Sep 30, 2024

ISA parser v2 has been merged greatly simplifying the way ISAs are written.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant