# HG changeset patch # User Mike Pavone # Date 1243414172 14400 # Node ID ea991f95ae1fa8f91c6d344730eef075d9ca5b6a # Parent d05184970c1c86fa7c9d333aa8679e842ca2caf6 C backend working well enough to generate Fib test diff -r d05184970c1c -r ea991f95ae1f backendutils.rhope --- a/backendutils.rhope Tue May 26 23:37:59 2009 -0400 +++ b/backendutils.rhope Wed May 27 04:49:32 2009 -0400 @@ -26,6 +26,7 @@ Make Op@AddRef[addref,func:out] { + //TODO: Make me work with other backends out <- [["add_ref("]Append[ [[addref]Value >>]Make Op[func] ]]Append[")"] } @@ -74,4 +75,17 @@ out <- [func]Result Reference[[result]Output Num>>] } +Blueprint NotCond +{ + Condition +} +NotCond[cond:out] +{ + out <- [Build["NotCond"]]Condition <<[cond] +} + +Make Op@NotCond[cond,func:out] +{ + out <- ["!"]Append[[[cond]Condition >>]Make Op[func]] +} diff -r d05184970c1c -r ea991f95ae1f cbackend.rhope --- a/cbackend.rhope Tue May 26 23:37:59 2009 -0400 +++ b/cbackend.rhope Wed May 27 04:49:32 2009 -0400 @@ -151,10 +151,10 @@ Null@C Function[func,pdest:out] { dest <- [pdest]Make Op[func] - out <- [func]Add Statement[[dest]Append[" = NULL;"]] + out <- [func]Add Statement[[dest]Append[" = NULL"]] } -_Method Arg[func,val,inputnum:out] +_Function Arg C[func,val,inputnum:out] { out <- [func]Add Statement[ [[["call->params[" @@ -166,9 +166,29 @@ Method Call@C Function[func,method,args:out] { + out <- [func]Func Base[[[func]Method Registry >>]Method ID[method],args, "MCall"] +} + +Call@C Function[func,name,args:out] +{ + out <- [func]Func Base[name,args, "Call"] +} + +Func Base@C Function[func,tocall,args,type:out] +{ rargs <- Map[args, ["Make Op"]Set Input[1, func]] - out <- [Fold["_Method Arg", func, rargs] - ]Add Raw Line[[[[["MCall("]Append[ [[func]Method Registry >>]Method ID[method] ]]Append[", "]]Append[ [rargs]Length ]]Append[")"]] + out <- [Fold["_Function Arg C", func, rargs] + ]Add Raw Line[[[[[ [type]Append["("] ]Append[tocall]]Append[", "]]Append[ [rargs]Length ]]Append[")"]] +} + +Tail Method Call@C Function[func,method,args:out] +{ + out <- [func]Func Base[[[func]Method Registry >>]Method ID[method],args, "TMCall"] +} + +Tail Call@C Function[func,name,args:out] +{ + out <- [func]Func Base[name,args, "TCall"] } Resolve@C Function[func,op:out] @@ -251,20 +271,18 @@ } _Output Defs C[string,varname:out] { - Print[varname] out <- [[[string]Append["\tobject *"]]Append[Escape Rhope Name[varname]]]Append[";\n"] } _Var Defs C[string,type,varname:out] { - Print[type] - {Print[varname]} out <- [[[string]Append["\tobject *"]]Append[Escape Rhope Name[varname]]]Append[";\n"] } + Definitions@C Function[func:out] { Print["Definitions"] - out <- [[[Fold["_Definitions C", Fold["_Definitions","typedef struct {\n", [func]Variables >>], [func]Outputs >>]]Append["} l_"]]Append[Escape Rhope Name[[func]Name >>]]]Append[";\n"] + out <- [[[Fold["_Output Defs C", Fold["_Var Defs C","typedef struct {\n", [func]Variables >>], [func]Outputs >>]]Append["} l_"]]Append[Escape Rhope Name[[func]Name >>]]]Append[";\n"] } Text@C Function[func:out] diff -r d05184970c1c -r ea991f95ae1f runtime/integer.c --- a/runtime/integer.c Tue May 26 23:37:59 2009 -0400 +++ b/runtime/integer.c Wed May 27 04:49:32 2009 -0400 @@ -45,7 +45,7 @@ release_ref(cdata->params[0]); Ret(0, No) } - release_ref(cdata->params[0]); + release_ref(cdata->params[1]); EndFunc MethodNoLocals(_GT_,Int32, @@ -63,7 +63,7 @@ release_ref(cdata->params[0]); Ret(0, No) } - release_ref(cdata->params[0]); + release_ref(cdata->params[1]); EndFunc object * make_Int32(int32_t val) diff -r d05184970c1c -r ea991f95ae1f test/build.bat --- a/test/build.bat Tue May 26 23:37:59 2009 -0400 +++ b/test/build.bat Wed May 27 04:49:32 2009 -0400 @@ -2,12 +2,12 @@ cd ..\build for %%f in (..\test\*.c ..\runtime\object.c ..\runtime\context.c ..\runtime\builtin.c ..\runtime\bool.c ..\runtime\integer.c) do ( - cl /c /Ox /I..\runtime %%f + cl /c /O2 /I..\runtime %%f if errorlevel 1 goto end ) -cl /Ox test.obj object.obj context.obj builtin.obj bool.obj integer.obj -cl /Ox fib.obj object.obj context.obj builtin.obj bool.obj integer.obj winmm.lib +cl /O2 test.obj object.obj context.obj builtin.obj bool.obj integer.obj +cl /O2 fib.obj object.obj context.obj builtin.obj bool.obj integer.obj winmm.lib :end cd ..\test \ No newline at end of file diff -r d05184970c1c -r ea991f95ae1f testc.rhope --- a/testc.rhope Tue May 26 23:37:59 2009 -0400 +++ b/testc.rhope Wed May 27 04:49:32 2009 -0400 @@ -15,18 +15,28 @@ ]Release[Result[0]] ]Move[AddRef[Constant["const_1"]], "out"] {Print["stream1 done"]} + + stream3 <- [[[base]Instruction Stream + ]Release["n"] + ]Tail Method Call["+", ("work1","work2")] - stream2 <- [[[[[[base]Instruction Stream + stream2 <- [[[[[[[[[[[base]Instruction Stream ]Release[Result[0]] ]Method Call["-", [[()]Append[AddRef["n"]]]Append[AddRef[Constant["const_1"]]]] ]Move[Result[0], "work1"] ]Method Call["-", [[()]Append[AddRef["n"]]]Append[AddRef[Constant["const_2"]]]] ]Move[Result[0], "work2"] + ]Call["Fib", ("work1")] + ]Move[Result[0], "work1"] + ]Call["Fib", ("work2")] + ]Move[Result[0], "work2"] + ]Do If[NotCond["out"], stream3] {Print["stream2 done"]} - func <- [[base + func <- [[[base ]Do If[Result[0], stream1] ]Do If[Result[1], stream2] + ]Release["n"] {Print["func done"] } Print[[func]Definitions]