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

Simplifying WyIL Bytecode #502

Closed
DavePearce opened this issue Jul 8, 2015 · 3 comments
Closed

Simplifying WyIL Bytecode #502

DavePearce opened this issue Jul 8, 2015 · 3 comments

Comments

@DavePearce
Copy link
Member

The WyIL bytecode could be significantly simplified by turning a large number of operations into builtin function calls. For example, removing the add bytecode and just having a function call to the builtin + operator.

The advantage of this is that it would make the bytecode language itself much more uniform and remove lots of the strange distinctions between unary, binary and nary relations. Furthermore, type information is included which will simplify type checking, etc.

@DavePearce
Copy link
Member Author

Related to #474 and #473

@DavePearce
Copy link
Member Author

DavePearce commented Mar 27, 2016

The Plan

  1. Replace Not, BinaryOperator, UnaryOperator, LengthOf, Invert, Dereference, and possibly also IndexOf with a single Operator class. (DONE)
  2. Replace NewArray, NewRecord, NewObject with a single New bytecode. Not sure how this would work for references, but perhaps we can figure it all out based on type. (DONE)
  3. Eliminate Operator altogether in favour of Invoke with internal name space?
  4. Split If bytecode into a single bytecode which takes a boolean operand. This can then be merged with the switch bytecode.(DONE)
  5. Turn if and ifis into switch and match.

At this point, we want to start turning the bytecode into a structured form:

  1. Make If bytecode take two optional blocks. The challenge here is how to handle short circuiting.
  2. Eliminate goto bytecode and replace with break instead.
  3. Replace Return bytecode with a break bytecode instead. Return values are then specified as assignments.

Also, allowing bytecode operands to be constants will enable further simplifications:

  1. FieldLoad is no longer distinguishable from IndexOf
  2. Const is just an Assign with a constant operand.

Other refactorings:

  1. Make CodeGenerator, Interpreter and Wyil2JavaBuilder treat operators uniformly (IN PROGRESS).
  2. Put preconditions for bytecodes into the schema, rather than having them hard-coded into VcGenerator.
  3. Refactor Wyil2JavaBuilder to pass around Context variable rather than the current collection of parameters.
  4. Add Not bytecode. At the moment, this is encoded using conditional branches which is rather ugly. (DONE)

DavePearce added a commit that referenced this issue Mar 27, 2016
The Codes.Void bytecode makes heaps of sense but is completely unused at
this stage.  For simplicity it's gone for now.

The Codes.NULL_REG and related constants are no longer required and have
been removed.
DavePearce added a commit that referenced this issue Mar 28, 2016
The Codes.Void bytecode makes heaps of sense but is completely unused at
this stage.  For simplicity it's gone for now.

The Codes.NULL_REG and related constants are no longer required and have
been removed.
DavePearce added a commit that referenced this issue Mar 28, 2016
These bytecodes have been folded into the <code>Operator</code> class.
DavePearce added a commit that referenced this issue Mar 29, 2016
This bytecode was not currently used, so has been removed.  However, I
will expect it to make a come back later on.
DavePearce added a commit that referenced this issue Mar 29, 2016
Have pulled out the "operators" from the interpreter and split them into
an array of InternalFunction instances.  The idea behind this is to
reduce the amount of code in the Interpreter class.
DavePearce added a commit that referenced this issue Mar 29, 2016
This refactors the interpreter and the JVM code generator to split out
the code responsible for simple bytecodes.  This exploits the uniformity
that is beginning to be seen in the WyIL bytecode format.
DavePearce added a commit that referenced this issue Mar 29, 2016
This refactors the JVM code generator to split out
the code responsible for simple bytecodes.  This exploits the uniformity
that is beginning to be seen in the WyIL bytecode format.
DavePearce added a commit that referenced this issue Mar 29, 2016
This remoces the bytecode Codes.NewRecord and turns it into an
"Operator".  This means it can be manipulated in a more uniform fashion.
DavePearce added a commit that referenced this issue Mar 29, 2016
These bytecodes have been merged into Codes.Operator.
DavePearce added a commit that referenced this issue Mar 29, 2016
Renamed Code to Bytecode, and Code.AbstractBranchingCode to
Bytecode.Branching and Code.AbstractCompoundCode to Bytecode.Compound.
This naming is better for sure, though there's more to go.
DavePearce added a commit that referenced this issue Mar 29, 2016
This is something of an experiment.  Basically, I'm wondering how far I
can push the refactoring done so far.  In particular, can we make the
Abstract Syntax Tree more uniform in the same way that we have done for
WyIL bytecodes?  I'd guess the answer is yes, but it probably needs a
fair bit of work.  I have succeeding in doing one example only so far,
and it wasn't easy.
DavePearce added a commit that referenced this issue Mar 30, 2016
Having everything centered around the Bytecode class is not ideal, but I
think it's more consistent and looks better.  Realistically, we need a
better language to get a better effect :)
DavePearce added a commit that referenced this issue Mar 30, 2016
This refactors Bytecode.If to accept only one argument rather than two
and a comparator.  Instead the comparator is implemented as a
Bytecode.Operator.
DavePearce added a commit that referenced this issue Mar 31, 2016
This refactors Bytecode.If to accept only one argument rather than two
and a comparator.  Instead the comparator is implemented as a
Bytecode.Operator.  Perhaps surprisingly, this does offer some useful
simplifications.
DavePearce added a commit that referenced this issue Mar 31, 2016
The Codes.Void bytecode makes heaps of sense but is completely unused at
this stage.  For simplicity it's gone for now.

