Skip to content

Added else child to the if statement.#400

Closed
Teemperor wants to merge 2 commits intoWebAssembly:masterfrom
Teemperor:patch-2
Closed

Added else child to the if statement.#400
Teemperor wants to merge 2 commits intoWebAssembly:masterfrom
Teemperor:patch-2

Conversation

@Teemperor
Copy link
Member

Without an else branch we would need a temp local for writing normal if/else statements. If someone just wants an normal if statement he/she can just use a empty block as an else.

Other suggestion if changing if is not up to debate: Add an ifelse and keep if the way it is.

Without an else branch we would need a temp local for writing normal if/else statements. If someone just wants an normal if statement he/she can just use a empty block as an else.

Other suggestion if changing `if` is not up to debate: Add an `ifelse` and keep `if` the way it is.
@kg
Copy link
Contributor

kg commented Oct 12, 2015

This is already the case for ml-proto, so lgtm.

@rossberg
Copy link
Member

Actually, ml-proto allows else-less if (and treats it as else nop).

AstSemantics.md Outdated
Copy link
Member

Choose a reason for hiding this comment

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

Children?

@Teemperor
Copy link
Member Author

Thanks JF, fixed the spelling!

@jfbastien
Copy link
Member

Is this mandating that both be present? Or is "else" optional?
Or should we have "ifelse" and "ifthenelse"?
@sunfishcode?

@Teemperor
Copy link
Member Author

IMHO: The problem with an optional else branch is that it's weird to encode in the binary format (in a sexpr it is no problem obviously). An ifthen and ifthenelse could be shorter in binary (even though I have no idea about the planned compression which has a big influence on that).

@rossberg
Copy link
Member

I'm not sure I understand the issue. This seems to be a concern about the binary format, not the AST semantics itself.

@Teemperor
Copy link
Member Author

The current AST encoding is to my knowledge something like opcode {opcode data} {child-node} and ifthen/ifthenelse would save us many nop child nodes in the else child.

So instead of if-opcode condition then-node **nop** for a simple if, one could use ifthen-opcode condition then-node and save the byte for the nop opcode.

I know the discussion is not about the binary format, but the preliminary format would suffer from that issue (and I assume it will not change that much).

@kg
Copy link
Contributor

kg commented Oct 13, 2015

(if (...) (nop)) and (if (nop) (...)) aren't especially difficult to encode, will stream compress okay, and shouldn't amount to that much of an executable's size. It's not really worth worrying about it at this stage, I think. We can introduce specialized if opcodes later.

Or we could introduce them now as syntax sugar, I guess, and reserve the right to turn them into actual opcodes if we need to.

@lukewagner
Copy link
Member

lgtm to land as is and we can refine layer as we get serious about the binary encoding.

@sunfishcode
Copy link
Member

With #427 merged, there are now separate if and if_else operators.

@Teemperor Teemperor deleted the patch-2 branch October 30, 2015 15:59
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.

6 participants