# HG changeset patch # User Mike Pavone # Date 1280258612 14400 # Node ID 2e2e55fc12f99799569328301fa0f18d0dabb99c # Parent dbe95bfec970533ffc3e62ba54dd41bfa5018995 Fix bug with conditionally assigning a literal or input to a named pipe diff -r dbe95bfec970 -r 2e2e55fc12f9 file.rhope --- a/file.rhope Thu Jul 22 05:39:08 2010 +0000 +++ b/file.rhope Tue Jul 27 15:23:32 2010 -0400 @@ -79,22 +79,22 @@ { If[[mode]=["r"]] { - imode <- Val[0i32] - type <- Val[File Read()] + imode <- 0i32 + type <- File Read() out <- Val[ofile] }{ If[[mode]=["w"]] { - imode <- Val[65i32] - type <- Val[File Write()] + imode <- 65i32 + type <- File Write() out <- Val[ofile] If[[fd]!=[-1i32]] { lseek[fd, 0i64, 2i32] } }{ ,error <- If[[mode]=["rw"]] { - imode <- Val[66i32] - type <- Val[File ReadWrite()] + imode <- 66i32 + type <- File ReadWrite() out <- [ofile]Read Offset <<[0i64] } } diff -r dbe95bfec970 -r 2e2e55fc12f9 nworker.rhope --- a/nworker.rhope Thu Jul 22 05:39:08 2010 +0000 +++ b/nworker.rhope Tue Jul 27 15:23:32 2010 -0400 @@ -149,9 +149,9 @@ { Name Convention - Inputs + Inputs Min Inputs - Outputs + Outputs Min Outputs Is Method? } @@ -184,10 +184,10 @@ { Type Data - Inputs + Inputs Min Inputs Input Types - Outputs + Outputs Min Outputs Output Types Wires From @@ -196,8 +196,8 @@ } Wire To@NWorker Node[node,from,output,pre input:out] -{ - existing cons <- [[node]Wires To >>]Index[input] {} +{ + existing cons <- [[node]Wires To >>]Index[input] {} { existing cons <- () } input <- [pre input]+[1] out <- [node]Wires To <<[ @@ -208,8 +208,8 @@ } Wire From@NWorker Node[node,to,input,output:out] -{ - existing cons <- [[node]Wires From >>]Index[output] {} +{ + existing cons <- [[node]Wires From >>]Index[output] {} { exist cons <- () } out <- [node]Wires From <<[ [[node]Wires From >>]Set[output, @@ -264,9 +264,9 @@ out <- [[[[[[[[[[[Build["NWorker Node"] ]Type <<[type] ]Data <<[data] - ]Inputs <<[inputs] + ]Inputs <<[inputs] ]Min Inputs <<[inputs] - ]Outputs <<[outputs] + ]Outputs <<[outputs] ]Min Outputs <<[outputs] ]Wires From <<[List of Lists[outputs]] ]Wires To <<[List of Lists[[inputs]+[1]]] @@ -300,8 +300,8 @@ { out <- [worker]Nodes <<[[[worker]Nodes >>]Append[NWorker Node[type,data,inputs,outputs]]] node index <- [[worker]Nodes >>]Length -} - +} + Add Full Node@NWorker[worker,type,data,inputs,min inputs,outputs,min outputs:out,node index] { out <- [worker]Nodes <<[[[worker]Nodes >>]Append[ [[NWorker Node[type,data,inputs,outputs]]Min Inputs <<[min inputs]]Min Outputs <<[min outputs] ]] @@ -358,7 +358,7 @@ Infer Types Node[nodelist,node,index,prog,worker:out] { If[[[node]Type >>] = ["const"]] - { + { const type <- Type Of[[node]Data >>] //Temporary hack If[[const type] = ["Whole Number"]] @@ -376,12 +376,12 @@ { base <- "UInt" } outtype <- Type Instance[[base]Append[ [[node]Data >>]Size >> ]] - }{ - If[[const type] = ["Worker Literal"]] - { - outtype <- Type Instance["Worker"] + }{ + If[[const type] = ["Worker Literal"]] + { + outtype <- Type Instance["Worker"] }{ - outtype <- Type Instance[const type] + outtype <- Type Instance[const type] } } } @@ -635,44 +635,56 @@ Format Input@NWorker[worker,noderef:out] { node <- [[worker]Nodes >>]Index[[noderef]Index >>] + [("call","getfield","setfield")]Find[[node]Type >>] { out <- AddRef[ [[["__result_"]Append[[noderef]Index >>]]Append["_"]]Append[[noderef]IO Num >>] ] }{ + conditions <- [node]Conditions >> + If[[[node]Type >>] = ["input"]] { input name <- [[worker]Inputs >>]Index[ [node]Data >> ] - out <- AddRef[input name] + [conditions]For Backend + { + out <- AddRef[ [[["__result_"]Append[[noderef]Index >>]]Append["_"]]Append[[noderef]IO Num >>] ] + }{ + out <- AddRef[input name] + } }{ If[[[node]Type >>] = ["const"]] { - If[[Type Of[[node]Data >>]] = ["Type Instance"]] + [conditions]For Backend { - //TODO: Support parametric types - datstring <- [[node]Data >>]Name >> + out <- AddRef[ [[["__result_"]Append[[noderef]Index >>]]Append["_"]]Append[[noderef]IO Num >>] ] }{ - If[[Type Of[[node]Data >>]] = ["Machine Integer"]] + If[[Type Of[[node]Data >>]] = ["Type Instance"]] { - 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 >> - } + //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 >>] }{ - datstring <- [node]Data >> + 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[[[Type Of[[node]Data >>]]Append["_"]]Append[datstring]] - } } } @@ -729,41 +741,41 @@ ]Move[Result[num], out var] */ out <- [func]Move[Result[num], out var] -} - -Save Maybe Result[func,num,node index:out] -{ - out var <- [[["__result_"]Append[node index]]Append["_"]]Append[num] - out <- [func]Move[Check Result[num], out var] -} - -Max Used Output[node,cur:out] -{ - If[[cur] < [0]] - { - out <- cur - }{ - [[[node]Wires From >>]Index[cur]]Index[0] - { - out <- cur - }{ - out <- Max Used Output[node, [cur]-[1]] - } - } +} + +Save Maybe Result[func,num,node index:out] +{ + out var <- [[["__result_"]Append[node index]]Append["_"]]Append[num] + out <- [func]Move[Check Result[num], out var] +} + +Max Used Output[node,cur:out] +{ + If[[cur] < [0]] + { + out <- cur + }{ + [[[node]Wires From >>]Index[cur]]Index[0] + { + out <- cur + }{ + out <- Max Used Output[node, [cur]-[1]] + } + } } Compile Call Node[node,program,func,inputs,node index:out] { If[[[node]Type >>] = ["getfield"]] { - with call <- [func]Get Field Call[[node]Data >>, [inputs]Index[0]] - save outs <- [node]Outputs >> + with call <- [func]Get Field Call[[node]Data >>, [inputs]Index[0]] + save outs <- [node]Outputs >> out <- Val[after save] }{ If[[[node]Type >>] = ["setfield"]] { - with call <- [func]Set Field Call[[node]Data >>, [inputs]Index[0], [inputs]Index[1]] - save outs <- [node]Outputs >> + with call <- [func]Set Field Call[[node]Data >>, [inputs]Index[0], [inputs]Index[1]] + save outs <- [node]Outputs >> out <- Val[after save] }{ [program]Method?[[[node]Data >>]Name >>] @@ -771,21 +783,21 @@ with call <- [func]Method Call[[[node]Data >>]Name >>, inputs] }{ with call <- [func]Call[[[node]Data >>]Name >>, inputs] - } - first unused <- [Max Used Output[node, [[node]Outputs >>]-[1]]]+[1] - If[[first unused] > [[node]Min Outputs >>]] - { - save outs <- [node]Min Outputs >> - after maybe <- Fold[["Save Maybe Result"]Set Input[2, node index], after save, Range[save outs, first unused]] - }{ - save outs <- Val[first unused] - after maybe <- Val[after save] - } - If[[first unused] < [[node]Outputs >>]] - { - out <- [after maybe]Discard Outputs[first unused] - }{ - out <- Val[after maybe] + } + first unused <- [Max Used Output[node, [[node]Outputs >>]-[1]]]+[1] + If[[first unused] > [[node]Min Outputs >>]] + { + save outs <- [node]Min Outputs >> + after maybe <- Fold[["Save Maybe Result"]Set Input[2, node index], after save, Range[save outs, first unused]] + }{ + save outs <- Val[first unused] + after maybe <- Val[after save] + } + If[[first unused] < [[node]Outputs >>]] + { + out <- [after maybe]Discard Outputs[first unused] + }{ + out <- Val[after maybe] } } } @@ -794,9 +806,10 @@ Compile Node@NWorker[worker,program,func,nodes,current:out,out worker] { + Print[[[["Compile node: "]Append[[node]Type >>]]Append[", "]]Append[node index]] node index <- [nodes]Index[current] node <- [[worker]Nodes >>]Index[node index] - conditions <- [worker]Collect Conditions[node] + conditions <- [node]Conditions >> [("call","getfield","setfield")]Find[[node]Type >>] { inputs <- [worker]Collect Inputs[node] @@ -837,39 +850,71 @@ { 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 >> - } + }{ + 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 >> + datstring <- [node]Data >> } } } - nfunc <- [func]Register Constant[[[Type Of[[node]Data >>]]Append["_"]]Append[datstring], [node]Data >>] + constname <- [[Type Of[[node]Data >>]]Append["_"]]Append[datstring] + withconst <- [func]Register Constant[constname, [node]Data >>] + [conditions]For Backend + { + stream <- [[withconst]Instruction Stream + ]Move[Constant[constname], [[["__result_"]Append[node index]]Append["_"]]Append[0]] + nfunc <- [withconst]Do If[~, stream] + }{ + nfunc <- Val[withconst] + } }{ - nfunc <- Val[func] + [conditions]For Backend + { + input name <- [[worker]Inputs >>]Index[ [node]Data >> ] + stream <- [[func]Instruction Stream + ]Move[input name, [[["__result_"]Append[node index]]Append["_"]]Append[0]] + nfunc <- [func]Do If[~, stream] + }{ + nfunc <- Val[func] + } } } } - If[[[node]Outputs >>] = [0]] - { - nworker <- Val[worker] - }{ - nworker <- [worker]Nodes <<[ [[worker]Nodes >>]Set[node index, [node]Conditions <<[conditions]] ] - } [nodes]Next[current] { - out,out worker <- [nworker]Compile Node[program,nfunc,nodes,~] + out,out worker <- [worker]Compile Node[program,nfunc,nodes,~] }{ out <- Val[nfunc] - out worker <- Val[nworker] + out worker <- Val[worker] + } +} + +Save Node Conditions@NWorker[worker,node index:out] +{ + node <- [[worker]Nodes >>]Index[node index] + conditions <- [worker]Collect Conditions[node] + out <- [worker]Nodes <<[ [[worker]Nodes >>]Set[node index, [node]Conditions <<[conditions]] ] + +} + +Save Group Conditions@NWorker[worker, groups,current:out] +{ + nodes <- [groups]Index[current] + nworker <- Fold["Save Node Conditions", worker, nodes] + + [groups]Next[current] + { + out <- [nworker]Save Group Conditions[groups,~] + }{ + out <- Val[nworker] } } @@ -922,12 +967,12 @@ Node Result Vars[vars,node,index:out] { [("call","getfield","setfield")]Find[[node]Type >>] - { - If[[[node]Type >>]=["call"]] - { - save outs <- [Max Used Output[node, [[node]Outputs >>]-[1]]]+[1] - }{ - save outs <- [node]Outputs >> + { + If[[[node]Type >>]=["call"]] + { + save outs <- [Max Used Output[node, [[node]Outputs >>]-[1]]]+[1] + }{ + save outs <- [node]Outputs >> } out <- Fold[["Result Var"]Set Input[2, index], vars, Range[0, save outs]] }{ @@ -940,6 +985,30 @@ out <- Fold["Node Result Vars", (), [worker]Nodes >>] } +_No Release[vars,node,index,worker:out] +{ + Print[["_No Release"]Append[[node]Type >>]] + [("const","input")]Find[[node]Type >>] + { + [[node]Conditions >>]For Backend + { + Print[["Const or input with conditions: "]Append[index]] + out <- Result Var[vars, 0, index] + }{ + Print[["Const or input with no conditions: "]Append[index]] + out <- vars + } + }{ + Print[["Other node type: "]Append[index]] + out <- vars + } +} + +No Release Results@NWorker[worker:out] +{ + out <- Fold[["_No Release"]Set Input[3, worker], (), [worker]Nodes >>] +} + Make Basic Type[type:out] { out <- [Type Instance[[type]Name >>]]Params <<[ [type]Params >> ] @@ -1071,7 +1140,8 @@ } Compile Worker@NWorker[worker,program,name:out] -{ +{ + Print[["Compile Worker: "]Append[[worker]Name >>]] If[[worker]Builtin? >>] { out <- program @@ -1080,16 +1150,20 @@ { ifunc <- Fold["Set Output Type", Fold["Set Input Type", [program]Create Function[name,[worker]Inputs >>, [worker]Outputs >>, [worker]Convention >>], [worker]Input Types >>], [worker]Output Types >>] - res vars <- [worker]Result Vars - func <- Fold["Set Null", Fold["Set Null", Fold[["Allocate Var"]Set Input[2, "Any Type"], ifunc, res vars], res vars], [worker]Outputs >>] + groups <- [worker]Dependency Groups [groups]First { - final func <- [worker]Compile Group[program,func,groups, ~] + with conds <- [worker]Save Group Conditions[groups, ~] + final func <- [with conds]Compile Group[program,func,groups, ~] }{ final func <- Val[func] } + res vars <- [worker]Result Vars + init vars <- Concatenate[res vars, [with conds]No Release Results] + + func <- Fold["Set Null", Fold["Set Null", Fold[["Allocate Var"]Set Input[2, "Any Type"], ifunc, init vars], init vars], [worker]Outputs >>] out <- [program]Store Function[Fold["Release", Fold[["Release Var"]Set Input[0, worker], final func, res vars], [worker]Inputs >>]] }{ out <- Compile Foreign Stub[worker,[program]Link[[worker]Convention >>, [worker]Library >> ],name] @@ -1162,12 +1236,12 @@ } _Compile Blueprint Methods[type,junk,name:out] -{ - If[[[name]=["Call"]] And [[[type]Name >>] = ["Worker"]]] - { - out <- type +{ + If[[[name]=["Call"]] And [[[type]Name >>] = ["Worker"]]] + { + out <- type }{ - out <- [type]Add Method[name] + out <- [type]Add Method[name] } } @@ -1358,18 +1432,19 @@ } Register Worker@NProgram[prog, name, convention, inputs, outputs: out] -{ - [[prog]Worker Refs >>]Index[name] - { - ref <- [[[[~]Inputs <<[ Max[[~]Inputs >>, inputs] ] - ]Min Inputs <<[ Min[[~]Min Inputs >>, inputs] ] - ]Outputs <<[ Max[[~]Outputs >>, outputs] ] - ]Min Outputs <<[ Min[[~]Min Outputs >>, outputs] ] - }{ - ref <- Worker Ref[name, convention, inputs, outputs, No] +{ + [[prog]Worker Refs >>]Index[name] + { + ref <- [[[[~]Inputs <<[ Max[[~]Inputs >>, inputs] ] + ]Min Inputs <<[ Min[[~]Min Inputs >>, inputs] ] + ]Outputs <<[ Max[[~]Outputs >>, outputs] ] + ]Min Outputs <<[ Min[[~]Min Outputs >>, outputs] ] + }{ + ref <- Worker Ref[name, convention, inputs, outputs, No] } after reg <- [prog]Worker Refs <<[ - [ [prog]Worker Refs >> ]Set[name, ref] ] + [ [prog]Worker Refs >> ]Set[name, ref] + ] parts <- [name]Split["@"] [parts]Index[1] @@ -1385,7 +1460,7 @@ registered <- [[[[[[prog]Register Worker["Print", "rhope", 1, 1] ]Register Worker["If@Boolean", "rhope", 1, 2] ]Register Worker["Build", "rhope", 1, 1] - ]Register Worker["Blueprint Of", "rhope", 1, 1] + ]Register Worker["Blueprint Of", "rhope", 1, 1] ]Register Worker["Call@Worker", "rhope", 1, 2] //We're using 2 because we need to assume that the outputs are conditional ]Register Number Methods @@ -1416,13 +1491,13 @@ ]Input Types <<[ [()]Append[Type Instance["Any Type"]]] ]Outputs <<[("type")] ]Output Types <<[ [()]Append[Type Instance["Blueprint"]]] - ]Builtin? <<[Yes]] - ]Bind Worker["Call@Worker", - [[[[[NWorker["rhope"] - ]Inputs <<[("worker")] - ]Input Types <<[ [()]Append[Type Instance["Worker"]] ] - ]Outputs <<[("ret1","ret2")] - ]Output Types <<[ [[()]Append[Type Instance["Any Type"]]]Append[Type Instance["Any Type"]] ] + ]Builtin? <<[Yes]] + ]Bind Worker["Call@Worker", + [[[[[NWorker["rhope"] + ]Inputs <<[("worker")] + ]Input Types <<[ [()]Append[Type Instance["Worker"]] ] + ]Outputs <<[("ret1","ret2")] + ]Output Types <<[ [[()]Append[Type Instance["Any Type"]]]Append[Type Instance["Any Type"]] ] ]Builtin? << [Yes]] } diff -r dbe95bfec970 -r 2e2e55fc12f9 parser_old.rhope --- a/parser_old.rhope Thu Jul 22 05:39:08 2010 +0000 +++ b/parser_old.rhope Tue Jul 27 15:23:32 2010 -0400 @@ -313,33 +313,16 @@ Add Multi Wire[worker,ref,junk,end index,input num:out] { - Print["Add Multi Wire"] - { Print[[ref]Index >>] - { Print[[ref]Output Number >>] - { Pretty Print[worker, ""] }}} out <- [worker]Add Wire[[ref]Index >>, [ref]Output Number >>, end index, input num] - { Print["Added wire"] } } Add Param Wire[worker,param,input num,end index,blocks,parse worker,assignments:out] { - Print[["Add Param Wire: "]Append[input num]] - { param worker, start index, output num <- [param]Add Wires[worker, blocks, parse worker, assignments] { Print["got param worker"] } { - Print[["got normal output for param: "]Append[input num]] - { - Print[["Start index: "]Append[start index]] - Print[["Output num: "]Append[output num]] - out <- [param worker]Add Wire[start index, output num, end index, input num] - { Print["Added param wire"] } - } }{}{ - Print["got multi output"] out <- Fold[[["Add Multi Wire"]Set Input[3, end index]]Set Input[4, input num], param worker, ~] - { Print["Added multi wire"] } - } } } @@ -409,22 +392,17 @@ Add Wires@Worker Node[node,worker,blocks,parse worker,assignments:worker,index,num,unused] { - Print[["Add Wires@Worker Node: "]Append[[node]Name >>]] - { worker,index,num <- Add Wires Worker or Field[node, worker, blocks, parse worker, assignments] - } } Add Wires Worker or Field[node,worker,blocks,parse worker,assignments:worker,index,num,unused] { Fold[[["Assignments Add Wires"]Set Input[3, parse worker]]Set Input[4, [node]Index >>], worker, [node]Assignments >>] { - Print["Assignments Add Wires done"] Fold[[[[["Add Block Wire"]Set Input[3, [node]Index >>]]Set Input[4, blocks]]Set Input[5, parse worker]]Set Input[6, assignments], ~, [node]Blocks >>] { - Print["Add Block Wire done"] params worker <- Fold[[[[["Add Param Wire"]Set Input[3, [node]Index >>]]Set Input[4, blocks]]Set Input[5, parse worker]]Set Input[6, assignments], ~, [node]Params >>] - { Print["Add Param Wire done"] + { index <- [node]Index >> num <- 0 } diff -r dbe95bfec970 -r 2e2e55fc12f9 runtime/fib.c --- a/runtime/fib.c Thu Jul 22 05:39:08 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,356 +0,0 @@ -#include -#include "builtin.h" -#include "object.h" -#include "context.h" -#include "func.h" -#include "integer.h" -#include "bool.h" - -typedef enum { - FUNC__LT_, - FUNC__LT__AT_Int32, - FUNC__MN_, - FUNC__MN__AT_Int32, - FUNC__PL_, - FUNC__PL__AT_Int32, - FUNC_Fib, - FUNC_Fib_1, - FUNC_Fib_2, - FUNC_Fib_3, - FUNC_Fib_4, - FUNC_Fib_5, - FUNC_Fib_6, - FUNC_If, - FUNC_If_AT_Yes_SP_No, - FUNC_Main, - FUNC_Main_1, - FUNC_Main_2, - FUNC_Print, - END -} funcids; - -#define DISPATCH switch(func) { \ - case FUNC__LT_: goto f__LT_;\ - case FUNC__LT__AT_Int32: goto f__LT__AT_Int32;\ - case FUNC__MN_: goto f__MN_;\ - case FUNC__MN__AT_Int32: goto f__MN__AT_Int32;\ - case FUNC__PL_: goto f__PL_;\ - case FUNC__PL__AT_Int32: goto f__PL__AT_Int32;\ - case FUNC_Fib: goto f_Fib;\ - case FUNC_Fib_1: goto r1_Fib;\ - case FUNC_Fib_2: goto r2_Fib;\ - case FUNC_Fib_3: goto r3_Fib;\ - case FUNC_Fib_4: goto r4_Fib;\ - case FUNC_Fib_5: goto r5_Fib;\ - case FUNC_Fib_6: goto r6_Fib;\ - case FUNC_If: goto f_If;\ - case FUNC_If_AT_Yes_SP_No: goto f_If_AT_Yes_SP_No;\ - case FUNC_Main: goto f_Main;\ - case FUNC_Main_1: goto r1_Main;\ - case FUNC_Main_2: goto r2_Main;\ - case FUNC_Print: goto f_Print;\ - case END: goto DO_END;\ -} - - -typedef struct { - struct object *____result__0__0; - struct object *____result__0__1; - struct object *____result__10__0; - struct object *____result__11__0; - struct object *____result__1__0; - struct object *____result__5__0; - struct object *____result__6__0; - struct object *____result__7__0; - struct object *out; -} lt_Fib; - -typedef struct { - struct object *____result__0__0; - struct object *____result__1__0; -} lt_Main; - -object * _const_Whole_SP_Number__1; -object * _const_Whole_SP_Number__2; -object * _const_Whole_SP_Number__30; - -void rhope(uint32_t func) -{ - uint16_t resume,idx; - context * ct; - calldata * cdata, *temp_cdata; -FuncDef(Fib) -FuncDef(Main) - - ct = new_context(); - cdata = alloc_cdata(ct, NULL, 0); - cdata->num_params = 0; - cdata->func = END; -DISPATCH -Method(_LT_) - MethodDispatch(TYPE_INT32,_LT_,Int32) -EndMethod - -MethodImplNoLocals(_LT_,Int32,TYPE_INT32, - NumParams 2) - - Param(1, TYPE_INT32) - - if(((t_Int32 *)cdata->params[0])->num < ((t_Int32 *)cdata->params[-1])->num) - { - release_ref(cdata->params[0]); - Ret(0, Yes) - } else { - release_ref(cdata->params[0]); - Ret(0, No) - } - - release_ref(cdata->params[-1]); -EndFuncNoLocals -DISPATCH - -Method(_MN_) - MethodDispatch(TYPE_INT32,_MN_,Int32) -EndMethod -DISPATCH - -MethodImplNoLocals(_MN_,Int32,TYPE_INT32, - NumParams 2) - - Param(1, TYPE_INT32) - - cdata->params[0] = copy_object(cdata->params[0]); - ((t_Int32 *)cdata->params[0])->num -= ((t_Int32 *)cdata->params[-1])->num; - - release_ref(cdata->params[-1]); -EndFuncNoLocals -DISPATCH - -Method(_PL_) - MethodDispatch(TYPE_INT32,_PL_,Int32) -EndMethod -DISPATCH - -MethodImplNoLocals(_PL_,Int32,TYPE_INT32, - NumParams 2) - - Param(1, TYPE_INT32) - - cdata->params[0] = copy_object(cdata->params[0]); - ((t_Int32 *)cdata->params[0])->num += ((t_Int32 *)cdata->params[-1])->num; - - release_ref(cdata->params[-1]); -EndFuncNoLocals -DISPATCH - -Func(Fib, - NumParams 1) - lv_Fib->____result__0__0 = NULL; - lv_Fib->____result__0__1 = NULL; - lv_Fib->____result__1__0 = NULL; - lv_Fib->____result__5__0 = NULL; - lv_Fib->____result__6__0 = NULL; - lv_Fib->____result__7__0 = NULL; - lv_Fib->____result__10__0 = NULL; - lv_Fib->____result__11__0 = NULL; - lv_Fib->out = NULL; - - PrepCall(2) - - SetParam(0, add_ref(cdata->lastframe->params[0])) - SetParam(1, add_ref(_const_Whole_SP_Number__2)) - Call(_LT_, - NumParams 2, 1, Fib) - lv_Fib->____result__1__0 = cdata->params[0]; - - SetParam(0, add_ref(lv_Fib->____result__1__0)) - Call(If, - NumParams 1, 2, Fib) - lv_Fib->____result__0__0 = cdata->params[0]; - lv_Fib->____result__0__1 = cdata->params[-1]; - - if(lv_Fib->____result__0__1) - { - SetParam(0, add_ref(cdata->lastframe->params[0])) - SetParam(1, add_ref(_const_Whole_SP_Number__1)) - Call(_MN_, - NumParams 2, 3, Fib) - lv_Fib->____result__7__0 = cdata->params[0]; - } - if(lv_Fib->____result__0__1) - { - SetParam(0, add_ref(cdata->lastframe->params[0])) - SetParam(1, add_ref(_const_Whole_SP_Number__2)) - Call(_MN_, - NumParams 2, 4, Fib) - lv_Fib->____result__11__0 = cdata->params[0]; - } - if(lv_Fib->____result__0__0) - { - lv_Fib->out = add_ref(_const_Whole_SP_Number__1); - } - if(lv_Fib->____result__0__1) - { - SetParam(0, add_ref(lv_Fib->____result__7__0)) - Call(Fib, - NumParams 1, 5, Fib) - lv_Fib->____result__6__0 = cdata->params[0]; - } - if(lv_Fib->____result__0__1) - { - SetParam(0, add_ref(lv_Fib->____result__11__0)) - Call(Fib, - NumParams 1, 6, Fib) - lv_Fib->____result__10__0 = cdata->params[0]; - } - if(lv_Fib->____result__0__1) - { - if(lv_Fib->____result__0__0) - { - release_ref(lv_Fib->____result__0__0); - } - if(lv_Fib->____result__0__1) - { - release_ref(lv_Fib->____result__0__1); - } - if(lv_Fib->____result__1__0) - { - release_ref(lv_Fib->____result__1__0); - } - if(lv_Fib->____result__7__0) - { - release_ref(lv_Fib->____result__7__0); - } - if(lv_Fib->____result__11__0) - { - release_ref(lv_Fib->____result__11__0); - } - TPrepCall(2) - SetParam(0, lv_Fib->____result__6__0) - SetParam(1, lv_Fib->____result__10__0) - TCall(_PL_, - NumParams 2) - //lv_Fib->____result__5__0 = cdata->params[0]; - } - FreeCall - if(lv_Fib->____result__0__1) - { - lv_Fib->out = add_ref(lv_Fib->____result__5__0); - } - if(lv_Fib->____result__0__0) - { - release_ref(lv_Fib->____result__0__0); - } - if(lv_Fib->____result__0__1) - { - release_ref(lv_Fib->____result__0__1); - } - if(lv_Fib->____result__1__0) - { - release_ref(lv_Fib->____result__1__0); - } - if(lv_Fib->____result__5__0) - { - release_ref(lv_Fib->____result__5__0); - } - if(lv_Fib->____result__6__0) - { - release_ref(lv_Fib->____result__6__0); - } - if(lv_Fib->____result__7__0) - { - release_ref(lv_Fib->____result__7__0); - } - if(lv_Fib->____result__10__0) - { - release_ref(lv_Fib->____result__10__0); - } - if(lv_Fib->____result__11__0) - { - release_ref(lv_Fib->____result__11__0); - } - release_ref(cdata->params[0]); - Ret(0, lv_Fib->out) -EndFunc(Fib) -DISPATCH - -Method(If) - MethodDispatch(TYPE_BOOLEAN,If,Yes_SP_No) -EndMethod - -MethodImplNoLocals(If,Yes_SP_No,TYPE_BOOLEAN, - NumParams 1) - - if(((t_Boolean *)(cdata->params[0]))->val) - { - Ret(1, NULL) - } else { - Ret(1, cdata->params[0]); - Ret(0, NULL) - } -EndFuncNoLocals -DISPATCH - -Func(Main, - NumParams 0) - - lv_Main->____result__0__0 = NULL; - lv_Main->____result__1__0 = NULL; - - PrepCall(1) - SetParam(0, add_ref(_const_Whole_SP_Number__30)) - Call(Fib, - NumParams 1, 1, Main) - lv_Main->____result__1__0 = cdata->params[0]; - FreeCall - - PrepCall(1) - SetParam(0, add_ref(lv_Main->____result__1__0)) - Call(Print, - NumParams 1, 2, Main) - lv_Main->____result__0__0 = cdata->params[0]; - FreeCall - - if(lv_Main->____result__0__0) - { - release_ref(lv_Main->____result__0__0); - } - if(lv_Main->____result__1__0) - { - release_ref(lv_Main->____result__1__0); - } -EndFunc(Main) -DISPATCH - -FuncNoLocals(Print, - NumParams 1) - - if(get_blueprint(cdata->params[0])->type_id == TYPE_INT32) - { - printf("%d\n", ((t_Int32 *)(cdata->params[0]))->num); - } else { - puts("Don't know how to print this type"); - } - release_ref(cdata->params[0]); - Ret(0, make_Int32(0)) -EndFuncNoLocals -DISPATCH - -DO_END: - return; - -_exception: - puts("whoops, exception!"); -} - -int main(int argc, char ** argv) -{ - register_builtin_types(); - - _const_Whole_SP_Number__1 = make_Int32(1); - _const_Whole_SP_Number__2 = make_Int32(2); - _const_Whole_SP_Number__30 = make_Int32(30); - - rhope(FUNC_Main); - return 0; -} diff -r dbe95bfec970 -r 2e2e55fc12f9 testfilewrite.rhope --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/testfilewrite.rhope Tue Jul 27 15:23:32 2010 -0400 @@ -0,0 +1,8 @@ + +Main[] +{ + Truncate[File["testwrite.txt"]] + { Close[[~]Write[ [Flatten["The quick brown fox jumped over the lazy dog.\n"]]Buffer >> ]] } + { Print["Error truncating file"] } +} +