Skip to content

Commit

Permalink
Match update to grammar for break/continue/return
Browse files Browse the repository at this point in the history
  • Loading branch information
rrthomas committed Nov 28, 2023
1 parent a08b4f6 commit 9bbe1a3
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,6 @@ semantics.addOperation<AST>('toAST(env,lval,inLoop,inFn)', {
return addLoc(compiledSeq, this)
},

PrimaryExp_continue(_continue) {
if (!this.args.inLoop) {
throw new UrsaCompilerError(_continue.source, 'continue used outside a loop')
}
return addLoc(new ArkCall(new ArkLiteral(intrinsics.get('continue')!), []), this)
},
PrimaryExp_ident(_sym) {
const symref = this.symref(this.args.env).value
return addLoc(this.args.lval ? symref : new ArkGet(symref), this)
Expand Down Expand Up @@ -361,24 +355,6 @@ semantics.addOperation<AST>('toAST(env,lval,inLoop,inFn)', {
return new ArkLet(['_for'], letBody)
},

UnaryExp_break(_break, exp) {
if (!this.args.inLoop) {
throw new UrsaCompilerError(_break.source, 'break used outside a loop')
}
return addLoc(new ArkCall(
new ArkLiteral(intrinsics.get('break')!),
[maybeVal(this.args.env, exp, this.args.inFn)],
), this)
},
UnaryExp_return(_return, exp) {
if (!this.args.inFn) {
throw new UrsaCompilerError(_return.source, 'return used outside a function')
}
return addLoc(new ArkCall(
new ArkLiteral(intrinsics.get('return')!),
[maybeVal(this.args.env, exp, this.args.inFn)],
), this)
},
UnaryExp_not(_not, exp) {
return addLoc(new ArkCall(
new ArkLiteral(intrinsics.get('not')!),
Expand Down Expand Up @@ -603,6 +579,31 @@ semantics.addOperation<AST>('toAST(env,lval,inLoop,inFn)', {
return addLoc(compiled, this)
},

Exp_break(_break, exp) {
if (!this.args.inLoop) {
throw new UrsaCompilerError(_break.source, 'break used outside a loop')
}
return addLoc(new ArkCall(
new ArkLiteral(intrinsics.get('break')!),
[maybeVal(this.args.env, exp, this.args.inFn)],
), this)
},
Exp_continue(_continue) {
if (!this.args.inLoop) {
throw new UrsaCompilerError(_continue.source, 'continue used outside a loop')
}
return addLoc(new ArkCall(new ArkLiteral(intrinsics.get('continue')!), []), this)
},
Exp_return(_return, exp) {
if (!this.args.inFn) {
throw new UrsaCompilerError(_return.source, 'return used outside a function')
}
return addLoc(new ArkCall(
new ArkLiteral(intrinsics.get('return')!),
[maybeVal(this.args.env, exp, this.args.inFn)],
), this)
},

Lets(lets) {
const parsedLets = []
const letIds: string[] = []
Expand Down

0 comments on commit 9bbe1a3

Please sign in to comment.