# HG changeset patch # User Mike Pavone # Date 1290406502 18000 # Node ID f3686f60985deb2927d1446576abb91fd7ebbba9 # Parent 1f39e69446f95aa3736b8894a21dbf0f1ae5d7e7 Sort of working port of framework. Transaction bug seems to be getting in the way. Going to work around, but want the old version in the repo so I can test later. diff -r 1f39e69446f9 -r f3686f60985d basicweb.rhope --- a/basicweb.rhope Sun Nov 21 22:47:14 2010 -0500 +++ b/basicweb.rhope Mon Nov 22 01:15:02 2010 -0500 @@ -9,7 +9,7 @@ { [args]Index[1] { port <- Int32[~] } - { port <- 80 } + { port <- Val[80] } Print["Starting webserver"] //Since we're just serving static files we don't need to setup any handlers handlers <- Dictionary[] diff -r 1f39e69446f9 -r f3686f60985d cbackend_c.rhope --- a/cbackend_c.rhope Sun Nov 21 22:47:14 2010 -0500 +++ b/cbackend_c.rhope Mon Nov 22 01:15:02 2010 -0500 @@ -1422,7 +1422,7 @@ } } -_Set List Els[text,el,index,type reg:out] +_Set List Els C[text,el,index,type reg:out] { out <- [[text]Append[ [["\tinout[1] = " @@ -1441,7 +1441,7 @@ { If[[~]>[3]] { - out <- [Fold[_Set List Els[?, ?, ?, type reg], [text]Append["\trhope(FUNC_List, inout, 0, 1);\n"], value] + out <- [Fold[_Set List Els C[?, ?, ?, type reg], [text]Append["\trhope(FUNC_List, inout, 0, 1);\n"], value] ]Append[[["\t_const_"]Append[Escape Rhope Name[name,[type reg]Escape Pattern >>]]]Append[" = inout[0];\n"]] }{ Const Construct C[value,type reg] diff -r 1f39e69446f9 -r f3686f60985d dict.rhope --- a/dict.rhope Sun Nov 21 22:47:14 2010 -0500 +++ b/dict.rhope Mon Nov 22 01:15:02 2010 -0500 @@ -282,6 +282,16 @@ out <- Print["Dictionary\n\t{Empty}"] } +New Like@Dictionary[in:out] +{ + out <- Dictionary[] +} + +New Like@Empty Dictionary[in:out] +{ + out <- in +} + Length@Empty Dictionary[dict:out] { out <- 0 diff -r 1f39e69446f9 -r f3686f60985d framework.rhope --- a/framework.rhope Sun Nov 21 22:47:14 2010 -0500 +++ b/framework.rhope Mon Nov 22 01:15:02 2010 -0500 @@ -1,38 +1,65 @@ Import webserver.rhope +_Key Value Map[list,index,newlist,worker:out] +{ + newval,newkey <- [worker]Call[[list]Index[index], index] + + next <- [newlist]Set[newkey, newval] + + [list]Next[index] + { + out <- _Key Value Map[list, ~, next, worker] + }{ + out <- Val[next] + } +} + +Key Value Map[list,worker:out] +{ + [list]First + { + out <- _Key Value Map[list, ~, New Like[list], worker] + }{ + out <- New Like[list] + } +} + Framework Handler[con,path,request type,queryvars,headers,handler,title,use session] { page <- Page[title, path, use session, queryvars, headers] - out list <- [handler]Do[ [[List[]]Append[page]]Append[path] ] - handler page <- [out list]Index[0] + handler page <- [handler]Call[page,path] If[[request type] = ["POST"]] { - final page <- Process POST[handler page, con, headers] + final page,ncon <- Process POST[handler page, con, headers] }{ final page <- Val[handler page] + ncon <- Val[con] } string,out headers <- [final page]Render - [HTTP OK[con, Get Content Type[".html"], [string]Length, out headers] - ]Put String[string] + after headers <- HTTP OK[ncon, Get Content Type[".html"], [string]Byte Length, out headers] + { Print["Sent status"] + { [[string]Write to File[after headers]]Close + { Print["Wrote data"] }}} } Handler Fixer[handler:out] { - If[[Type Of[handler]] = ["List"]] + [(List(),List Leaf())]Find[=[?,Blueprint Of[handler]]] { - out <- [[["Framework Handler"]Set Input[5, [handler]Index[0]]]Set Input[6, [handler]Index[1]]]Set Input[7, [handler]Index[2]] + out <- Val[Framework Handler[?, ?, ?, ?, ?, [handler]Index[0], [handler]Index[1], [handler]Index[2]]] }{ out <- handler } } -Start Web[handlers] +Start Web[handlers,port] { Print["Starting Rhope Web Server"] - Init Sessions[] - { Listen on Port[80,["Connection Start"]Set Input[1, Map[handlers,"Handler Fixer"]]] } - Wait Forever[] + workaround <- Init Sessions[] + Val[workaround] + { Listen on Port[port,Connection Start[?, ?, Map[handlers,Handler Fixer[?]]]] + { Wait Forever[] }} } Get Class[container:class] @@ -54,7 +81,7 @@ Web Event[name,origin,data:out] { - out <- [[[Build["Web Event"]]Event Name <<[name]]Origin <<[origin]]Data <<[data] + out <- [[[Build[Web Event()]]Event Name <<[name]]Origin <<[origin]]Data <<[data] } Blueprint Web Container @@ -72,7 +99,7 @@ Web Container[class:out] { - out <- [[[[[[[[Build["Web Container"] + out <- [[[[[[[[Build[Web Container()] ]Tag Name <<["div"] ]Class <<[class] ]Propagate Events <<[No] @@ -95,11 +122,11 @@ _Preformatted[child,val:out] { - If[[Type Of[child]] = ["Web Text"]] + If[[Blueprint Of[child]] = [Web Text()]] { out <- [child]Preformatted <<[val] }{ - If[[Type Of[child]] = ["Web Container"]] + If[[Blueprint Of[child]] = [Web Container()]] { out <- [child]Preformatted[val] }{ @@ -110,7 +137,7 @@ Preformatted@Web Container[cont,preformatted?:out] { - out <- [[cont]Children <<[ Map[[cont]Children >>, ["_Preformatted"]Set Input[1, preformatted?]] ] + out <- [[cont]Children <<[ Map[[cont]Children >>, _Preformatted[?, preformatted?]] ] ]Preformatted <<[preformatted?] } @@ -120,7 +147,7 @@ [ [container]Use Session <<[Yes] ]Session <<[session] - ]Children <<[ Map[ [container]Children >>, ["Set Session"]Set Input[1, session] ] ] + ]Children <<[ Map[ [container]Children >>, Set Session[?, session] ] ] } Set Handler@Web Container[container,event name,handler:out] @@ -141,7 +168,7 @@ out <- [[[[[[["<"]Append[ [container]Tag Name >> ] ]Append[Get Class[container]] ]Append[[[">"]Append[newline]]Append[tab]] - ]Append[Fold[["Render Child"]>]] + ]Append[Fold[Render Child[?], "", [container]Children >>]] ]Append[[newline]Append["> ] ]Append[[">"]Append[newline]] @@ -152,18 +179,19 @@ event <- [events]Index[index] [[container]Handlers >>]Index[ [event]Event Name >>] { - result list <- [~]Do[ - [[List[]]Append[container]]Append[event] - ] - new container <- [result list]Index[0] - [result list]Index[1] + //The original version, you had to populate the container output + //and optionally populate the new event output, but that won't work + //now. None of my existing code really needs to populate both so I've + //made them mutually exclusive. + new container <- [~]Call[container,event] { - out events <- [result events]Append[~] + out events <- Val[result events] }{ - out events <- Val[result events] + out events <- [result events]Append[~] + new container <- Val[container] } }{ - new container <- container + new container <- Val[container] out events <- Val[result events] } @@ -261,7 +289,7 @@ Page[title,url,use session,queryvars,headers:out] { - page <- [[[[[[[Build["Page"] + page <- [[[[[[[Build[Page()] ]Title <<[title] ]URL <<[url] ]CSS <<[[List[]]Append["/default.css"]] @@ -271,7 +299,7 @@ ]Use Session <<[use session] If[use session] { - Load@Session[queryvars, headers] + Load Session[queryvars, headers] { out <- [[page]Session <<[~]]Session ID <<[ [~]Session ID>>] } @@ -302,7 +330,7 @@ ]Append[[[page]CSS >>]Join["\">\n\t\t\n\t\n\t\n\t
\n"]] - ]Append[Fold[["Render Child"]>]] + ]Append[Fold[Render Child[?], "", [page]Children >>]] ]Append["\t\n\t\n"] If[[page]Use Session>>] { @@ -350,7 +378,8 @@ Decode Helper Decode[list,destlist,index:out] { code,rest <- [[list]Index[index]]Slice[2] - newlist <- [destlist]Set[index, [[""]Put Byte[From Hex@Whole Number[code]]]Append[rest]] + decoded <- String[[Array[]]Append[Trunc UInt8[Abs UInt[Hex Int32[code]]]]] + newlist <- [destlist]Set[index, [decoded]Append[rest]] [list]Next[index] { out <- Decode Helper Decode[list, newlist, ~] @@ -392,13 +421,13 @@ okey <- URL Decode[key] } -Process POST[page,con,headers:out] +Process POST[page,con,headers:out,ncon] { - [con]Get FString[[headers]Index["Content-Length"]] {} + ,ncon <- [con]Read[[headers]Index["Content-Length"]] { - post string <- [~]Replace["+"," "] + post string <- [String[~]]Replace["+"," "] } - post data <- Key Value Map[Dict Split[post string, "=", "&"], ["Decode Pair"]>, session] + Session::Sessions <- [Session::Sessions]Set[[session]Session ID >>, session] } Finalize@Session[session,headers:out headers] @@ -684,7 +721,7 @@ Web Link[text,target:out] { - out <- [[[[Build["Web Link"]]Text <<[text]]Target <<[target]]Class <<[""]]Query Params <<[Dictionary[]] + out <- [[[[Build[Web Link()]]Text <<[text]]Target <<[target]]Class <<[""]]Query Params <<[Dictionary[]] } @@ -742,7 +779,7 @@ Web Table[headers,data:out] { - out <- [[Build["Web Table"]]Headers <<[headers]]Data <<[data] + out <- [[Build[Web Table()]]Headers <<[headers]]Data <<[data] } Name@Web Table[link:name,none] @@ -770,7 +807,7 @@ { If[[[[table]Headers >>]Length] > [0]] { - out <- [Fold[["Make Header Row"]\n", [table]Headers >>]]Append["\t\t\n"] + out <- [Fold[Make Header Row[?], "\t\t\n", [table]Headers >>]]Append["\t\t\n"] }{ out <- "" } @@ -783,7 +820,7 @@ Make Table Row[string,row:out] { - out <- [Fold[["Make Table Cell"]\n"], row]]Append["\t\t"] + out <- [Fold[Make Table Cell[?], [string]Append["\t\t\n"], row]]Append["\t\t"] } Render@Web Table[table:out,headers] @@ -791,7 +828,7 @@ out <- [ [ ["\t\n"]Append[[table]Get Header Row] - ]Append[ Fold[["Make Table Row"]>] ] + ]Append[ Fold[Make Table Row[?], "", [table]Data >>] ] ]Append["\t
\n"] } @@ -801,9 +838,9 @@ Alt } -New@Web Image[source,alt:out] +Web Image[source,alt:out] { - out <- [[Build["Web Image"]]Source <<[source]]Alt <<[alt] + out <- [[Build[Web Image()]]Source <<[source]]Alt <<[alt] } Name@Web Image[image:name,none] diff -r 1f39e69446f9 -r f3686f60985d kernel.rhope --- a/kernel.rhope Sun Nov 21 22:47:14 2010 -0500 +++ b/kernel.rhope Mon Nov 22 01:15:02 2010 -0500 @@ -302,3 +302,46 @@ out <- Pause[Resume[?,Yes]] } +Foreign C:libc +{ + rand[:out(Int32,Naked)] + srand[seed(Int32,Naked)] + time[storage(Int64,Raw Pointer,Mutable):storage] +} + +Globals _rand +{ + seeded <- No +} + +_Seeded?[:yep,nope] uses _rand +{ + Print["Seeded"] + yep,nope <- If[_rand::seeded] {} + { + _rand::seeded <- Yes + } +} + +_srand[val:out] +{ + srand[] + out <- Yes +} + +Random[:out] +{ + Print["Random"] + yep,nope <- _Seeded?[] + Val[yep] + { + _srand[Trunc Int32[time[0i64]]] + { out <- rand[] } + } + Val[nope] + { + out <- rand[] + } +} + + diff -r 1f39e69446f9 -r f3686f60985d net.rhope --- a/net.rhope Sun Nov 21 22:47:14 2010 -0500 +++ b/net.rhope Mon Nov 22 01:15:02 2010 -0500 @@ -433,7 +433,7 @@ { data,out con,err <- [con]_Read Delim[delim,poffset,buflist] }{ - err <- [Fold[_Add Len[?], 0, buflist]]+[Length[[con]Buffer >>]] + err <- [Fold[_Add Len[?], 0, buflist]]+[Length[[con]Read Buffer >>]] } }{ ,checknew <- If[[poffset]>=[0]] @@ -441,18 +441,18 @@ If[[[delim]Length]>[[outbuf]Length]] { //Avoid possibility of having to check across more than 2 buffers - data,out con,err <-[[con]Buffer <<[ - _Merge Buffers[[[buflist]Append[[con]Buffer >>]]Append[outbuf]] + data,out con,err <-[[con]Read Buffer <<[ + _Merge Buffers[[[buflist]Append[[con]Read Buffer >>]]Append[outbuf]] ] ]Read Delim[delim] }{ - ,checknew <- _Check Split[[con]Buffer >>, outbuf, delim ,poffset] + ,checknew <- _Check Split[[con]Read Buffer >>, outbuf, delim ,poffset] { before <- [_internal_array_copychunk[[con]Read Buffer >>, 0, _internal_array_allocnaked[~, UInt8()], 0, ~] ]Length <<[~] data <- _Merge Buffers[[buflist]Append[before]] - after off <- [[delim]Length]- [[[[con]Buffer >>]Length]-[~]] + after off <- [[delim]Length]- [[[[con]Read Buffer >>]Length]-[~]] rbufferlen <- [[outbuf]Length]-[after off] out con <- [con]Read Buffer <<[ [_internal_array_copychunk[outbuf, after off, diff -r 1f39e69446f9 -r f3686f60985d said.rhope --- a/said.rhope Sun Nov 21 22:47:14 2010 -0500 +++ b/said.rhope Mon Nov 22 01:15:02 2010 -0500 @@ -17,7 +17,7 @@ //Then we empty the page object ]Clear Children //And we add a hyperlink - ]Add Child[New@Web Link["Click Here","/said"]] + ]Add Child[Web Link["Click Here","/said"]] } //This worker defines our page @@ -30,17 +30,20 @@ out <- [page]Add Child[ ["You said: "]Append[~] ] }{ //Otherwise we provide them with a form to enter a word - out <- [[[page]Add Child[New@Web Field["foo","","text"]] + out <- [[[page]Add Child[Web Field["foo","","text"]] ]Add Child[ - New@Web Button["blah","Click!"] + Web Button["blah","Click!"] //The Set Handler call here attaches the worker Save Text to the click event for the page //Events propagate can propagate themselves up the page hierarchy and handled wherever appropriate ]]Set Handler["click","Save Text"] } } -Main[] +Main[args] { + [args]Index[1] + { port <- Int32[~] } + { port <- Val[80] } //Start Web starts the webserver and initializes the web framework Start Web[ //It takes a dictionary mapping paths to Workers that define dynamic pages @@ -48,6 +51,6 @@ //that allows the framework to take care of some of the drudgework for us //The first element in the list is the worker name, the second the page title //and the third element indicates whether this page will be using session data or not - [New@Dictionary[]]Set["/said",("Said","That's what she said",Yes)] + [Dictionary[]]Set["/said",[(0,"That's what she said",Yes)]Set[0,Said[?]]], port ] } diff -r 1f39e69446f9 -r f3686f60985d webserver.rhope --- a/webserver.rhope Sun Nov 21 22:47:14 2010 -0500 +++ b/webserver.rhope Mon Nov 22 01:15:02 2010 -0500 @@ -95,7 +95,7 @@ string <- "Document Not FoundThe document you requested is not available on this server." HTTP Response[client, Get Content Type[".html"], [string]Length, Dictionary[], "404 Not Found"] { - [string]Write to File[~] + [[string]Write to File[~]]Close } } @@ -134,8 +134,9 @@ If[[content length] > [0]] { data <- [file]Read[content length] - [HTTP OK[client, Get Content Type[path], content length, Dictionary[]] + [[HTTP OK[client, Get Content Type[path], content length, Dictionary[]] ]Write[data] + ]Close { Close[file] } }{ HTTP Not Found[client] @@ -161,6 +162,7 @@ Connection Start[con,address,handlers] { + Print["New connection!"] ,client <- [con]Read Delim[["\r\n"]Buffer >>] { request <- String[~] } parts <- [request]Split[" "]