The Codes.NULL_REG and related constants are no longer required and have
been removed.
DavePearce added a commit that referenced this issue Mar 31, 2016
These bytecodes have been folded into the <code>Operator</code> class.
DavePearce added a commit that referenced this issue Mar 31, 2016
This bytecode was not currently used, so has been removed.  However, I
will expect it to make a come back later on.
DavePearce added a commit that referenced this issue Mar 31, 2016
Have pulled out the "operators" from the interpreter and split them into
an array of InternalFunction instances.  The idea behind this is to
reduce the amount of code in the Interpreter class.
DavePearce added a commit that referenced this issue Mar 31, 2016
This refactors the JVM code generator to split out
the code responsible for simple bytecodes.  This exploits the uniformity
that is beginning to be seen in the WyIL bytecode format.
DavePearce added a commit that referenced this issue Mar 31, 2016
This remoces the bytecode Codes.NewRecord and turns it into an
"Operator".  This means it can be manipulated in a more uniform fashion.
DavePearce added a commit that referenced this issue Mar 31, 2016
These bytecodes have been merged into Codes.Operator.
DavePearce added a commit that referenced this issue Mar 31, 2016
Renamed Code to Bytecode, and Code.AbstractBranchingCode to
Bytecode.Branching and Code.AbstractCompoundCode to Bytecode.Compound.
This naming is better for sure, though there's more to go.
DavePearce added a commit that referenced this issue Mar 31, 2016
This is something of an experiment.  Basically, I'm wondering how far I
can push the refactoring done so far.  In particular, can we make the
Abstract Syntax Tree more uniform in the same way that we have done for
WyIL bytecodes?  I'd guess the answer is yes, but it probably needs a
fair bit of work.  I have succeeding in doing one example only so far,
and it wasn't easy.
DavePearce added a commit that referenced this issue Mar 31, 2016
Having everything centered around the Bytecode class is not ideal, but I
think it's more consistent and looks better.  Realistically, we need a
better language to get a better effect :)
DavePearce added a commit that referenced this issue Mar 31, 2016
This refactors Bytecode.If to accept only one argument rather than two
and a comparator.  Instead the comparator is implemented as a
Bytecode.Operator.  Perhaps surprisingly, this does offer some useful
simplifications.
DavePearce added a commit that referenced this issue Apr 16, 2016
This removes the so-called bytecode constructors, which were static
methods that actually instantiated Bytecode objects.  Whilst these were
actually quite nice in some ways, they were just accounting for yet more
code.  Removing makes little or no difference.
DavePearce added a commit that referenced this issue Apr 16, 2016
This adds an explicit Operator kind for logical not expressions.  This
can simplify code generation in some situations.
@DavePearce
Copy link
Member Author

Done and merged into develop

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