-
Notifications
You must be signed in to change notification settings - Fork 230
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
Miscellaneous fixes #294
Miscellaneous fixes #294
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bunch of good stuff here! I have one thought about the builder library utility… let me know what you think.
bril-ts/builder.ts
Outdated
* Checks whether the last emitted instruction in the current function is the specified op code. | ||
* Useful for checking for terminating instructions. | ||
*/ | ||
isLastEmittedEffectOp(op: bril.EffectOpCode): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like useful behavior! But the name is a little odd, in two ways:
Emitted
: Maybe it would be a little more straightforward to just say it's the last op currently in the function? It seems less material that it's the last thing we emitted.Effect
: I think this would look for both effect and value ops, right?
Another alternative, FWIW, would be to just get the last (non-label) instruction. So the return type would be bril.Instruction?
, and callers could get this behavior by doing stuff like lastInstr()?.op === "add"
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, works for me.
I'll just note that I don't think the the ?
sugar works on return types? microsoft/TypeScript#51332 Maybe I missed something obvious.
Instead I'm using bril.Instruction | undefined
which the rest of the code base seems to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops; you're absolutely right. I forgot that T?
was a special argument thing rather than an actual type.
// Number accepts empty/whitespace only strings and rejects numbers with seperators | ||
// Use both and only accept the intersection of the results? | ||
let f2 = Number(s); | ||
if (!isNaN(f) && f === f2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weird but true! It'll do.
ts2bril.ts
Outdated
@@ -215,12 +215,18 @@ function emitBril(prog: ts.Node, checker: ts.TypeChecker): bril.Program { | |||
// Statement chunks. | |||
builder.buildLabel(thenLab); | |||
emit(if_.thenStatement); | |||
builder.buildEffect("jmp", [], undefined, [endLab]); | |||
const then_branch_terminated = builder.isLastEmittedEffectOp("ret"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A little tricky, but makes sense!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks perfect; thanks!!
bril2json
positions for the first rowbrili
to be a little more strict on the cli input it expects (related to mod_inv)ts2bril
tool to not unconditionally output the final endif label and corresponding jump when it isn't needed(related to bitshift and fact)--check
The typescript stuff could use a double check, I'm not super familiar with this language. I also don't use
ts2bril
to know all of the edge cases.