# HG changeset patch # User Mike Pavone # Date 1301895679 14400 # Node ID 690ed78ead8a840f8dd9ac4b18ce479415d03aaa # Parent 1bfc19076f1bfb54e5ff68cfdf033d709c47f50c Some type inference fixes and make method calls into regular calls when first arg type is known at compile time diff -r 1bfc19076f1b -r 690ed78ead8a nworker_c.rhope --- a/nworker_c.rhope Thu Mar 10 04:16:38 2011 +0000 +++ b/nworker_c.rhope Mon Apr 04 01:41:19 2011 -0400 @@ -223,12 +223,13 @@ _Has Input Types@NWorker Node[node,input num:does,does not] { - does <- If[[input num] > [[node]Inputs >>]] {} + does <- If[[input num] >= [[node]Inputs >>]] {} { ,does not <- [[node]Input Types >>]Index[input num] { + Print[[[[[["Input: "]Append[String[input num]]]Append[", count: "]]Append[String[count]]]Append[", wires: "]]Append[String[[[[node]Wires To >>]Index[ [input num]+[1] ]]Length]]] count <- [~]Index[1] - ,does not <- If[[count] = [[[[node]Wires To >>]Index[input num]]Length]] + ,does not <- If[[count] = [[[[node]Wires To >>]Index[[input num]+[1]]]Length]] { does,does not <- [node]_Has Input Types[[input num]+[1]] } @@ -241,6 +242,8 @@ If[[[node]Inputs >>] > [0]] { does,does not <- _Has Input Types[node,0] + { Print["does have input types"] } + { Print["does not have input types"] } }{ does <- Yes } @@ -323,53 +326,76 @@ Propagate Type[nodelist,dest,prog,worker,type:out] { - node <- [nodelist]Index[[dest]Index >>] - - [[node]Input Types >>]Index[[dest]IO Num >>] + If[[[dest]IO Num >>] >= [0]] { - existing type <- [~]Index[0] - new count <- [[~]Index[1]]+[1] - If[[[existing type]Name >>] = [[type]Name >>]] - { - If[[[existing type]Variant >>] = [[type]Variant >>]] + Print[[[["Propagate Type, Index: "]Append[String[[dest]Index >>]]]Append[" io num: "]]Append[String[[dest]IO Num >>]]] + node <- [nodelist]Index[[dest]Index >>] + + [[node]Input Types >>]Index[[dest]IO Num >>] + { + Print[["Existing type: "]Append[[existing type]Name >>]] + existing type <- [~]Index[0] + new count <- [[~]Index[1]]+[1] + If[[[existing type]Name >>] = [[type]Name >>]] { - If[[[existing type]Params >>] = [[type]Params >>]] + If[[[existing type]Variant >>] = [[type]Variant >>]] { - new type <- Val[existing type] + If[[[existing type]Params >>] = [[type]Params >>]] + { + new type <- Val[existing type] + }{ + new variant <- [existing type]Variant >> + new params <- () + } }{ - new variant <- [existing type]Variant >> - new params <- () + new variant <- "Boxed" + If[[[existing type]Params >>] = [[type]Params >>]] + { + new params <- [existing type]Params >> + }{ + new params <- () + } } + new type <- [[existing type]Set Variant[new variant]]Params <<[new params] }{ - new variant <- "Boxed" - If[[[existing type]Params >>] = [[type]Params >>]] - { - new params <- [existing type]Params >> - }{ - new params <- () - } + new type <- Type Instance["Any Type"] } - new type <- [[existing type]Set Variant[new variant]]Params <<[new params] }{ - new type <- Type Instance["Any Type"] + Print["No existing type info for this input"] + new type <- Val[type] + new count <- 1 } + Print[[[["new type: "]Append[[new type]Name >>]]Append[", new count: "]]Append[String[new count]]] + new node <- [node]Input Types <<[ + [ [node]Input Types >> ]Set[ [dest]IO Num >>, [[()]Append[new type]]Append[new count] ] + ] + { Print["got new node"] } + out <- Infer Types Node[[nodelist]Set[[dest]Index >>, new node], new node, [dest]Index >>, prog, worker] }{ - new type <- Val[type] - new count <- 1 + out <- nodelist } - new node <- [node]Input Types <<[ - [ [node]Input Types >> ]Set[ [dest]IO Num >>, [[()]Append[new type]]Append[new count] ] - ] - out <- Infer Types Node[[nodelist]Set[[dest]Index >>, new node], new node, [dest]Index >>, prog, worker] } Propagate Types[nodelist,dests,output num,prog,worker,source node:out] { - out <- Fold[Propagate Type[?, ?, prog, worker, [[source node]Output Types >>]Index[output num]], nodelist, dests] + [[source node]Output Types >>]Index[output num] + { + out <- Fold[Propagate Type[?, ?, prog, worker, ~], nodelist, dests] + }{ + Print[["Output type is missing for output #"]Append[String[output num]]] + out <- nodelist + } } Infer Types Node[nodelist,node,index,prog,worker:out] { + If[[[node]Type >>]=["call"]] + { + extra <- [", worker: "]Append[[[node]Data >>]Name >>] + }{ + extra <- "" + } + Print[[[[["Infer Types Node: "]Append[String[index]]]Append[", type: "]]Append[[node]Type >>]]Append[extra]] If[[[node]Type >>] = ["const"]] { const type <- Blueprint Of[[node]Data >>] @@ -384,76 +410,95 @@ nextnode <- [node]Output Types <<[ [()]Append[Type Instance[outtype]] ] }{ - If[[[node]Type >>] = ["input"]] + If[[[node]Type >>] = ["setglobal"]] { - nextnode <- [node]Output Types <<[ [()]Append[ [[worker]Input Types >>]Index[[node]Data >>] ] ] + out <- nodelist }{ - If[[[node]Type >>] = ["output"]] + If[[[node]Type >>] = ["input"]] { - out <- nodelist - + nextnode <- [node]Output Types <<[ [()]Append[ [[worker]Input Types >>]Index[[node]Data >>] ] ] }{ - If[[[node]Type >>] = ["getglobal"]] + If[[[node]Type >>] = ["output"]] { - nextnode <- [node]Output Types <<[ [()]Append[Type Instance["Any Type"]] ] + out <- nodelist + }{ - [node]Has Input Types? + If[[[node]Type >>] = ["getglobal"]] { - If[[[node]Type >>] = ["setfield"]] + nextnode <- [node]Output Types <<[ [()]Append[Type Instance["Any Type"]] ] + }{ + [node]Has Input Types? { - nextnode <- [node]Output Types <<[ [()]Append[ [[[node]Input Types >>]Index[0]]Index[0] ] ] - }{ - If[[[node]Type >>] = ["getfield"]] + If[[[node]Type >>] = ["setfield"]] { - type <- [[[node]Input Types >>]Index[0]]Index[0] - If[[[type]Name >>] = ["Any Type"]] + nextnode <- [node]Output Types <<[ [()]Append[ [[[node]Input Types >>]Index[0]]Index[0] ] ] + }{ + If[[[node]Type >>] = ["getfield"]] { - outtype <- Val[type] - }{ - outtype <- [prog]Find Field[[node]Data >>, type] {} + type <- [[[node]Input Types >>]Index[0]]Index[0] + If[[[type]Name >>] = ["Any Type"]] { - //TODO: Return errors rather than printing them - Print[ - [[[[["Type " - ]Append[[type]Name >>] - ]Append[" does not have a field named "] - ]Append[[node]Data >>] - ]Append[" in worker "] - ]Append[worker name]] - } - } - nextnode <- [node]Output Types <<[ [()]Append[outtype] ] - }{ - - worker name <- [[node]Data >>]Name >> - [prog]Is Method?[worker name] - { - first arg type <- [[[node]Input Types >>]Index[0]]Index[0] - If[[[first arg type]Name >>] = ["Any Type"]] - { - outtypes <- Fold[Append[?, Type Instance["Any Type"]], (), Range[0, [node]Inputs >>]] + outtype <- Val[type] }{ - worker def <- [prog]Find Method[worker name, first arg type] {} + outtype <- [prog]Find Field[[node]Data >>, type] {} { - //TODO: Return errors instead of printing them + //TODO: Return errors rather than printing them Print[ [[[[["Type " - ]Append[[first arg type]Name >>] - ]Append[" does not support method "] - ]Append[worker name] + ]Append[[type]Name >>] + ]Append[" does not have a field named "] + ]Append[[node]Data >>] ]Append[" in worker "] - ]Append[ [worker]Name >> ]] + ]Append[worker name]] } } + nextnode <- [node]Output Types <<[ [()]Append[outtype] ] }{ - worker def <- [prog]Find Worker Def[worker name] + worker name <- [[node]Data >>]Name >> + [prog]Is Method?[worker name] + { + Print[[["Infer Types: "]Append[worker name]]Append[" is a method"]] + first arg type <- [[[node]Input Types >>]Index[0]]Index[0] + If[[[first arg type]Name >>] = ["Any Type"]] + { + Print["No type info for first arg"] + outtypes <- Fold[Append[?, Type Instance["Any Type"]], (), Range[0, [node]Inputs >>]] + Print[["outtypes length: "]Append[String[Length[outtypes]]]] + nextnode <- [node]Output Types <<[ outtypes ] + }{ + worker def <- [prog]Find Method[worker name, first arg type] + { + new worker name <- [[worker name]Append["@"]]Append[[first arg type]Name >>] + new ref <- [prog]Find Worker[new worker name] {} { + Print[["Could not find worker ref for "]Append[new worker name]] + } + nextnode <- [[node]Output Types <<[outtypes] + ]Data <<[new ref] + Print[["New worker name:"]Append[new worker name]] + }{ + //TODO: Return errors instead of printing them + Print[ + [[[[["Type " + ]Append[[first arg type]Name >>] + ]Append[" does not support method "] + ]Append[worker name] + ]Append[" in worker "] + ]Append[ [worker]Name >> ]] + } + } + }{ + Print[[["Infer Types: "]Append[worker name]]Append[" is not a method"]] + worker def <- [prog]Find Worker Def[worker name] {} + { Print["Error, could not find worker def"] } + nextnode <- [node]Output Types <<[ outtypes ] + } + outtypes <- [worker def]Output Types >> } - outtypes <- [worker def]Output Types >> - nextnode <- [node]Output Types <<[ outtypes ] } + }{ + Print["Skipping node because input type info not present"] + out <- nodelist } - }{ - out <- nodelist } } } @@ -463,7 +508,8 @@ Val[nextnode] { nextlist <- [nodelist]Set[index, nextnode] - out <- Fold[Propagate Types[?, ?, ?, prog, worker, nextnode], nodelist, [nextnode]Wires From >>] + { Print["Calling Propagate types on descdendants of this node"] } + out <- Fold[Propagate Types[?, ?, ?, prog, worker, nextnode], nextlist, [nextnode]Wires From >>] } } @@ -1318,6 +1364,7 @@ Add Method@NBlueprint[bp,name:out] { out <- [bp]Methods <<[ [[bp]Methods >>]Set[name, Yes] ] + } Understands Method@NBlueprint[bp,name:out] @@ -1326,10 +1373,15 @@ { out <- No } } +Eq Field Name[field,name:out] +{ + out <- [[field]Index[0]]=[name] +} + Get Field Type@NBlueprint[bp,name:out,notfound] { - ,notfound <- [[bp]Fields >>]Index[name] - { out <- [~]Index[1] } + ,not found <- [[bp]Fields >>]Find[Eq Field Name[?, name]] + { out <- [[[bp]Fields >>]Index[~]]Index[1] } } _Compile Blueprint Fields[type,field:out] @@ -1561,10 +1613,11 @@ { [[prog]Worker Refs >>]Index[name] { - ref <- [[[[~]Inputs <<[ Max[[~]Inputs >>, inputs] ] + ref <- [[[[[~]Inputs <<[ Max[[~]Inputs >>, inputs] ] ]Min Inputs <<[ Min[[~]Min Inputs >>, inputs] ] ]Outputs <<[ Max[[~]Outputs >>, outputs] ] ]Min Outputs <<[ Min[[~]Min Outputs >>, outputs] ] + ]Is Method? <<[Yes] }{ ref <- Worker Ref[name, convention, inputs, outputs, Yes] }