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

A bug that might occur if base_decimal or base_hexadecimal are put inside an if-branching #34

Open
FlatAssembler opened this issue Feb 2, 2025 · 1 comment

Comments

@FlatAssembler
Copy link
Owner

This program (you can see it live here):

address 0
if 2+2=4
	base_decimal
endif
constant ten, 10
inst ten
inst 10

assembles into:

0000a
00010

I'd expect it to assemble into:

0000a
0000a

It has to do with the fact that the assembler doesn't look into if-branchings, it simply jumps over them while assembling, because mnemonics must not be put inside the if-branchings. Given the way the assembler is structured, there doesn't seem to be a simple solution.

@FlatAssembler
Copy link
Owner Author

FlatAssembler commented Feb 2, 2025

An obvious solution might be to make the assembler, when it encounters an if-statement, check whether the condition of the if-statement is true, and then, if it's true, invoke the preprocessor again with the if's second child (the body) as an argument. Putting something like this in assembler.js:

if (/^if$/i.test(node_of_depth_1.text) || /^while$/i.test(node_of_depth_1.text))
	if (node_of_depth_1.children[0].interpretAsArithmeticExpression(output_of_preprocessor.constants))
		makeCompilationContext(node_of_depth_1.children[1]); //Notice that we are not modifying the output_of_preprocessor

However, that would just replace this problem with another problem. Consider this code:

address 0
constant i, 1
if i>1
	base_decimal
endif
constant i, 2
inst 10

The problem here is that when the preprocessor sees if i>1, the i>1 will evaluate to false. But when the assembler sees that, it will evaluate to true.
So, once again, there is no obvious solution given the way the assembler is structured.

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

No branches or pull requests

1 participant