From ef52cc20d09fe98e78827d5c1894dc76464fc111 Mon Sep 17 00:00:00 2001 From: Ian Grant Jeffries Date: Mon, 4 Nov 2019 12:53:17 -0500 Subject: [PATCH] Replace Panic js constructor with Throw --- bowtie-js/src/Bowtie/JS/AST.hs | 8 ++------ bowtie-js/src/Bowtie/JS/Imperativize.hs | 8 ++++---- bowtie-js/src/Bowtie/JS/Serialize.hs | 14 ++------------ 3 files changed, 8 insertions(+), 22 deletions(-) diff --git a/bowtie-js/src/Bowtie/JS/AST.hs b/bowtie-js/src/Bowtie/JS/AST.hs index a327c8b..f20e1fc 100644 --- a/bowtie-js/src/Bowtie/JS/AST.hs +++ b/bowtie-js/src/Bowtie/JS/AST.hs @@ -16,19 +16,15 @@ data AST | IndexArray AST Natural | IfThen AST AST | Else AST - | Throw Text + | Throw AST -- Will only be used with JSString | Equal AST AST | LambdaUnit AST -- ^ @(() => { " <> ast <> "})()@ | JSInt Integer | JSString Text - | JSOp Operation - deriving (Eq, Show) -data Operation - = Compare AST AST + | Compare AST AST | Plus AST AST -- ^ Only works on Ints | Multiply AST AST -- ^ Only works on Ints | ShowInt AST -- ^ Only works on Int - | Panic AST -- ^ Only works on Text deriving (Eq, Show) diff --git a/bowtie-js/src/Bowtie/JS/Imperativize.hs b/bowtie-js/src/Bowtie/JS/Imperativize.hs index a691c1b..a9a3893 100644 --- a/bowtie-js/src/Bowtie/JS/Imperativize.hs +++ b/bowtie-js/src/Bowtie/JS/Imperativize.hs @@ -80,16 +80,16 @@ coreToImp topExpr = (Block ( Assignment (Var (Id "$1")) (coreToImp expr) : fmap altToImp alts - <> [Else (Throw "no match")] + <> [Else (Throw (JSString "no match"))] )) Core.PrimInt n -> JSInt n Core.PrimOp op -> - JSOp (coreOperationToImp op) + coreOperationToImp op -coreOperationToImp :: Core.Operation -> JS.Operation +coreOperationToImp :: Core.Operation -> JS.AST coreOperationToImp op = case op of Core.Compare e1 e2 -> @@ -105,7 +105,7 @@ coreOperationToImp op = ShowInt (coreToImp expr) Core.Panic expr -> - Panic (coreToImp expr) + LambdaUnit (Throw (coreToImp expr)) -- eg ["Maybe", 5], not [Maybe, 5] conToString :: Id -> JS.AST diff --git a/bowtie-js/src/Bowtie/JS/Serialize.hs b/bowtie-js/src/Bowtie/JS/Serialize.hs index b76ae96..2bff2a8 100644 --- a/bowtie-js/src/Bowtie/JS/Serialize.hs +++ b/bowtie-js/src/Bowtie/JS/Serialize.hs @@ -1,7 +1,6 @@ module Bowtie.JS.Serialize ( serializeTop , serialize - , serializeOperation ) where import Bowtie.JS.AST @@ -51,8 +50,8 @@ serialize topAst = Else ast -> " else { " <> serialize ast <> " }" - Throw t -> - "throw \"" <> t <> "\"" + Throw ast -> + "throw " <> serialize ast Equal a1 a2 -> serialize a1 <> " === " <> serialize a2 @@ -66,12 +65,6 @@ serialize topAst = JSString t -> "\"" <> t <> "\"" - JSOp op -> - serializeOperation op - -serializeOperation :: Operation -> Text -serializeOperation op = - case op of Compare ast1 ast2 -> "$compareBuiltin(" <> serialize ast1 <> ", " <> serialize ast2 <> ")" @@ -84,9 +77,6 @@ serializeOperation op = ShowInt ast -> "$unicodeListizeBuiltin(" <> serialize ast <> ".toString())" - Panic expr -> -- Will only be used with Text - "(() => { throw " <> serialize expr <> "})()" - serializeId :: Id -> Text serializeId (Id t) = "_" <> t