Merge branch 'master' of github.com:urbit/urbit

Conflicts:
	urb/urbit.pill
This commit is contained in:
C. Guy Yarvin 2014-07-01 13:34:06 -07:00
commit a857ff6445
3 changed files with 219 additions and 32 deletions

View File

@ -1147,6 +1147,21 @@
(new | (add +.c +.d))
++ sun |=(a=@u (mul 2 a)) :: @u to @s
++ syn |=(a=@s =(0 (end 0 1 a))) :: sign test
++ cmp |= [a=@s b=@s] :: compare
^- @s
?: =(a b)
--0
?: (syn a)
?: (syn b)
?: (gth a b)
--1
-1
--1
?: (syn b)
-1
?: (gth a b)
-1
--1
--
++ fe :: modulo bloq
|_ a=bloq
@ -1351,7 +1366,7 @@
++ te
|%
++ zer |= [b=@u p=@u n=[s=? e=@s a=@u]]
&(=(e.n (dec (^mul b 2))) =(0 (ira a.n)))
=(e.n (dec (^mul b 2)))
++ nan |= [b=@u n=[s=? e=@s a=@u]]
&(=(e.n (^mul 2 +(b))) !=(0 (ira a.n)))
@ -1399,12 +1414,12 @@
m
?: (zer:te:fl b p m)
n
?: &(!s.n !s.m) :: both negative
?: &(!s.n !s.m) :: both negative
=+ r=$(s.n %.y, s.m %.y)
[s=%.n e=e.r a=a.r]
?. &(s.n s.m) :: if not both positive
(sub b p n [s=!s.m e=e.m a=a.m]) :: is actually sub
?. (^gte e.n e.m) :: guarantee e.n > e.m
?. &(s.n s.m) :: if not both positive
(sub b p n [s=!s.m e=e.m a=a.m]) :: is actually sub
?: =(-1 (cmp:si e.n e.m)) :: guarantee e.n > e.m
$(n m, m n)
=+ dif=(abs:si (dif:si e.n e.m)) :: always pos
=+ a2=(lsh 0 dif a.n) :: p+1+dif bits
@ -1418,12 +1433,12 @@
?: ?=(^ g)
u.g
?: |((zer:te:fl b p n) (zer:te:fl b p m))
(add b p n m) :: why not
(add b p n m(s !s.m)) :: why not
?: &(!s.n s.m) :: -a-b
(add b p m [s=%.n e.m a.m]) :: add handles negative case
(add b p n [s=%.n e.m a.m]) :: add handles negative case
?: &(s.n !s.m) :: a+b
(add b p m [s=%.y e.m a.m]) :: is actually add
?. |((^gth e.n e.m) &(=(e.n e.m) (^gte a.n a.m))) :: n > m
(add b p n [s=%.y e.m a.m]) :: is actually add
?. |(=(--1 (cmp:si e.n e.m)) &(=(e.n e.m) (^gte a.n a.m))) :: n > m
$(n m(s !s.m), m n(s !s.n))
=+ dif=(abs:si (dif:si e.n e.m))
=+ a2=(lsh 0 dif a.n) :: p+1+dif bits
@ -1453,10 +1468,10 @@
(szer:vl:fl b p =(s.n s.m))
?: (zer:te:fl b p m)
(inft:vl:fl b p =(s.n s.m))
=+ b=(lia p (^div (lsh 0 (^mul p 3) a.n) a.m))
=+ c=(lia p (^div (lsh 0 (^mul p 3) a.n) a.m))
?: (^gte a.n a.m)
(pro:te:fl b p [s==(s.n s.m) e=(dif:si e.n e.m) a=b])
(pro:te:fl b p [s=|(s.n s.m) e=(dif:si (dif:si e.n e.m) (sun:si 1)) a=b])
(pro:te:fl b p [s==(s.n s.m) e=(dif:si e.n e.m) a=c])
(pro:te:fl b p [s==(s.n s.m) e=(dif:si (dif:si e.n e.m) (sun:si 1)) a=c])
++ lte |= [n=[s=? e=@s a=@u] m=[s=? e=@s a=@u]] ^- ?
?: (^lte e.n e.m)
@ -1504,7 +1519,7 @@
(hol:fl 52 (sea a))
:: Convert to sign/exp/ari form
++ sea |= a=@rd ^- [s=? e=@s a=@u]
[s=(sig a) e=(exp a) a=(ari:fl 52 (end 0 52 a))]
(pro:te:fl 1.023 52 [s=(sig a) e=(exp a) a=(ari:fl 52 (end 0 52 a))])
++ err |= a=@rd ^- (unit tape)
(err:te:fl 1.023 52 (sea a))

View File

