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

Optimize binary expressions #5

Open
Nickforall opened this issue Feb 24, 2018 · 1 comment
Open

Optimize binary expressions #5

Nickforall opened this issue Feb 24, 2018 · 1 comment
Labels
Compiler Optimization This issue or pull request is about optimizing the output of the compiler. enhancement New feature or request

Comments

@Nickforall
Copy link
Owner

So, we have this AST, representing 100 + 200 + 300.

{
	"type": "binary",
	"operator": "+",
	"left": {
		"type": "binary",
		"operator": "+",
		"left": {
			"type": "numberLiteral",
			"value": 100
		},
		"right": {
			"type": "numberLiteral",
			"value": 200
		}
	},
	"right": {
		"type": "numberLiteral",
		"value": 300
	}
}

In the end they are all number literals, so we can just optimize this to the expression below, because at compiletime we know these numbers will never change, they are constant.

{
	"type": "numberLiteral",
	"value": 600
}
@Nickforall Nickforall added enhancement New feature or request Compiler Optimization This issue or pull request is about optimizing the output of the compiler. labels Feb 24, 2018
@Nickforall
Copy link
Owner Author

Nickforall commented Feb 24, 2018

oh, we could also optimize this, but that looks really hard

fn some_function {
	test = 40
	yo = 1000
	hello = 10

	print yo * test + hello
}

I'll probably make a different issue sometime

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Compiler Optimization This issue or pull request is about optimizing the output of the compiler. enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant