From 0f5a6ae8052fc15ad92934fae869e9da51f03bb9 Mon Sep 17 00:00:00 2001 From: Adam Sampson Date: Mon, 2 Oct 2006 22:32:14 +0000 Subject: [PATCH] Represent formals with a list of names declared in Tree --- fco/Parse.hs | 14 +++++++------- fco/PhaseIntermediate.hs | 11 ----------- fco/SExpression.hs | 4 ++-- fco/Tree.hs | 4 ++-- 4 files changed, 11 insertions(+), 22 deletions(-) diff --git a/fco/Parse.hs b/fco/Parse.hs index fdd2ca7..af2cabc 100644 --- a/fco/Parse.hs +++ b/fco/Parse.hs @@ -417,8 +417,8 @@ fieldName = name "fieldName" --- This is rather different from the grammar. --- FIXME should this lot actually be done in a pass? probably... +-- This is rather different from the grammar, since I had some difficulty +-- getting Parsec to parse it as a list of lists of arguments. formalList = do { sLeftR ; fs <- sepBy formalArg sComma ; sRightR ; return $ markTypes fs } "formalList" @@ -431,12 +431,12 @@ formalList markTypes :: [(Maybe N.Node, N.Node)] -> [N.Node] markTypes [] = [] markTypes ((Nothing, _):_) = error "Formal list must start with a type" - markTypes ((Just ft,fn):is) = (N.Formal ft fn) : markRest ft is + markTypes ((Just ft, fn):is) = markRest ft [fn] is - markRest :: N.Node -> [(Maybe N.Node, N.Node)] -> [N.Node] - markRest _ [] = [] - markRest t ((Nothing, n):is) = (N.Formal t n) : markRest t is - markRest _ ((Just t, n):is) = (N.Formal t n) : markRest t is + markRest :: N.Node -> [N.Node] -> [(Maybe N.Node, N.Node)] -> [N.Node] + markRest lt ns [] = [N.Formals lt ns] + markRest lt ns ((Nothing, n):is) = markRest lt (ns ++ [n]) is + markRest lt ns ((Just t, n):is) = (markRest lt ns []) ++ (markRest t [n] is) functionHeader = do { sFUNCTION ; n <- name ; fs <- formalList ; return $ (n, fs) } diff --git a/fco/PhaseIntermediate.hs b/fco/PhaseIntermediate.hs index 208099f..3b24357 100644 --- a/fco/PhaseIntermediate.hs +++ b/fco/PhaseIntermediate.hs @@ -23,17 +23,6 @@ nestDecls l n = foldl (\a b -> b a) n [N.IntDecl n d | (N.Name n, d) <- l] markDecls :: Transform () markDecls next top node = case node of - N.Decl (N.Proc nn@(N.Name n) args code) body -> do - body' <- top body - code' <- top code - let pdecl = nestDecls [(n, d) | d@(N.Formal _ n) <- args] (N.Proc nn args code') - return $ N.IntDecl n pdecl body' - N.Decl (N.Func nn@(N.Name n) args rets code) body -> do - error "blah" - body' <- top body - code' <- top code - let pdecl = nestDecls [(n, d) | d@(N.Formal _ n) <- args] (N.Func nn args rets code') - return $ N.IntDecl n pdecl body' -- FIXME same for functions N.Decl d body -> do body' <- top body diff --git a/fco/SExpression.hs b/fco/SExpression.hs index 0965b1b..a57817b 100644 --- a/fco/SExpression.hs +++ b/fco/SExpression.hs @@ -89,7 +89,7 @@ nodeToSExp node N.Protocol a b -> wrapl1 "protocol" (top a) (map top b) N.TaggedProtocol a b -> wrapl1 "protocol-tagged" (top a) (map top b) N.Tag a b -> wrapl1 "tag" (top a) (map top b) - N.Formal a b -> wrap2 "formal" (top a) (top b) + N.Formals a b -> wrapl1 "formal" (top a) (map top b) N.Proc a b c -> wrap3 "proc" (top a) (List $ map top b) (top c) N.Func a b c d -> wrap4 "function" (top a) (List $ map top b) (List $ map top c) (top d) N.FuncIs a b c d -> wrap4 "function-is" (top a) (List $ map top b) (List $ map top c) (top d) @@ -201,7 +201,7 @@ nodeToSOccam node N.Protocol a b -> wrapl1 "protocol" (top a) (map top b) N.TaggedProtocol a b -> wrapl1 "protocol" (top a) (map top b) N.Tag a b -> List ((top a) : (map top b)) - N.Formal a b -> l2 (top a) (top b) + N.Formals a b -> List ((top a) : (map top b)) N.Proc a b c -> wrap3 "proc" (top a) (List $ map top b) (top c) N.Func a b c d -> wrap4 "function" (top a) (List $ map top b) (List $ map top c) (top d) N.FuncIs a b c d -> wrap4 "function-is" (top a) (List $ map top b) (List $ map top c) (top d) diff --git a/fco/Tree.hs b/fco/Tree.hs index 7d553d1..a76011c 100644 --- a/fco/Tree.hs +++ b/fco/Tree.hs @@ -55,8 +55,8 @@ data Node = | Protocol Node [Node] | TaggedProtocol Node [Node] | Tag Node [Node] --- e.g. Proc (Name "out.string") [Formal Int (Name "x"), Formal Bool (Name "y")] - | Formal Node Node +-- e.g. Proc (Name "out.string") [Formals Int [Name "x", Name "y"], Formal Bool [Name "z"]] + | Formals Node [Node] | Proc Node [Node] Node | Func Node [Node] [Node] Node | FuncIs Node [Node] [Node] Node