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

Transform bytecode.yaml into bytecode.py #21

Closed
TkTech opened this issue Mar 10, 2018 · 1 comment
Closed

Transform bytecode.yaml into bytecode.py #21

TkTech opened this issue Mar 10, 2018 · 1 comment

Comments

@TkTech
Copy link
Owner

TkTech commented Mar 10, 2018

Our current process is to update bytecode.yaml, run a small transform on it to fill in some defaults and convert it to JSON (so we don't add pyyaml as a distribution dependency). At runtime this JSON file is loaded and used as the bytecode reference.

Instead, lets transform bytecode.yaml directly into python. The primary reasoning for this is to support autocomplete, help tags and type hinting for operand values. For example in our yaml file we have ->

aaload:
    op: 0x32
    desc: load onto the stack a reference from an array
    stack:
        before:
            - ArrayRef
            - Index
        after:
            - Value
    runtime:
        - NullPointerException
        - ArrayIndexOutOfBoundsException

We can turn this into ->

class aaload(Instruction):
    """load onto the stack a reference from an array"""
    __slots__ = ('op', 'mnemonic', 'stack', 'runtime', 'operands')
    op = 0x32
    mnemonic = 'aaload'
    ...

So that we can do for example...

import jawa.bytecode as I

method.code.assemble((
    I.aaload,
    I.bipush(6),
    I.return_
))
@TkTech TkTech added this to the 2.0.0 milestone Mar 10, 2018
@TkTech TkTech modified the milestones: 2.0.0, Version 3.0.0 Nov 1, 2018
TkTech added a commit that referenced this issue Feb 11, 2020
@TkTech
Copy link
Owner Author

TkTech commented Jul 31, 2021

This is part of the switch to Lawu in the develop branch, and the CLI tools include a generator to go from .yaml to .py.

@TkTech TkTech closed this as completed Jul 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant