# HG changeset patch # User Mike Pavone # Date 1255406854 14400 # Node ID aabda74c7a880f330aa885d8f4387abdfd1399b4 # Parent 1b86a1ee500a09664a45227157b43c809366a3d9 Fields can now be defined to have naked primitive types diff -r 1b86a1ee500a -r aabda74c7a88 backendutils.rhope --- a/backendutils.rhope Sat Oct 10 16:40:50 2009 -0400 +++ b/backendutils.rhope Tue Oct 13 00:07:34 2009 -0400 @@ -178,7 +178,7 @@ out <- [[[Build["Type Instance"]]Name <<[name]]Params <<[()]]Variant <<["Boxed"] } -Set Variant[type,variant:out,invalid] +Set Variant@Type Instance[type,variant:out,invalid] { [("Boxed","Naked","Pointer","Raw Pointer")]Find[variant] { @@ -187,3 +187,15 @@ invalid <- type } } + +=@Type Instance[type,compare:out] +{ + If[[Type Of[compare]] = ["String"]] + { + out <- [[type]Name >>] = [compare] + }{ + //TODO: Compare parameters + ,out <- If[[[type]Name >>] = [[compare]Name >>]] + { out <- [[type]Variant >>] = [[compare]Variant >>] } + } +} diff -r 1b86a1ee500a -r aabda74c7a88 cbackend.rhope --- a/cbackend.rhope Sat Oct 10 16:40:50 2009 -0400 +++ b/cbackend.rhope Tue Oct 13 00:07:34 2009 -0400 @@ -230,7 +230,12 @@ Type Def@C Type[ctype:out] { - out <- [Fold["_Type Def C Type", "OBegin", [ctype]Fields >>]]Append[ [["\nObject("]Append[Escape Rhope Name[[ctype]Name >>]]]Append[")"] ] + If[[[[ctype]Fields >>]Length] = [1]] + { + out <- [[[_Type Def C Type["typedef struct {\n\tobject _SP_header;\n\t", [[ctype]Fields >>]Index[0]]]Append["\n} t_"]]Append[[ctype]Name >>]]Append[";"] + }{ + out <- [Fold["_Type Def C Type", "OBegin", [ctype]Fields >>]]Append[ [["\nObject("]Append[Escape Rhope Name[[ctype]Name >>]]]Append[")"] ] + } } _Type Init C[type name,method reg,text,method:out] @@ -334,6 +339,16 @@ out,notfound <- [[reg]Lookup >>]Index[name] } +Simple Type?@C Type Registry[reg,name:yep,nope,notfound] +{ + Print[["Symple Type?: "]Append[name]] + ,notfound <- [[reg]Definitions >>]Index[name] + { + Print["found type"] + yep,nope <- If[[[[~]Fields >>]Length] = [1]] + } +} + Blueprint C Function { Name @@ -352,10 +367,10 @@ C Function[name,inputs,outputs,convention:out] { - out <- C Function With Registry[name,inputs,outputs,convention, C Method Registry[], C Field Registry[]] + out <- C Function With Registry[name,inputs,outputs,convention, C Method Registry[], C Field Registry[], C Type Registry[]] } -C Function With Registry[name,inputs,outputs,convention,registry,field reg:out] +C Function With Registry[name,inputs,outputs,convention,registry,field reg,type reg:out] { out <- [[[[[[[[[[[[Build["C Function"] ]Name <<[name] @@ -366,7 +381,7 @@ ]Statements <<[()] ]Method Registry <<[registry] ]Field Registry <<[field reg] - ]Type Registry <<[C Type Registry[]] + ]Type Registry <<[type reg] ]Constants <<[New@Dictionary[]] ]Input Types <<[ Fold[["Append"]Set Input[1, "Any Type"], (), inputs] ] ]Output Types <<[ Fold[["Append"]Set Input[1, "Any Type"], (), outputs] ] @@ -475,24 +490,37 @@ Field Result@C Function[func,var,field:out] { as op <- [var]Make Op[func] - If[[[Type Of[var]] = ["String"]] And[ [[func]Convention >>] = ["rhope"]] ] + If[[Type Of[var]] = ["String"]] { [[func]Inputs >>]Find[var] { type <- [[func]Input Types >>]Index[~] - If[[type] = ["Any Type"]] - { - rvar <- Val[as op] - }{ - rvar <- [[[["(("]Append[ Rhope Type to C[type] ]]Append[")("]]Append[as op]]Append["))"] + }{ + type <- [[func]Variables >>]Index[var] {} + { + //Does it make sense for us to do this? + type <- Type Instance["Any Type"] } + } + }{ + type <- Type Instance["Any Type"] + } + If[[[func]Convention >>] = ["rhope"]] + { + If[[type] = ["Any Type"]] + { + rvar <- Val[as op] }{ - rvar <- Val[as op] + rvar <- [[[["(("]Append[ Rhope Type to C[type] ]]Append[")("]]Append[as op]]Append["))"] } }{ rvar <- Val[as op] } - out <- [[rvar]Append["->"]]Append[Escape Rhope Name[field]] + + [[func]Type Registry >>]Simple Type?[[type]Name >>] + { access <- "->" } + { access <- "->payload." } + out <- [[rvar]Append[access]]Append[Escape Rhope Name[field]] } Read Field@C Function[func,var,field:out,result op] @@ -509,6 +537,7 @@ Set Field Null@C Function[func,var,field:out] { + Print["Set Field Null"] out <- [func]Add Statement[ [[func]Field Result[var,field]]Append[" = NULL"] ] } @@ -518,7 +547,7 @@ out <- [func]Add Statement[ [dest]Append[[[" = copy_object("]Append[dest]]Append[")"]] ] } -Box@C Function[func,pdest,psource,type:out] +Box@C Function[func,psource,pdest,type:out] { dest <- [pdest]Make Op[func] source <- [psource]Make Op[func] @@ -531,7 +560,7 @@ ]Append[")"] ] } -Unbox@C Function[func,pdest,psource:out] +Unbox@C Function[func,psource,pdest:out] { dest <- [pdest]Make Op[func] source <- [psource]Make Op[func] @@ -669,11 +698,11 @@ } _Output Defs C[string,varname,index,func:out] { - out <- [[[string]Append[ ["\t"]Append[Rhope Type to C[[[func]Output Types >>]Index[index]]] ]]Append[Escape Rhope Name[varname]]]Append[";\n"] + out <- [[[string]Append[ ["\t"]Append[Rhope Type to C[[[func]Output Types >>]Index[index]]] ]]Append[[" "]Append[Escape Rhope Name[varname]]]]Append[";\n"] } _Var Defs C[string,type,varname:out] { - out <- [[[string]Append[ ["\t"]Append[Rhope Type to C[type]] ]]Append[Escape Rhope Name[varname]]]Append[";\n"] + out <- [[[string]Append[ ["\t"]Append[Rhope Type to C[type]] ]]Append[[" "]Append[Escape Rhope Name[varname]]]]Append[";\n"] } @@ -707,10 +736,7 @@ _Proto Input[list,input,index,types:out] { - Print[["_Proto Input: "]Append[input]] - { Print[[types]Index[index]] } out <- [list]Append[ [[Rhope Type to C[[types]Index[index]]]Append[" "]]Append[Escape Rhope Name[input]] ] - { Pretty Print[~, ""] } } Naked Proto@C Function[func:out] @@ -823,7 +849,7 @@ Create Function@C Program[program,name,inputs,outputs,convention:out] { - out <- C Function With Registry[name,inputs,outputs,convention, [program]Method Registry >>, [program]Field Registry >>] + out <- C Function With Registry[name,inputs,outputs,convention, [program]Method Registry >>, [program]Field Registry >>, [program]Type Registry >>] } Store Function@C Program[program,func:out] diff -r 1b86a1ee500a -r aabda74c7a88 nworker.rhope --- a/nworker.rhope Sat Oct 10 16:40:50 2009 -0400 +++ b/nworker.rhope Tue Oct 13 00:07:34 2009 -0400 @@ -766,10 +766,13 @@ Make Init[func,field:out] { name <- [field]Index[0] + Print[["Field: "]Append[name]] + { Print[[" Variant: "]Append[variant]] } variant <- [[field]Index[1]]Variant >> If[[variant] = ["Boxed"]] { out <- [func]Set Field Null["obj", name] + { Print["done"] } }{ out <- func } @@ -811,8 +814,9 @@ Make Special@NBlueprint[bp,backend,func name,bp name,pop worker:out] { + Print[[["Make Special: "]Append[func name]]Append[bp name]] func <- [[backend]Create Function[func name,("obj"),(),"cdecl"] - ]Set Input Type[bp name, 0] + ]Set Input Type[Type Instance[bp name], 0] out <- [backend]Store Function[Fold[pop worker, func, [bp]Fields >>]] } @@ -822,28 +826,43 @@ Print[["Getters Setters: "]Append[name]] name <- [field]Index[0] type <- [field]Index[1] - ,getref <- [[[[backend]Create Function[ [[[name]Append[" >>"]]Append["@"]]Append[type name], ("obj"), ("out"), "rhope"] - ]Set Input Type[type name, 0] - ]Set Output Type[type, 0] + mytype <- Type Instance[type name] + start getter,getref <- [[[[backend]Create Function[ [[[name]Append[" >>"]]Append["@"]]Append[type name], ("obj"), ("out"), "rhope"] + ]Set Input Type[mytype, 0] + ]Set Output Type[[type]Set Variant["Boxed"], 0] ]Read Field["obj", name] - { getter <- [[~]Do AddRef[getref, "out"]]Release["obj"] - { Print["Got getter"] } } + If[[[type]Variant >>] = ["Boxed"]] + { + getter <- [[start getter]Do AddRef[getref, "out"]]Release["obj"] + }{ + getter <- [[start getter]Box[getref, "out", type]]Release["obj"] + } + + begin setter <- [[[[[backend]Create Function[ [[[name]Append[" <<"]]Append["@"]]Append[type name], ("obj","newval"), ("out"), "rhope"] + ]Set Input Type[mytype, 0] + ]Set Input Type[[type]Set Variant["Boxed"], 1] + ]Set Output Type[mytype, 0] + ]Copy["obj"] - ,origref <- [[[[[[backend]Create Function[ [[[name]Append[" <<"]]Append["@"]]Append[type name], ("obj","newval"), ("out"), "rhope"] - ]Set Input Type[type name, 0] - ]Set Input Type[type, 1] - ]Set Output Type[type name, 0] - ]Copy["obj"] - ]Read Field["obj", name] - { - stream <- [[~]Instruction Stream - ]Release[origref] - ,setref <- [[~]Do If[origref, stream] - ]Write Field["obj", name] - { - setter <- [[~]Move["newval", setref] + If[[[type]Variant >>] = ["Boxed"]] + { + ,origref <- [begin setter]Read Field["obj", name] + { + stream <- [[~]Instruction Stream + ]Release[origref] + ,setref <- [[~]Do If[origref, stream] + ]Write Field["obj", name] + { + setter <- [[~]Move["newval", setref] + ]Move["obj", "out"] + { Print["got setter"] } + } + } + }{ + ,setref <- [begin setter]Write Field["obj", name] + { + setter <- [[~]Unbox["newval", setref] ]Move["obj", "out"] - { Print["got setter"] } } } @@ -853,7 +872,7 @@ Compile Blueprint@NBlueprint[bp,backend,name:out] { - + Print[["Compiling blueprint: "]Append[name]] //Rhope identifiers can't start with spaces, so we can use identifiers that start with spaces for special functions init name <- [" init "]Append[name] copy name <- [" copy "]Append[name] @@ -862,10 +881,19 @@ ]Init <<[init name] ]Copy <<[copy name] ]Cleanup <<[cleanup name] + { Print["Created type on backend"] } + out <- [backend]Register Type[type] +} + +Compile Special@NBlueprint[bp,backend,name:out] +{ + init name <- [" init "]Append[name] + copy name <- [" copy "]Append[name] + cleanup name <- [" cleanup "]Append[name] got specials <- [bp]Make Special[ [bp]Make Special[ - [bp]Make Special[[backend]Register Type[type], init name, name, "Make Init"], + [bp]Make Special[backend, init name, name, "Make Init"], copy name, name, "Make Copy"], cleanup name, name, "Make Cleanup"] out <- Fold[["Getters Setters"]Set Input[2, name], got specials, [bp]Fields >>] @@ -906,6 +934,11 @@ out <- [blueprint]Compile Blueprint[backend, name] } +_Compile Program BP Special[backend, blueprint, name:out] +{ + out <- [blueprint]Compile Special[backend, name] +} + _Compile Program[backend, worker, name:out] { out <- [worker]Compile Worker[backend, name] @@ -913,7 +946,7 @@ Compile Program@NProgram[prog, backend:out] { - out <- Fold["_Compile Program", Fold["_Compile Program BP", backend, [prog]Blueprints >>], [prog]Workers >>] + out <- Fold["_Compile Program", Fold["_Compile Program BP Special", Fold["_Compile Program BP", backend, [prog]Blueprints >>], [prog]Blueprints >>], [prog]Workers >>] } Register Worker@NProgram[prog, name, convention, inputs, outputs: out] diff -r 1b86a1ee500a -r aabda74c7a88 parser_old.rhope --- a/parser_old.rhope Sat Oct 10 16:40:50 2009 -0400 +++ b/parser_old.rhope Tue Oct 13 00:07:34 2009 -0400 @@ -1388,6 +1388,7 @@ { registered <- Fold["Register Workers Compile", Fold["Add Blueprint Compile", [NProgram[]]Register Builtins, [parse tree]Blueprints >>], [parse tree]Workers >>] out <- Fold["Add Workers Compile", registered, [parse tree]Workers >>] + { Print["Transformed AST to dataflow graph "] } } Needs Imports[needs import,not imported?,name:out] diff -r 1b86a1ee500a -r aabda74c7a88 runtime/blueprint.h --- a/runtime/blueprint.h Sat Oct 10 16:40:50 2009 -0400 +++ b/runtime/blueprint.h Tue Oct 13 00:07:34 2009 -0400 @@ -4,9 +4,7 @@ #include "object.h" #include "func.h" -OBegin - blueprint * bp; -Object(Blueprint) +Box(blueprint *,bp,Blueprint) object * make_Blueprint(int32_t type_id); FuncDef(Build) diff -r 1b86a1ee500a -r aabda74c7a88 runtime/bool.h --- a/runtime/bool.h Sat Oct 10 16:40:50 2009 -0400 +++ b/runtime/bool.h Tue Oct 13 00:07:34 2009 -0400 @@ -2,9 +2,7 @@ #define BOOL_H_ #include "object.h" -OBegin - int32_t val; -Object(Boolean) +Box(int32_t,val,Boolean) #define Yes add_ref((object *)val_yes) #define No add_ref((object *)val_no) diff -r 1b86a1ee500a -r aabda74c7a88 runtime/integer.h --- a/runtime/integer.h Sat Oct 10 16:40:50 2009 -0400 +++ b/runtime/integer.h Tue Oct 13 00:07:34 2009 -0400 @@ -4,9 +4,7 @@ #include "object.h" #include "func.h" -OBegin - int32_t num; -Object(Int32) +Box(int32_t,num,Int32) MethodDef(_PL_,Int32) MethodDef(_MN_,Int32) diff -r 1b86a1ee500a -r aabda74c7a88 runtime/object.h --- a/runtime/object.h Sat Oct 10 16:40:50 2009 -0400 +++ b/runtime/object.h Tue Oct 13 00:07:34 2009 -0400 @@ -52,8 +52,9 @@ object *params[1]; } calldata; -#define OBegin typedef struct { object header; -#define Object(name) } t_ ## name; +#define OBegin typedef struct { +#define Object(name) } nt_ ## name; typedef struct { object _SP_header; nt_ ## name payload; } t_ ## name; +#define Box(nakedtype,fieldname,objectname) typedef struct{ object _SP_header; nakedtype fieldname; } t_ ## objectname; #define MOBegin typedef struct { multisize header;