@ -416,24 +416,30 @@
==
::
++ stud :: parse UTC format
|= cut=tape
^- date
=+ ^= tuc
%+ scan cut
;~ plug
;~(pfix (stun [5 5] next) dim:ag)
%+ cook
|= a=tape
=+ b=0
|- ^- @
?: =(a (snag b (turn mon:yu |=(a=tape (scag 3 a)))))
+(b)
$(b +(b))
(ifix [ace ace] (star alf))
;~(sfix dim:ag ace) ;~(sfix dim:ag col)
;~(sfix dim:ag col) dim:ag (cold ~ (star next))
==
[[%.y &3.tuc] &2.tuc &1.tuc &4.tuc &5.tuc &6.tuc ~]
|= cud=tape
^- (unit date)
=- ?~ tud ~
`[[%.y &3.u.tud] &2.u.tud &1.u.tud &4.u.tud &5.u.tud &6.u.tud ~]
^= tud
%+ rust cud
;~ plug
;~(pfix (stun [5 5] next) dim:ag)
::
%+ cook
|= a=tape
=+ b=0
|- ^- @
?: =(a (snag b (turn mon:yu |=(a=tape (scag 3 a)))))
+(b)
$(b +(b))
(ifix [ace ace] (star alf))
::
;~(sfix dim:ag ace)
;~(sfix dim:ag col)
;~(sfix dim:ag col)
dim:ag
(cold ~ (star next))
==
::
++ unt :: UGT to UTC time
|= a=@
@ -617,6 +623,147 @@
==
==
::
++ ja !: :: json reparser
=> |% ++ grub (unit ,*)
++ fist $+(json grub)
--
|%
++ ar :: array as list
|* wit=fist
|= jon=json
?. ?=([%a *] jon) ~
%- zl
|-
?~ p.jon ~
[(wit i.p.jon) $(p.jon t.p.jon)]
::
++ at :: array as tuple
|* wil=(list fist)
|= jon=json
?. ?=([%a *] jon) ~
%- zt
|-
?~ wil ~
[?~(p.jon ~ (i.wil i.p.jon)) $(p.jon ?~(p.jon ~ t.p.jon))]
::
++ bo :: boolean
|=(jon=json ?.(?=([%b *] jon) ~ [~ u=p.jon]))
::
++ bu :: boolean not
|=(jon=json ?.(?=([%b *] jon) ~ [~ u=!p.jon]))
::
++ cu :: transform
|* [poq=$+(* *) wit=fist]
|= jon=json
(bind (wit jon) poq)
::
++ da :: UTC date
|= jon=json
?. ?=([%s *] jon) ~
(bind (stud (trip p.jon)) |=(a=date (year a)))
::
++ mu :: true unit
|* wit=fist
|= jon=json
?~(jon (some ~) (wit jon))
::
++ ne :: number as real
|= jon=json
^- (unit ,@rd)
!!
::
++ ni :: number as integer
|= jon=json
?. ?=([%n *] jon) ~
(slaw %ui (cat 3 '0i' p.jon))
::
++ no :: number as cord
|= jon=json
?. ?=([%n *] jon) ~
(some p.jon)
::
++ of :: object as frond
|* wer=(list (pair cord fist))
|= jon=json
?. ?=([%o [@ *] ~ ~] jon) ~
|-
?~ wer ~
?: =(p.i.wer p.n.p.jon)
((pe p.i.wer q.i.wer) q.n.p.jon)
$(wer t.wer)
::
++ ot :: object as tuple
|* wer=(list (pair cord fist))
|= jon=json
?. ?=([%o *] jon) ~
%- zt
|-
?~ wer ~
=+ ten=(~(get by p.jon) p.i.wer)
[?~(ten ~ (q.i.wer u.ten)) $(wer t.wer)]
::
++ om :: object as map
|* wit=fist
|= jon=json
?. ?=([%o *] jon) ~
%- zm
|-
?~ p.jon ~
[[p.n.p.jon (wit q.n.p.jon)] $(p.jon l.p.jon) $(p.jon r.p.jon)]
::
++ pe :: prefix
|* [pre=* wit=fist]
|= jon=json
(cu |*(a=* [pre a]) wit)
::
++ sa :: string as tape
|= jon=json
?.(?=([%s *] jon) ~ (some (trip p.jon)))
::
++ so :: string as cord
|= jon=json
?.(?=([%s *] jon) ~ (some p.jon))
::
++ su :: parse string
|* sab=rule
|= jon=json
?. ?=([%s *] jon) ~
(rush p.jon sab)
::
++ ul |=(jon=json ?~(jon (some ~) ~)) :: null
++ zl :: collapse unit list
|* lut=(list (unit))
?. |- ^- ?
?~(lut & ?~(i.lut | $(lut t.lut)))
~
%- some
|-
?~ lut ~
[u:+.i.lut $(lut t.lut)]
::
++ zt :: unit tuple
|* lut=(list (unit))
?: =(~ lut) ~
?. |- ^- ?
?~(lut & ?~(i.lut | $(lut t.lut)))
~
%- some
|-
?~ lut !!
?~ t.lut u:+.i.lut
[u:+.i.lut $(lut t.lut)]
::
++ zm :: collapse unit map
|* lum=(map term (unit))
?. |- ^- ?
?~(lum & ?~(q.n.lum | &($(lum l.lum) $(lum r.lum))))
~
%- some
|-
?~ lum ~
[[p.n.lum u:+.q.n.lum] $(lum l.lum) $(lum r.lum)]
--
::
++ joba
|= [p=@t q=jval]
^- json
@ -2216,7 +2363,7 @@
== ::
++ kite ,[p=care q=case r=ship s=desk t=spur] :: parsed global name
++ json :: normal json value
$| ~ ::
$| ~ :: null
$% [%a p=(list json)] :: array
[%b p=?] :: boolean
[%o p=(map ,@t json)] :: object

25
try/bin/fptest.hoon Normal file
View File

@ -0,0 +1,25 @@
::
:: /=try=/bin/aestest/hoon
::
|= [est=time eny=@uw]
|= ~
:_ ~ :_ ~
=+ i=0
:- %$
!>
|- ^- @
?: =(1.000.000 i) 0
=+ n=`@rd`(end 6 1 (en:aesc eny i))
=+ m=`@rd`(rsh 6 1 (en:aesc +(eny) i))
~& [%try `@ux`n `@ux`m]
=+ a=(add:rd n m)
=+ b=(sub:rd n m)
=+ c=(mul:rd n m)
=+ d=(div:rd n m)
=+ suc=%.y
?. suc
~| [%fail i `@ux`n `@ux`m]
!!
?: &(!=(0 i) =(0 (mod i 1.000)))
$(i +(i))
$(i +(i))