Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ Implement a native `Map` type with syntax support.

Change to left-to-right association to minimize surprise.

## Operator overloading

Allow a standard battery of `class`-affiliated arms to process values.

## `Path` type

Implement a `List(String)` type with syntax support.
Expand Down
8 changes: 8 additions & 0 deletions common/hoon/lib/hoon.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -639,4 +639,12 @@
=+ d=(get b)
(~(put by a) b (~(put in d) c))
--
::
:: String support operations
::
++ concat
|= [p=@t q=@t]
^- @t
(cat 3 p q)
::
--
79 changes: 53 additions & 26 deletions common/hoon/lib/jock.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
:: +>+>+ jeam door, in middle
:: +>+>+>+ parse core, next
::
:: We automatically supply a copy of Hoon into the namespace as an FFI because
:: so many built-in tools like arithmetic depend on it.
=< |_ libs=(map term cord)
++ tokenize
|= txt=@
Expand Down Expand Up @@ -125,7 +123,14 @@
++ tokenize
=| fun=?(%.y %.n)
|%
++ string (stag %string (cook crip (ifix [soq soq] (star ;~(less soq prn)))))
++ string %+ stag
%string
%+ cook
crip
;~ pose
(ifix [soq soq] (star ;~(less soq prn)))
(ifix [doq doq] (star ;~(less doq prn)))
==
++ number (stag %number dem:ag)
++ hexadecimal (stag %hexadecimal ;~(pfix (jest %'0x') hex))
++ loobean
Expand Down Expand Up @@ -516,23 +521,26 @@
%type (match-start-name tokens)
==
:: match jocks with no terminating jock (i.e. func bodies)
:: use with +curr
++ match-jock-body
|= [=tokens end=jpunc]
^- [jock (list token)]
?: =(~ tokens)
~|("expect jock. token: ~" !!)
?: (has-punctuator -.tokens end) !!
=^ jock tokens
?- -<.tokens
%literal
:: TODO: check if we're in a compare
(match-literal tokens)
::
%name (match-start-name tokens)
%keyword (match-keyword tokens)
%punctuator (match-start-punctuator tokens)
%type (match-start-name tokens)
==
(match-jock tokens)
:: ?- -<.tokens
:: %literal
:: :: TODO: check if we're in a compare
:: (match-literal tokens)
:: ::
:: %name (match-start-name tokens)
:: %keyword (match-keyword tokens)
:: %punctuator (match-start-punctuator tokens)
:: %type (match-start-name tokens)
:: ==
?> (has-punctuator -.tokens end)
[jock tokens]
::
++ match-trait
Expand Down Expand Up @@ -1922,6 +1930,7 @@
?+ -.func.j ~|('must call a limb' !!)
%limb
=/ old-jyp jyp
~& call-limb+j
~| %call-limb
=/ limbs=(list jlimb) p.func.j
?> ?=(^ limbs)
Expand Down Expand Up @@ -1961,9 +1970,12 @@
:: We have to +slam the gate into the Hoon library,
:: thus two separate wings.
~| %call-case-6
~& 'here'
?> ?=(^ limbs)
?~ arg.j ~|("expect function argument" !!)
~& here2+u.arg.j
=+ [val val-jyp]=$(j u.arg.j)
~& val+val
:: Construct the AST for the Hoon RPC using the bunt for now.
=+ ast=(j2h ljl ~)
?> ?=(%hoon -<.typ)
Expand Down Expand Up @@ -2183,36 +2195,51 @@
::
%operator
~| %operator
:_ [%atom %number %.n]^%$
:_ ?+ a.j
~|('operator: no valid result type' !!)
::
[%atom [[%number p=@ud] q=?]]
[%atom %number %.n]^%$
::
[%atom [[%string p=cord] q=?]]
[%atom %string %.n]^%$
::
==
:: TODO support unary operands
?~ b.j !!
=/ b u.b.j ::$(j u.b.j)
?- op.j
%'+'
?~ b.j !!
=/ j=jock [%call [%limb p=~[[%name %hoon] [%name %add]]] arg=`[a.j u.b.j]]
=/ j=jock
?+ a.j
~|('binary + requires two arguments' !!)
::
[%atom [[%number p=@ud] q=?]]
[%call [%limb p=~[[%name %hoon] [%name %add]]] arg=`[a.j b]]
::
[%atom [[%string p=cord] q=?]]
[%call [%limb p=~[[%name %hoon] [%name %concat]]] arg=`[a.j b]]
==
-:$(j j)
::
%'-'
?~ b.j !!
=/ j=jock [%call [%limb p=~[[%name %hoon] [%name %sub]]] arg=`[a.j u.b.j]]
=/ j=jock [%call [%limb p=~[[%name %hoon] [%name %sub]]] arg=`[a.j b]]
-:$(j j)
::
%'*'
?~ b.j !!
=/ j=jock [%call [%limb p=~[[%name %hoon] [%name %mul]]] arg=`[a.j u.b.j]]
=/ j=jock [%call [%limb p=~[[%name %hoon] [%name %mul]]] arg=`[a.j b]]
-:$(j j)
::
%'/'
?~ b.j !!
=/ j=jock [%call [%limb p=~[[%name %hoon] [%name %div]]] arg=`[a.j u.b.j]]
=/ j=jock [%call [%limb p=~[[%name %hoon] [%name %div]]] arg=`[a.j b]]
-:$(j j)
::
%'%'
?~ b.j !!
=/ j=jock [%call [%limb p=~[[%name %hoon] [%name %mod]]] arg=`[a.j u.b.j]]
=/ j=jock [%call [%limb p=~[[%name %hoon] [%name %mod]]] arg=`[a.j b]]
-:$(j j)
::
%'**'
?~ b.j !!
=/ j=jock [%call [%limb p=~[[%name %hoon] [%name %pow]]] arg=`[a.j u.b.j]]
=/ j=jock [%call [%limb p=~[[%name %hoon] [%name %pow]]] arg=`[a.j b]]
-:$(j j)
::
==
Expand Down
2 changes: 1 addition & 1 deletion crates/jockc/hoon/main.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
=/ args (turn args.cau (cury scot %ud))
=/ code (preprocess text.cau args)
=/ libs `(map term cord)`(malt libs-list.cau)
~& libs+[~(tap by libs)]
~& libs+[~(key by libs)]
~& code+[code]
~& parse+(parse:~(. runner libs) code)
~& jeam+(jeam:~(. runner libs) code)
Expand Down
9 changes: 8 additions & 1 deletion crates/jockt/hoon/lib/test-jock.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
/* hoon-alias %jock /lib/tests/hoon-alias/jock
/* fib %jock /lib/tests/fib/jock
/* lists-indexing %jock /lib/tests/lists-indexing/jock
/* strings %jock /lib/tests/strings/jock
::
/* test-let-edit %hoon /tests/lib/let-edit/hoon
/* test-let-inner-exp %hoon /tests/lib/let-inner-exp/hoon
Expand Down Expand Up @@ -73,6 +74,7 @@
:: /* test-hoon-alias %hoon /tests/lib/hoon-alias/hoon
:: /* test-fib %hoon /tests/lib/fib/hoon
:: /* test-lists-indexing %hoon /tests/lib/lists-indexing/hoon
:: /* test-strings %hoon /tests/lib/strings/hoon
::
|_ libs=(map term cord)
++ list-jocks
Expand Down Expand Up @@ -113,7 +115,8 @@
[%hoon-alias q.hoon-alias] :: 33
[%fib q.fib] :: 34
[%lists-indexing q.lists-indexing] :: 35
==
[%strings q.strings] :: 36
==
::
++ test-jocks
~+
Expand Down Expand Up @@ -258,6 +261,10 @@
:: [%test-lists-indexing-jeam test-jeam:test-lists-indexing]
:: [%test-lists-indexing-mint test-mint:test-lists-indexing]
:: [%test-lists-indexing-nock test-nock:test-lists-indexing]
:: [%test-strings-tokens test-tokenize:test-strings]
:: [%test-strings-jeam test-jeam:test-strings]
:: [%test-strings-mint test-mint:test-strings]
:: [%test-strings-nock test-nock:test-strings]
==
::
++ parse
Expand Down
7 changes: 7 additions & 0 deletions crates/jockt/hoon/lib/tests/strings.jock
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Define a function that returns a greeting
func greet(name: String) -> String {
'Hello, ' + name + '!'
};

print(greet("Zorp"));
greet('Zorp')