Commit 046fa80f authored by Julian Kranz's avatar Julian Kranz

Merge branch 'master' of bitbucket.org:simona/gdsl-toolkit into experimental

parents a5701d5d 14cf1248
......@@ -817,15 +817,15 @@ structure C1 = struct
in
foldl recAdd recStripped fs
end
| emitExp s (UPDATEexp (rs,t as RECORDvtype (boxed,fsTys),fs,IDexp sym)) =
| emitExp s (UPDATEexp (rs,t as RECORDvtype (boxed,fsTys),fs,e)) =
let
fun genFieldExpr (f,ty) = case List.find (fn (fid,_) => SymbolTable.eq_symid (f,fid)) fs of
NONE => (f,SELECTexp (rs,RECORDvtype (boxed,fsTys),f,IDexp sym))
NONE => (f,SELECTexp (rs,RECORDvtype (boxed,fsTys),f,e))
| SOME (_,e) => (f,e)
in
emitExp s (RECORDexp (rs,t,List.map genFieldExpr fsTys))
end
| emitExp s (UPDATEexp (rs,_,fs,e)) = raise CodeGenBug (* we can't copy a C struct and set a field as a C expression *)
| emitExp s (UPDATEexp (rs,_,fs,e)) = raise CodeGenBug
| emitExp s (LITexp (t,VEClit pat)) =
let
fun genNum (c,acc) = IntInf.fromInt 2*acc+(if c= #"1" then 1 else 0)
......
......@@ -546,6 +546,11 @@ structure Simplify = struct
stmtsRef : stmt list ref
}
fun canDuplicate (IDexp _) = true
| canDuplicate (PRIexp (GETSTATEprim,_,[])) = true
| canDuplicate (SELECTexp (_,_,_,e)) = canDuplicate e
| canDuplicate _ = false
fun visitStmt s (ASSIGNstmt (NONE, PRIexp (GET_CON_ARGprim,_,[_,e]))) = visitStmt s (ASSIGNstmt (NONE, e))
| visitStmt s (ASSIGNstmt (res,exp)) = (case visitExp s exp of
PRIexp (RAISEprim,t,es) => ASSIGNstmt (NONE, PRIexp (RAISEprim,t,es))
......@@ -721,10 +726,11 @@ structure Simplify = struct
IDexp sym => SymbolTable.eq_symid (arg,sym)
| _ => false) (ListPair.zip (args,map #2 fs @ [recArg]))) orelse
not (List.length es=List.length args) orelse
not (canDuplicate (List.last es)) orelse
not (SymbolTable.eq_symid (res,symRes)) then NONE else
let
val tab = !SymbolTables.varTable
val (tab, symDum) = SymbolTable.fresh (tab, Atom.atom "dummy_select")
val (tab, symDum) = SymbolTable.fresh (tab, Atom.atom "dummy_update")
val _ = SymbolTables.varTable := tab
in
SOME (UPDATEexp (symDum, t, ListPair.zip (map #1 fs, es), List.last es))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment