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

bytecode: Implement addition and subtraction #274

Merged
merged 1 commit into from
Feb 16, 2024
Merged

Conversation

Rossiar
Copy link
Collaborator

@Rossiar Rossiar commented Feb 13, 2024

These simple operations for integer mathematics will
be expanded upon in the next change, which will add
the multiplication, division and modulo operations.
This change also standardises the compiler and vm test
layouts to increase their readability.

Co-authored-by: joshcarp [email protected]
Co-authored-by: pgmitche [email protected]

Copy link
Member

@juliaogris juliaogris left a comment

Choose a reason for hiding this comment

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

Looks good to me just a couple of comments, mostly food for thought.
I'll wait for @camh- if he's got anything to add again.

pkg/bytecode/code.go Show resolved Hide resolved
pkg/bytecode/vm.go Outdated Show resolved Hide resolved
pkg/bytecode/vm.go Outdated Show resolved Hide resolved
Copy link
Member

@camh- camh- left a comment

Choose a reason for hiding this comment

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

mostly comments around tests - I'm sorry I didn't get around to reviewing the tests last time, some of this I could have picked up then.

pkg/bytecode/code.go Outdated Show resolved Hide resolved
pkg/bytecode/vm_test.go Show resolved Hide resolved
pkg/bytecode/vm_test.go Show resolved Hide resolved
pkg/bytecode/vm_test.go Show resolved Hide resolved
pkg/bytecode/compiler_test.go Outdated Show resolved Hide resolved
pkg/bytecode/vm_test.go Outdated Show resolved Hide resolved
pkg/bytecode/compiler_test.go Outdated Show resolved Hide resolved
pkg/bytecode/vm.go Outdated Show resolved Hide resolved
Copy link
Collaborator Author

@Rossiar Rossiar left a comment

Choose a reason for hiding this comment

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

fixed most issues, some outstanding conversations to follow up on.

What do we think of unifying vm_test and compiler_test? The inputs and test cases are the same and vm_test runs the compiler - would this simplify or complicate things?

pkg/bytecode/code.go Outdated Show resolved Hide resolved
pkg/bytecode/vm.go Outdated Show resolved Hide resolved
pkg/bytecode/vm.go Outdated Show resolved Hide resolved
pkg/bytecode/vm_test.go Show resolved Hide resolved
pkg/bytecode/vm_test.go Outdated Show resolved Hide resolved
pkg/bytecode/vm_test.go Show resolved Hide resolved
pkg/bytecode/vm_test.go Show resolved Hide resolved
@camh-
Copy link
Member

camh- commented Feb 13, 2024

What do we think of unifying vm_test and compiler_test? The inputs and test cases are the same and vm_test runs the compiler - would this simplify or complicate things?

Agree 100%. I was going to comment on this but felt I had said enough already. I'm glad you brought it up.

This is what we've done elsewhere - more of end-to-end testing that unit testing. As you point out, the test cases are the same and they will surface the same errors. If you plan to keep the compiler and vm in the same package, this is easy since it is logically valid to have a single test that covers both. I originally had a mental model of package bytecode containing the representation of the bytecode, bytecode/compiler that generates a stream of bytecode and bytecode/vm that executes a stream of bytecode. With that split it becomes a little weird that tests in the bytecode/vm pacakge would catch errors in the compiler. I'm not sure if you're considering a structure like this at all, but I guess we'll deal with that when the time comes if the time comes.

Copy link
Collaborator Author

@Rossiar Rossiar left a comment

Choose a reason for hiding this comment

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

I have:

  • merged the tests into vm_test
  • set operand widths to nil instead of empty slice
  • refactored the vm to use panics instead of errors and added ErrInternal
  • changed the binary expression handling to avoid helper methods
  • changed numVal to be a float64 (in doing so I had to remove Set because you can't have a pointer receiver on a float64, I think this is ok because you can now just write a = numVal(12) to reset the value)

pkg/bytecode/code.go Outdated Show resolved Hide resolved
pkg/bytecode/vm_test.go Outdated Show resolved Hide resolved
pkg/bytecode/vm.go Outdated Show resolved Hide resolved
Copy link
Member

@juliaogris juliaogris left a comment

Choose a reason for hiding this comment

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

looks pretty solid to me. Just a little bit around error grouping
sentinel errors.
All of this is foundational work for the bytecode package and this back and forth will hopefully soon drop away.

pkg/bytecode/code.go Outdated Show resolved Hide resolved
pkg/bytecode/compiler.go Outdated Show resolved Hide resolved
pkg/bytecode/vm.go Outdated Show resolved Hide resolved
pkg/bytecode/compiler.go Outdated Show resolved Hide resolved
pkg/bytecode/vm.go Outdated Show resolved Hide resolved
Copy link
Member

@juliaogris juliaogris left a comment

Choose a reason for hiding this comment

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

ok, i'm happy with this - Thank You - there is only one last unresolved comment:
#274 (comment)

Copy link
Member

@juliaogris juliaogris left a comment

Choose a reason for hiding this comment

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

ok, this is all good from my end now, but maybe @camh- has still something else to add? I'll leave it up to him.
Also, if you can please squash all fix-ups.

These simple operations for integer mathematics will
be expanded upon in the next change, which will add
the multiplication, division and modulo operations.
This change also standardises the compiler and vm test
layouts to increase their readability.

Co-authored-by: joshcarp <[email protected]>
Co-authored-by: pgmitche <[email protected]>
@juliaogris juliaogris merged commit 29545f8 into main Feb 16, 2024
3 checks passed
@juliaogris juliaogris deleted the compiler-add-subtract branch February 16, 2024 23:08
Rossiar added a commit that referenced this pull request Feb 16, 2024
This change follows on from #274 by adding
compiler support for the remaining
mathematical operators in evy. The compiler
must also understand the `parser.GroupExpression`
to expand expressions inside parenthesis.

Co-authored-by: joshcarp [email protected]
Co-authored-by: pgmitche [email protected]
Rossiar added a commit that referenced this pull request Feb 17, 2024
This change follows on from #274 by adding
compiler support for the remaining
mathematical operators in evy. The compiler
must also understand the `parser.GroupExpression`
to expand expressions inside parenthesis.

Co-authored-by: joshcarp <[email protected]>
Co-authored-by: pgmitche <[email protected]>
Rossiar added a commit that referenced this pull request Feb 19, 2024
This change follows on from #274 by adding
compiler support for the remaining
mathematical operators in evy. The compiler
must also understand the `parser.GroupExpression`
to expand expressions inside parenthesis.

Co-authored-by: joshcarp <[email protected]>
Co-authored-by: pgmitche <[email protected]>
juliaogris pushed a commit that referenced this pull request Feb 19, 2024
This change follows on from #274 by adding
compiler support for the remaining
mathematical operators in evy. The compiler
must also understand the `parser.GroupExpression`
to expand expressions inside parenthesis.

Co-authored-by: joshcarp <[email protected]>
Co-authored-by: pgmitche <[email protected]>
Pull-request: #277
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants