Mercurial > repos > rhope
changeset 48:a24eb366195c
Fixed some bugs introduced in previous commit and moved definition of integer methods out of runtime and into the compiler
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 02 Mar 2010 00:18:49 -0500 |
parents | 6202b866d72c |
children | 3e20ed8959c4 |
files | backendutils.rhope cbackend.rhope extendlib.rhope kernel.rhope number.rhope nworker.rhope parser_old.rhope runtime/block_alloc.h runtime/bool.c runtime/bool.h runtime/builtin.c runtime/fixed_alloc.c runtime/fixed_alloc.h runtime/func.h runtime/integer.c runtime/integer.h runtime/plat_types.h |
diffstat | 17 files changed, 390 insertions(+), 324 deletions(-) [+] |
line wrap: on
line diff
--- a/backendutils.rhope Tue Dec 22 01:22:09 2009 -0500 +++ b/backendutils.rhope Tue Mar 02 00:18:49 2010 -0500 @@ -1,18 +1,21 @@ Escape Rhope Name NU[name:escaped] { - escaped <- [[[[[[[[[[[[name]Replace["@","_AT_"] - ]Replace[" ","_SP_"] - ]Replace[":","_CN_"] - ]Replace["?","_QN_"] - ]Replace["+","_PL_"] - ]Replace["-","_MN_"] - ]Replace["*","_TM_"] - ]Replace["/","_DV_"] - ]Replace["<","_LT_"] - ]Replace[">","_GT_"] - ]Replace["(","_LP_"] - ]Replace[")","_RP_"] + escaped <- [[[[[[[[[[[[[[[name]Replace["_","UN_"] + ]Replace["@","AT_"] + ]Replace[" ","SP_"] + ]Replace[":","CN_"] + ]Replace["?","QN_"] + ]Replace["+","PL_"] + ]Replace["-","MN_"] + ]Replace["*","TM_"] + ]Replace["/","DV_"] + ]Replace["<","LT_"] + ]Replace[">","GT_"] + ]Replace["(","LP_"] + ]Replace[")","RP_"] + ]Replace["!","NT_"] + ]Replace["=","EQ_"] } Escape Rhope Name[name:escaped]
--- a/cbackend.rhope Tue Dec 22 01:22:09 2009 -0500 +++ b/cbackend.rhope Tue Mar 02 00:18:49 2010 -0500 @@ -1,5 +1,6 @@ Import extendlib.rhope -Import backendutils.rhope +Import backendutils.rhope +Import number.rhope Blueprint Blueprint Def { @@ -11,7 +12,7 @@ Blueprint Def[name] { - out <- [[[[Build["Blueprint Def"]]Name <<[name]]Fixed Size <<[0]]Fields <<[()]]Methods <<[New@Dictionary[]] + out <- [[[[Build["Blueprint Def"]]Name <<[name]]Fixed Size <<[0]]Fields <<[()]]Methods <<[Dictionary[]] } Blueprint C Method Registry @@ -22,7 +23,7 @@ C Method Registry[:out] { - builtins <- [[[[[[[[[[[[[New@Dictionary[] + builtins <- [[[[[[[[[[[[[Dictionary[] ]Set["+", "METHOD_ADD"] ]Set["-", "METHOD_SUB"] ]Set["/", "METHOD_DIV"] @@ -65,7 +66,7 @@ C Field Registry[:out] { - out <- [[Build["C Field Registry"]]Lookup <<[New@Dictionary[]]]Next ID<<[1] + out <- [[Build["C Field Registry"]]Lookup <<[Dictionary[]]]Next ID<<[1] } @@ -280,7 +281,7 @@ C Type Registry[:out] { out <- [[[Build["C Type Registry"]]Lookup << [ - [[[[[[[[[[[[[[[[New@Dictionary[] + [[[[[[[[[[[[[[[[Dictionary[] ]Set["UInt8", "TYPE_UINT8"] ]Set["UInt16", "TYPE_UINT16"] ]Set["UInt32", "TYPE_UINT32"] @@ -289,7 +290,7 @@ ]Set["Int16", "TYPE_INT16"] ]Set["Int32", "TYPE_INT32"] ]Set["Int64", "TYPE_INT64"] - ]Set["Yes No", "TYPE_BOOLEAN"] + ]Set["Boolean", "TYPE_BOOLEAN"] ]Set["Float32", "TYPE_FLOAT32"] ]Set["Float64", "TYPE_FLOAT64"] ]Set["Real Number", "TYPE_FLOAT64"] @@ -297,7 +298,7 @@ ]Set["Method Missing Exception", "TYPE_METHODMISSINGEXCEPTION"] ]Set["Field Missing Exception", "TYPE_FIELDMISSINGEXCEPTION"] ]Set["Wrong Type Exception", "TYPE_WRONGTYPEEXCEPTION"]] - ]Definitions << [New@Dictionary[]] + ]Definitions << [Dictionary[]] ]Next ID <<[0] } @@ -325,8 +326,14 @@ { name <- [def]Name >> [[reg]Lookup >>]Index[name] - { - out <- reg + { + [[reg]Definitions >>]Index[name] + { + out <- reg + }{ + Print[["Registered def for "]Append[name]] + out <- [reg]Definitions <<[[[reg]Definitions >>]Set[name, def]] + } }{ out <- [[[reg]Lookup <<[ [[reg]Lookup >>]Set[name, ["TYPE_FIRST_USER+"]Append[[reg]Next ID >>]] ] ]Definitions <<[ [[reg]Definitions >>]Set[name, def] ] @@ -346,6 +353,8 @@ { Print["found type"] yep,nope <- If[[[[~]Fields >>]Length] = [1]] + }{ + Pretty Print[reg, ""] } } @@ -377,12 +386,12 @@ ]Inputs <<[inputs] ]Outputs <<[outputs] ]Convention <<[convention] - ]Variables <<[New@Dictionary[]] + ]Variables <<[Dictionary[]] ]Statements <<[()] ]Method Registry <<[registry] ]Field Registry <<[field reg] ]Type Registry <<[type reg] - ]Constants <<[New@Dictionary[]] + ]Constants <<[Dictionary[]] ]Input Types <<[ Fold[["Append"]Set Input[1, "Any Type"], (), inputs] ] ]Output Types <<[ Fold[["Append"]Set Input[1, "Any Type"], (), outputs] ] } @@ -447,6 +456,46 @@ Divide@C Function[func,source1,source2,dest:out] { out <- [func]Add Operator Statement[source1,source2,dest," / "] +} + +DoLShift@C Function[func,source1,source2,dest:out] +{ + out <- [func]Add Operator Statement[source1,source2,dest," << "] +} + +DoRShift@C Function[func,source1,source2,dest:out] +{ + out <- [func]Add Operator Statement[source1,source2,dest," >> "] +} + +CompLess@C Function[func,source1,source2,dest:out] +{ + out <- [func]Add Operator Statement[source1,source2,dest," < "] +} + +CompGreater@C Function[func,source1,source2,dest:out] +{ + out <- [func]Add Operator Statement[source1,source2,dest," > "] +} + +CompEqual@C Function[func,source1,source2,dest:out] +{ + out <- [func]Add Operator Statement[source1,source2,dest," == "] +} + +CompLessEqual@C Function[func,source1,source2,dest:out] +{ + out <- [func]Add Operator Statement[source1,source2,dest," <= "] +} + +CompGreaterEqual@C Function[func,source1,source2,dest:out] +{ + out <- [func]Add Operator Statement[source1,source2,dest," >= "] +} + +CompNotEqual@C Function[func,source1,source2,dest:out] +{ + out <- [func]Add Operator Statement[source1,source2,dest," != "] } Move@C Function[func,psource,pdest:out] @@ -497,9 +546,14 @@ type <- [[func]Input Types >>]Index[~] }{ type <- [[func]Variables >>]Index[var] {} - { - //Does it make sense for us to do this? - type <- Type Instance["Any Type"] + { + [[func]Outputs >>]Find[var] + { + type <- [[func]Output Types >>]Index[~] + }{ + //Does it make sense for us to do this? + type <- Type Instance["Any Type"] + } } } }{ @@ -832,7 +886,7 @@ C Program[:out] { - out <- [[[[Build["C Program"]]Functions <<[New@Dictionary[]]]Method Registry <<[C Method Registry[]]]Type Registry <<[C Type Registry[]]]Field Registry <<[C Field Registry[]] + out <- [[[[Build["C Program"]]Functions <<[Dictionary[]]]Method Registry <<[C Method Registry[]]]Type Registry <<[C Type Registry[]]]Field Registry <<[C Field Registry[]] } Register Type@C Program[program,def:out] @@ -918,7 +972,7 @@ Text@C Program[program:out] { Print["Text@C Program"] - constants <- Fold["Combine Consts", New@Dictionary[], [program]Functions >>] + constants <- Fold["Combine Consts", Dictionary[], [program]Functions >>] headers <- "#include <stdio.h> #include \"builtin.h\" #include \"object.h\" @@ -934,7 +988,7 @@ Fold["_Defs C Program", "", [program]Functions >>], constants ], [program]Functions >>]] - ]Append["int main(int argc, char **argv) + ]Append["#include \"builtin.c\"\n\nint main(int argc, char **argv) { returntype ret; calldata *cdata;
--- a/extendlib.rhope Tue Dec 22 01:22:09 2009 -0500 +++ b/extendlib.rhope Tue Mar 02 00:18:49 2010 -0500 @@ -30,6 +30,32 @@ } } +_SMap[list,index,worker:out] +{ + newval <- [ + [worker]Do[ + [()]Append[ [list]Index[index] ] + ] + ]Index[0] + + [list]Next[index] + { + out <- _SMap[[list]Set[index, newval], ~, worker] + }{ + out <- [list]Set[index, newval] + } +} + +SMap[list,worker:out] +{ + [list]First + { + out <- _SMap[list, ~, worker] + }{ + out <- list + } +} + _Key Value Map[list,index,newlist,worker:out] { [worker]Do[
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kernel.rhope Tue Mar 02 00:18:49 2010 -0500 @@ -0,0 +1,67 @@ + +Blueprint Boolean +{ + Val(Int32,Naked) +} + +Blueprint Int32 +{ + Num(Int32,Naked) +} + +If@Int32[num:yes,no] +{ + yes,no <- If[[num]=[0]] +} + +Blueprint Int16 +{ + Num(Int16,Naked) +} + +If@Int16[num:yes,no] +{ + yes,no <- If[[num]=[0]] +} + +Blueprint Int8 +{ + Num(Int8,Naked) +} + +If@Int8[num:yes,no] +{ + yes,no <- If[[num]=[0]] +} + +Blueprint UInt32 +{ + Num(UInt32,Naked) +} + +If@UInt32[num:yes,no] +{ + yes,no <- If[[num]=[0]] +} + +Blueprint UInt16 +{ + Num(UInt16,Naked) +} + +If@UInt16[num:yes,no] +{ + yes,no <- If[[num]=[0]] +} + +Blueprint UInt8 +{ + Num(UInt8,Naked) +} + +If@UInt8[num:yes,no] +{ + yes,no <- If[[num]=[0]] +} + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/number.rhope Tue Mar 02 00:18:49 2010 -0500 @@ -0,0 +1,109 @@ + + +Compile Number Method[backend, op, type:out] +{ + name <- [[[op]Index[0]]Append["@"]]Append[type] + backend func <- [op]Index[1] + type inst <- Type Instance[type] + func <- [[[[backend]Create Function[name,("a","b"), ("out"), "rhope"] + ]Set Input Type[type inst, 0] + ]Set Input Type[type inst, 1] + ]Set Output Type[type inst, 0] + + ,ina <- [[func]Copy["a"] + ]Read Field["a", "Num"] + { ,inb <- [~]Read Field["b", "Num"] + { ,outa <- [~]Write Field["a", "Num"] + { after op <- [ + [backend func]Do[ + [ + [ + [ + [()]Append[~] + ]Append[ina] + ]Append[inb] + ]Append[outa] ] + ]Index[0] }}} + + out <- [backend]Store Function[ [[after op]Move["a","out"]]Release["b"] ] + +} + +Compile Number Comp Method[backend, op, type:out] +{ + name <- [ [ [op]Index[0] ]Append["@"] ]Append[type] + backend func <- [op]Index[1] + type inst <- Type Instance[type] + func <- [[[[[[ [backend]Create Function[name,("a","b"), ("out"), "rhope"] + ]Set Input Type[type inst, 0] + ]Set Input Type[type inst, 1] + ]Set Output Type[Type Instance["Boolean"], 0] + ]Register Constant["Blueprint_Boolean", Type Instance["Boolean"]] + ]Call["Build", [()]Append[Constant["Blueprint_Boolean"]]] + ]Move[Result[0], "out"] + + ,ina <- [func]Read Field["a", "Num"] + { ,inb <- [~]Read Field["b", "Num"] + { ,outa <- [~]Write Field["out", "Val"] + { after op <- [ + [backend func]Do[ + [ + [ + [ + [()]Append[~] + ]Append[ina] + ]Append[inb] + ]Append[outa] ] + ]Index[0] }}} + + out <- [backend]Store Function[ [[after op]Release["a"]]Release["b"] ] + +} + +_Generate Number Methods[backend, type:out] +{ + opmap <- (("+", "Add"), ("-", "Sub"), ("*", "Multiply"), ("/", "Divide"), ("LShift", "DoLShift"), ("RShift", "DoRShift")) + compops <- (("<", "CompLess"), (">", "CompGreater"), ("=", "CompEqual"), ("<=", "CompLessEqual"), (">=", "CompGreaterEqual"), ("!=", "CompNotEqual")) + + Fold[["Compile Number Method"]Set Input[2, type], backend, opmap] + { out <- Fold[["Compile Number Comp Method"]Set Input[2, type], ~, compops] } +} + +Generate Number Methods[backend:out] +{ + numtypes <- ("Int8","Int16","Int32","UInt8","UInt16","UInt32") + + out <- Fold["_Generate Number Methods", backend, numtypes] +} + +Register Number Method[program, method, type, outtype:out] +{ + name <- [[method]Append["@"]]Append[type] + Print[["Regsiter Number Method: "]Append[name]] + out <- [[program]Register Worker[name, "rhope", 2, 1] + ]Bind Worker[name, + [[[[[NWorker["rhope"] + ]Inputs <<[("left","right")] + ]Input Types <<[ [[()]Append[ Type Instance[type]]]Append[Type Instance[type]] ] + ]Outputs <<[("out")] + ]Output Types <<[ [()]Append[Type Instance[outtype]] ] + ]Builtin? <<[Yes] + ] +} + +_Register Number Methods[program,type:out] +{ + Print[["_Regsiter Number Methods: "]Append[type]] + methods <- ("+", "-", "*", "/", "LShift", "RShift") + compmethods <- ("<", ">", "=", "<=", ">=", "!=") + register <- ["Register Number Method"]Set Input[2, type] + Fold[[register]Set Input[3, type], program, methods] + { out <- Fold[[register]Set Input[3, "Boolean"], ~, compmethods] } +} + +Register Number Methods[program:out] +{ + numtypes <- ("Int8","Int16","Int32","UInt8","UInt16","UInt32") + out <- Fold["_Register Number Methods", program, numtypes] +} +
--- a/nworker.rhope Tue Dec 22 01:22:09 2009 -0500 +++ b/nworker.rhope Tue Mar 02 00:18:49 2010 -0500 @@ -11,12 +11,12 @@ AndSet[:out] { - out <- [[[Build["Condition Set"]]Variables <<[New@Dictionary[]]]Subsets <<[New@Dictionary[]]]Condition Type <<["And"] + out <- [[[Build["Condition Set"]]Variables <<[Dictionary[]]]Subsets <<[Dictionary[]]]Condition Type <<["And"] } OrSet[:out] { - out <- [[[Build["Condition Set"]]Variables <<[New@Dictionary[]]]Subsets <<[New@Dictionary[]]]Condition Type <<["Or"] + out <- [[[Build["Condition Set"]]Variables <<[Dictionary[]]]Subsets <<[Dictionary[]]]Condition Type <<["Or"] } To String@Condition Set[set:out] @@ -345,10 +345,8 @@ new type <- Val[type] new count <- 1 } - new node <- [node]Input Types <<[ - [[()]Append[ - [ [node]Input Types >> ]Set[ [dest]IO Num >>, new type ] - ]]Append[new count] + new node <- [node]Input Types <<[ + [ [node]Input Types >> ]Set[ [dest]IO Num >>, [[()]Append[new type]]Append[new count] ] ] out <- Infer Types Node[[nodelist]Set[[dest]Index >>, new node], new node, [dest]Index >>, prog, worker] } @@ -454,8 +452,10 @@ } Infer Types@NWorker[worker,prog:out] -{ - out <- [worker]Nodes <<[Fold[[["Infer Types Node"]Set Input[3, prog]]Set Input[4, worker], [worker]Nodes >>, [worker]Nodes >>]] +{ + Print[["Start inference: "]Append[[worker]Name >>]] + out <- [worker]Nodes <<[Fold[[["Infer Types Node"]Set Input[3, prog]]Set Input[4, worker], [worker]Nodes >>, [worker]Nodes >>]] + { Print[["End inference: "]Append[[worker]Name >>]] } } Add Worker Call@NWorker[worker,tocall:out,node index] @@ -924,7 +924,7 @@ NBlueprint[:out] { - out <- [[Build["NBlueprint"]]Fields <<[()]]Methods <<[New@Dictionary[]] + out <- [[Build["NBlueprint"]]Fields <<[()]]Methods <<[Dictionary[]] } Add Field@NBlueprint[bp,name,type:out] @@ -1033,7 +1033,8 @@ { getter <- [[start getter]Do AddRef[getref, "out"]]Release["obj"] }{ - getter <- [[start getter]Box[getref, "out", type]]Release["obj"] + getter <- [[start getter]Box[getref, "out", type]]Release["obj"] + { Print["Got getter"] } } begin setter <- [[[[[backend]Create Function[ [[[name]Append[" <<"]]Append["@"]]Append[type name], ("obj","newval"), ("out"), "rhope"] @@ -1060,7 +1061,8 @@ ,setref <- [begin setter]Write Field["obj", name] { setter <- [[~]Unbox["newval", setref] - ]Move["obj", "out"] + ]Move["obj", "out"] + { Print ["got setter"] } } } @@ -1106,7 +1108,7 @@ NProgram[:out] { - out <- [[[Build["NProgram"]]Blueprints <<[New@Dictionary[]]]Workers <<[New@Dictionary[]]]Worker Refs <<[New@Dictionary[]] + out <- [[[Build["NProgram"]]Blueprints <<[Dictionary[]]]Workers <<[Dictionary[]]]Worker Refs <<[Dictionary[]] } Bind Worker@NProgram[prog,name,worker:out] @@ -1138,13 +1140,18 @@ } _Compile Program[backend, worker, name:out] -{ +{ + Print["_Compile Program"] out <- [worker]Compile Worker[backend, name] } Compile Program@NProgram[prog, backend:out] -{ - out <- Fold["_Compile Program", Fold["_Compile Program BP Special", Fold["_Compile Program BP", backend, [prog]Blueprints >>], [prog]Blueprints >>], Map[[prog]Workers >>, ["Infer Types"]Set Input[1, prog]] ] +{ + backend with bps <- Generate Number Methods[Fold["_Compile Program BP Special", Fold["_Compile Program BP", backend, [prog]Blueprints >>], [prog]Blueprints >>]] + { Print["All blueprints added"] } + workers with infer <- SMap[[prog]Workers >>, ["Infer Types"]Set Input[1, prog]] + { Print["Type inference complete"] } + out <- Fold["_Compile Program", backend with bps, workers with infer] } Register Method@NProgram[prog, name, convention, inputs, outputs: out] @@ -1171,77 +1178,12 @@ Register Builtins@NProgram[prog:out] { - registered <- [[[[[[[[[[[prog]Register Worker["+@Int32", "rhope", 2, 1] - ]Register Worker["-@Int32", "rhope", 2, 1] - ]Register Worker["*@Int32", "rhope", 2, 1] - ]Register Worker["/@Int32", "rhope", 2, 1] - ]Register Worker["LShift@Int32", "rhope", 2, 1] - ]Register Worker["RShift@Int32", "rhope", 2, 1] - ]Register Worker["Print", "rhope", 1, 1] + registered <- [[[[prog]Register Worker["Print", "rhope", 1, 1] ]Register Worker["If@Boolean", "rhope", 1, 2] - ]Register Worker["<@Int32", "rhope", 2, 1] - ]Register Worker[">@Int32", "rhope", 2, 1] - ]Register Worker["Build", "rhope", 1, 1] + ]Register Worker["Build", "rhope", 1, 1] + ]Register Number Methods - out <- [[[[[[[[[[[[[registered]Bind Blueprint["Int32", NBlueprint[]] - ]Bind Worker["+@Int32", - [[[[[NWorker["rhope"] - ]Inputs <<[("left","right")] - ]Input Types <<[ [[()]Append[ Type Instance["Int32"]]]Append[Type Instance["Int32"]] ] - ]Outputs <<[("out")] - ]Output Types <<[ [()]Append[Type Instance["Int32"]] ] - ]Builtin? <<[Yes]] - ]Bind Worker["-@Int32", - [[[[[NWorker["rhope"] - ]Inputs <<[("left","right")] - ]Input Types <<[ [[()]Append[ Type Instance["Int32"]]]Append[Type Instance["Int32"]] ] - ]Outputs <<[("out")] - ]Output Types <<[ [()]Append[Type Instance["Int32"]] ] - ]Builtin? <<[Yes]] - ]Bind Worker["*@Int32", - [[[[[NWorker["rhope"] - ]Inputs <<[("left","right")] - ]Input Types <<[ [[()]Append[ Type Instance["Int32"]]]Append[Type Instance["Int32"]] ] - ]Outputs <<[("out")] - ]Output Types <<[ [()]Append[Type Instance["Int32"]] ] - ]Builtin? <<[Yes]] - ]Bind Worker["/@Int32", - [[[[[NWorker["rhope"] - ]Inputs <<[("left","right")] - ]Input Types <<[ [[()]Append[ Type Instance["Int32"]]]Append[Type Instance["Int32"]] ] - ]Outputs <<[("out")] - ]Output Types <<[ [()]Append[Type Instance["Int32"]] ] - ]Builtin? <<[Yes]] - ]Bind Worker["LShift@Int32", - [[[[[NWorker["rhope"] - ]Inputs <<[("left","right")] - ]Input Types <<[ [[()]Append[ Type Instance["Int32"]]]Append[Type Instance["Int32"]] ] - ]Outputs <<[("out")] - ]Output Types <<[ [()]Append[Type Instance["Int32"]] ] - ]Builtin? <<[Yes]] - ]Bind Worker["RShift@Int32", - [[[[[NWorker["rhope"] - ]Inputs <<[("left","right")] - ]Input Types <<[ [[()]Append[ Type Instance["Int32"]]]Append[Type Instance["Int32"]] ] - ]Outputs <<[("out")] - ]Output Types <<[ [()]Append[Type Instance["Int32"]] ] - ]Builtin? <<[Yes]] - ]Bind Worker["<@Int32", - [[[[[NWorker["rhope"] - ]Inputs <<[("left","right")] - ]Input Types <<[ [[()]Append[ Type Instance["Int32"]]]Append[Type Instance["Int32"]] ] - ]Outputs <<[("out")] - ]Output Types <<[ [()]Append[Type Instance["Int32"]] ] - ]Builtin? <<[Yes]] - ]Bind Worker[">@Int32", - [[[[[NWorker["rhope"] - ]Inputs <<[("left","right")] - ]Input Types <<[ [[()]Append[ Type Instance["Int32"]]]Append[Type Instance["Int32"]] ] - ]Outputs <<[("out")] - ]Output Types <<[ [()]Append[Type Instance["Int32"]] ] - ]Builtin? <<[Yes]] - ]Bind Blueprint["Boolean", NBlueprint[]] - ]Bind Worker["If@Boolean", + out <- [[[registered]Bind Worker["If@Boolean", [[[[[NWorker["rhope"] ]Inputs <<[("condition")] ]Input Types <<[ [()]Append[Type Instance["Boolean"]] ]
--- a/parser_old.rhope Tue Dec 22 01:22:09 2009 -0500 +++ b/parser_old.rhope Tue Mar 02 00:18:49 2010 -0500 @@ -67,7 +67,7 @@ ]Global Separator <<["::"] ]Hex Escape <<["x"] ]Uses <<["uses"] - ]Escape Map <<[[[[New@Dictionary[]]Set["n","\n"]]Set["r","\r"]]Set["t","\t"]] + ]Escape Map <<[[[[Dictionary[]]Set["n","\n"]]Set["r","\r"]]Set["t","\t"]] } Blueprint Output Reference @@ -85,7 +85,7 @@ { reflist <- [refs]Index[name] {} { - reflist <- New@List[] + reflist <- () } out <- [refs]Set[name, [reflist]Append[reference]] } @@ -111,9 +111,9 @@ New@Parse Program[:out] { out <- [[[Build["Parse Program"] - ]Workers <<[New@Dictionary[]] - ]Imports <<[New@Dictionary[]] - ]Blueprints <<[New@Dictionary[]] + ]Workers <<[Dictionary[]] + ]Imports <<[[Dictionary[]]Set["kernel.rhope", Yes]] + ]Blueprints <<[Dictionary[]] } Blueprint Blueprint Definition @@ -141,7 +141,7 @@ New@Parse Worker[name,inputs,outputs,intypes,outtypes,line:out] { - out <- [[[[[[[[Build["Parse Worker"]]Name <<[name]]Inputs <<[inputs]]Outputs <<[outputs]]Line Number <<[line]]Trees <<[New@List[]]]Uses Stores <<[New@List[]]]Input Types <<[intypes]]Output Types <<[outtypes] + out <- [[[[[[[[Build["Parse Worker"]]Name <<[name]]Inputs <<[inputs]]Outputs <<[outputs]]Line Number <<[line]]Trees <<[()]]Uses Stores <<[()]]Input Types <<[intypes]]Output Types <<[outtypes] } Blueprint Worker Node @@ -155,7 +155,7 @@ New@Worker Node[name,params:out] { - out <- [[[[Build["Worker Node"]]Name <<[name]]Params <<[params]]Assignments <<[New@List[]]]Blocks <<[New@List[]] + out <- [[[[Build["Worker Node"]]Name <<[name]]Params <<[params]]Assignments <<[()]]Blocks <<[()] } Add List Helper[inlist,worker,program,key,parse worker,refs:out list,out worker,out refs] @@ -417,7 +417,7 @@ New@Field Node[name,params,set:out] { - out <- [[[[[Build["Field Node"]]Name <<[name]]Assignments <<[New@List[]]]Blocks <<[New@List[]]]Set? <<[set]]Params <<[params] + out <- [[[[[Build["Field Node"]]Name <<[name]]Assignments <<[()]]Blocks <<[()]]Set? <<[set]]Params <<[params] } Add to Worker@Field Node[node,worker,program,parse worker,refs:out node,out worker,out refs] @@ -474,7 +474,7 @@ New@Named Pipe Node[name:out] { - out <- [[[Build["Named Pipe Node"]]Name <<[name]]Assignments <<[New@List[]]]Blocks <<[New@List[]] + out <- [[[Build["Named Pipe Node"]]Name <<[name]]Assignments <<[()]]Blocks <<[()] } Add to Worker@Named Pipe Node[node,worker,program,parse worker,refs:out node,out worker,out refs] @@ -551,7 +551,7 @@ New@Global Node[store,name:out] { - out <- [[[[Build["Global Node"]]Store <<[store]]Name <<[name]]Assignments <<[New@List[]]]Blocks <<[New@List[]] + out <- [[[[Build["Global Node"]]Store <<[store]]Name <<[name]]Assignments <<[()]]Blocks <<[()] } Add to Worker@Global Node[node,worker,unused,parse worker,refs:out node,out worker,refs] @@ -589,7 +589,7 @@ New@Literal Node[value:out] { - out <- [[[Build["Literal Node"]]Value <<[value]]Assignments <<[New@List[]]]Blocks <<[New@List[]] + out <- [[[Build["Literal Node"]]Value <<[value]]Assignments <<[()]]Blocks <<[()] } Add to Worker@Literal Node[node,worker,unused,parse worker,refs:out node,out worker,out refs] @@ -706,7 +706,7 @@ { If[[block count] > [0]] { - after, before <- [string]Get DString[[[New@List[]]Append[begin comment]]Append[end comment]] {} {} + after, before <- [string]Get DString[[[()]Append[begin comment]]Append[end comment]] {} {} { If[[~] = [begin comment]] { @@ -804,7 +804,7 @@ { body lines <- [body]Split["\n"] more lines <- [[[body lines]Length] - [1]] + [name lines] - fields <- Fold[["Process Blueprint Field"]Set Input[2, params], New@List[], Filter[Map[body lines, ["Trim"]Set Input[1,"\n\r\t "]], "Filter Empty"]] + fields <- Fold[["Process Blueprint Field"]Set Input[2, params], (), Filter[Map[body lines, ["Trim"]Set Input[1,"\n\r\t "]], "Filter Empty"]] new tree <- [tree]Blueprints << [ [[tree]Blueprints >>]Set[name, New@Blueprint Definition[name, fields]] ] out <- Null[~, params, new tree, [lines] + [more lines]] } {} { @@ -837,7 +837,7 @@ If[[check block]Starts With[[params]Block Begin >>]] { ,begin block <- [check block]Slice[[[params]Block Begin >>]Length] - trees, after block <- Worker Body[begin block, params, New@List[]] + trees, after block <- Worker Body[begin block, params, ()] blocks, after <- Get Expression Blocks[after block, params, [blocks]Append[trees]] }{ If[[check block]Starts With[[params]Empty Block >>]] @@ -869,7 +869,7 @@ Parse String[string,params,current:value,after] { - delims <- [[New@List[]]Append[[params]String End >>]]Append[[params]String Escape >>] + delims <- [[()]Append[[params]String End >>]]Append[[params]String Escape >>] afters, before, delim <- [string]Get Comment DString[delims, params] { If[[delim] = [[params]String End >>]] @@ -952,7 +952,7 @@ If[[name]Starts With[[params]List Begin >>]] { ,list start <- [name]Slice[[[params]List Begin >>]Length] - value,after <- Parse List[list start, params, New@List[]] + value,after <- Parse List[list start, params, ()] }{ If[[[name]Slice[1]]In["-0123456789"]] { @@ -1055,7 +1055,7 @@ Postfix or Infix[string,params:expression,after] { - args, after args <- Parse Arguments[string, params, New@List[]] + args, after args <- Parse Arguments[string, params, ()] delims <- [[[[[("\n")]Append[[params]Arg Begin >>]]Append[[params]Empty Block >>]]Append[[params]Block Begin >>]]Append[[params]Arg End >>]]Append[[params]List Delim >>] aftere,before,delim <- [after args]Get Comment DString[delims, params] { @@ -1093,7 +1093,7 @@ after expression <- [after literal]Append[[delim]Append[after]] expression, after literal <- Named Pipe or Literal[Right Trim[before, "\r\n\t "], params] }{ - expression, after expression <- Prefix[after, params, maybe name, New@List[]] + expression, after expression <- Prefix[after, params, maybe name, ()] } } }{ @@ -1125,7 +1125,7 @@ } //Any expression can be followed by one or more blocks mapping the inputs of other expressions //to the outputs of the current one - blocks,after blocks <- Get Expression Blocks[after expression, params, New@List[]] + blocks,after blocks <- Get Expression Blocks[after expression, params, ()] final expression <- [expression]Blocks <<[blocks] } } @@ -1236,7 +1236,7 @@ Print[["Parsing worker: "]Append[worker name]] in out <- [params]In Out Delim >> arg end <- [params]Arg End >> - delims <- [[New@List[]]Append[in out]]Append[arg end] + delims <- [[()]Append[in out]]Append[arg end] after <- [~]Get Comment DString[delims, params] {} { arglist <- Trim[~,"\r\n\t "] @@ -1268,7 +1268,7 @@ Print["Got parse worker"] body text, modifiers <- [after arglist]Get Comment DString[[params]Block Begin >>, params] modified <- Process Modifiers[~, params, modifiers] - expression trees, after body <- Worker Body[body text, params, New@List[]] + expression trees, after body <- Worker Body[body text, params, ()] worker <- [modified]Trees <<[expression trees] new worker dict <- [[tree]Workers >>]Set[worker name, worker] out <- Null[after body, params, [tree]Workers <<[new worker dict], 0] @@ -1318,7 +1318,7 @@ { Print[["Add Workers Compile: "]Append[name]] { - trees, nworker, refs <- Add List to Worker[[worker]Trees >>, [NWorker["rhope"]]Uses[[worker]Uses Stores >>], prog, worker, New@Dictionary[]] + trees, nworker, refs <- Add List to Worker[[worker]Trees >>, [NWorker["rhope"]]Uses[[worker]Uses Stores >>], prog, worker, Dictionary[]] final nworker <- Fold[[["Add Wires Helper"]Set Input[3, worker]]Set Input[4, refs], nworker, trees] out <- [prog]Bind Worker[name, final nworker] } @@ -1328,7 +1328,7 @@ { Print["Add Wires Helper"] { - out <- [node]Add Wires[worker, New@List[], parse worker, assignments] + out <- [node]Add Wires[worker, (), parse worker, assignments] { Print["Add Wires Helper Done"] } } } @@ -1337,7 +1337,7 @@ { Print[["Add Contents: "]Append[name]] worker <- [[program]Find Worker[name]]Uses[[parse worker]Uses Stores >>] - trees, contents worker, refs <- Add List to Worker[[parse worker]Trees >>, worker, program, parse worker, New@Dictionary[]] + trees, contents worker, refs <- Add List to Worker[[parse worker]Trees >>, worker, program, parse worker, Dictionary[]] Fold[[["Add Wires Helper"]Set Input[3, parse worker]]Set Input[4, refs], contents worker, trees] out <- [parse worker]Trees <<[trees] key <- name @@ -1380,13 +1380,13 @@ Tree to Program[parse tree:out] { Print["Tree to Program"] - out <- _Tree to Program[parse tree, [New@Program[]]Add Builtins] + out <- _Tree to Program[parse tree, [Program[]]Add Builtins] { Print["done"] } } Tree to Program Native[parse tree:out] { - registered <- Fold["Register Workers Compile", Fold["Add Blueprint Compile", [NProgram[]]Register Builtins, [parse tree]Blueprints >>], [parse tree]Workers >>] + registered <- Fold["Register Workers Compile", [Fold["Add Blueprint Compile", NProgram[], [parse tree]Blueprints >>]]Register Builtins, [parse tree]Workers >>] out <- Fold["Add Workers Compile", registered, [parse tree]Workers >>] { Print["Transformed AST to dataflow graph "] } } @@ -1411,7 +1411,7 @@ Process Imports[parse tree,params:out] { - needs import <- Fold["Needs Imports", New@List[], [parse tree]Imports >>] + needs import <- Fold["Needs Imports", (), [parse tree]Imports >>] If[[[needs import]Length] > [0]] { import tree <- Fold[["Do Import"]Set Input[3, params], parse tree, needs import] @@ -1476,16 +1476,16 @@ } }{ Print["Expression"] - trees <- Worker Body[[line]Append["}"], params, New@List[]] + trees <- Worker Body[[line]Append["}"], params, ()] { Print["Parse done"] } - tree <- [New@Worker Node["Val", [New@List[]]Append[[trees]Index[0]]]]Assignments <<[("__out")] + tree <- [New@Worker Node["Val", [()]Append[[trees]Index[0]]]]Assignments <<[("__out")] { Print["Constructed new tree"] } - this stores <- [[tree]Gather Stores[params, New@Dictionary[]]]Keys + this stores <- [[tree]Gather Stores[params, Dictionary[]]]Keys { Print["Got stores"] } next stores <- Fold["_Init Used Store", stores, this stores] { Print["Initialized stores"] - pworker <- [[New@Parse Worker["__Eval", New@List[], ("__out"), 0]]Trees <<[[New@List[]]Append[tree]]]Uses Stores <<[this stores] + pworker <- [[New@Parse Worker["__Eval", (), ("__out"), 0]]Trees <<[[()]Append[tree]]]Uses Stores <<[this stores] { Print["Constructed parse worker"] } } [[prog]Find Worker["__Eval"]]Clear @@ -1494,7 +1494,7 @@ Add Contents[pworker, "__Eval", prog] { Print["Added Contents"] - Pretty Print[[[[prog]Find Worker["__Eval"]]Do[New@List[]]]Index[0], ""] + Pretty Print[[[[prog]Find Worker["__Eval"]]Do[()]]Index[0], ""] { Print["Finished executeion"] _REPL[params, prog, next stores] } } } @@ -1506,7 +1506,7 @@ { Print["Rhope Alpha 2\nCopyright 2008 by Michael Pavone\nEntering interactive mode\n"] prog <- Tree to Program[Null["Val[in:out]\n{\n out <- in\n}\n__Eval[:__out]\n{\n}\n", params, New@Parse Program[], 0]] - _REPL[params, prog, New@Dictionary[]] + _REPL[params, prog, Dictionary[]] } Add If Store[stores,name,params:out]
--- a/runtime/block_alloc.h Tue Dec 22 01:22:09 2009 -0500 +++ b/runtime/block_alloc.h Tue Mar 02 00:18:49 2010 -0500 @@ -6,7 +6,14 @@ #include <windows.h> #define block_alloc(size) VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); -#define block_free(block,size) VirtualFree(block, size, MEM_RELEASE) +#define block_free(block,size) VirtualFree(block, size, MEM_RELEASE) + +#else +#define BLOCK_SIZE 1024*8 +#include <sys/mman.h> + +#define block_alloc(size) mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0) +#define block_free(block,size) munmap(block, size) #endif
--- a/runtime/bool.c Tue Dec 22 01:22:09 2009 -0500 +++ b/runtime/bool.c Tue Mar 02 00:18:49 2010 -0500 @@ -4,21 +4,4 @@ #include "context.h" #include <stddef.h> -t_Boolean * val_yes; -t_Boolean * val_no; -#define lval ((t_Boolean *)(cdata->params[0]))->val -MethodNoLocals(If,Boolean, - NumParams 1, - CallSpace 1) - - Param(0, TYPE_BOOLEAN) - - if(lval) - { - Ret(1, NULL) - } else { - Ret(1, cdata->params[0]); - Ret(0, NULL) - } -EndFunc
--- a/runtime/bool.h Tue Dec 22 01:22:09 2009 -0500 +++ b/runtime/bool.h Tue Mar 02 00:18:49 2010 -0500 @@ -2,13 +2,6 @@ #define BOOL_H_ #include "object.h" -Box(int32_t,val,Boolean) - -#define Yes add_ref((object *)val_yes) -#define No add_ref((object *)val_no) - -extern t_Boolean * val_yes; -extern t_Boolean * val_no; MethodDef(If,Boolean)
--- a/runtime/builtin.c Tue Dec 22 01:22:09 2009 -0500 +++ b/runtime/builtin.c Tue Mar 02 00:18:49 2010 -0500 @@ -10,25 +10,6 @@ blueprint * bp; switch(type) { - case TYPE_INT32: - bp = register_type_byid(TYPE_INT32, sizeof(int32_t), NULL, NULL, NULL); - add_method(bp, METHOD_ADD, MethodName(_PL_,Int32)); - add_method(bp, METHOD_SUB, MethodName(_MN_,Int32)); - add_method(bp, METHOD_MUL, MethodName(_TM_,Int32)); - add_method(bp, METHOD_DIV, MethodName(_DV_,Int32)); - add_method(bp, METHOD_LSHIFT, MethodName(LShift,Int32)); - add_method(bp, METHOD_RSHIFT, MethodName(RShift,Int32)); - add_method(bp, METHOD_LESS, MethodName(_LT_,Int32)); - add_method(bp, METHOD_GREATER, MethodName(_GT_,Int32)); - break; - case TYPE_BOOLEAN: - bp = register_type_byid(TYPE_BOOLEAN, sizeof(int32_t), NULL, NULL, NULL); - add_method(bp, METHOD_IF, MethodName(If,Boolean)); - val_yes = (t_Boolean *)new_object(TYPE_BOOLEAN); - val_yes->val = 1; - val_no = (t_Boolean *)new_object(TYPE_BOOLEAN); - val_no->val = 0; - break; case TYPE_BLUEPRINT: bp = register_type_byid(TYPE_BLUEPRINT, sizeof(blueprint *), NULL, NULL, NULL); break; @@ -49,10 +30,37 @@ if(get_blueprint(cdata->params[0]) == get_blueprint_byid(TYPE_INT32)) { - printf("%d\n", ((t_Int32 *)(cdata->params[0]))->num); + 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)) EndFunc +object * make_Int32(int32_t val) +{ + t_Int32 * obj; + object * ret = new_object(TYPE_INT32); + obj = (t_Int32 *)ret; + obj->Num = val; + return ret; +} + +#define lval ((t_Boolean *)(cdata->params[0]))->Val + +MethodNoLocals(If,Boolean, + NumParams 1, + CallSpace 1) + + Param(0, TYPE_BOOLEAN) + + if(lval) + { + Ret(1, NULL) + } else { + Ret(1, cdata->params[0]); + Ret(0, NULL) + } +EndFunc + +
--- a/runtime/fixed_alloc.c Tue Dec 22 01:22:09 2009 -0500 +++ b/runtime/fixed_alloc.c Tue Mar 02 00:18:49 2010 -0500 @@ -1,5 +1,6 @@ #include "fixed_alloc.h" -#include <stdlib.h> +#include <stdlib.h> +#include <string.h> uint16_t max_free[(MAX_SIZE-MIN_SIZE)/STRIDE];
--- a/runtime/fixed_alloc.h Tue Dec 22 01:22:09 2009 -0500 +++ b/runtime/fixed_alloc.h Tue Mar 02 00:18:49 2010 -0500 @@ -5,7 +5,7 @@ #include "plat_types.h" #include "block_alloc.h" -#define GET_BLOCK(ptr) ((void*)(((uint32_t)(ptr))&(~(BLOCK_SIZE-1)))) +#define GET_BLOCK(ptr) ((void*)(((uintptr_t)(ptr))&(~((uintptr_t)(BLOCK_SIZE-1))))) #define MAX_SIZE (BLOCK_SIZE/32) #define STRIDE (BLOCK_SIZE/1024)
--- a/runtime/func.h Tue Dec 22 01:22:09 2009 -0500 +++ b/runtime/func.h Tue Mar 02 00:18:49 2010 -0500 @@ -13,7 +13,7 @@ typedef returntype (*rhope_func)(struct calldata *); typedef void (*special_func) (struct object *); -#define MethodName(name,type) f_ ## name ## _AT_ ## type +#define MethodName(name,type) f_ ## name ## AT_ ## type #define Func(name,numparams,callspace,localtype) \ returntype f_ ## name (calldata * cdata)\ @@ -201,4 +201,4 @@ return TAIL_RETURN; -#endif //_FUNC_H_ \ No newline at end of file +#endif //_FUNC_H_
--- a/runtime/integer.c Tue Dec 22 01:22:09 2009 -0500 +++ b/runtime/integer.c Tue Mar 02 00:18:49 2010 -0500 @@ -3,122 +3,4 @@ #include "context.h" #include "bool.h" -#define left ((t_Int32 *)cdata->params[0]) -#define right ((t_Int32 *)cdata->params[1]) -MethodNoLocals(_PL_,Int32, - NumParams 2, - CallSpace 1) - - CopiedParam(0, TYPE_INT32) - Param(1, TYPE_INT32) - - left->num += right->num; - - release_ref((object *)right); -EndFunc - -MethodNoLocals(_MN_,Int32, - NumParams 2, - CallSpace 1) - - CopiedParam(0, TYPE_INT32) - Param(1, TYPE_INT32) - - left->num -= right->num; - - release_ref((object *)right); -EndFunc - -MethodNoLocals(_TM_,Int32, - NumParams 2, - CallSpace 1) - - CopiedParam(0, TYPE_INT32) - Param(1, TYPE_INT32) - - left->num *= right->num; - - release_ref((object *)right); -EndFunc - -MethodNoLocals(_DV_,Int32, - NumParams 2, - CallSpace 1) - - CopiedParam(0, TYPE_INT32) - Param(1, TYPE_INT32) - - left->num /= right->num; - - release_ref((object *)right); -EndFunc - -MethodNoLocals(LShift,Int32, - NumParams 2, - CallSpace 1) - - CopiedParam(0, TYPE_INT32) - Param(1, TYPE_INT32) - - left->num <<= right->num; - - release_ref((object *)right); -EndFunc - -MethodNoLocals(RShift,Int32, - NumParams 2, - CallSpace 1) - - CopiedParam(0, TYPE_INT32) - Param(1, TYPE_INT32) - - left->num <<= right->num; - - release_ref((object *)right); -EndFunc - -MethodNoLocals(_LT_,Int32, - NumParams 2, - CallSpace 1) - - Param(0, TYPE_INT32) - Param(1, TYPE_INT32) - - if(left->num < right->num) - { - release_ref(cdata->params[0]); - Ret(0, Yes) - } else { - release_ref(cdata->params[0]); - Ret(0, No) - } - release_ref(cdata->params[1]); -EndFunc - -MethodNoLocals(_GT_,Int32, - NumParams 2, - CallSpace 1) - - Param(0, TYPE_INT32) - Param(1, TYPE_INT32) - - if(left->num > right->num) - { - release_ref(cdata->params[0]); - Ret(0, Yes) - } else { - release_ref(cdata->params[0]); - Ret(0, No) - } - release_ref(cdata->params[1]); -EndFunc - -object * make_Int32(int32_t val) -{ - t_Int32 * obj; - object * ret = new_object(TYPE_INT32); - obj = (t_Int32 *)ret; - obj->num = val; - return ret; -}
--- a/runtime/integer.h Tue Dec 22 01:22:09 2009 -0500 +++ b/runtime/integer.h Tue Mar 02 00:18:49 2010 -0500 @@ -4,16 +4,6 @@ #include "object.h" #include "func.h" -Box(int32_t,num,Int32) - -MethodDef(_PL_,Int32) -MethodDef(_MN_,Int32) -MethodDef(_TM_,Int32) -MethodDef(_DV_,Int32) -MethodDef(LShift,Int32) -MethodDef(RShift,Int32) -MethodDef(_LT_,Int32) -MethodDef(_GT_,Int32) object * make_Int32(int32_t val);
--- a/runtime/plat_types.h Tue Dec 22 01:22:09 2009 -0500 +++ b/runtime/plat_types.h Tue Mar 02 00:18:49 2010 -0500 @@ -10,7 +10,8 @@ typedef unsigned char uint8_t; typedef unsigned short uint16_t; typedef unsigned int uint32_t; -typedef unsigned long long uint64_t; +typedef unsigned long long uint64_t; +typedef unsigned int uintptr_t; #else #include <stdint.h>