# HG changeset patch # User Mike Pavone # Date 1273111943 14400 # Node ID 04baa003de5a0b3ab39bafbbf2598f327e150bb8 # Parent b218af069da7e89d86e7c18d67b238f07943d552# Parent 048046186d22b8e9438be6ed09ac3d87d94aee0c Merged latest changes with better C branch diff -r b218af069da7 -r 04baa003de5a backendutils.rhope --- a/backendutils.rhope Sat Oct 10 16:43:37 2009 -0400 +++ b/backendutils.rhope Wed May 05 22:12:23 2010 -0400 @@ -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] @@ -33,22 +36,62 @@ Make Op@AddRef[addref,func:out] { //TODO: Make me work with other backends - out <- [["add_ref("]Append[ [[addref]Value >>]Make Op[func] ]]Append[")"] + out <- [["add_ref((object *)"]Append[ [[addref]Value >>]Make Op[func] ]]Append[")"] +} + +Strip Addref@AddRef[op:out] +{ + out <- [[op]Value >>]Strip Addref } Make Op@String[string,func:out] { out <- [func]Resolve[string] +} + +Strip Addref@String[op:out] +{ + out <- op } Make Op@Whole Number[num,func:out] { out <- num +} + +Strip Addref@Whole Number[op:out] +{ + out <- op } Make Op@Real Number[num,func:out] { out <- num +} + +Strip Addref@Real Number[op:out] +{ + out <- op +} + +Blueprint Output +{ + Name +} + +Output[name:out] +{ + out <- [Build["Output"]]Name <<[name] +} + +Make Op@Output[op,func:out] +{ + out <- [func]Resolve Output[[op]Name >>] +} + +Strip Addref@Output[op:out] +{ + out <- op } Blueprint Constant @@ -64,6 +107,11 @@ Make Op@Constant[const,func:out] { out <- [func]Lookup Constant[[const]Value >>] +} + +Strip Addref@Constant[op:out] +{ + out <- op } Blueprint Result @@ -79,6 +127,21 @@ Make Op@Result[result,func:out] { out <- [func]Result Reference[[result]Output Num>>] +} + +Strip Addref@Result[op:out] +{ + out <- op +} + +Make Condition[op:out] +{ + If[[Type Of[op]]=["OrValue"]] + { + out <- OrCond[Make Condition[[op]Left >>], Make Condition[[op]Right >>]] + }{ + out <- op + } } Blueprint OrValue @@ -94,7 +157,12 @@ Make Op@OrValue[orval,func:out] { - out <- [func]If Null Else[[[func]Left >>]Make Op[func], [[func]Right >>]Make Op[func]] + out <- [func]If Null Else[[orval]Left >>, [orval]Right >>] +} + +Strip Addref@OrValue[op:out] +{ + out <- [[op]Left <<[ [[op]Left >>]Strip Addref ]]Right <<[ [[op]Right >>]Strip Addref ] } Blueprint NotCond @@ -104,12 +172,17 @@ NotCond[cond:out] { - out <- [Build["NotCond"]]Condition <<[cond] + out <- [Build["NotCond"]]Condition <<[[cond]Strip Addref] } Make Op@NotCond[cond,func:out] { out <- ["!"]Append[[[cond]Condition >>]Make Op[func]] +} + +Strip Addref@NotCond[op:out] +{ + out <- op } Blueprint OrCond @@ -120,12 +193,17 @@ OrCond[cond1,cond2:out] { - out <- [[Build["OrCond"]]Condition1 <<[cond1]]Condition2 <<[cond2] + out <- [[Build["OrCond"]]Condition1 <<[[cond1]Strip Addref]]Condition2 <<[[cond2]Strip Addref] } Make Op@OrCond[cond,func:out] { out <- ["("]Append[[[ [[cond]Condition1 >>]Make Op[func] ]Append[" || "]]Append[[ [[cond]Condition2 >>]Make Op[func] ]Append[")"]]] +} + +Strip Addref@OrCond[op:out] +{ + out <- op } Blueprint AndCond @@ -136,12 +214,17 @@ AndCond[cond1,cond2:out] { - out <- [[Build["AndCond"]]Condition1 <<[cond1]]Condition2 <<[cond2] + out <- [[Build["AndCond"]]Condition1 <<[[cond1]Strip Addref]]Condition2 <<[[cond2]Strip Addref] } Make Op@AndCond[cond,func:out] { out <- ["("]Append[[[ [[cond]Condition1 >>]Make Op[func] ]Append[" && "]]Append[[ [[cond]Condition2 >>]Make Op[func] ]Append[")"]]] +} + +Strip Addref@AndCond[op:out] +{ + out <- op } Blueprint Field Ref @@ -158,13 +241,19 @@ Make Op@Field Ref[ref,func:out] { out <- [func]Field Result[[ref]Variable >>,[ref]Field >>] +} + +Strip Addref@Field Ref[op:out] +{ + out <- op } Blueprint Type Instance { Name Params - Variant + Variant + Mutable? } Type Instance[raw name:out] @@ -175,10 +264,10 @@ }{ name <- raw name } - out <- [[[Build["Type Instance"]]Name <<[name]]Params <<[()]]Variant <<["Boxed"] + out <- [[[[Build["Type Instance"]]Name <<[name]]Params <<[()]]Variant <<["Boxed"]]Mutable? <<[No] } -Set Variant[type,variant:out,invalid] +Set Variant@Type Instance[type,variant:out,invalid] { [("Boxed","Naked","Pointer","Raw Pointer")]Find[variant] { @@ -187,3 +276,15 @@ invalid <- type } } + +=@Type Instance[type,compare:out] +{ + If[[Type Of[compare]] = ["String"]] + { + out <- [[type]Name >>] = [compare] + }{ + //TODO: Compare parameters + ,out <- If[[[type]Name >>] = [[compare]Name >>]] + { out <- [[type]Variant >>] = [[compare]Variant >>] } + } +} diff -r b218af069da7 -r 04baa003de5a basicweb.rhope --- a/basicweb.rhope Sat Oct 10 16:43:37 2009 -0400 +++ b/basicweb.rhope Wed May 05 22:12:23 2010 -0400 @@ -9,7 +9,7 @@ { Print["Starting webserver"] //Since we're just serving static files we don't need to setup any handlers - handlers <- New@Dictionary[] + handlers <- Dictionary[] //Start listening on port 80 Listen on Port[80,["Connection Start"]Set Input[1, handlers]] Wait Forever[] diff -r b218af069da7 -r 04baa003de5a cbackend.rhope --- a/cbackend.rhope Sat Oct 10 16:43:37 2009 -0400 +++ b/cbackend.rhope Wed May 05 22:12:23 2010 -0400 @@ -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] } @@ -136,7 +137,9 @@ If[[[type]Name >>] = ["Array"]] { [("Naked","Raw Pointer")]Find[variant] - { + { + /* + //Below code assumes that paramaterized types are implemented pre param <- [[type]Params >>]Index[0] {} { pre param <- Type Instance["Any Type"] } [[type]Params >>]Index[1] @@ -150,7 +153,9 @@ }{ out <- [child type]Append[" *"] array <- "" - } + } */ + out <- "void *" + array <- "" }{ typename <- "Array" } @@ -158,13 +163,13 @@ }{ ,regulartype <- [("Naked","Raw Pointer")]Find[variant] { - [("Int32","Int16","Int8")]Find[[type]Name >>] + [("Int64","Int32","Int16","Int8")]Find[[type]Name >>] { primitive <- Yes [[type]Name >>]Slice[3] {} { typename <- [["int"]Append[~]]Append["_t"] } }{ - ,regulartype <- [("UInt32","UInt16","UInt8")]Find[[type]Name >>] + ,regulartype <- [("UInt64","UInt32","UInt16","UInt8")]Find[[type]Name >>] { primitive <- Yes [[type]Name >>]Slice[4] {} @@ -230,7 +235,21 @@ Type Def@C Type[ctype:out] { - out <- [Fold["_Type Def C Type", "OBegin", [ctype]Fields >>]]Append[ [["\nObject("]Append[Escape Rhope Name[[ctype]Name >>]]]Append[")"] ] + If[[[[ctype]Fields >>]Length] = [1]] + { + out <- [[[_Type Def C Type["typedef struct {\n\tobject _SP_header;\n\t", [[ctype]Fields >>]Index[0]]]Append["\n} t_"]]Append[[ctype]Name >>]]Append[";"] + }{ + //HACK!!! + If[[[ctype]Name >>]=["Blueprint"]] + { + out <- "" + }{ + If[[[ctype]Name >>]=["Array"]] + { oend <- "\nMObject(" } + { oend <- "\nObject(" } + out <- [Fold["_Type Def C Type", "OBegin", [ctype]Fields >>]]Append[ [[oend]Append[Escape Rhope Name[[ctype]Name >>]]]Append[")"] ] + } + } } _Type Init C[type name,method reg,text,method:out] @@ -246,15 +265,37 @@ } Type Init@C Type[ctype,id,method reg,field reg:out] -{ +{ + If[[[ctype]Name >>]=["Array"]] + { size <- "-1" } + { + [("Int64","Int32","Int16","Int8")]Find[[ctype]Name >>] + { + [[ctype]Name >>]Slice[3] {} + { typename <- [["int"]Append[~]]Append["_t"] } + }{ + [("UInt64","UInt32","UInt16","UInt8")]Find[[ctype]Name >>] + { + [[ctype]Name >>]Slice[4] {} + { typename <- [["uint"]Append[~]]Append["_t"] } + }{ + If[[[ctype]Name >>]=["Blueprint"]] + { typename <- "blueprint *" } + { + If[[[ctype]Name >>]=["Boolean"]] + { typename <- "int32_t" } + { typename <- ["nt_"]Append[Escape Rhope Name[[ctype]Name >>]] } + } + } + } + size <- [["sizeof("]Append[typename]]Append[")"] + } start <- [["\tbp = register_type_byid(" ]Append[id] - ]Append[ - [[", sizeof(" + ]Append[ + [[", "]Append[size] ]Append[ - ["t_"]Append[Escape Rhope Name[ [ctype]Name >> ]]] - ]Append[ - ["), (special_func)"]Append[ + [", (special_func)"]Append[ [ [[[[Escape Rhope Name NU[[ctype]Init >>] ]Append[", (special_func)"] @@ -275,7 +316,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"] @@ -284,15 +325,16 @@ ]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"] + ]Set["Real Number", "TYPE_FLOAT64"] + ]Set["Blueprint", "TYPE_BLUEPRINT"] ]Set["Array", "TYPE_ARRAY"] ]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] } @@ -313,15 +355,22 @@ Type Inits@C Type Registry[reg,method reg,field reg:out] { - out <- Fold[[[["_Type Inits C"]Set Input[0, reg]]Set Input[1, method reg]]Set Input[2, field reg], "", [reg]Definitions >>] + out <- Fold[[[["_Type Inits C"]Set Input[0, reg]]Set Input[1, method reg]]Set Input[2, field reg], "", [reg]Definitions >>] + { Print["Type inits got output"] } } Register Type@C Type Registry[reg,def:out] { 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] ] @@ -331,7 +380,23 @@ Type ID@C Type Registry[reg,name:out,notfound] { - out,notfound <- [[reg]Lookup >>]Index[name] + out <- [[reg]Lookup >>]Index[name] {} + { + ,notfound <- If[[name]=["Any Type"]] + { out <- "0" } + } +} + +Simple Type?@C Type Registry[reg,name:yep,nope,notfound] +{ + Print[["Symple Type?: "]Append[name]] + ,notfound <- [[reg]Definitions >>]Index[name] + { + Print["found type"] + yep,nope <- If[[[[~]Fields >>]Length] = [1]] + }{ + Pretty Print[reg, ""] + } } Blueprint C Function @@ -352,22 +417,22 @@ C Function[name,inputs,outputs,convention:out] { - out <- C Function With Registry[name,inputs,outputs,convention, C Method Registry[], C Field Registry[]] + out <- C Function With Registry[name,inputs,outputs,convention, C Method Registry[], C Field Registry[], C Type Registry[]] } -C Function With Registry[name,inputs,outputs,convention,registry,field reg:out] +C Function With Registry[name,inputs,outputs,convention,registry,field reg,type reg:out] { out <- [[[[[[[[[[[[Build["C Function"] ]Name <<[name] ]Inputs <<[inputs] ]Outputs <<[outputs] ]Convention <<[convention] - ]Variables <<[New@Dictionary[]] + ]Variables <<[Dictionary[]] ]Statements <<[()] ]Method Registry <<[registry] ]Field Registry <<[field reg] - ]Type Registry <<[C Type Registry[]] - ]Constants <<[New@Dictionary[]] + ]Type Registry <<[type reg] + ]Constants <<[Dictionary[]] ]Input Types <<[ Fold[["Append"]Set Input[1, "Any Type"], (), inputs] ] ]Output Types <<[ Fold[["Append"]Set Input[1, "Any Type"], (), outputs] ] } @@ -432,6 +497,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] @@ -445,18 +550,19 @@ { source <- [psource]Make Op[func] dest <- [pdest]Make Op[func] - out <- [func]Add Statement[[[[dest]Append[" = add_ref("]]Append[source]]Append[")"]] + out <- [func]Add Statement[[[[dest]Append[" = add_ref((object *)"]]Append[source]]Append[")"]] } AddRef No Dest@C Function[func,psource:out] { source <- [psource]Make Op[func] - out <- [func]Add Statement[[["add_ref("]Append[source]]Append[")"]] + out <- [func]Add Statement[[["add_ref((object *)"]Append[source]]Append[")"]] } Release@C Function[func,psource:out] { - source <- [psource]Make Op[func] + source <- [psource]Make Op[func] + Print[["Release: "]Append[source]] out <- [func]Add Statement[[["release_ref("]Append[source]]Append[")"]] } @@ -475,24 +581,42 @@ Field Result@C Function[func,var,field:out] { as op <- [var]Make Op[func] - If[[[Type Of[var]] = ["String"]] And[ [[func]Convention >>] = ["rhope"]] ] + If[[Type Of[var]] = ["String"]] { [[func]Inputs >>]Find[var] { type <- [[func]Input Types >>]Index[~] - If[[type] = ["Any Type"]] - { - rvar <- Val[as op] - }{ - rvar <- [[[["(("]Append[ Rhope Type to C[type] ]]Append[")("]]Append[as op]]Append["))"] + }{ + type <- [[func]Variables >>]Index[var] {} + { + [[func]Outputs >>]Find[var] + { + type <- [[func]Output Types >>]Index[~] + }{ + //Does it make sense for us to do this? + type <- Type Instance["Any Type"] + } } + } + }{ + type <- Type Instance["Any Type"] + } + If[[[func]Convention >>] = ["rhope"]] + { + If[[type] = ["Any Type"]] + { + rvar <- Val[as op] }{ - rvar <- Val[as op] + rvar <- [[[["(("]Append[ Rhope Type to C[type] ]]Append[")("]]Append[as op]]Append["))"] } }{ rvar <- Val[as op] } - out <- [[rvar]Append["->"]]Append[Escape Rhope Name[field]] + + [[func]Type Registry >>]Simple Type?[[type]Name >>] + { access <- "->" } + { access <- "->payload." } + out <- [[rvar]Append[access]]Append[Escape Rhope Name[field]] } Read Field@C Function[func,var,field:out,result op] @@ -509,6 +633,7 @@ Set Field Null@C Function[func,var,field:out] { + Print["Set Field Null"] out <- [func]Add Statement[ [[func]Field Result[var,field]]Append[" = NULL"] ] } @@ -518,7 +643,7 @@ out <- [func]Add Statement[ [dest]Append[[[" = copy_object("]Append[dest]]Append[")"]] ] } -Box@C Function[func,pdest,psource,type:out] +Box@C Function[func,psource,pdest,type:out] { dest <- [pdest]Make Op[func] source <- [psource]Make Op[func] @@ -531,7 +656,7 @@ ]Append[")"] ] } -Unbox@C Function[func,pdest,psource:out] +Unbox@C Function[func,psource,pdest:out] { dest <- [pdest]Make Op[func] source <- [psource]Make Op[func] @@ -541,7 +666,21 @@ ]Append[", &"] ]Append[dest] ]Append[")"] ] -} +} + +Get Raw Pointer@C Function[func,psource,pdest:out] +{ + dest <- [pdest]Make Op[func] + source <- [psource]Make Op[func] + out <- [func]Add Statement[ [[[dest]Append[" = &("]]Append[source]]Append["->payload)"] ] +} + +Array Raw Pointer@C Function[func,psource,pdest:out] +{ + dest <- [pdest]Make Op[func] + source <- [psource]Make Op[func] + out <- [func]Add Statement[ [[[dest]Append[" = ((char *)"]]Append[source]]Append[")+ sizeof(t_Array)"] ] +} _Function Arg C[func,val,inputnum:out] { @@ -564,10 +703,29 @@ } Func Base@C Function[func,tocall,args,type:out] -{ +{ + Pretty Print[args, ""] + { rargs <- Map[args, ["Make Op"]Set Input[1, func]] out <- [Fold["_Function Arg C", func, rargs] - ]Add Raw Line[[[[[ [type]Append["("] ]Append[tocall]]Append[", "]]Append[ [rargs]Length ]]Append[")"]] + ]Add Raw Line[[[[[ [type]Append["("] ]Append[tocall]]Append[", "]]Append[ [rargs]Length ]]Append[")"]] + } +} + +Call Foreign@C Function[func,name,language,args,store result:out] +{ + rargs <- Map[args, ["Make Op"]Set Input[1, func]] + //Assume language = "C" for now + base <- [[[name]Append["("]]Append[ Join[rargs, ", "] ]]Append[")"] + ,do store <- If[[Type Of[store result]]=["String"]] + { + ,do store <- If[[store result]=[""]] + { stmt <- Val[base] } + } + + Val[do store] + { stmt <- [[Make Op[store result, func]]Append[" = "]]Append[base] } + out <- [func]Add Statement[stmt] } Field Base@C Function[func,field,args,type:out] @@ -610,6 +768,16 @@ }{ out <- Escape Rhope Name[op] } +} + +Resolve Output@C Function[func,name:out] +{ + If[[[func]Convention >>] = ["rhope"]] + { + out <- ["locals->"]Append[Escape Rhope Name[name]] + }{ + out <- Escape Rhope Name[name] + } } Instruction Stream@C Function[func:out] @@ -638,13 +806,16 @@ } If Null Else@C Function[func,left,right:out] -{ +{ + check <- [[Make Condition[left]]Strip Addref]Make Op[func] + l <- [left]Make Op[func] + r <- [right]Make Op[func] out <- [[[[[["(" - ]Append[left] + ]Append[check] ]Append[" ? "] - ]Append[left] + ]Append[l] ]Append[" : "] - ]Append[right] + ]Append[r] ]Append[")"] } @@ -669,16 +840,18 @@ } _Output Defs C[string,varname,index,func:out] { - out <- [[[string]Append[ ["\t"]Append[Rhope Type to C[[[func]Output Types >>]Index[index]]] ]]Append[Escape Rhope Name[varname]]]Append[";\n"] + out <- [[[string]Append[ ["\t"]Append[Rhope Type to C[[[func]Output Types >>]Index[index]]] ]]Append[[" "]Append[Escape Rhope Name[varname]]]]Append[";\n"] } _Var Defs C[string,type,varname:out] { - out <- [[[string]Append[ ["\t"]Append[Rhope Type to C[type]] ]]Append[Escape Rhope Name[varname]]]Append[";\n"] + out <- [[[string]Append[ ["\t"]Append[Rhope Type to C[type]] ]]Append[[" "]Append[Escape Rhope Name[varname]]]]Append[";\n"] } Definitions@C Function[func:out] -{ +{ + Print[["Definitions@C Function: "]Append[[func]Name >>]] + { If[ [[[func]Convention >>] = ["rhope"]] And [[ [[[func]Variables >>]Length]+[[[func]Outputs >>]Length] ] > [0]] ] { localtype <- [[[Fold[["_Output Defs C"]Set Input[3, func], Fold["_Var Defs C","typedef struct {\n", [func]Variables >>], [func]Outputs >>]]Append["} l_"]]Append[Escape Rhope Name[[func]Name >>]]]Append[";\n"] @@ -702,15 +875,13 @@ }{ proto <- [[func]Naked Proto]Append[";\n"] } - out <- [localtype]Append[proto] + out <- [localtype]Append[proto] + } } _Proto Input[list,input,index,types:out] { - Print[["_Proto Input: "]Append[input]] - { Print[[types]Index[index]] } out <- [list]Append[ [[Rhope Type to C[[types]Index[index]]]Append[" "]]Append[Escape Rhope Name[input]] ] - { Pretty Print[~, ""] } } Naked Proto@C Function[func:out] @@ -757,7 +928,8 @@ } Text@C Function[func:out] -{ +{ + Print[["Text@C Function: "]Append[[func]Name >>]] If[ [[func]Convention >>] = ["rhope"] ] { cname <- Escape Rhope Name[[func]Name >>] @@ -801,12 +973,25 @@ Functions Method Registry Field Registry - Type Registry + Type Registry + Libraries } 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[]]]Libraries <<[Dictionary[]] +} + +Link@C Program[program,language,library:out] +{ + If[[library] = ["runtime"]] + { + out <- program + }{ + langlibs <- [[program]Libraries >>]Index[language] {} + { langlibs <- Dictionary[] } + out <- [program]Libraries <<[ [[program]Libraries >>]Set[language, [langlibs]Set[library, Yes]] ] + } } Register Type@C Program[program,def:out] @@ -823,7 +1008,7 @@ Create Function@C Program[program,name,inputs,outputs,convention:out] { - out <- C Function With Registry[name,inputs,outputs,convention, [program]Method Registry >>, [program]Field Registry >>] + out <- C Function With Registry[name,inputs,outputs,convention, [program]Method Registry >>, [program]Field Registry >>, [program]Type Registry >>] } Store Function@C Program[program,func:out] @@ -863,52 +1048,82 @@ } _Set Consts C Program[text,value,name,type reg:out] -{ +{ + Print[["_Set Consts: "]Append[valtype]] + Pretty Print[value, "_Set Consts: "] //TODO: Support more constant types valtype <- Type Of[value] [("Int32","Whole Number")]Find[valtype] { - out <- [text]Append[[[[["\t_const_"]Append[Escape Rhope Name[name]]]Append[" = make_Int32("]]Append[value]]Append[");\n"]] + out <- [text]Append[[[[["\t_const_"]Append[Escape Rhope Name[name]]]Append[" = make_Int32("]]Append[value]]Append[");\n"]] + { Print["_Set Consts got output integer"] } }{ If[[valtype] = ["Type Instance"]] { //TODO: Support parametric types typeid <- [type reg]Type ID[[value]Name >>] - out <- [text]Append[[[[["\t_const_"]Append[Escape Rhope Name[name]]]Append[" = make_Blueprint("]]Append[typeid]]Append[");\n"]] + out <- [text]Append[[[[["\t_const_"]Append[Escape Rhope Name[name]]]Append[" = make_Blueprint("]]Append[typeid]]Append[");\n"]] + { Print["_Set Consts got output blueprint"] } }{ If[[valtype] = ["Yes No"]] { If[value] { - out <- [text]Append[[["\t_const_"]Append[Escape Rhope Name[name]]]Append[" = (object *)val_yes;\n"]] + out <- [text]Append[[["\t_const_"]Append[Escape Rhope Name[name]]]Append[" = (object *)val_yes;\n"]] + { Print["_Set Consts got output yes"] } }{ - out <- [text]Append[[["\t_const_"]Append[Escape Rhope Name[name]]]Append[" = (object *)val_no;\n"]] + out <- [text]Append[[["\t_const_"]Append[Escape Rhope Name[name]]]Append[" = (object *)val_no;\n"]] + { Print["_Set Consts got output no"] } } + }{ + If[[valtype] = ["Machine Integer"]] + { + If[[value]Signed? >>] + { s <- "I" } + { s <- "UI" } + + make <- [[[" = make_"]Append[s]]Append["nt"]]Append[[value]Size >>] + out <- [text]Append[ [[[[["\t_const_"]Append[Escape Rhope Name[name]]]Append[make]]Append["("]]Append[[value]Value >>]]Append[");\n"] ] + }{ + out <- text + } } } } +} + +_Set Late Consts C[text,value,name,type reg:out] +{ + valtype <- Type Of[value] + If[[valtype] = ["String"]] + { + out <- [text]Append[ [[[["\t_const_"]Append[Escape Rhope Name[name]]]Append[" = make_String(\""]]Append[ [[value]Replace["\n", "\\n"]]Replace["\\", "\\\\"]]]Append["\");\n"] ] + }{ + out <- text + } } 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 #include \"builtin.h\" #include \"object.h\" #include \"context.h\" #include \"func.h\" #include \"integer.h\" -#include \"blueprint.h\" +#include \"blueprint.h\" +#include \"array.h\" #include \"bool.h\"\n\n" - out <- [[[[[[headers + out <- [[[[[[[headers ]Append[[[program]Type Registry >>]Type Defs] ]Append[Fold[["_Text C Program"]Set Input[2, [program]Type Registry >>], Fold["_Consts C Program", Fold["_Defs C Program", "", [program]Functions >>], constants ], [program]Functions >>]] - ]Append["int main(int argc, char **argv) + ]Append["#include \"builtin.c\"\n#include \"array.c\"\n\nint main(int argc, char **argv) { returntype ret; calldata *cdata; @@ -916,7 +1131,8 @@ blueprint * bp; register_builtin_types();\n\n"] ]Append[ [[program]Type Registry >>]Type Inits[[program]Method Registry >>, [program]Field Registry >>] ] - ]Append[Fold[["_Set Consts C Program"]Set Input[3, [program]Type Registry >>], "", constants]] + ]Append[Fold[["_Set Consts C Program"]Set Input[3, [program]Type Registry >>], "", constants]] + ]Append[Fold[["_Set Late Consts C"]Set Input[3, [program]Type Registry >>], "", constants]] ]Append[" ct = new_context(); cdata = alloc_cdata(ct, 0); diff -r b218af069da7 -r 04baa003de5a compile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/compile Wed May 05 22:12:23 2010 -0400 @@ -0,0 +1,23 @@ +#!/bin/sh + +if test -f "$1.c"; then + rm "$1.c" +fi + +./rhope -t 1 parser_old.rhope $1 + +if test ! -f "$1.c"; then + echo "Compilation to C failed" + exit 1 +fi + +cp runtime/* build/ +cp "$1.c" build/ +cd build +bin=`echo $1 | sed s/\.rhope//` + +if test -f "$bin"; then + rm "$bin" +fi +gcc -Wformat=0 -o $bin $2 "$1.c" blueprint.c context.c fixed_alloc.c object.c + diff -r b218af069da7 -r 04baa003de5a date.rhope --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/date.rhope Wed May 05 22:12:23 2010 -0400 @@ -0,0 +1,241 @@ +//Note that the following code does not currently take into account leap seconds + +Days From Secs[secs:days,secs left] +{ + secs per day <- [[60]*[60]]*[24] + days <- [secs]/[secs per day] + secs left <- [secs]%[secs per day] +} + +//This doesn't take into account the mod 100 rule +Year From Unix Days[days:year,day in year] +{ + block days <- [[365]*[4]]+[1] + base year <- [1970]+[[[days]/[block days]]*[4]] + after base <- [days]%[block days] + If[[after base] > [365]] + { + year <- [[base year]+[1]]+[ [[after base]-[366]]/[365] ] + day in year <- [[after base]-[366]]%[365] + }{ + year <- Val[base year] + day in year <- Val[after base] + } +} + +Is Leap Year[year:is,is not] +{ + is <-If[[[year]%[400]]=[0]] {} + { + ,is not <- If[[[year]%[100]]=[0]] + { + is,is not <- If[[[year]%[4]]=[0]] + } + } +} + +_Month From Day[day,days,current:month,day in month] +{ + curdays <- [days]Index[current] + If[[day]<[curdays]] + { + month <- current + day in month <- day + }{ + month,day in month <- _Month From Day[[day]-[curdays], days, [current]+[1]] + } +} + +Month From Day[day,year:month,day in month] +{ + base <- (31,28,31,30,31,30,31,31,30,31,30,31) + Is Leap Year[year] + { + days <- [base]Set[1, 29] + }{ + days <- Val[base] + } + month,day in month <- _Month From Day[day, days, 0] +} + +Blueprint Date Time +{ + Long:Fifty Micros + Word:Year + Byte:Month + Byte:Day +} + +Date Time From Unix[unix:date] +{ + ,sec in day <- Days From Secs[unix] + { year <- Year From Unix Days[~] {} + { month, day <- Month From Day[~, year] }} + date <- [[[[Build["Date Time"]]Fifty Micros <<[[sec in day]*[20000]]]Year <<[year]]Month <<[[month]+[1]]]Day <<[[day]+[1]] +} + +Now[:date] +{ + date <- Date Time From Unix[Unix Time[]] +} + +Seconds@Date Time[date:out] +{ + out <- [[[date]Fifty Micros >>]/[20000]]%[60] +} + +Milliseconds@Date Time[date:out] +{ + out <- [[[date]Fifty Micros >>]/[20]]%[60000] +} + +Microseconds@Date Time[date:out] +{ + out <- [[[date]Fifty Micros >>]%[20]]*[50] +} + +Hours@Date Time[date:out] +{ + out <- [[date]Fifty Micros >>]/[[[20000]*[60]]*[60]] +} + +Minutes@Date Time[date:out] +{ + out <- [[[date]Fifty Micros >>]/[[20000]*[60]]]%[60] +} + +Day in Year@Date Time[date:out] +{ + base day <- [(0,0,31,59,90,120,151,181,212,243,273,304,334)]Index[[date]Month >>] + ,noleap <- If[[[date]Month >>] > [2]] + { + ,noleap <- Is Leap Year[[date]Year >>] + { + out <- [base day] + [[date]Day >>] + } + } + Val[noleap] + { + out <- [[base day] + [[date]Day >>]]-[1] + } +} + +//Gregorian only for the moment +//Sunday = 0, Saturday = 6 +//Uses Zeller's algorithm +Day of Week@Date Time[date:out] +{ + If[[[date]Month >>] < [3]] + { + zmonth <- [[date]Month >>]+[12] + zyear <- [[date]Year >>]-[1] + }{ + zmonth <- [date]Month >> + zyear <- [date]Year >> + } + [zyear]Slice@String[2] + { century <- >, a], b], c], d]] + [6]] % [7] +} + +Format@Date Time[date,format:out] +{ + If[[format]=[""]] + { + out <- "" + }{ + months <- ("", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December") + days <- ("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday") + cur,rest format <- [format]Slice[1] + If[[cur] = ["Y"]] + { + piece <- [date]Year >> + }{ If[[cur] = ["M"]] + { + piece <- [date]Month >> + }{ If[[cur] = ["N"]] + { + tpiece <- [months]Index[[date]Month >>] + }{ If[[cur] = ["B"]] + { + tpiece <- [[months]Index[[date]Month >>]]Slice[3] + }{ If[[cur] = ["D"]] + { + ppiece <- [date]Day >> + }{ If[[cur] = ["d"]] + { + piece <- [date]Day >> + }{ If[[cur] = ["n"]] + { + tpiece <- [days]Index[[date]Day of Week] + }{ If[[cur] = ["b"]] + { + tpiece <- [[days]Index[[date]Day of Week]]Slice[3] + }{ If[[cur] = ["w"]] + { + piece <- Day of Week[date] + }{ If[[cur] = ["h"]] + { + hour <- [date]Hours + If[[hour] > [12]] + { + ppiece <- [hour]-[12] + }{ + If[[hour] = [0]] + { ppiece <- 12 } + { ppiece <- Val[hour] } + } + }{ If[[cur] = ["H"]] + { + ppiece <- Hours[date] + }{ If[[cur] = ["m"]] + { + ppiece <- Minutes[date] + }{ If[[cur] = ["s"]] + { + ppiece <- Seconds[date] + }{ If[[cur] = ["a"]] + { + If[[[date]Hours] < [12]] + { tpiece <- "AM" } + { tpiece <- "PM" } + }{ If[[cur] = ["t"]] + { + ppiece <- Milliseconds[date] + }{ + tpiece <- Val[cur] + }}}}}}}}}}}}}}} + + sppiece <- >, ["_Preformatted"]Set Input[1, preformatted?]] ] + ]Preformatted <<[preformatted?] +} + Set Session@Web Container[container,session:out] { out <- [ @@ -107,13 +130,21 @@ Render@Web Container[container:out,headers] { + If[[container]Preformatted >>] + { + newline <- "" + tab <- "" + }{ + newline <- "\n" + tab <- "\t" + } out <- [[[[[[["<"]Append[ [container]Tag Name >> ] ]Append[Get Class[container]] - ]Append[">\n\t"] + ]Append[[[">"]Append[newline]]Append[tab]] ]Append[Fold[["Render Child"]>]] - ]Append["\n> ] - ]Append[">\n"] + ]Append[[">"]Append[newline]] } Container Event Handler[container,events,index:cont,out events] @@ -122,7 +153,7 @@ [[container]Handlers >>]Index[ [event]Event Name >>] { result list <- [~]Do[ - [[New@List[]]Append[container]]Append[event] + [[List[]]Append[container]]Append[event] ] new container <- [result list]Index[0] [result list]Index[1] @@ -141,7 +172,7 @@ cont, result events <- Container Event Handler[new container, events, ~] }{ cont <- Val[new container] - result events <- New@List[] + result events <- List[] } } @@ -171,16 +202,16 @@ { [[container]Children >>]First { - out, postback events <- Container Postback Helper[container, post data, ~, New@List[]] + out, postback events <- Container Postback Helper[container, post data, ~, List[]] If[[container]Propagate Events >>] { events <- Val[postback events] }{ - events <- New@List[] + events <- List[] } }{ out <- container - events <- New@List[] + events <- List[] } } @@ -228,17 +259,16 @@ out <- [container]Handlers <<[ [[container]Handlers >> ]Set[event name, handler] ] } -New@Page[title,url,use session,queryvars,headers:out] +Page[title,url,use session,queryvars,headers:out] { page <- [[[[[[[Build["Page"] ]Title <<[title] ]URL <<[url] - ]CSS <<[[New@List[]]Append["/default.css"]] - ]Children <<[New@List[]] - ]Named Children <<[New@Dictionary[]] - ]Handlers <<[New@Dictionary[]] + ]CSS <<[[List[]]Append["/default.css"]] + ]Children <<[List[]] + ]Named Children <<[Dictionary[]] + ]Handlers <<[Dictionary[]] ]Use Session <<[use session] - If[use session] { Load@Session[queryvars, headers] @@ -276,15 +306,15 @@ ]Append["\t\n\t\n"] If[[page]Use Session>>] { - headers <- [[page]Session >>]Finalize[New@Dictionary[]] + headers <- [[page]Session >>]Finalize[Dictionary[]] }{ - headers <- New@Dictionary[] + headers <- Dictionary[] } } Clear Children[page:out] { - out <- [[page]Children <<[New@List[]]]Named Children <<[New@Dictionary[]] + out <- [[page]Children <<[List[]]]Named Children <<[Dictionary[]] } Set@Page[page,key,val:out] @@ -314,7 +344,7 @@ Clear CSS@Page[page:out] { - out <- [page]CSS <<[New@List[]] + out <- [page]CSS <<[List[]] } Decode Helper Decode[list,destlist,index:out] @@ -345,7 +375,7 @@ parts <- [val]Split["%"] [parts]First { - out <- [Decode Helper Straight[parts, New@List[], ~]]Join[""] + out <- [Decode Helper Straight[parts, List[], ~]]Join[""] }{ out <- val } @@ -376,22 +406,23 @@ { [[page]Children >>]First { - out, events <- Container Postback Helper[page, post data, ~, New@List[]] + out, events <- Container Postback Helper[page, post data, ~, List[]] }{ out <- page } - events <- New@List[] + events <- List[] } Blueprint Web Text { Text Enclosing Tag + Preformatted } -New@Web Text[text,tag:out] +Web Text[text,tag:out] { - out <- [[Build["Web Text"]]Text <<[text]]Enclosing Tag <<[tag] + out <- [[[Build["Web Text"]]Text <<[text]]Enclosing Tag <<[tag]]Preformatted <<[No] } Name@Web Text[text:out,none] @@ -406,7 +437,13 @@ Render@Web Text[text:out,headers] { - processed text <- [Escape HTML Text[[text]Text >>]]Replace["\n","
\n\t"] + escaped <- Escape HTML Text[[text]Text >>] + If[[text]Preformatted >>] + { + processed text <- Val[escaped] + }{ + processed text <- [escaped]Replace["\n","
\n\t"] + } If[[[[text]Enclosing Tag >>]Length] = [0]] { out <- Val[processed text] @@ -418,17 +455,17 @@ Postback@Web Text[text,post data:out,events] { out <- text - events <- New@List[] + events <- List[] } Set Session@Web Text[text,session:out] { - out <- session + out <- text } Render@String[string:out,headers] { - out <- [New@Web Text[string,""]]Render + out <- [Web Text[string,""]]Render } Name@String[string:out,none] @@ -439,7 +476,7 @@ Postback@String[in,post data:out,events] { out <- in - events <- New@List[] + events <- List[] } Set Session@String[in,session:out] @@ -460,7 +497,7 @@ name <- [field]Name >> } -New@Web Field[name,value,type:out] +Web Field[name,value,type:out] { out <- [[[[Build["Web Field"]]Name <<[name]]Value <<[value]]Type <<[type]]Class <<[""] } @@ -489,13 +526,13 @@ If[[[field]Value >>] = [~]] { - event <- New@List[] + event <- List[] }{ - event <- [New@List[]]Append[ New@Web Event["change", [field]Name >>, [field]Value >>] ] + event <- [List[]]Append[ Web Event["change", [field]Name >>, [field]Value >>] ] } }{ out <- field - event <- New@List[] + event <- List[] } } @@ -506,7 +543,7 @@ Class } -New@Web Button[name,label:out] +Web Button[name,label:out] { out <- [[[Build["Web Button"]]Name <<[name]]Label <<[label]]Class <<[""] } @@ -526,9 +563,9 @@ out <- button [post data]Index[[button]Name >>] { - events <- [New@List[]]Append[ New@Web Event["click", [button]Name >>, 0] ] + events <- [List[]]Append[ Web Event["click", [button]Name >>, 0] ] }{ - events <- New@List[] + events <- List[] } } @@ -543,6 +580,7 @@ IP Address Use Cookies Data + Dirty } Get Unique ID[:out] uses Session @@ -551,9 +589,9 @@ ::ID <- [::ID]+[1] } -New@Session[:out] +Session[:out] { - out <- [[[Build["Session"]]Session ID <<[Get Unique ID[]]]Use Cookies <<[No]]Data <<[New@Dictionary[]] + out <- [[[[Build["Session"]]Session ID <<[Get Unique ID[]]]Use Cookies <<[No]]Data <<[Dictionary[]]]Dirty <<[No] } Load@Session[queryvars,headers:out] uses Session @@ -581,7 +619,7 @@ Val[makenew] { - out <- New@Session[] + out <- Session[] } } @@ -597,7 +635,7 @@ Set@Session[session,key,val:out] { - out <- [session]Data <<[ [[session]Data >>]Set[key, val] ] + out <- [[session]Data <<[ [[session]Data >>]Set[key, val] ]]Dirty <<[Yes] } Index@Session[session,key:out,not found] @@ -618,13 +656,21 @@ Init Sessions[:out] uses Session { ::ID <- 1 - ::Sessions <- New@Dictionary[] + ::Sessions <- Dictionary[] out <- 0 } -Finalize@Session[session,headers:out headers] uses Session +Save@Session[session:out] uses Session { ::Sessions <- [::Sessions]Set[[session]Session ID >>, session] +} + +Finalize@Session[session,headers:out headers] +{ + If[[session]Dirty >>] + { + Save[session] + } out headers <- [headers]Set["Set-Cookie", ["session_id="]Append[[session]Session ID >>]] } @@ -636,15 +682,15 @@ Query Params } -New@Web Link[text,target:out] +Web Link[text,target:out] { - out <- [[[[Build["Web Link"]]Text <<[text]]Target <<[target]]Class <<[""]]Query Params <<[New@Dictionary[]] + out <- [[[[Build["Web Link"]]Text <<[text]]Target <<[target]]Class <<[""]]Query Params <<[Dictionary[]] } With Session@Web Link[text,target,session:out] { - New@Web Link[text, target] + Web Link[text, target] { out <- [~]Query Params <<[[[~]Query Params >>]Set["session_id", [session]Session ID >>]] } @@ -658,14 +704,14 @@ }{ queryvars <- "" } - out <- [[[[[[[">]Replace["\"", "%22"]]]Append[queryvars]]Append["\""] + out <- [[[[[[[">]]Append[queryvars]]Append["\""] ]Append[Get Class[link]]]Append[">"]]Append[Escape HTML Text[[link]Text>>]]]Append[""] } Postback@Web Link[in,post data:out,events] { out <- in - events <- New@List[] + events <- List[] } Name@Web Link[link:name,none] @@ -694,7 +740,7 @@ Data } -New@Web Table[headers,data:out] +Web Table[headers,data:out] { out <- [[Build["Web Table"]]Headers <<[headers]]Data <<[data] } diff -r b218af069da7 -r 04baa003de5a interp.c --- a/interp.c Sat Oct 10 16:43:37 2009 -0400 +++ b/interp.c Wed May 05 22:12:23 2010 -0400 @@ -1482,6 +1482,11 @@ aworker->input_types[0] = BUILTIN_TYPE_WHOLE; aworker->input_types[1] = BUILTIN_TYPE_WHOLE; + aworker = create_worker(prog, "%@Whole Number", 2, 1, WORKER_TYPE); + aworker->implement_func=(custom_worker *)vis_whole_modulus; + aworker->input_types[0] = BUILTIN_TYPE_WHOLE; + aworker->input_types[1] = BUILTIN_TYPE_WHOLE; + //add_method(this_comp, aworker); current_method = 0; @@ -1567,6 +1572,14 @@ aworker->implement_func=(custom_worker *)vis_real_sqrt; aworker->input_types[0] = BUILTIN_TYPE_REAL; + aworker = create_worker(prog, "Truncate to Whole@Real Number", 1, 1, WORKER_TYPE); + aworker->implement_func=(custom_worker *)vis_whole_fromreal; + aworker->input_types[0] = BUILTIN_TYPE_REAL; + + aworker = create_worker(prog, "implement_func=(custom_worker *)vis_real_fromwhole; + aworker->input_types[0] = BUILTIN_TYPE_WHOLE; + //add_method(this_comp, aworker); current_method = 0; @@ -1623,7 +1636,7 @@ aworker->input_types[0] = BUILTIN_TYPE_LIST; //add_method(this_comp, aworker); - aworker = create_worker(prog, "New@List",0, 1, WORKER_TYPE); + aworker = create_worker(prog, "List",0, 1, WORKER_TYPE); aworker->implement_func=(custom_worker *)vis_list_new; //add_method(this_comp, aworker); @@ -1672,7 +1685,7 @@ //add_method(this_comp, aworker); - aworker = create_worker(prog, "New@Dictionary",0, 1, WORKER_TYPE); + aworker = create_worker(prog, "Dictionary",0, 1, WORKER_TYPE); aworker->implement_func=(custom_worker *)vis_dict_new; //add_method(this_comp, aworker); @@ -1829,7 +1842,7 @@ aworker->input_types[1] = BUILTIN_TYPE_WHOLE; aworker->input_types[2] = BUILTIN_TYPE_WHOLE; - aworker = create_worker(prog, "New@Worker", 1, 1, WORKER_TYPE); + aworker = create_worker(prog, "Worker", 1, 1, WORKER_TYPE); aworker->implement_func=(custom_worker *)vis_worker_new; aworker->input_types[0] = BUILTIN_TYPE_STRING; @@ -1838,7 +1851,7 @@ this_comp = create_company(prog, "Window", 3, 0, FALSE); - aworker = create_worker(prog, "New@Window", 3, 1, WORKER_TYPE); + aworker = create_worker(prog, "Window", 3, 1, WORKER_TYPE); aworker->implement_func=(custom_worker *)vis_window_new; aworker->input_types[0] = BUILTIN_TYPE_STRING; aworker->input_types[1] = BUILTIN_TYPE_REAL; @@ -1899,7 +1912,7 @@ current_method = 0; create_company(prog, "Button", 2, 0, FALSE); - aworker = create_worker(prog, "New@Button", 3, 1, WORKER_TYPE); + aworker = create_worker(prog, "Button", 3, 1, WORKER_TYPE); aworker->implement_func=(custom_worker *)vis_button_new; aworker->input_types[0] = BUILTIN_TYPE_STRING; aworker->input_types[1] = BUILTIN_TYPE_REAL; @@ -1916,7 +1929,7 @@ current_method = 0; create_company(prog, "Input Box", 2, 0, FALSE); - aworker = create_worker(prog, "New@Input Box", 3, 1, WORKER_TYPE); + aworker = create_worker(prog, "Input Box", 3, 1, WORKER_TYPE); aworker->implement_func=(custom_worker *)vis_inputbox_new; aworker->input_types[0] = BUILTIN_TYPE_STRING; aworker->input_types[1] = BUILTIN_TYPE_REAL; @@ -1932,7 +1945,7 @@ #endif #ifndef NO_NET this_comp = create_company(prog, "Net Client", 3, 0, FALSE); - aworker = create_worker(prog, "New@Net Client", 2, 1, WORKER_TYPE); + aworker = create_worker(prog, "Net Client", 2, 1, WORKER_TYPE); aworker->implement_func =(custom_worker *)net_client_new; aworker->input_types[0] = BUILTIN_TYPE_STRING; aworker->input_types[1] = BUILTIN_TYPE_WHOLE; @@ -1972,7 +1985,7 @@ create_company(prog, "Program", 5, 0, FALSE); - aworker = create_worker(prog, "New@Program", 0, 1, WORKER_TYPE); + aworker = create_worker(prog, "Program", 0, 1, WORKER_TYPE); aworker->implement_func = (custom_worker *)vis_program_new; aworker = create_worker(prog, "New Worker@Program", 2, 2, WORKER_TYPE); @@ -2003,7 +2016,7 @@ #ifdef SYLLABLE create_company(prog, "Custom Widget", 2, 0, FALSE); - aworker = create_worker(prog, "New@Custom Widget", 3, 1, WORKER_TYPE); + aworker = create_worker(prog, "Custom Widget", 3, 1, WORKER_TYPE); aworker->implement_func=(custom_worker *)vis_customwidget_new; aworker->input_types[0] = BUILTIN_TYPE_STRING; aworker->input_types[1] = BUILTIN_TYPE_REAL; @@ -2082,7 +2095,7 @@ #endif create_company(prog, "Buffer", 7, 0, FALSE); - aworker = create_worker(prog, "New@Buffer", 1, 1, WORKER_TYPE); + aworker = create_worker(prog, "Buffer", 1, 1, WORKER_TYPE); aworker->implement_func=(custom_worker *)vis_buffer_new; aworker->input_types[0] = BUILTIN_TYPE_WHOLE; @@ -2138,7 +2151,7 @@ create_company(prog, "Blueprint", 4, 0, FALSE); - aworker = create_worker(prog, "New@Blueprint", 1, 1, WORKER_TYPE); + aworker = create_worker(prog, "Blueprint", 1, 1, WORKER_TYPE); aworker->implement_func=(custom_worker *)vis_blueprint_new; aworker->input_types[0] = BUILTIN_TYPE_STRING; @@ -2180,7 +2193,7 @@ #ifdef SYLLABLE create_company(prog, "Checkbox", 2, 0, FALSE); - aworker = create_worker(prog, "New@Checkbox", 4, 1, WORKER_TYPE); + aworker = create_worker(prog, "Checkbox", 4, 1, WORKER_TYPE); aworker->implement_func=(custom_worker *)vis_checkbox_new; aworker->input_types[0] = BUILTIN_TYPE_STRING; aworker->input_types[1] = BUILTIN_TYPE_REAL; @@ -2195,7 +2208,7 @@ create_company(prog, "Dropdown", 4, 0, FALSE); - aworker = create_worker(prog, "New@Dropdown", 3, 1, WORKER_TYPE); + aworker = create_worker(prog, "Dropdown", 3, 1, WORKER_TYPE); aworker->implement_func=(custom_worker *)vis_dropdown_new; aworker->input_types[0] = BUILTIN_TYPE_LIST; aworker->input_types[1] = BUILTIN_TYPE_REAL; @@ -3060,7 +3073,7 @@ DEBUGPRINTF( "Magic method: %s\n", process_def->name); if(!params || !params[0]) { - ERRORPRINTF("Error: null first parmeter or null parameter array for worker %s\n", process_def->name); + ERRORPRINTF("Error: null first parmeter or null parameter array for worker %s, params: %X, params[0]: %X\n", process_def->name, params, params[0]); print_stack_trace(worker_entry.instance); execute_active = FALSE; return -1; diff -r b218af069da7 -r 04baa003de5a interp.h --- a/interp.h Sat Oct 10 16:43:37 2009 -0400 +++ b/interp.h Wed May 05 22:12:23 2010 -0400 @@ -113,6 +113,7 @@ int vis_whole_and(datum ** inputlist, queue_entry * worker_entry); int vis_whole_lsh(datum ** inputlist, queue_entry * worker_entry); int vis_whole_rsh(datum ** inputlist, queue_entry * worker_entry); +int vis_whole_modulus(datum ** inputlist, queue_entry * worker_entry); int vis_inttostring(datum ** inputlist, queue_entry * worker_entry); int vis_stringequal(datum ** inputlist, queue_entry * worker_entry); int vis_string_split(datum ** inputlist, queue_entry * worker_entry); @@ -136,6 +137,8 @@ int vis_greaterreal(datum ** inputlist, queue_entry * worker_entry); int vis_lesserreal(datum ** inputlist, queue_entry * worker_entry); int vis_realtostring(datum ** inputlist, queue_entry * worker_entry); +int vis_whole_fromreal(datum ** inputlist, queue_entry * worker_entry); +int vis_real_fromwhole(datum ** inputlist, queue_entry * worker_entry); //Index, Append, Swap, Insert, Remove, Set, Length, New int vis_list_index(datum ** inputlist, queue_entry * worker_entry); int vis_list_append(datum ** inputlist, queue_entry * worker_entry); diff -r b218af069da7 -r 04baa003de5a kernel.rhope --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kernel.rhope Wed May 05 22:12:23 2010 -0400 @@ -0,0 +1,295 @@ + +Val[in:out] +{ + out <- in +} + +Blueprint Boolean +{ + Val(Int32,Naked) +} + +/* +Blueprint Blueprint +{ + Val(Blueprint,Naked) +}*/ + +Blueprint Int64 +{ + Num(Int64,Naked) +} + +If@Int64[num:yes,no] +{ + yes,no <- If[[num]!=[0i64]] +} + +Blueprint Int32 +{ + Num(Int32,Naked) +} + +If@Int32[num:yes,no] +{ + yes,no <- If[[num]!=[0i32]] +} + +Foreign C:libc +{ + write[filedes(Int32,Naked),buf(Array,Raw Pointer),nbyte(Int64,Naked):written(Int32,Naked)] +} + +_Print Int32[n,buf:out] +{ + If[[n] < [10i32]] + { + byte <- [[n]Trunc Int8] + [48i8] + out <- [buf]Append[byte] + }{ + next <- [n]/[10i32] + + byte <- [[[n]-[[next]*[10i32]]]Trunc Int8] + [48i8] + out <- [_Print Int32[next, buf]]Append[byte] + } +} + +Print@Int32[n:out] +{ + If[[n] < [0i32]] + { + val <- [0i32]-[n] + buf <- [Array[1]]Append[45i8] + }{ + val <- Val[n] + buf <- Array[1] + } + fbuf <- [_Print Int32[val, buf]]Append[10i8] + out <- write[1i32, fbuf, Int64[[fbuf]Length >>]] +} + +Blueprint Int16 +{ + Num(Int16,Naked) +} + +If@Int16[num:yes,no] +{ + yes,no <- If[[num]!=[0i16]] +} + +Blueprint Int8 +{ + Num(Int8,Naked) +} + +If@Int8[num:yes,no] +{ + yes,no <- If[[num]!=[0i8]] +} + +Blueprint UInt64 +{ + Num(UInt64,Naked) +} + +If@UInt64[num:yes,no] +{ + yes,no <- If[[num]!=[0u64]] +} + +Blueprint UInt32 +{ + Num(UInt32,Naked) +} + +If@UInt32[num:yes,no] +{ + yes,no <- If[[num]!=[0u32]] +} + +Blueprint UInt16 +{ + Num(UInt16,Naked) +} + +If@UInt16[num:yes,no] +{ + yes,no <- If[[num]!=[0u16]] +} + +Blueprint UInt8 +{ + Num(UInt8,Naked) +} + +If@UInt8[num:yes,no] +{ + yes,no <- If[[num]!=[0u8]] +} + + +Blueprint Array +{ + Eltype(Blueprint) + Length(Int32,Naked) + Storage(Int32,Naked) +} + +Foreign C:runtime +{ + _internal_array_copyout[array(Array), index(Int32,Naked), dest(Any Type,Boxed,Mutable):dest] + _internal_array_copyin[array(Array,Boxed,Mutable), index(Int32,Naked), val:array] + _internal_array_getboxed[array(Array), index(Int32,Naked):out] + _internal_array_setboxed[array(Array,Boxed,Mutable), index(Int32,Naked), val:array] + _internal_array_allocboxed[size(Int32,Naked):out(Array)] + _internal_array_allocnaked[size(Int32,Naked),type(Blueprint):out(Array)] + _internal_blueprint_eq[left(Blueprint),right(Blueprint):out(Int32,Naked)] +} + +=@Blueprint[left,right:out] +{ + out <- [_internal_blueprint_eq[left,right]]!=[0] +} + +Array[n:out(Array)] +{ + out <- [[_internal_array_allocboxed[0] + ]Length <<[0] + ]Storage <<[0] +} + +First@Array[array:out(Int32),empty] +{ + ,empty <- If[[array]Length >>] + { out <- 0 } +} + +Next@Array[array,current:out(Int32),empty] +{ + next <- [current]+[1] + ,empty <- If[[next] < [[array]Length >>]] + { + out <- Val[next] + } +} + +Last@Array[array:out(Int32),empty] +{ + ,empty <- If[[array]Length >>] + { out <- [[array]Length >>] - [1] } +} + +Append@Array[array,newval:out(Array)] +{ + out <- [array]Set[[array]Length >>, newval] +} + +Index@Array[array,index(Int32):out,notfound] +{ + ,notfound <- If[[index] >= [0]] + { + ,notfound <- If[[index] < [[array]Length >>]] + { + eltype <- [array]Eltype >> + If[[eltype] = [Any Type()]] + { + out <- _internal_array_getboxed[array, index] + }{ + out <- _internal_array_copyout[array, index, Build[eltype]] + } + } + } +} + +_Copy to Boxed[source,dest,current:out] +{ + ndest <- _internal_array_setboxed[dest, current, [source]Index[current]] + + [source]Next[current] + { + out <- _Copy to Boxed[source, ndest, ~] + }{ + out <- Val[ndest] + } +} + +_Copy Naked[source,dest,current:out] +{ + ndest <- _internal_array_copyin[dest, current, [source]Index[current]] + + [source]Next[current] + { + out <- _Copy Naked[source, ndest, ~] + }{ + out <- Val[ndest] + } +} + +Set@Array[array,index(Int32),val:out(Array)] +{ + If[[index] < [[array]Storage >>]] + { + If[[index] > [[array]Length >>]] + { + farray <- [[array]Set[[index]-[1], val]]Length <<[ [index]+[1] ] + }{ + If[[index] = [[array]Length >>]] + { + farray <- [array]Length <<[ [index]+[1] ] + }{ + farray <- Val[array] + } + } + eltype <- [array]Eltype >> + If[[eltype] = [Any Type()]] + { + out <- _internal_array_setboxed[farray, index, val] + }{ + If[[Blueprint Of[val]] = [eltype]] + { + out <- _internal_array_copyin[farray, index, val] + }{ + boxed <- _internal_array_allocboxed[[farray]Storage >>] + [array]First + { + copied <- _Copy to Boxed[farray, boxed, ~] + }{ + //I don't think this case should happen normally + copied <- Val[boxed] + } + out <- _internal_array_setboxed[copied, index, val] + } + } + }{ + If[[array]Length >>] + { + If[[index] < [4]] + { + new storage <- [index]+[index] + }{ + new storage <- [index]+[[index]RShift[1]] + } + + do boxed <- If[[[array]Eltype >>] = [Any Type()]] + { + copied <- _Copy to Boxed[array, _internal_array_allocboxed[new storage], 0] + }{ + bp <- Blueprint Of[val] + If[[[array]Eltype >>] = [bp]] + { + copied <- _Copy Naked[array, _internal_array_allocnaked[new storage, bp], 0] + }{ + copied <- _Copy to Boxed[array, _internal_array_allocboxed[new storage], 0] + } + } + out <- [[copied]Length <<[[array]Length >>]]Set[index,val] + }{ + len <- [index]+[1] + out <- [_internal_array_allocnaked[len, Blueprint Of[val]] + ]Set[index,val] + } + } +} + + diff -r b218af069da7 -r 04baa003de5a makefile.linux --- a/makefile.linux Sat Oct 10 16:43:37 2009 -0400 +++ b/makefile.linux Wed May 05 22:12:23 2010 -0400 @@ -2,7 +2,7 @@ OBJS = datum.o dict.o file.o interp.o list.o net.o number.o parser.o saveload.o string.o visuality_cmd.o worker.o vis_threading.o mt19937ar.o buffer.o blueprint.o rhope: $(OBJS) - $(CC) -g -o rhope -lpthread $(OBJS) + $(CC) -g -o rhope -lpthread -lm $(OBJS) %.o:%.c $(CC) $(CFLAGS) -g -c $< diff -r b218af069da7 -r 04baa003de5a number.c --- a/number.c Sat Oct 10 16:43:37 2009 -0400 +++ b/number.c Wed May 05 22:12:23 2010 -0400 @@ -180,6 +180,14 @@ return 0; } +int vis_whole_modulus(datum ** inputlist, queue_entry * worker_entry) +{ + inputlist[0] = copy_datum(inputlist[0], 0); + inputlist[0]->c.integers.num_a %= inputlist[1]->c.integers.num_a; + release_ref(inputlist[1]); + return 0; +} + int vis_greaterint(datum ** inputlist, queue_entry * worker_entry) { @@ -424,4 +432,14 @@ release_ref(inputlist[0]); inputlist[0] = output; return 0; -} \ No newline at end of file +} + +int vis_real_fromwhole(datum ** inputlist, queue_entry * worker_entry) +{ + datum * output = new_datum(BUILTIN_TYPE_REAL, 3, 0, worker_entry->instance->def->program); + output->c.real = inputlist[0]->c.integers.num_a; + release_ref(inputlist[0]); + inputlist[0] = output; + return 0; +} + diff -r b218af069da7 -r 04baa003de5a number.rhope --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/number.rhope Wed May 05 22:12:23 2010 -0400 @@ -0,0 +1,167 @@ + + +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"] ] + +} + +Compile Conversion Method[backend,intype,outtype,prefix:out] +{ + func <- [[[[[[backend]Create Function[[prefix]Append[[[outtype]Append["@"]]Append[intype]], ("in"), ("out"), "rhope"] + ]Set Input Type[Type Instance[intype], 0] + ]Set Output Type[Type Instance[outtype], 0] + ]Register Constant[["Blueprint_"]Append[outtype], Type Instance[outtype]] + ]Call["Build", [()]Append[ Constant[["Blueprint_"]Append[outtype]] ]] + ]Move[Result[0], "out"] + + ,src <- [func]Read Field["in", "Num"] + { ,dst <- [~]Write Field["out", "Num"] + { ffunc <- [[~]Move[src, dst]]Release["in"] }} + + out <- [backend]Store Function[ffunc] +} + +_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] + { Fold[["Compile Number Comp Method"]Set Input[2, type], ~, compops] + { Fold[[["Compile Conversion Method"]Set Input[1, type]]Set Input[3, ""], ~, Legal Conversions[type]] + { out <- Fold[[["Compile Conversion Method"]Set Input[1, type]]Set Input[3, "Trunc "], ~, Truncations[type]] }}} +} + +Generate Number Methods[backend:out] +{ + numtypes <- ("Int8","Int16","Int32","Int64","UInt8","UInt16","UInt32","UInt64") + + 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 Conversion Method[program, intype, outtype,prefix:out] +{ + name <- [prefix]Append[[[outtype]Append["@"]]Append[intype]] + Print[["Registering conversion: "]Append[name]] + out <- [[program]Register Worker[name, "rhope", 1, 1] + ]Bind Worker[name, + [[[[[NWorker["rhope"] + ]Inputs <<[("in")] + ]Input Types <<[ [()]Append[Type Instance[intype]] ] + ]Outputs <<[("out")] + ]Output Types <<[ [()]Append[Type Instance[outtype]] ] + ]Builtin? <<[Yes] + ] +} + +Legal Conversions[type:convs] +{ + bigger <- Filter[(16,32,64), [">"]Set Input[1, size]] + base convs <- Map[bigger, ["Append"]Set Input[0, "Int"]] + If[[type]Starts With["U"]] + { + [type]Slice[4] {} + { size <- ", "=", "<=", ">=", "!=") + register <- ["Register Number Method"]Set Input[2, type] + Fold[[register]Set Input[3, type], program, methods] + { Fold[[register]Set Input[3, "Boolean"], ~, compmethods] + { Fold[[["Register Conversion Method"]Set Input[1, type]]Set Input[3, ""], ~, Legal Conversions[type]] + { out <- Fold[[["Register Conversion Method"]Set Input[1, type]]Set Input[3, "Trunc "], ~, Truncations[type]] }}} +} + +Register Number Methods[program:out] +{ + numtypes <- ("Int8","Int16","Int32","Int64","UInt8","UInt16","UInt32","UInt64") + out <- Fold["_Register Number Methods", program, numtypes] +} + diff -r b218af069da7 -r 04baa003de5a nworker.rhope --- a/nworker.rhope Sat Oct 10 16:43:37 2009 -0400 +++ b/nworker.rhope Wed May 05 22:12:23 2010 -0400 @@ -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] @@ -167,11 +167,12 @@ Convention Inputs Outputs + Is Method? } -Worker Ref[name,convention,inputs,outputs:out] +Worker Ref[name,convention,inputs,outputs,ismethod?:out] { - out <- [[[[Build["Worker Ref"]]Name <<[name]]Convention <<[convention]]Inputs <<[inputs]]Outputs <<[outputs] + out <- [[[[[Build["Worker Ref"]]Name <<[name]]Convention <<[convention]]Inputs <<[inputs]]Outputs <<[outputs]]Is Method? <<[ismethod?] } Blueprint Node Ref @@ -198,7 +199,9 @@ Type Data Inputs + Input Types Outputs + Output Types Wires From Wires To Conditions @@ -225,6 +228,31 @@ ] } +_Has Input Types@NWorker Node[node,input num:does,does not] +{ + does <- If[[input num] > [[node]Inputs >>]] {} + { + ,does not <- [[node]Input Types >>]Index[input num] + { + count <- [~]Index[1] + ,does not <- If[[count] = [[[[node]Wires To >>]Index[input num]]Length]] + { + does,does not <- [node]_Has Input Types[[input num]+[1]] + } + } + } +} + +Has Input Types?@NWorker Node[node:does,does not] +{ + If[[[[node]Inputs >>]Length] > [0]] + { + does,does not <- _Has Input Types[node,0] + }{ + does <- Yes + } +} + _Dependency[dlist,ref:out] { [dlist]Find[ref] @@ -243,7 +271,7 @@ NWorker Node[type,data,inputs,outputs:out] { - out <- [[[[[[[Build["NWorker Node"] + out <- [[[[[[[[[Build["NWorker Node"] ]Type <<[type] ]Data <<[data] ]Inputs <<[inputs] @@ -251,6 +279,8 @@ ]Wires From <<[List of Lists[outputs]] ]Wires To <<[List of Lists[[inputs]+[1]]] ]Conditions <<[AndSet[]] + ]Input Types <<[()] + ]Output Types <<[()] } Blueprint NWorker @@ -264,11 +294,14 @@ Uses NodeResults Free Temps + Name + Builtin? + Library } NWorker[convention:out] { - out <- [[[[[[Build["NWorker"]]Convention <<[convention]]Nodes <<[()]]Inputs <<[()]]Outputs <<[()]]Input Types <<[()]]Output Types <<[()] + out <- [[[[[[[[[Build["NWorker"]]Convention <<[convention]]Nodes <<[()]]Inputs <<[()]]Outputs <<[()]]Input Types <<[()]]Output Types <<[()]]Name <<["Anonymous"]]Builtin? <<[No]]Library << [""] } Add Node@NWorker[worker,type,data,inputs,outputs:out,node index] @@ -277,6 +310,164 @@ node index <- [[worker]Nodes >>]Length } +Propagate Type[nodelist,dest,prog,worker,type:out] +{ + node <- [nodelist]Index[[dest]Index >>] + + [[node]Input Types >>]Index[[dest]IO Num >>] + { + existing type <- [~]Index[0] + new count <- [[~]Index[1]]+[1] + If[[[existing type]Name >>] = [[type]Name >>]] + { + If[[[existing type]Variant >>] = [[type]Variant >>]] + { + If[[[existing type]Params >>] = [[type]Params >>]] + { + new type <- Val[existing type] + }{ + new variant <- [existing type]Variant >> + new params <- () + } + }{ + new variant <- "Boxed" + If[[[existing type]Params >>] = [[type]Params >>]] + { + new params <- [existing type]Params >> + }{ + new params <- () + } + } + new type <- [[existing type]Set Variant[new variant]]Params <<[new params] + }{ + new type <- Type Instance["Any Type"] + } + }{ + new type <- Val[type] + new count <- 1 + } + 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] +} + +Propagate Types[nodelist,dests,output num,prog,worker,source node:out] +{ + out <- Fold[[[["Propagate Type"]Set Input[2, prog]]Set Input[3, worker]]Set Input[4, [[source node]Output Types >>]Index[output num]], nodelist, dests] +} + +Infer Types Node[nodelist,node,index,prog,worker:out] +{ + If[[[node]Type >>] = ["const"]] + { + //Temporary hack + If[[Type Of[[node]Data >>]] = ["Whole Number"]] + { + outtype <- Type Instance["Int32"] + }{ + If[[Type Of[[node]Data >>]] = ["Type Instance"]] + { + outtype <- Type Instance["Blueprint"] + }{ + If[[Type Of[[node]Data >>]] = ["Machine Integer"]] + { + If[[[node]Data >>]Signed? >>] + { base <- "Int" } + { base <- "UInt" } + + outtype <- Type Instance[[base]Append[ [[node]Data >>]Size >> ]] + }{ + outtype <- Type Instance[Type Of[[node]Data >>]] + } + } + } + nextnode <- [node]Output Types <<[ [()]Append[outtype] ] + + }{ + If[[[node]Type >>] = ["input"]] + { + nextnode <- [node]Output Types <<[ [()]Append[ [[worker]Input Types >>]Index[[node]Data >>] ] ] + }{ + If[[[node]Type >>] = ["output"]] + { + out <- nodelist + }{ + [node]Has Input Types? + { + If[[[node]Type >>] = ["setfield"]] + { + nextnode <- [node]Output Types <<[ [()]Append[ [[[node]Input Types >>]Index[0]]Index[0] ] ] + }{ + If[[[node]Type >>] = ["getfield"]] + { + type <- [[[node]Input Types >>]Index[0]]Index[0] + If[[[type]Name >>] = ["Any Type"]] + { + outtype <- Val[type] + }{ + outtype <- [prog]Find Field[[node]Data >>, type] {} + { + //TODO: Return errors rather than printing them + Print[ + [[[[["Type " + ]Append[[type]Name >>] + ]Append[" does not have a field named "] + ]Append[[node]Data >>] + ]Append[" in worker "] + ]Append[worker name]] + } + } + nextnode <- [node]Output Types <<[ [()]Append[outtype] ] + }{ + worker name <- [[node]Data >>]Name >> + [prog]Is Method?[worker name] + { + first arg type <- [[[node]Input Types >>]Index[0]]Index[0] + If[[[first arg type]Name >>] = ["Any Type"]] + { + outtypes <- Fold[["Append"]Set Input[1, Type Instance["Any Type"]], (), Range[0, [node]Inputs >>]] + }{ + worker def <- [prog]Find Method[worker name, first arg type] {} + { + //TODO: Return errors instead of printing them + Print[ + [[[[["Type " + ]Append[[first arg type]Name >>] + ]Append[" does not support method "] + ]Append[worker name] + ]Append[" in worker "] + ]Append[ [worker]Name >> ]] + } + } + }{ + worker def <- [prog]Find Worker Def[worker name] + } + outtypes <- [worker def]Output Types >> + nextnode <- [node]Output Types <<[ outtypes ] + } + } + }{ + out <- nodelist + } + } + } + } + + Val[nextnode] + { + nextlist <- [nodelist]Set[index, nextnode] + out <- Fold[[[["Propagate Types"]Set Input[3, prog]]Set Input[4, worker]]Set Input[5, nextnode], nodelist, [nextnode]Wires From >>] + } +} + +Infer Types@NWorker[worker,prog:out] +{ + 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] { out, node index <- [worker]Add Node["call",tocall,[tocall]Inputs >>,[tocall]Outputs >>] @@ -463,8 +654,16 @@ { //TODO: Support parametric types datstring <- [[node]Data >>]Name >> - }{ - datstring <- [node]Data >> + }{ + 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 >> + } } out <- Constant[[[Type Of[[node]Data >>]]Append["_"]]Append[datstring]] @@ -550,8 +749,12 @@ with call <- [func]Method Call[[[node]Data >>]Name >>, inputs] { Print["Method Call done"] } }{ - Print["Function!"] - with call <- [func]Call[[[node]Data >>]Name >>, inputs] + Print["Function!"] + { + Pretty Print[inputs, ""] + { with call <- [func]Call[[[node]Data >>]Name >>, inputs]} + } + } } } @@ -581,13 +784,16 @@ nstream <- Compile Call Node[node, program, stream, inputs, node index] }{ If[[[node]Type >>] = ["output"]] - { + { + Print["Compiling output node"] inputs <- [worker]Collect Inputs[node] [conditions]For Backend - { + { + Print["has conditions"] stream <- [func]Instruction Stream nfunc <- [func]Do If[~, nstream] - }{ + }{ + Print["no conditions"] stream <- Val[func] nfunc <- Val[nstream] } @@ -601,7 +807,15 @@ //TODO: Support parametric types datstring <- [[node]Data >>]Name >> }{ - datstring <- [node]Data >> + 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 >> + } } nfunc <- [func]Register Constant[[[Type Of[[node]Data >>]]Append["_"]]Append[datstring], [node]Data >>] }{ @@ -684,25 +898,172 @@ Result Vars@NWorker[worker:out] { out <- Fold["Node Result Vars", (), [worker]Nodes >>] -} +} + +Make Basic Type[type:out] +{ + out <- [Type Instance[[type]Name >>]]Params <<[ [type]Params >> ] +} + +FInputs[ifunc, input type, index, inputs:out] +{ + func <- [ifunc]Set Input Type[Make Basic Type[input type], index] + name <- [inputs]Index[index] + Print[["FInputs: "]Append[index]] + Pretty Print[input type, ""] + { + If[[[input type]Variant >>] = ["Naked"]] + { + + naked <- [" naked"]Append[name] + + out <- [[[func]Allocate Var[naked, input type] + ]Unbox[name, naked] + ]Release[name] + }{ + If[[input type]Mutable? >>] + { + name <- [inputs]Index[index] + copied <- [func]Copy[name, name] + + }{ + copied <- Val[func] + } + If[[[input type]Variant >>] = ["Raw Pointer"]] + { + raw <- [" raw"]Append[name] + If[[[input type]Name >>]=["Array"]] + { + + out <- [[copied]Allocate Var[raw, input type] + ]Array Raw Pointer[name, raw] + }{ + out <- [[copied]Allocate Var[raw, input type] + ]Get Raw Pointer[name, raw] + } + }{ + out <- Val[copied] + } + } + } +} + +FParams[input:out] +{ + iname <- [input]Index[0] + type <- [input]Index[1] + If[[[type]Variant >>] = ["Naked"]] + { out <- [" naked"]Append[iname] } + { + If[[[type]Variant >>] = ["Raw Pointer"]] + { out <- [" raw"]Append[iname] } + { out <- Val[iname] } + } +} +_Return Param[outputs, inputs, input types, index:out,none] +{ + Print[["_Return Param: "]Append[output]] + output <- [outputs]Index[index] + [inputs]Find[output] + { + If[[[input types]Index[~]]Mutable? >>] + { + ,none <- [outputs]Next[index] + { + out,none <- _Return Param[outputs, inputs, input types, ~] + } + } { + out <- index + } + }{ + out <- index + } +} + +Return Param[outputs, inputs, input types:out,none] +{ + Print["Return Param"] + ,none <- [outputs]First + { out,none <- _Return Param[outputs, inputs, input types, ~] } + +} + +Save Foreign Result[func, output, index, output types, inputs, input types:out] +{ + type <- [output types]Index[index] + If[[[type]Variant >>] = ["Naked"]] + { + out <- [func]Box[[" naked"]Append[output], output, type] + }{ + [inputs]Find[output] + { + If[[[input types]Index[~]]Mutable? >>] + { + out <- [func]Move[output, Output[output]] + }{ + out <- func + } + }{ + out <- func + } + } +} + +Compile Foreign Stub[worker,program,name:out] +{ + Print[["Compiling FFI stub for "]Append[name]] + ifunc <- [[program]Create Function[name, [worker]Inputs >>, [worker]Outputs >>, "rhope"] + ]Output Types <<[Map[[worker]Output Types >>, "Make Basic Type"]] + + rp num <- Return Param[[worker]Outputs >>, [worker]Inputs >>, [worker]Input Types >>] + { + rbase <- [[worker]Outputs >>]Index[rp num] + If[[[[[worker]Output Types >>]Index[rp num]]Variant >>] = ["Naked"]] + { + rparam <- [" naked"]Append[rbase] + rfunc <- [ifunc]Allocate Var[rparam, [[worker]Output Types >>]Index[rp num]] + }{ + rparam <- Val[rbase] + rfunc <- Val[ifunc] + } + }{ + rparam <- "" + rfunc <- Val[ifunc] + } + + Fold[["FInputs"]Set Input[3, [worker]Inputs >>], rfunc, [worker]Input Types >>] + { [~]Call Foreign[name, [worker]Convention >>, Map[Zip[[worker]Inputs >>, [worker]Input Types >>], "FParams"], rparam] + { Fold[[[["Save Foreign Result"]Set Input[3, [worker]Output Types >>]]Set Input[4, [worker]Inputs >>]]Set Input[5, [worker]Input Types >>], ~, [worker]Outputs >>] + { out <- [program]Store Function[~] }}} +} Compile Worker@NWorker[worker,program,name:out] { - Print[["Compiling: "]Append[name]] + If[[worker]Builtin? >>] { - 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, ~] - }{ - final func <- Val[func] - } - out <- [program]Store Function[Fold["Release", Fold[["Release Var"]Set Input[0, worker], final func, res vars], [worker]Inputs >>]] + out <- program + }{ + If[[[worker]Library >>] = [""]] + { + Print[["Compiling: "]Append[name]] + { + 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, ~] + }{ + final func <- Val[func] + } + 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] + } } } @@ -738,7 +1099,7 @@ NBlueprint[:out] { - out <- [[Build["NBlueprint"]]Fields <<[()]]Methods <<[New@Dictionary[]] + out <- [[Build["NBlueprint"]]Fields <<[()]]Methods <<[Dictionary[]] } Add Field@NBlueprint[bp,name,type:out] @@ -751,6 +1112,18 @@ out <- [bp]Methods <<[ [[bp]Methods >>]Set[name, Yes] ] } +Understands Method@NBlueprint[bp,name:out] +{ + out <- [[bp]Methods >>]Index[name] {} + { out <- No } +} + +Get Field Type@NBlueprint[bp,name:out,notfound] +{ + ,notfound <- [[bp]Fields >>]Index[name] + { out <- [~]Index[1] } +} + _Compile Blueprint Fields[type,field:out] { name <- [field]Index[0] @@ -766,10 +1139,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 +1187,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 +1199,45 @@ 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"] + { Print["Got getter"] } + } + + 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] - ]Move["obj", "out"] - { Print["got setter"] } + 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 +1247,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 +1256,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 >>] @@ -880,16 +1283,18 @@ 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] { - after bind <- [prog]Workers << [ [[prog]Workers >>]Set[name, worker] ] + after bind <- [prog]Workers << [ [[prog]Workers >>]Set[name, [worker]Name <<[name]] ] parts <- [name]Split["@"] [parts]Index[1] - { - out <- [after bind]Blueprints <<[ [[after bind]Blueprints >>]Set[~, [[[after bind]Blueprints >>]Index[~]]Add Method[[parts]Index[0]] ] ] + { + orig bp <- [[after bind]Blueprints >>]Index[~] {} + { orig bp <- NBlueprint[] } + out <- [after bind]Blueprints <<[ [[after bind]Blueprints >>]Set[~, [orig bp]Add Method[[parts]Index[0]] ] ] }{ out <- Val[after bind] } @@ -906,42 +1311,84 @@ 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] -{ +{ + Print["_Compile Program"] out <- [worker]Compile Worker[backend, name] } Compile Program@NProgram[prog, backend:out] +{ + 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] { - out <- Fold["_Compile Program", Fold["_Compile Program BP", backend, [prog]Blueprints >>], [prog]Workers >>] + out <- [prog]Worker Refs <<[ [[prog]Worker Refs >>]Set[name, Worker Ref[name, convention, inputs, outputs, Yes]]] } Register Worker@NProgram[prog, name, convention, inputs, outputs: out] { Print[["Register Worker "]Append[name]] - after reg <- [prog]Worker Refs <<[ [[prog]Worker Refs >>]Set[name, Worker Ref[name, convention, inputs, outputs]]] - parts <- [name]Split["@"] - [parts]Index[1] - { - out <- [prog]Register Worker[[parts]Index[0], convention, inputs, outputs] - }{ - out <- Val[after reg] - } + after reg <- [prog]Worker Refs <<[ + [ [prog]Worker Refs >> ]Set[name, + Worker Ref[name, convention, inputs, outputs, No] + ] + ] + parts <- [name]Split["@"] + [parts]Index[1] + { + out <- [after reg]Register Method@NProgram[[parts]Index[0], convention, inputs, outputs] + }{ + out <- Val[after reg] + } } Register Builtins@NProgram[prog:out] { - out <- [[[[[[[[[[[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] - ]Register Worker["If@Yes No", "rhope", 1, 2] - ]Register Worker["<@Int32", "rhope", 2, 1] - ]Register Worker[">@Int32", "rhope", 2, 1] - ]Register Worker["Build", "rhope", 1, 1] + 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 Number Methods + + out <- [[[[registered]Bind Worker["If@Boolean", + [[[[[NWorker["rhope"] + ]Inputs <<[("condition")] + ]Input Types <<[ [()]Append[Type Instance["Boolean"]] ] + ]Outputs <<[("isyes","isno")] + ]Output Types <<[ [[()]Append[Type Instance["Boolean"]]]Append[Type Instance["Boolean"]] ] + ]Builtin? <<[Yes]] + ]Bind Worker["Print", + [[[[[NWorker["rhope"] + ]Inputs <<[("value")] + ]Input Types <<[ [()]Append[Type Instance["Any Type"]] ] + ]Outputs <<[("out")] + ]Output Types <<[ [()]Append[Type Instance["Int32"]] ] + ]Builtin? <<[Yes]] + ]Bind Worker["Build", + [[[[[NWorker["rhope"] + ]Inputs <<[("type")] + ]Input Types <<[ [()]Append[Type Instance["Blueprint"]] ] + ]Outputs <<[("out")] + ]Output Types <<[ [()]Append[Type Instance["Any Type"]] ] + ]Builtin? <<[Yes]] + ]Bind Worker["Blueprint Of", + [[[[[NWorker["rhope"] + ]Inputs <<[("object")] + ]Input Types <<[ [()]Append[Type Instance["Any Type"]]] + ]Outputs <<[("type")] + ]Output Types <<[ [()]Append[Type Instance["Blueprint"]]] + ]Builtin? <<[Yes]] } Find Worker@NProgram[prog, name:out,notfound] @@ -950,3 +1397,35 @@ out,notfound <- [[prog]Worker Refs >>]Index[name] } +Find Worker Def@NProgram[prog,name:out,notfound] +{ + out,notfound <- [[prog]Workers >>]Index[name] +} + +Find Method@NProgram[prog, name, type:out,notfound] +{ + bp,notfound <- [[prog]Blueprints >>]Index[[type]Name >>] + ,notfound <- If[[bp]Understands Method[name]] + { + out <- [[prog]Workers >>]Index[[[name]Append["@"]]Append[[type]Name >>]] + } +} + +Find Field@NProgram[prog, name, type:fieldtype,notfound] +{ + bp,notfound <- [[prog]Blueprints >>]Index[[type]Name >>] + fieldtype,notfound <- [bp]Get Field Type[name] +} + +Implicit Conversion@NProgram[prog, fromtype, totype:func,notfound] +{ + notfound <- No +} + +Is Method?@NProgram[prog,name:is,is not] +{ + ,is not <- [[prog]Worker Refs>>]Index[name] + { + is,is not <- If[[~]Is Method? >>] + } +} diff -r b218af069da7 -r 04baa003de5a parser.vistxt --- a/parser.vistxt Sat Oct 10 16:43:37 2009 -0400 +++ b/parser.vistxt Wed May 05 22:12:23 2010 -0400 @@ -69,7 +69,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"]] :| Company Output Reference @@ -87,7 +87,7 @@ |: reflist <- [refs(0)]Index[name(1)] |::| |: - reflist <- New@List[] + reflist <- List[] :| out(0) <- [refs(0)]Set[name(1), [reflist]Append[reference(2)]] :| @@ -113,9 +113,9 @@ New@Parse Program(0,1) |: out(0) <- [[[Build["Parse Program"] - ]Workers <<[New@Dictionary[]] - ]Imports <<[New@Dictionary[]] - ]Blueprints <<[New@Dictionary[]] + ]Workers <<[Dictionary[]] + ]Imports <<[Dictionary[]] + ]Blueprints <<[Dictionary[]] :| Company Blueprint Definition @@ -141,7 +141,7 @@ New@Parse Worker(4,1) |: - out(0) <- [[[[[[Build["Parse Worker"]]Name <<[name(0)]]Inputs <<[inputs(1)]]Outputs <<[outputs(2)]]Line Number <<[line(3)]]Trees <<[New@List[]]]Uses Stores <<[New@List[]] + out(0) <- [[[[[[Build["Parse Worker"]]Name <<[name(0)]]Inputs <<[inputs(1)]]Outputs <<[outputs(2)]]Line Number <<[line(3)]]Trees <<[List[]]]Uses Stores <<[List[]] :| Company Worker Node @@ -155,7 +155,7 @@ New@Worker Node(2,1) |: - out(0) <- [[[[Build["Worker Node"]]Name <<[name(0)]]Params <<[params(1)]]Assignments <<[New@List[]]]Blocks <<[New@List[]] + out(0) <- [[[[Build["Worker Node"]]Name <<[name(0)]]Params <<[params(1)]]Assignments <<[List[]]]Blocks <<[List[]] :| Add List Helper(6,3) @@ -351,7 +351,7 @@ New@Field Node(3,1) |: - out(0) <- [[[[[Build["Field Node"]]Name <<[name(0)]]Assignments <<[New@List[]]]Blocks <<[New@List[]]]Set? <<[set(2)]]Params <<[params(1)] + out(0) <- [[[[[Build["Field Node"]]Name <<[name(0)]]Assignments <<[List[]]]Blocks <<[List[]]]Set? <<[set(2)]]Params <<[params(1)] :| Add to Worker@Field Node(5,3) @@ -405,7 +405,7 @@ New@Named Pipe Node(1,1) |: - out(0) <- [[[Build["Named Pipe Node"]]Name <<[name(0)]]Assignments <<[New@List[]]]Blocks <<[New@List[]] + out(0) <- [[[Build["Named Pipe Node"]]Name <<[name(0)]]Assignments <<[List[]]]Blocks <<[List[]] :| Add to Worker@Named Pipe Node(5,3) @@ -478,7 +478,7 @@ New@Global Node(2,1) |: - out(0) <- [[[[Build["Global Node"]]Store <<[store(0)]]Name <<[name(1)]]Assignments <<[New@List[]]]Blocks <<[New@List[]] + out(0) <- [[[[Build["Global Node"]]Store <<[store(0)]]Name <<[name(1)]]Assignments <<[List[]]]Blocks <<[List[]] :| Add to Worker@Global Node(5,3) @@ -516,7 +516,7 @@ New@Literal Node(1,1) |: - out(0) <- [[[Build["Literal Node"]]Value <<[value(0)]]Assignments <<[New@List[]]]Blocks <<[New@List[]] + out(0) <- [[[Build["Literal Node"]]Value <<[value(0)]]Assignments <<[List[]]]Blocks <<[List[]] :| Add to Worker@Literal Node(5,3) @@ -599,7 +599,7 @@ |: If[[block count(3)] > [0]] |: - after, before <- [string(0)]Get DString[[[New@List[]]Append[begin comment(1)]]Append[end comment(2)]] |::| |::| + after, before <- [string(0)]Get DString[[[List[]]Append[begin comment(1)]]Append[end comment(2)]] |::| |::| |: If[[~] = [begin comment(1)]] |: @@ -686,7 +686,7 @@ :| :| -Blueprint(4,1) +PBlueprint(4,1) |: ,whitespace name <- [string(0)]Get Comment DString[[params(1)]Block Begin >>, params(1)] |: @@ -697,7 +697,7 @@ |: body lines <- [body]Split["\n"] more lines <- [[[body lines]Length] - [1]] + [name lines] - fields <- Fold[["Process Blueprint Field"]Set Input[2, [params(1)]Blueprint Type Delim >>], New@List[], Filter[Map[body lines, ["Trim"]Set Input[1,"\n\r\t "]], "Filter Empty"]] + fields <- Fold[["Process Blueprint Field"]Set Input[2, [params(1)]Blueprint Type Delim >>], List[], Filter[Map[body lines, ["Trim"]Set Input[1,"\n\r\t "]], "Filter Empty"]] new tree <- [tree(2)]Blueprints << [ [[tree(2)]Blueprints >>]Set[name, New@Blueprint Definition[name, fields]] ] out(0) <- Null[~, params(1), new tree, [lines(3)] + [more lines]] :| |::| |: @@ -730,7 +730,7 @@ If[[check block]Starts With[[params(1)]Block Begin >>]] |: ,begin block <- [check block]Slice[[[params(1)]Block Begin >>]Length] - trees, after block <- Worker Body[begin block, params(1), New@List[]] + trees, after block <- Worker Body[begin block, params(1), List[]] blocks(0), after(1) <- Get Expression Blocks[after block, params(1), [blocks(2)]Append[trees]] :||: If[[check block]Starts With[[params(1)]Empty Block >>]] @@ -762,7 +762,7 @@ Parse String(3,2) |: - delims <- [[New@List[]]Append[[params(1)]String End >>]]Append[[params(1)]String Escape >>] + delims <- [[List[]]Append[[params(1)]String End >>]]Append[[params(1)]String Escape >>] after, before, delim <- [string(0)]Get Comment DString[delims, params(1)] |: If[[delim] = [[params(1)]String End >>]] @@ -839,7 +839,7 @@ If[[name]Starts With[[params(1)]List Begin >>]] |: ,list start <- [name]Slice[[[params(1)]List Begin >>]Length] - value,after(1) <- Parse List[list start, params(1), New@List[]] + value,after(1) <- Parse List[list start, params(1), List[]] :||: If[[[name]Slice[1]]In["-0123456789"]] |: @@ -933,7 +933,7 @@ Postfix or Infix(2,2) |: - args, after args <- Parse Arguments[string(0), params(1), New@List[]] + args, after args <- Parse Arguments[string(0), params(1), List[]] delims <- [[[[[{"\n"}]Append[[params(1)]Arg Begin >>]]Append[[params(1)]Empty Block >>]]Append[[params(1)]Block Begin >>]]Append[[params(1)]Arg End >>]]Append[[params(1)]List Delim >>] after,before,delim <- [after args]Get Comment DString[delims, params(1)] |: @@ -971,7 +971,7 @@ after expression <- [after literal]Append[[delim]Append[after]] expression, after literal <- Named Pipe or Literal[Right Trim[before, "\r\n\t "], params(1)] :||: - expression, after expression <- Prefix[after, params(1), maybe name, New@List[]] + expression, after expression <- Prefix[after, params(1), maybe name, List[]] :| :| :||: @@ -1003,7 +1003,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(1) <- Get Expression Blocks[after expression, params(1), New@List[]] + blocks,after blocks(1) <- Get Expression Blocks[after expression, params(1), List[]] final expression(0) <- [expression]Blocks <<[blocks] :| :| @@ -1043,7 +1043,7 @@ worker name <- Trim[whitespace name, "\n\r\t "] in out <- [params(1)]In Out Delim >> arg end <- [params(1)]Arg End >> - delims <- [[New@List[]]Append[in out]]Append[arg end] + delims <- [[List[]]Append[in out]]Append[arg end] after <- [~]Get Comment DString[delims, params(1)] |::| |: arglist <- Trim[~,"\r\n\t "] @@ -1067,7 +1067,7 @@ |: body text, modifiers <- [after arglist]Get Comment DString[[params(1)]Block Begin >>, params(1)] modified <- Process Modifiers[~, params(1), modifiers] - expression trees, after body <- Worker Body[body text, params(1), New@List[]] + expression trees, after body <- Worker Body[body text, params(1), List[]] worker <- [modified]Trees <<[expression trees] new worker dict <- [[tree(2)]Workers >>]Set[worker name, worker] out(0) <- Null[after body, params(1), [tree(2)]Workers <<[new worker dict], 0] @@ -1084,7 +1084,7 @@ current line <- 0//[lines(3)] + [Count Substring[whitespace, "\n"]] If[[trimmed]Starts With[ [params(1)]Blueprint >> ]] |: - out(0) <- Blueprint[trimmed, params(1), tree(2), current line] + out(0) <- PBlueprint[trimmed, params(1), tree(2), current line] :||: If[[trimmed]Starts With[ [params(1)]Import >> ]] |: @@ -1109,13 +1109,13 @@ Add Wires Helper(5,1) |: - worker(0) <- [node(1)]Add Wires[worker(0), New@List[], parse worker(3), assignments(4)] + worker(0) <- [node(1)]Add Wires[worker(0), List[], parse worker(3), assignments(4)] :| Add Contents(3,2) |: worker <- [[program(2)]Find Worker[name(1)]]Uses[[parse worker(0)]Uses Stores >>] - trees, contents worker, refs <- Add List to Worker[[parse worker(0)]Trees >>, worker, program(2), parse worker(0), New@Dictionary[]] + trees, contents worker, refs <- Add List to Worker[[parse worker(0)]Trees >>, worker, program(2), parse worker(0), Dictionary[]] Fold[[["Add Wires Helper"]Set Input[3, parse worker(0)]]Set Input[4, refs], contents worker, trees] out(0) <- [parse worker(0)]Trees <<[trees] key(1) <- name(1) @@ -1147,7 +1147,7 @@ Tree to Program(1,1) |: - out(0) <- _Tree to Program[parse tree(0), [New@Program[]]Add Builtins] + out(0) <- _Tree to Program[parse tree(0), [Program[]]Add Builtins] :| Needs Imports(3,1) @@ -1170,7 +1170,7 @@ Process Imports(2,1) |: - needs import <- Fold["Needs Imports", New@List[], [parse tree(0)]Imports >>] + needs import <- Fold["Needs Imports", List[], [parse tree(0)]Imports >>] If[[[needs import]Length] > [0]] |: import tree <- Fold[["Do Import"]Set Input[3, params(1)], parse tree(0), needs import] @@ -1234,16 +1234,16 @@ |: _REPL[params(0), _Tree to Program[import tree, prog(1)], ~] :| :| :||: - trees <- Worker Body[[line]Append["}"], params(0), New@List[]] - tree <- [New@Worker Node["Val", [New@List[]]Append[[trees]Index[0]]]]Assignments <<[{"__out"}] - this stores <- [[tree]Gather Stores[params(0), New@Dictionary[]]]Keys + trees <- Worker Body[[line]Append["}"], params(0), List[]] + tree <- [New@Worker Node["Val", [List[]]Append[[trees]Index[0]]]]Assignments <<[{"__out"}] + this stores <- [[tree]Gather Stores[params(0), Dictionary[]]]Keys next stores <- Fold["_Init Used Store", stores(2), this stores] |: - pworker <- [[New@Parse Worker["__Eval", New@List[], {"__out"}, 0]]Trees <<[[New@List[]]Append[tree]]]Uses Stores <<[this stores] + pworker <- [[New@Parse Worker["__Eval", List[], {"__out"}, 0]]Trees <<[[List[]]Append[tree]]]Uses Stores <<[this stores] :| [[prog(1)]Find Worker["__Eval"]]Clear |: Add Contents[pworker, "__Eval", prog(1)] - |: Pretty Print[[[[prog(1)]Find Worker["__Eval"]]Do[New@List[]]]Index[0], ""] + |: Pretty Print[[[[prog(1)]Find Worker["__Eval"]]Do[List[]]]Index[0], ""] |: _REPL[params(0), prog(1), next stores] :| :| :| :| :| @@ -1253,7 +1253,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(0), New@Parse Program[], 0]] - _REPL[params(0), prog, New@Dictionary[]] + _REPL[params(0), prog, Dictionary[]] :| Add If Store(3,1) @@ -1313,7 +1313,7 @@ Null[text, params, New@Parse Program[], 0] |: tree <- Process Imports[~, params] - Init Used Stores[tree, New@Dictionary[]] + Init Used Stores[tree, Dictionary[]] |: [Tree to Program[tree]]Run[[args(0)]Tail[1]] :| :| :||: diff -r b218af069da7 -r 04baa003de5a parser_old.rhope --- a/parser_old.rhope Sat Oct 10 16:43:37 2009 -0400 +++ b/parser_old.rhope Wed May 05 22:12:23 2010 -0400 @@ -33,11 +33,12 @@ Uses Hex Escape Escape Map + Foreign } New@Parser[:out] { - out <- [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[Build["Parser"] + out <- [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[Build["Parser"] ]Arg Begin << ["["] ]Arg End <<["]"] ]Line Comment <<["//"] @@ -67,7 +68,8 @@ ]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"]] + ]Foreign <<["Foreign"] } Blueprint Output Reference @@ -85,7 +87,7 @@ { reflist <- [refs]Index[name] {} { - reflist <- New@List[] + reflist <- () } out <- [refs]Set[name, [reflist]Append[reference]] } @@ -100,6 +102,19 @@ } } +Blueprint Foreign Lib +{ + Language + Name +} + +New Foreign Lib[language, library:out] +{ + out <- [[Build["Foreign Lib"] + ]Language <<[language] + ]Name <<[library] +} + Blueprint Parse Program { Workers @@ -111,9 +126,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]]Set["string.rhope", Yes]] + ]Blueprints <<[Dictionary[]] } Blueprint Blueprint Definition @@ -141,7 +156,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 +170,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 +432,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 +489,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 +566,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 +604,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] @@ -645,7 +660,7 @@ out <- [[[Build["Parse Error"]]Type <<[type]]Text <<[text]]Line Number <<[number] } -Filter Empty[string:out] +Not Empty[string:out] { If[[[string]Length] > [0]] { @@ -706,7 +721,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 +819,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 "]], "Not Empty"]] new tree <- [tree]Blueprints << [ [[tree]Blueprints >>]Set[name, New@Blueprint Definition[name, fields]] ] out <- Null[~, params, new tree, [lines] + [more lines]] } {} { @@ -837,7 +852,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 +884,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 >>]] @@ -912,6 +927,18 @@ out <- node } +Blueprint Machine Integer +{ + Value + Size + Signed? +} + +Machine Integer[value,size,signed?:out] +{ + out <- [[[Build["Machine Integer"]]Value <<[value]]Size <<[size]]Signed? <<[signed?] +} + Parse Number[string,params:value,after] { delims <- [[[[(" ","\t","\n","\r")]Append[[params]List Delim >>]]Append[[params]Block Begin >>]]Append[[params]Arg End >>]]Append[[params]List End >>] @@ -930,7 +957,12 @@ { value <- >]] { ,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 +1087,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 +1125,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 +1157,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] } } @@ -1196,15 +1228,21 @@ { ,warn <- If[[Type Of[~]] = ["Named Pipe Node"]] { - paramtype,warn <- [before variant]Set Variant[[variant]Name >>] + before mutable,warn <- [before variant]Set Variant[[variant]Name >>] } Val[warn] { Print[[[["Warning: Invalid variant for type "]Append[[before variant]Name >>]]Append[" on input "]]Append[param name]] - paramtype <- Val[before variant] + before mutable <- Val[before variant] } }{ - paramtype <- Val[before variant] + before mutable <- Val[before variant] + } + [type info]Index[2] + { + paramtype <- [before mutable]Mutable? <<[ [[~]Name >>] = ["Mutable"] ] + }{ + paramtype <- Val[before mutable] } }{ paramtype <- Type Instance["Any Type"] @@ -1228,7 +1266,7 @@ } } -Worker Name[string,params,tree,lines:out] +Worker Declaration[string,params:worker,rest,no match] { ,whitespace name <- [string]Get Comment DString[[params]Arg Begin >>, params] { @@ -1236,7 +1274,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 "] @@ -1245,40 +1283,79 @@ //if it isn't present, everything in the arglist is an input If[[~] = [in out]] { - after arglist <- [after]Get Comment DString[arg end, params] {} + rest <- [after]Get Comment DString[arg end, params] {} { outputs,output types <- Parse Param List[~, (), (), params] { Print["got outputs"] } { Print["got output types"] } } }{ - after arglist <- Val[after] + rest <- Val[after] outputs <- () output types <- () } inputs,input types <- Parse Param List[arglist, (), (), params] { Print["got inputs"] } { Print["got input types"] } - - //inputs <- Map[[arglist]Split[[params]List Delim >>], ["Trim"]Set Input[1,"\n\r\t "]] - //outputs <- Map[[output string]Split[[params]List Delim >>], ["Trim"]Set Input[1,"\n\r\t "]] - - New@Parse Worker[worker name, inputs, outputs, input types, output types, 0] - { - 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[]] - 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] - } + worker <- New@Parse Worker[worker name, inputs, outputs, input types, output types, 0] } }{}{}{ + no match <- string + } +} + +Worker Name[string,params,tree,lines:out] +{ + ,after arglist <- Worker Declaration[string, params] + { + Print["Got parse worker"] + worker name <- [~]Name >> + 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, ()] + 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] + } {} { out <- tree } } +Parse Foreign Worker[tree, string, lib, params:out] +{ + ,rest <- Worker Declaration[string, params] + { + foreign <- [~]Trees << [lib] + next <- [tree]Workers << [[[tree]Workers >>]Set[[foreign]Name >>, foreign]] + out <- Parse Foreign Worker[next, rest, lib, params] + } {} { + out <- tree + } +} + +Parse Foreign[string,params,tree,lines:out] +{ + Print["Foreign block"] + ,after foreign <- [string]Slice[[[params]Foreign >>]Length] + Print[[after foreign]Slice[20]] + [after foreign]Get Comment DString[[params]Blueprint Type Delim >>, params] + { + [~]Get Comment DString[[params]Block Begin >>, params] + { + rest, body <- [~]Get Comment DString[[params]Block End >>, params] + } + { lib <- Trim[~, "\r\n\t "] } + } + { language <- Trim[~, "\r\n\t "] } + Print[[[["Language: "]Append[language]]Append[" Library: "]]Append[lib]] + { + Parse Foreign Worker[tree, body, New Foreign Lib[language, lib], params] + { + out <- Null[rest, params, ~, 0] + } + } +} + Null[string,params,tree,lines:out] { trimmed <- Comment Left Trim[string, " \n\r\t", params] @@ -1291,7 +1368,12 @@ { out <- Parse Import[trimmed, params, tree, current line] }{ - out <- Worker Name[trimmed, params, tree, current line] + If[[trimmed]Starts With[ [params]Foreign >> ]] + { + out <- Parse Foreign[trimmed, params, tree, current line] + }{ + out <- Worker Name[trimmed, params, tree, current line] + } } } } @@ -1311,16 +1393,31 @@ Register Workers Compile[prog, worker, name:out] { Print[["Registering "]Append[name]] - out <- [prog]Register Worker[name, "rhope", [[worker]Inputs >>]Length, [[worker]Outputs >>]Length] + If[[ Type Of[[worker]Trees >>] ] = ["Foreign Lib"]] + { convention <- Val[[[worker]Trees >>]Language >>] } + { convention <- "rhope" } + out <- [prog]Register Worker[name, convention, [[worker]Inputs >>]Length, [[worker]Outputs >>]Length] } Add Workers Compile[prog, worker, name:out] { 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[]] - final nworker <- Fold[[["Add Wires Helper"]Set Input[3, worker]]Set Input[4, refs], nworker, trees] - out <- [prog]Bind Worker[name, final nworker] + If[[Type Of[[worker]Trees >>]] = ["Foreign Lib"]] + { + //TODO: Handle foreign func + final nworker <- [[[[[NWorker[[[worker]Trees >>]Language >>] + ]Inputs <<[ [worker]Inputs >> ] + ]Input Types <<[ [worker]Input Types >> ] + ]Outputs <<[ [worker]Outputs >> ] + ]Output Types <<[ [worker]Output Types >> ] + ]Library <<[ [[worker]Trees >>]Name >> ] + + }{ + 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 +1425,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 +1434,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,14 +1477,15 @@ 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 "] } } Needs Imports[needs import,not imported?,name:out] @@ -1410,7 +1508,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] @@ -1475,16 +1573,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 @@ -1493,7 +1591,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] } } } @@ -1505,7 +1603,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] diff -r b218af069da7 -r 04baa003de5a putchar.rhope --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/putchar.rhope Wed May 05 22:12:23 2010 -0400 @@ -0,0 +1,17 @@ + + +Foreign C:libc +{ + putchar[char(Int32,Naked):out(Int32,Naked)] +} + +Main[] +{ + putchar[72] + { putchar[101] + { putchar[108] + { putchar[108] + { putchar[111] + { putchar[10] }}}}} +} + diff -r b218af069da7 -r 04baa003de5a runtime/array.c --- a/runtime/array.c Sat Oct 10 16:43:37 2009 -0400 +++ b/runtime/array.c Wed May 05 22:12:23 2010 -0400 @@ -1,26 +1,55 @@ -#include "array.h" -#include "integer.h" - -Func(Array,0, - ;) - Ret(0, new_object(TYPE_ARRAY)) - Return -EndFunc +#include "integer.h" +#include "object.h" -Method(Index,Array,2, - _t_Int32 * idx;) - Param(1,idx,Int32) - if (idx->num < 0 || idx->num >= me->numels) { - Ret(0, NULL) - Ret(1, me) - } else { - Ret(1, NULL) - if (me->contents_type) { - Ret(0, copy_from_raw(me->conents_type, (char *)me + sizeof(*me) + (idx->num * sizeof(object *)))) - } else { - Ret(0, add_ref((object *)((char *)me + sizeof(*me) + (idx->num * sizeof(object *))))) - } - release_ref(me); - } -EndFunc +void _internal_array_copyout(object * array, int32_t index, object * dest) +{ + t_Array * arr = (t_Array *)array; + memcpy(((char *)dest) + sizeof(object), ((char *)array) + sizeof(t_Array) + arr->payload.Eltype->bp->size * index, get_blueprint(dest)->size); +} + +void _internal_array_copyin(object * array, int32_t index, object * val) +{ + t_Array * arr = (t_Array *)array; + memcpy(((char *)array) + sizeof(t_Array) + arr->payload.Eltype->bp->size * index, ((char *)val) + sizeof(object), arr->payload.Eltype->bp->size); +} + +object * _internal_array_getboxed(object * array, int32_t index) +{ + object * ret; + object ** intarr = (object **)(((char *) array) + sizeof(t_Array)); + ret = add_ref(intarr[index]); + release_ref(array); + return ret; +} + +void _internal_array_setboxed(object *array, int32_t index, object * val) +{ + object ** intarr = (object **)(((char *) array) + sizeof(t_Array)); + intarr[index] = val; +} + +object *_internal_array_allocboxed(int32_t size) +{ + t_Array * ret = (t_Array *)new_multisize(TYPE_ARRAY, sizeof(nt_Array)+sizeof(object *)*size); + ret->payload.Length = 0; + ret->payload.Storage = size; + ret->payload.Eltype = (t_Blueprint *)make_Blueprint(0); + + return (object *)ret; +} + +object * _internal_array_allocnaked(int32_t size , object * type) +{ + t_Array * ret; + t_Blueprint * bp = (t_Blueprint *)type; + if (bp->bp->size < 0) { + return _internal_array_allocboxed(size); + } + ret = (t_Array *)new_multisize(TYPE_ARRAY, sizeof(nt_Array)+bp->bp->size*size); + ret->payload.Length = 0; + ret->payload.Storage = size; + ret->payload.Eltype = bp; + + return ret; +} diff -r b218af069da7 -r 04baa003de5a runtime/array.h --- a/runtime/array.h Sat Oct 10 16:43:37 2009 -0400 +++ b/runtime/array.h Wed May 05 22:12:23 2010 -0400 @@ -3,12 +3,14 @@ #include "object.h" #include "func.h" -#include "builtin.h" +#include "builtin.h" -MOBegin - blueprint *contents_type; - int32 numels; -Object(Array) +void _internal_array_copyout(object * array, int32_t index, object * dest); +void _internal_array_copyin(object * array, int32_t index, object * val); +object * _internal_array_getboxed(object * array, int32_t index); +void _internal_array_setboxed(object *, int32_t index, object * val); +object *_internal_array_allocboxed(int32_t size); +object * _internal_array_allocnaked(int32_t size , object * type); -#endif //_ARRAY_H_ \ No newline at end of file +#endif //_ARRAY_H_ diff -r b218af069da7 -r 04baa003de5a runtime/block_alloc.h --- a/runtime/block_alloc.h Sat Oct 10 16:43:37 2009 -0400 +++ b/runtime/block_alloc.h Wed May 05 22:12:23 2010 -0400 @@ -6,7 +6,14 @@ #include #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*4 +#include + +#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 diff -r b218af069da7 -r 04baa003de5a runtime/blueprint.c --- a/runtime/blueprint.c Sat Oct 10 16:43:37 2009 -0400 +++ b/runtime/blueprint.c Wed May 05 22:12:23 2010 -0400 @@ -1,6 +1,7 @@ #include "blueprint.h" #include "builtin.h" -#include "context.h" +#include "context.h" +#include typedef struct { @@ -18,6 +19,18 @@ release_ref(cdata->params[0]); Ret(0, new_object_bp(locals->bp)) +EndFunc + +Func(BlueprintSP_Of, + NumParams 1, + CallSpace 1, + l_Build) + + locals->bp = get_blueprint(cdata->params[0]); + release_ref(cdata->params[0]); + + Ret(0, new_object(TYPE_BLUEPRINT)) + ((t_Blueprint *)cdata->params[0])->bp = locals->bp; EndFunc object * make_Blueprint(int32_t type_id) @@ -25,6 +38,15 @@ t_Blueprint * obj; object * ret = new_object(TYPE_BLUEPRINT); obj = (t_Blueprint *)ret; - obj->bp = get_blueprint_byid(type_id); + obj->bp = type_id ? get_blueprint_byid(type_id) : NULL; return ret; -} +} + +int32_t _internal_blueprint_eq(object * left, object * right) +{ + t_Blueprint * l = (t_Blueprint *)left; + t_Blueprint * r = (t_Blueprint *)right; + return l->bp == r->bp; +} + + diff -r b218af069da7 -r 04baa003de5a runtime/blueprint.h --- a/runtime/blueprint.h Sat Oct 10 16:43:37 2009 -0400 +++ b/runtime/blueprint.h Wed May 05 22:12:23 2010 -0400 @@ -4,11 +4,11 @@ #include "object.h" #include "func.h" -OBegin - blueprint * bp; -Object(Blueprint) +Box(blueprint *,bp,Blueprint) object * make_Blueprint(int32_t type_id); -FuncDef(Build) +FuncDef(Build) +FuncDef(BlueprintSP_Of) +int32_t _internal_blueprint_eq(object * left, object * right); #endif //BLUEPRINT_H_ diff -r b218af069da7 -r 04baa003de5a runtime/bool.c --- a/runtime/bool.c Sat Oct 10 16:43:37 2009 -0400 +++ b/runtime/bool.c Wed May 05 22:12:23 2010 -0400 @@ -4,5 +4,4 @@ #include "context.h" #include -t_Boolean * val_yes; -t_Boolean * val_no; + diff -r b218af069da7 -r 04baa003de5a runtime/bool.h --- a/runtime/bool.h Sat Oct 10 16:43:37 2009 -0400 +++ b/runtime/bool.h Wed May 05 22:12:23 2010 -0400 @@ -2,15 +2,6 @@ #define BOOL_H_ #include "object.h" -OBegin - int32_t val; -Object(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; #endif //BOOL_H_ diff -r b218af069da7 -r 04baa003de5a runtime/builtin.c --- a/runtime/builtin.c Sat Oct 10 16:43:37 2009 -0400 +++ b/runtime/builtin.c Wed May 05 22:12:23 2010 -0400 @@ -3,35 +3,18 @@ #include "integer.h" #include "bool.h" #include -#include +#include +#include +#include void register_builtin_type(uint32_t type) { 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)); */ + case TYPE_BLUEPRINT: + bp = register_type_byid(TYPE_BLUEPRINT, sizeof(blueprint *), NULL, NULL, NULL); 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;*/ } } @@ -40,5 +23,107 @@ uint32_t i; for(i = 0; i < TYPE_FIRST_USER; ++i) register_builtin_type(i); -} +} +object * make_Int64(int64_t val) +{ + t_Int64 * obj; + object * ret = new_object(TYPE_INT64); + obj = (t_Int64 *)ret; + obj->Num = val; + return ret; +} + +object * make_Int32(int32_t val) +{ + t_Int32 * obj; + object * ret = new_object(TYPE_INT32); + obj = (t_Int32 *)ret; + obj->Num = val; + return ret; +} + +object * make_Int16(int16_t val) +{ + t_Int16 * obj; + object * ret = new_object(TYPE_INT16); + obj = (t_Int16 *)ret; + obj->Num = val; + return ret; +} + +object * make_Int8(int8_t val) +{ + t_Int8 * obj; + object * ret = new_object(TYPE_INT8); + obj = (t_Int8 *)ret; + obj->Num = val; + return ret; +} + +object * make_UInt64(uint64_t val) +{ + t_UInt64 * obj; + object * ret = new_object(TYPE_UINT64); + obj = (t_UInt64 *)ret; + obj->Num = val; + return ret; +} + +object * make_UInt32(uint32_t val) +{ + t_UInt32 * obj; + object * ret = new_object(TYPE_UINT32); + obj = (t_UInt32 *)ret; + obj->Num = val; + return ret; +} + +object * make_UInt16(uint16_t val) +{ + t_UInt16 * obj; + object * ret = new_object(TYPE_UINT16); + obj = (t_UInt16 *)ret; + obj->Num = val; + return ret; +} + +object * make_UInt8(uint8_t val) +{ + t_UInt8 * obj; + object * ret = new_object(TYPE_UINT8); + obj = (t_UInt8 *)ret; + obj->Num = val; + return ret; +} + +object * make_String(char * text) +{ + returntype ret; + context * ct; + calldata * cdata; + object * retobj; + t_Array * arr = (t_Array *)_internal_array_allocnaked(strlen(text), make_Blueprint(TYPE_UINT8)); + arr->payload.Length = arr->payload.Storage; + memcpy(((char *)arr) + sizeof(t_Array), text, arr->payload.Length); + + //This is really ugly, but I don't see a good way around it at the moment + ct = new_context(); + cdata = alloc_cdata(ct, 1); + cdata->params[0] = (object *)arr; + cdata->num_params = 1; + cdata->resume = 0; + ret = f_String(cdata); + while(ret == TAIL_RETURN) + ret = cdata->tail_func(cdata); + if(ret == EXCEPTION_RETURN) + { + puts("Exception while building string literal!"); + exit(-1); + } + retobj = cdata->params[0]; + free_context(ct); + return retobj; +} + + diff -r b218af069da7 -r 04baa003de5a runtime/context.c --- a/runtime/context.c Sat Oct 10 16:43:37 2009 -0400 +++ b/runtime/context.c Wed May 05 22:12:23 2010 -0400 @@ -19,6 +19,18 @@ c->stack_begin = new_stack(); c->current_stack = c->stack_begin; return c; +} + +void free_context(context * c) +{ + stackchunk *next,*current = c->stack_begin; + while(current) + { + next = current->next; + free(current); + current = next; + } + free(c); } void * alloc_stack(context * ct, uint32_t size) diff -r b218af069da7 -r 04baa003de5a runtime/context.h --- a/runtime/context.h Sat Oct 10 16:43:37 2009 -0400 +++ b/runtime/context.h Wed May 05 22:12:23 2010 -0400 @@ -22,6 +22,7 @@ stackchunk * new_stack(); context * new_context(); void * alloc_stack(context * ct, uint32_t size); -struct calldata * alloc_cdata(context * ct, struct calldata * lastframe, uint32_t num_params); -void free_stack(context * ct, void * data); +calldata * alloc_cdata(context * ct, uint32_t num_params); +void free_stack(context * ct, void * data); +void free_context(context * c); #endif //_CONTEXT_H_ diff -r b218af069da7 -r 04baa003de5a runtime/fixed_alloc.c --- a/runtime/fixed_alloc.c Sat Oct 10 16:43:37 2009 -0400 +++ b/runtime/fixed_alloc.c Wed May 05 22:12:23 2010 -0400 @@ -1,5 +1,6 @@ #include "fixed_alloc.h" -#include +#include +#include uint16_t max_free[(MAX_SIZE-MIN_SIZE)/STRIDE]; @@ -35,11 +36,13 @@ if(block) { --manager->freecount; - manager->freelist = block->next; + manager->freelist = block->next; + memset(block, 0xCD, BLOCK_SIZE); } else { - block = block_alloc(BLOCK_SIZE); + block = block_alloc(BLOCK_SIZE); + memset(block, 0xAB, BLOCK_SIZE); } manager->inuse[bucket] = block; block->next = NULL; @@ -78,7 +81,6 @@ block->next->last = block->last; } i = i*8+bit; - //printf("%X\n", ((char *)block)+BLOCK_SIZE-((i+1)*size)); return (void *)(((char *)block)+BLOCK_SIZE-((i+1)*size)); } @@ -92,7 +94,8 @@ return; } //puts("ffree"); - size = ADJUST_SIZE(size); + size = ADJUST_SIZE(size); + memset(ptr, 0xEF, size); block = GET_BLOCK(ptr); i = (((((char *)block) + BLOCK_SIZE) - ((char *)ptr))/size)-1; bit = i & 0x7; @@ -118,8 +121,10 @@ manager->inuse[bucket] = block->next; if(block->next) block->next->last = block->last; - if(manager->freecount == MAX_FREE) - block_free(block, BLOCK_SIZE); + if(manager->freecount == MAX_FREE) + { + block_free(block, BLOCK_SIZE); + } else { block->next = manager->freelist; diff -r b218af069da7 -r 04baa003de5a runtime/fixed_alloc.h --- a/runtime/fixed_alloc.h Sat Oct 10 16:43:37 2009 -0400 +++ b/runtime/fixed_alloc.h Wed May 05 22:12:23 2010 -0400 @@ -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) diff -r b218af069da7 -r 04baa003de5a runtime/func.h --- a/runtime/func.h Sat Oct 10 16:43:37 2009 -0400 +++ b/runtime/func.h Wed May 05 22:12:23 2010 -0400 @@ -1,6 +1,9 @@ #ifndef _FUNC_H_ #define _FUNC_H_ +typedef struct object object; +typedef struct calldata calldata; + typedef enum { NORMAL_RETURN=0, EXCEPTION_RETURN, @@ -10,10 +13,10 @@ } returntype; -typedef returntype (*rhope_func)(struct calldata *); -typedef void (*special_func) (struct object *); +typedef returntype (*rhope_func)(calldata *); +typedef void (*special_func) (object *); -#define MethodName(name,type) f_ ## name ## _AT_ ## type +#define MethodName(name,type) f_ ## name ## AT_ ## type #define Func(name,numparams) \ @@ -134,4 +137,4 @@ goto sf_ ## tocall; -#endif //_FUNC_H_ \ No newline at end of file +#endif //_FUNC_H_ diff -r b218af069da7 -r 04baa003de5a runtime/integer.c --- a/runtime/integer.c Sat Oct 10 16:43:37 2009 -0400 +++ b/runtime/integer.c Wed May 05 22:12:23 2010 -0400 @@ -3,11 +3,4 @@ #include "context.h" #include "bool.h" -object * make_Int32(int32_t val) -{ - t_Int32 * obj; - object * ret = new_object(TYPE_INT32); - obj = (t_Int32 *)ret; - obj->num = val; - return ret; -} + diff -r b218af069da7 -r 04baa003de5a runtime/integer.h --- a/runtime/integer.h Sat Oct 10 16:43:37 2009 -0400 +++ b/runtime/integer.h Wed May 05 22:12:23 2010 -0400 @@ -4,9 +4,6 @@ #include "object.h" #include "func.h" -OBegin - int32_t num; -Object(Int32) object * make_Int32(int32_t val); diff -r b218af069da7 -r 04baa003de5a runtime/object.c --- a/runtime/object.c Sat Oct 10 16:43:37 2009 -0400 +++ b/runtime/object.c Wed May 05 22:12:23 2010 -0400 @@ -294,10 +294,10 @@ blueprint * bp = get_blueprint(obj); if(bp->cleanup) bp->cleanup(obj); - ffree(multi, sizeof(multi) + multi->size, manager); + ffree(multi, sizeof(multisize) + multi->size, manager); } -blueprint * new_blueprint(uint32_t type, uint32_t size, special_func init, special_func copy, special_func cleanup) +blueprint * new_blueprint(uint32_t type, int32_t size, special_func init, special_func copy, special_func cleanup) { blueprint * bp = malloc(sizeof(blueprint)); //dirty hack!, move elsewhere @@ -322,7 +322,7 @@ return bp; } -blueprint * register_type_byid(uint32_t type, uint32_t size, special_func init, special_func copy, special_func cleanup) +blueprint * register_type_byid(uint32_t type, int32_t size, special_func init, special_func copy, special_func cleanup) { check_type_storage(type); if(registered_types[type]) diff -r b218af069da7 -r 04baa003de5a runtime/object.h --- a/runtime/object.h Sat Oct 10 16:43:37 2009 -0400 +++ b/runtime/object.h Wed May 05 22:12:23 2010 -0400 @@ -27,14 +27,14 @@ uint32_t last_convertto; uint32_t first_convertfrom; uint32_t last_convertfrom; - uint32_t size; - uint32_t boxed_size; + int32_t size; + int32_t boxed_size; } blueprint; -typedef struct object { +struct object { rh_atomic32(refcount); blueprint *bprint; -} object; +}; typedef struct { object base; @@ -48,13 +48,13 @@ uint16_t num_params; uint16_t resume; uint32_t func; -} calldata; +}; #pragma pack(pop) -#define OBegin typedef struct { object header; -#define Object(name) } t_ ## name; - -#define MOBegin typedef struct { multisize header; +#define OBegin typedef struct { +#define Object(name) } nt_ ## name; typedef struct { object SP_header; nt_ ## name payload; } t_ ## name; +#define MObject(name) } nt_ ## name; typedef struct { multisize SP_header; nt_ ## name payload; } t_ ## name; +#define Box(nakedtype,fieldname,objectname) typedef struct{ object SP_header; nakedtype fieldname; } t_ ## objectname; #define get_blueprint(object) (object)->bprint @@ -69,8 +69,8 @@ object * new_object_bp(blueprint * bp); multisize * new_multisize(uint32_t type, uint32_t size); void release_ref(object * obj); -blueprint * register_type_byid(uint32_t type, uint32_t size, special_func init, special_func copy, special_func cleanup); -blueprint * new_blueprint(uint32_t type, uint32_t size, special_func init, special_func copy, special_func cleanup); +blueprint * register_type_byid(uint32_t type, int32_t size, special_func init, special_func copy, special_func cleanup); +blueprint * new_blueprint(uint32_t type, int32_t size, special_func init, special_func copy, special_func cleanup); void add_method(blueprint * bp, uint32_t methodid, rhope_func impl); void add_getter(blueprint * bp, uint32_t fieldid, rhope_func impl); void add_setter(blueprint * bp, uint32_t fieldid, rhope_func impl); diff -r b218af069da7 -r 04baa003de5a runtime/plat_types.h --- a/runtime/plat_types.h Sat Oct 10 16:43:37 2009 -0400 +++ b/runtime/plat_types.h Wed May 05 22:12:23 2010 -0400 @@ -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 diff -r b218af069da7 -r 04baa003de5a string.rhope --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/string.rhope Wed May 05 22:12:23 2010 -0400 @@ -0,0 +1,123 @@ + +UTF8 Expect[num,arr,index,count,consumed:out] +{ + byte <- [arr]Index[index] + { + If[[128u8]>[byte]] + { + //Error: ASCII byte when we were expecting part of a mutlibyte sequence + //treat each byte as a separate character + ncount <- [1i32]+[[count]+[consumed]] + }{ + If[[192u8]>[byte]] + { + If[[num]=[1]] + { + //Sequence is complete count as single character + ncount <- [1i32]+[count] + }{ + out <- UTF8 Expect[[num]-[1], arr, [index]+[1], count, [1i32]+[consumed]] + } + }{ + //Error: too high to be a continuation byte + ncount <- [1i32]+[[count]+[consumed]] + } + } + }{ + //Error: string ended in the middle of a multi-byte sequence + out <- [count]+[consumed] + } + Val[ncount] + { + [arr]Next[index] + { + out <- Count UTF8[arr, ~, ncount] + }{ + out <- Val[ncount] + } + } +} + +Count UTF8[arr,index,count:out] +{ + byte <- [arr]Index[index] + If[[128u8]>[byte]] + { ncount <- [1i32]+[count] } + { + If[[192u8]>[byte]] + { + //Error: Encoding for 2nd,3rd or 4th byte of sequence + //treat as a single character + ncount <- [1i32]+[count] + }{ + If[[224u8]>[byte]] + { + out <- UTF8 Expect[1, arr, [index]+[1], count, 1] + }{ + If[[240u8]>[byte]] + { + out <- UTF8 Expect[2, arr, [index]+[1], count, 1] + }{ + If[[245u8]>[byte]] + { + out <- UTF8 Expect[3, arr, [index]+[1], count, 1] + }{ + //Error: Out of range of Unicode standard + //treat as a single character + ncount <- [1i32]+[count] + } + } + } + } + } + [arr]Next[index] + { + out <- Count UTF8[arr, ~, ncount] + }{ + out <- Val[ncount] + } +} + +Blueprint String +{ + Buffer + Length(Int32,Naked) +} + +String[in(Array):out(String)] +{ + out <- [[Build[String()]]Buffer <<[in]]Length <<[Count UTF8[in, 0, 0]] +} + +Print@String[string:out] +{ + //TODO: Sanitize string (remove terminal escapes and replace invalid UTF) + write[1i32, [string]Buffer >>, Int64[[[string]Buffer >>]Length >>]] + { out <- write[1i32, [Array[1]]Append[10u8], 1i64] } +} + +Flatten@String[string:out] +{ + out <- string +} + +Slice@String[string,slicepoint:left,right] +{ + //TODO: Handle invalid slicepoints + left <- String Slice[string, 0i32, slicepoint] + right <- String Slice[string, slicepoint, [[string]Length >>]-[slicepoint]] +} + +Blueprint String Slice +{ + Source + Offset(Int32,Naked) + Length(Int32,Naked) +} + +String Slice[source,offset,length:out(String Slice)] +{ + out <- [[[Build[String Slice()]]Source <<[source]]Offset <<[offset]]Length <<[length] +} + + diff -r b218af069da7 -r 04baa003de5a webserver.rhope --- a/webserver.rhope Sat Oct 10 16:43:37 2009 -0400 +++ b/webserver.rhope Wed May 05 22:12:23 2010 -0400 @@ -34,7 +34,7 @@ HTTP Response[client,type,content length,headers,code:out] { - start headers <- [New@Dictionary[]]Set["Content-Type", type] + start headers <- [Dictionary[]]Set["Content-Type", type] If[[content length] < [0]] { default headers <- [start headers]Set["Transfer-Encoding", "Chunked"] @@ -59,7 +59,7 @@ HTTP Not Found[client] { string <- "Document Not FoundThe document you requested is not available on this server." - HTTP Response[client, Get Content Type[".html"], [string]Length, New@Dictionary[], "404 Not Found"] + HTTP Response[client, Get Content Type[".html"], [string]Length, Dictionary[], "404 Not Found"] { [~]Put String[string] } @@ -75,28 +75,43 @@ }{ handlerpath <- "/" } - [handler]Index[handlerpath] + host <- [headers]Index["Host"] {} + { + host <- "" + } + + the handler <- [handler]Index[[host]Append[handlerpath]] {} + { + the handler <- [handler]Index[handlerpath] {} + { + ,newpath <- [path]Slice[1] + If[[newpath] = ["default.css"]] + { + file <- [0]] + { + junk,data <- [file]Get FString[content length] + [HTTP OK[client, Get Content Type[path], content length, Dictionary[]] + ]Put String@Net Client[data] + }{ + HTTP Not Found[client] + } + }{ + HTTP Not Found[client] + } + } + } + + Val[the handler] { If[[[parts]Length] > [1]] { queryvars <- Dict Split[[parts]Index[1], "=", "&"] }{ - queryvars <- New@Dictionary[] + queryvars <- Dictionary[] } - [~]Do@Worker[ [[[[[New@List[]]Append[client]]Append[path]]Append[type]]Append[queryvars]]Append[headers] ] - }{ - - ,newpath <- [path]Slice[1] - file <- [0]] - { - junk,data <- [file]Get FString[content length] - [HTTP OK[client, Get Content Type[path], content length, New@Dictionary[]] - ]Put String@Net Client[data] - }{ - HTTP Not Found[client] - } + [~]Do@Worker[ [[[[[List[]]Append[client]]Append[path]]Append[type]]Append[queryvars]]Append[headers] ] } }