Mercurial > repos > rhope
view cbackend.rhope @ 12:31f8182f3433
Finished fib test and did some small work on the c backend
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 25 May 2009 23:34:36 -0400 |
parents | 73e978d590c7 |
children | 69dfca29565f |
line wrap: on
line source
Import extendlib.rhope Import backendutils.rhope Blueprint Blueprint Def { Name Fixed Size Fields Methods } Blueprint Def[name] { out <- [[[[Build["Blueprint Def"]]Name <<[name]]Fixed Size <<[0]]Fields <<[()]]Methods <<[New@Dictionary[]] } Blueprint C Function { Name Inputs Outputs Convention Variables Statements } C Function[name,inputs,outputs,convention:out] { out <- [[[[[[Build["C Function"] ]Name <<[name] ]Inputs <<[inputs] ]Outputs <<[outputs] ]Convention <<[convention] ]Variables <<[New@Dictionary[]] ]Statements <<[()] } Allocate Var@C Function[func,name,type:out] { out <- [func]Variables <<[ [[func]Variables >>]Set[name,type] ] } Add Statement@C Function[func,statement:out] { out <- [func]Statements <<[ [[func]Statements >>]Append[["\t"]Append[[statement]Append[";\n"]]] ] } Add Operator Statement@C Function[func,source1,source2,dest,op:out] { out <- [func]Add Statement[[[[[dest]Append[" = "]]Append[source1]]Append[op]]Append[source2]] } Add@C Function[func,source1,source2,dest:out] { out <- [func]Add Operator Statement[source1,source2,dest," + "] } Sub@C Function[func,source1,source2,dest:out] { out <- [func]Add Operator Statement[source1,source2,dest," - "] } Multiply@C Function[func,source1,source2,dest:out] { out <- [func]Add Operator Statement[source1,source2,dest," * "] } Divide@C Function[func,source1,source2,dest:out] { out <- [func]Add Operator Statement[source1,source2,dest," / "] } Move@C Function[func,source,dest:out] { out <- [func]Add Statement[[[dest]Append[" = "]]Append[source]] } Init Outputs@C Function[func] { If[[[[func]Outputs >>]Length ] > [0]] { out <- [["\tlocals->"]Append[ [[func]Outputs >>]Join[" = NULL;\n\tlocals->"] ]]Append[" = NULL;\n"] }{ out <- "" } } Release Inputs@C Function[func] { If[[[[func]Inputs >>]Length ] > [0]] { out <- [["\trelease_ref(->"]Append[ [[func]Outputs >>]Join[" = NULL;\n\tlocals->"] ]]Append[" = NULL;\n"] }{ out <- "" } } Definitions@C Function[func:out] { } Text@C Function[func:out] { cname <- Escape Rhope Name[[func]Name >>] out <- [[[[[[["Func(" ]Append[cname] ]Append[",\n\tNumParams "] ]Append[ [[func]Inputs >>]Length ] ]Append[",\n\tCallSpace 32,\n\t"]//TODO: Fill in with calculated callspace value ]Append[["l_"]Append[cname]] ]Append[")\n\n"] ]Append[[func]Init Outputs] }