Mercurial > repos > rhope
diff nworker.rhope @ 42:aabda74c7a88
Fields can now be defined to have naked primitive types
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 13 Oct 2009 00:07:34 -0400 |
parents | 789a146a48e1 |
children | 709df3e82bb4 |
line wrap: on
line diff
--- 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]