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

Fix wrong register when superclass is a member #388

Merged
merged 1 commit into from
Jan 23, 2024

Conversation

s-hadinger
Copy link
Contributor

Fix a compilation bug when the superclass is a member, the code containing the static initialization code does not contain anymore the class in R0. This fix removes an optimization that would assume that R0 has the class, and forces reading the class again into R0.

# the following would fail

> class B end m = module('m') m.B = B
> class A : m.B static aa = 1 end
attribute_error: class 'B' cannot assign to static attribute 'aa'
stack traceback:
	stdin:1: in function `main`

Showing the problem:

> class B end m = module('m') m.B = B
> f = compile("class A : m.B static aa = 1 end") import debug debug.codedump(f)
source 'string', function 'main':
; line 1
  0000  LDCONST	R0	K1
  0001  SETNGBL	R0	K0
  0002  CLASS	K1
  0003  GETNGBL	R0	K2
  0004  GETNGBL	R1	K0
  0005  GETMBR	R0	R0	K3     <- R0 contains `m.B`
  0006  SETSUPER	R1	R0
  0007  SETMBR	R0	K4	K5     <- R0 does not contain `A`
  0008  RET	0

After the fix:

> class B end m = module('m') m.B = B
> f = compile("class A : m.B static aa = 1 end") import debug debug.codedump(f)
source 'string', function 'main':
; line 1
  0000  LDCONST	R0	K1
  0001  SETNGBL	R0	K0
  0002  CLASS	K1
  0003  GETNGBL	R0	K2
  0004  GETNGBL	R1	K0
  0005  GETMBR	R0	R0	K3
  0006  SETSUPER	R1	R0
  0007  GETNGBL	R0	K0             <- force loading class in R0
  0008  SETMBR	R0	K4	K5
  0009  RET	0

@skiars skiars merged commit 3d8aee8 into berry-lang:master Jan 23, 2024
@skiars skiars added the bug Something isn't working label Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants