# HG changeset patch # User Mike Pavone # Date 1280611043 14400 # Node ID bcdc326b3d6e93de9227a53839d57ced8510575b # Parent c25d75c2440b1343756d315e0cf7417c7feb6244 Added basic support for list literals in compiler. Updated todo list. diff -r c25d75c2440b -r bcdc326b3d6e cbackend.rhope --- a/cbackend.rhope Sat Jul 31 15:08:15 2010 -0400 +++ b/cbackend.rhope Sat Jul 31 17:17:23 2010 -0400 @@ -1252,7 +1252,7 @@ _Set Consts C Program[text,value,name,type reg:out] { valtype <- Type Of[value] - [("String","Worker Literal")]Find[valtype] + [("String","Worker Literal","List")]Find[valtype] { out <- text }{ @@ -1261,19 +1261,37 @@ } } +_Set List Els[text,el,index,type reg:out] +{ + out <- [[text]Append[ + [["\tinout[1] = " + ]Append[Const Construct C[index,type reg]] + ]Append[ + [[";\n\tinout[2] = " + ]Append[Const Construct C[el, type reg]] + ]Append[";\n"] + ]]]Append["\trhope(FUNC_Set, inout, 3, 3);\n"] +} + _Set Late Consts C[text,value,name,type reg:out] { valtype <- Type Of[value] - [("String","Worker Literal")]Find[valtype] + [("String","Worker Literal","List")]Find[valtype] { - Const Construct C[value,type reg] - { init <- [text]Append[ [[[["\t_const_"]Append[Escape Rhope Name[name]]]Append[" = "]]Append[~]]Append[";\n"] ] } + If[[valtype]=["List"]] + { + out <- [Fold[["_Set List Els"]Set Input[3, type reg], "\trhope(FUNC_List, inout, 0, 1);\n", value] + ]Append[[["\t_const_"]Append[Escape Rhope Name[name]]]Append[" = inout[0];\n"]] + }{ + Const Construct C[value,type reg] + { init <- [text]Append[ [[[["\t_const_"]Append[Escape Rhope Name[name]]]Append[" = "]]Append[~]]Append[";\n"] ] } - If[[valtype]=["Worker Literal"]] - { - out <- Fold[[["_Set Worker Params C"]Set Input[3, type reg]]Set Input[4, Escape Rhope Name[name]], init, [value]Args >>] - }{ - out <- Val[init] + If[[valtype]=["Worker Literal"]] + { + out <- Fold[[["_Set Worker Params C"]Set Input[3, type reg]]Set Input[4, Escape Rhope Name[name]], init, [value]Args >>] + }{ + out <- Val[init] + } } }{ out <- text @@ -1442,7 +1460,7 @@ DispatchVar FuncDef(Build) FuncDef(BlueprintSP_Of) - FuncDef(ID) + FuncDef(ID) FuncDef(BlueprintSP_FromSP_ID)\n"] ]Append[Fold["Local Pointers", "", [program]Functions >>]] ]Append[" @@ -1533,7 +1551,7 @@ blueprint * bp; int numret; int idx; - object * inout[2]; + object * inout[3]; register_builtin_types();\n\n"] ]Append[ [[program]Type Registry >>]Type Inits[[program]Method Registry >>, [program]Field Registry >>] ] ]Append[Fold[["_Set Consts C Program"]Set Input[3, [program]Type Registry >>], "", constants]] diff -r c25d75c2440b -r bcdc326b3d6e nworker.rhope --- a/nworker.rhope Sat Jul 31 15:08:15 2010 -0400 +++ b/nworker.rhope Sat Jul 31 17:17:23 2010 -0400 @@ -632,6 +632,46 @@ out <- [worker]_Dependency Groups[no deps, no deps, [()]Append[no deps]] } +Const Name[val,node index,worker name:out] +{ + If[[Type Of[val]] = ["Type Instance"]] + { + //TODO: Support parametric types + datstring <- [val]Name >> + }{ + If[[Type Of[val]] = ["Machine Integer"]] + { + If[[val]Signed? >>] + { s <- "i" } + { s <- "u" } + datstring <- [[[val]Value >>]Append[s]]Append[[val]Size >>] + }{ + If[[Type Of[val]] = ["Worker Literal"]] + { + If[[[[val]Args >>]Length] > [0]] + { + datstring <- [[["Arg "]Append[node index]]Append[" "]]Append[worker name] + }{ + datstring <- [val]Name >> + } + }{ + If[[Type Of[val]] = ["List"]] + { + If[[[val]Length] > [0]] + { + datstring <- [[["Arg "]Append[node index]]Append[" "]]Append[worker name] + }{ + datstring <- "Empty" + } + }{ + datstring <- val + } + } + } + } + out <- [[Type Of[val]]Append["_"]]Append[datstring] +} + Format Input@NWorker[worker,noderef:out] { node <- [[worker]Nodes >>]Index[[noderef]Index >>] @@ -658,32 +698,7 @@ { out <- AddRef[ [[["__result_"]Append[[noderef]Index >>]]Append["_"]]Append[[noderef]IO Num >>] ] }{ - If[[Type Of[[node]Data >>]] = ["Type Instance"]] - { - //TODO: Support parametric types - datstring <- [[node]Data >>]Name >> - }{ - If[[Type Of[[node]Data >>]] = ["Machine Integer"]] - { - If[[[node]Data >>]Signed? >>] - { s <- "i" } - { s <- "u" } - datstring <- [[[[node]Data >>]Value >>]Append[s]]Append[[[node]Data >>]Size >>] - }{ - If[[Type Of[[node]Data >>]] = ["Worker Literal"]] - { - If[[[[[node]Data >>]Args >>]Length] > [0]] - { - datstring <- [[["Arg "]Append[[noderef]Index >>]]Append[" "]]Append[[worker]Name >>] - }{ - datstring <- [[node]Data >>]Name >> - } - }{ - datstring <- [node]Data >> - } - } - } - out <- Constant[[[Type Of[[node]Data >>]]Append["_"]]Append[datstring]] + out <- Constant[Const Name[[node]Data >>, [noderef]Index >>, [worker]Name >>]] } } } @@ -837,33 +852,7 @@ }{ If[[[node]Type >>] = ["const"]] { - //TODO: Handle list constants - If[[Type Of[[node]Data >>]] = ["Type Instance"]] - { - //TODO: Support parametric types - datstring <- [[node]Data >>]Name >> - }{ - If[[Type Of[[node]Data >>]] = ["Machine Integer"]] - { - If[[[node]Data >>]Signed? >>] - { s <- "i" } - { s <- "u" } - datstring <- [[[[node]Data >>]Value >>]Append[s]]Append[[[node]Data >>]Size >>] - }{ - If[[Type Of[[node]Data >>]] = ["Worker Literal"]] - { - If[[[[[node]Data >>]Args >>]Length] > [0]] - { - datstring <- [[["Arg "]Append[node index]]Append[" "]]Append[[worker]Name >>] - }{ - datstring <- [[node]Data >>]Name >> - } - }{ - datstring <- [node]Data >> - } - } - } - constname <- [[Type Of[[node]Data >>]]Append["_"]]Append[datstring] + constname <- Const Name[[node]Data >>, node index, [worker]Name >>] withconst <- [func]Register Constant[constname, [node]Data >>] [conditions]For Backend { diff -r c25d75c2440b -r bcdc326b3d6e testlistliteral.rhope --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/testlistliteral.rhope Sat Jul 31 17:17:23 2010 -0400 @@ -0,0 +1,5 @@ + +Main[] +{ + Print[Fold[+[?], 0, (5,27,39,43)]] +} diff -r c25d75c2440b -r bcdc326b3d6e todo.txt --- a/todo.txt Sat Jul 31 15:08:15 2010 -0400 +++ b/todo.txt Sat Jul 31 17:17:23 2010 -0400 @@ -4,8 +4,6 @@ Fix Array and Worker memory leaks Needed for compiler to be self-hosting: - Add support for List literals in compiler - Implement iteration support in Dictionary Tweak extendlib to work with language changes introduced with compiler Tweak compiler to work with language changes introduced with compiler