Skip to content

Conversation

@breakfast-champion
Copy link

  • make ifStatement take only a single condition & body; more complex branching structures (i.e. if/else) can have their own cases
  • let evalTokensXDS return an array to simplify while loop compilation as [.location, .ifStatement]
  • parse while loops out of the instruction stack

looks like a lot of the guts (printing, instruction count, etc.) were there already from work you did before; I really just had to implement the patterns for compilation and decompilation

let me know if this looks reasonable to you

lines[last] = lines[last].replacingOccurrences(of: "\n", with: "") + " " + keyword + " {\n"

// Pulled out in converting from a loop to a single condition + block
// Can reuse the below code when more complex if/else blocks are supported
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can create a commented out ifElse case for use in future which contains the old code with the loop through each block. Then here we can clean this code up by removing the references to the loop counter since we know it will always be the 0 case for a singular if block.


// while loop
if tokens[0] == "while" {
// cheat parsing by transforming to an `if` and inserting the additional location and jump
Copy link
Collaborator

Choose a reason for hiding this comment

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

I like this a lot 👍

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.

2 participants