diff options
author | dos-reis <gdr@axiomatics.org> | 2008-02-15 04:28:18 +0000 |
---|---|---|
committer | dos-reis <gdr@axiomatics.org> | 2008-02-15 04:28:18 +0000 |
commit | 8042d68702fdeda99a7e9e240b40e580ec82a8d8 (patch) | |
tree | a21605ba0dc42deae3e42ec6d2d60e886f3499a5 /src/boot/ast.boot | |
parent | 3287ad75396e6528ddc6fb7ca722d0b1d2aa75d5 (diff) | |
download | open-axiom-8042d68702fdeda99a7e9e240b40e580ec82a8d8.tar.gz |
Add try/catch to Boot.
* boot/tokens.boot (shoeKeyWords): Add new keywords.
* boot/ast.boot (Ast): Include three new nodes.
(bfTry): New.
(bfThrow): Likewise.
* boot/parser.boot ($bodyHasReturn): Remove.
(bpNoteReturnStmt): Likewise.
(bpThrow): New.
(bpTry): Likewise.
(bpPiledCatchItems): Likewise.
(bpCatchItemList): Likewise.
(bpExceptionHead): Likewise.
(bpExceptionTail): Likewise.
(bpException): Likewise.
(bpCatchItem): Likewise.
(bpReturn): Include `throw' expressions.
(bpStatement): Include `try' expressions.
* interp/macros.lisp (|tryLine|): Rename from |try|.
* interp/pspad1.boot: Replace `try' with `tryLine' throughout.
Diffstat (limited to 'src/boot/ast.boot')
-rw-r--r-- | src/boot/ast.boot | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/boot/ast.boot b/src/boot/ast.boot index 8670dfd4..210d5b2e 100644 --- a/src/boot/ast.boot +++ b/src/boot/ast.boot @@ -109,6 +109,9 @@ structure Ast == Append(%Sequence) -- concatenate lists Case(Ast,%Sequence) -- case x of ... Return(Ast) -- return x + %Throw(Ast) -- throw OutOfRange 3 + %Catch(Ast) -- catch OutOfRange + %Try(Ast,%Sequence) -- try x / y catch DivisionByZero Where(Ast,%Sequence) -- e where f x == y Structure(Ast,%Sequence) -- structure Foo == ... @@ -1138,3 +1141,19 @@ bfDs: %Short -> %String bfDs n== if n=0 then '"" else CONCAT('"D",bfDs(n-1)) + +++ Generate code for try-catch expressions. +bfTry: (%Thing,%List) -> %Thing +bfTry(e,cs) == + null cs => e + case first cs of + %Catch(tag) => + atom tag => bfTry(["CATCH",["QUOTE",tag],e],rest cs) + bpTrap() -- sorry + otherwise => bpTrap() + +++ Generate code for `throw'-expressions +bfThrow e == + atom e => ["THROW",["QUOTE",e],nil] + not atom first e => bpTrap() + ["THROW",["QUOTE",first e],:rest e] |