Compare commits

..

33 Commits

Author SHA1 Message Date
Jarvis Carroll
540b2c513b Fill AACI and coerce type specs
Any error reasons or paths are just term() still, and ACI doesn't have a defined spec in the compiler, so whatever, but the AACI types, the erlang representation of terms, and the four different kinds of coerce function are all spec'd now.

Also some internal type substitution functions were given types, just in the hopes of catching some errors, but dyalizer doesn't seem to complain at all no matter how badly I break my code. Strange approach to making a type system, but oh well.
2026-02-26 12:57:49 +00:00
bda4e89e58 Merge branch 'parser' of ssh://git.qpq.swiss:21203/QPQ-AG/hakuzaru into parser 2026-02-25 16:21:23 +09:00
f277e79096 Minor doc and style edits 2026-02-25 16:20:52 +09:00
Jarvis Carroll
ddec3bfa74 add more format options to decode_bytearray
I reversed the argument order here, since the Format option is sort of kind of almost optional, but I am not sure if that was a good idea.
2026-02-24 06:12:00 +00:00
Jarvis Carroll
a0fbeebcdb Pretty print Sophia expressions.
I think all of the tests roundtrip now, so if my parser was thorough, the pretty printer should be as thorough.
2026-02-17 07:26:42 +00:00
Jarvis Carroll
78c9c67f38 typecheck bits
Sophia bitstrings aren't really something you initialize manually, so we have to make up a literal format for them. Failing that, we just accept arbitrary integers and bytearrays as bitstrings.
2026-02-13 06:25:24 +00:00
Jarvis Carroll
9bc0ffafd1 bool/char literals
Character literals were the main complexity here, but I threw booleans in as well, since that covers all the major literals.
2026-02-13 06:25:24 +00:00
a1fc5f19fa Merge branch 'parser' of ssh://git.qpq.swiss:21203/QPQ-AG/hakuzaru into parser 2026-02-13 13:50:57 +09:00
efe0a64056 Update comments, add fate and sophia tagged args 2026-02-13 13:50:29 +09:00
Jarvis Carroll
60985130cb Refine tuple parsing errors
There are four major fixes here:
1. some eof tokens were being pattern matched with the wrong arity
2. tuples that are too long actually speculatively parse as an untyped tuple, and then complain that there were too many elements,
3. singleton tuples with a trailing comma are now handled differently to grouping parentheses, consistently between typed and untyped logic
4. the extra return values used to detect untyped singleton tuples are also used to pass the close paren position, so that too_many_elements can report the correct file position too.

Point 4. also completely removes the need for tracking open paren positions that I was doing, and that I thought I would need to do even more of in the ambiguous-open-paren-stack case.
2026-02-13 04:08:58 +00:00
6c172c4783 Adjusting a few calls. 2026-02-12 17:44:56 +09:00
Jarvis Carroll
3838a7e3c5 Parse qualified names.
This seemed like it was going to be insanely insanely complex, but
then it turns out the compiler doesn't accept spaces in qualified
names, so I can just dump periods in the lexer and hit it with
string:split/3. Easy.
2026-02-05 07:13:25 +00:00
Jarvis Carroll
d014ae0982 Handle token/parse errors more carefully 2026-02-04 07:00:39 +00:00
Jarvis Carroll
bb4bcbb7de remove 'tk' atom from file positions 2026-02-03 06:08:54 +00:00
Jarvis Carroll
a695c21fc9 Parse address literals.
Also signatures.
2026-02-03 06:00:40 +00:00
Jarvis Carroll
493bdb990c Fix lexer row/column calculations. 2026-02-03 01:42:17 +00:00
Jarvis Carroll
17f635af61 Parse long hex escape codes
This doesn't work super consistently in the compiler, for codepoints above 127, but it should work fine for us, so, oh well!
2026-02-03 00:41:00 +00:00
Jarvis Carroll
272ed01fdc Singleton record/tuple parsing.
Records are a simple case to detect and handle correctly.

Tuples took an entire rewrite of the little tuple parsing bit of the code.
2026-01-30 08:12:32 +00:00
Jarvis Carroll
49cd8b6687 Parse strings 2026-01-29 06:18:06 +00:00
Jarvis Carroll
966b4b2748 Calculate scalar values during lexing
This saves some effort and probably some performance for things like integers, but I'm mainly doing this in anticipation of string literals, because it would just be ridiculous to read code that lexes string literals twice.
2026-01-29 04:06:19 +00:00
Jarvis Carroll
fe182a5233 Handle underscores in integers/bytes
This forces us to test for alpha/num/hex enough times that it's now worth making macros for these things.
2026-01-29 03:03:11 +00:00
Jarvis Carroll
f1696e2b9e Bytes lexing
I don't handle underscores in bytes correctly... Nor in integers, for that matter.
2026-01-29 02:01:16 +00:00
Jarvis Carroll
2bf384ca82 Infer correct values for tests automatically
Now tests compare the literal parser against the output of the
compiler. The little example contracts we are compiling for the
AACI already had the FATE value in them, in the form of the
instruction
	{'RETURNR', {immediate, FateValue}}
so we just extract that and use it for the tests.
2026-01-27 06:42:55 +00:00
Jarvis Carroll
4f2a3c6c6f Variant parsing 2026-01-23 06:18:39 +00:00
Jarvis Carroll
7df04a81be Tuple parsing 2026-01-23 02:45:23 +00:00
Jarvis Carroll
6f02d4c4e6 Record parsing 2026-01-23 00:48:06 +00:00
Jarvis Carroll
56e63051bc Map parsing 2026-01-16 05:46:27 +00:00
Jarvis Carroll
3f1c9bd626 List parsing
Slowly chipping away at cases...
2026-01-15 09:38:04 +00:00
Jarvis Carroll
97e32574c4 set up parsing structure
We tokenize, and then do the simplest possible recursive descent.

We don't want to evaluate anything, so infix operators are out,
meaning no shunting yard or tree rearranging or LR(1) shenanigans
are necessary, just write the code.

If we want to 'peek', just take the next token, and pass it around
from that point on, until it can actually be consumed.
2026-01-15 01:52:30 +00:00
Jarvis Carroll
6f5525afcf Rename get_function_signature
hz_aaci:aaci_get_function_signature is a bit redundant.
2026-01-15 01:50:50 +00:00
Jarvis Carroll
4f1958b210 use lists:unzip/1
Just a little thing I noticed could be improved.
2026-01-13 01:19:29 +00:00
Jarvis Carroll
3da9bd570b split coerce/3 into two functions
Also renamed coerce_bindings to erlang_args_to_fate, to match.
2026-01-09 04:39:58 +00:00
Jarvis Carroll
d2163c1ff8 split AACI out of hz.erl
So far the interface to hz.erl is mostly unchanged, apart from prepare_aaci/1

Maybe prepare_aaci should be re-exported, but using it is exactly in line with the
'inconvenient but more flexible primitives' that hz_aaci.erl is meant to represent,
so, maybe that is a fine place to have to go for it, dunno.
2026-01-07 09:40:55 +00:00
15 changed files with 2846 additions and 1203 deletions

2
.gitignore vendored
View File

@ -8,7 +8,9 @@ cancer
erl_crash.dump
ebin/*.beam
doc/*.html
doc/*.css
doc/edoc-info
doc/erlang.png
rel/example_project
.concrete/DEV_MODE
.rebar

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

View File

@ -1,75 +0,0 @@
/* standard EDoc style sheet */
body {
font-family: Verdana, Arial, Helvetica, sans-serif;
margin-left: .25in;
margin-right: .2in;
margin-top: 0.2in;
margin-bottom: 0.2in;
color: #696969;
background-color: #ffffff;
}
a:link{
color: #000000;
}
a:visited{
color: #000000;
}
a:hover{
color: #d8613c;
}
h1,h2 {
margin-left: -0.2in;
}
div.navbar {
background-color: #000000;
padding: 0.2em;
}
h2.indextitle {
padding: 0.4em;
color: #dfdfdf;
background-color: #000000;
}
div.navbar a:link {
color: #dfdfdf;
}
div.navbar a:visited {
color: #dfdfdf;
}
div.navbar a:hover {
color: #d8613c;
}
h3.function,h3.typedecl {
background-color: #000000;
color: #dfdfdf;
padding-left: 1em;
}
div.spec {
margin-left: 2em;
background-color: #eeeeee;
}
a.module {
text-decoration:none
}
a.module:hover {
background-color: #eeeeee;
}
ul.definitions {
list-style-type: none;
}
ul.index {
list-style-type: none;
background-color: #eeeeee;
}
/*
* Minor style tweaks
*/
ul {
list-style-type: square;
}
table {
border-collapse: collapse;
}
td {
padding: 3
}

View File

@ -3,7 +3,7 @@
{included_applications,[]},
{applications,[stdlib,kernel]},
{description,"Gajumaru interoperation library"},
{vsn,"0.8.3"},
{vsn,"0.8.2"},
{modules,[hakuzaru,hz,hz_fetcher,hz_format,hz_grids,
hz_key_master,hz_man,hz_sup]},
{mod,{hakuzaru,[]}}]}.

View File

@ -6,7 +6,7 @@
%%% @end
-module(hakuzaru).
-vsn("0.8.3").
-vsn("0.8.2").
-author("Craig Everett <ceverett@tsuriai.jp>").
-copyright("Craig Everett <ceverett@tsuriai.jp>").
-license("GPL-3.0-or-later").

1206
src/hz.erl

File diff suppressed because it is too large Load Diff

1269
src/hz_aaci.erl Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
-module(hz_fetcher).
-vsn("0.8.3").
-vsn("0.8.2").
-author("Craig Everett <ceverett@tsuriai.jp>").
-copyright("Craig Everett <ceverett@tsuriai.jp>").
-license("MIT").

View File

@ -21,7 +21,7 @@
%%% @end
-module(hz_format).
-vsn("0.8.3").
-vsn("0.8.2").
-author("Craig Everett <ceverett@tsuriai.jp>").
-copyright("Craig Everett <ceverett@tsuriai.jp>").
-license("GPL-3.0-or-later").

View File

@ -37,8 +37,8 @@
%%% @end
-module(hz_grids).
-vsn("0.8.3").
-export([url/2, url/3, url/4, parse/1, req/2, req/3, req/4]).
-vsn("0.8.2").
-export([url/2, url/3, url/4, parse/1, req/2, req/3]).
-spec url(Instruction, HTTP) -> Result
@ -193,28 +193,24 @@ l_to_i(S) ->
req(Type, Message) ->
req(Type, Message, false).
req(Type, Message, ID) ->
{ok, NetworkID} = hz:network_id(),
req(Type, Message, ID, NetworkID).
req(sign, Message, ID, NetworkID) ->
req(sign, Message, ID) ->
#{"grids" => 1,
"chain" => "gajumaru",
"network_id" => NetworkID,
"network_id" => hz:network_id(),
"type" => "message",
"public_id" => ID,
"payload" => Message};
req(tx, Data, ID, NetworkID) ->
req(tx, Data, ID) ->
#{"grids" => 1,
"chain" => "gajumaru",
"network_id" => NetworkID,
"network_id" => hz:network_id(),
"type" => "tx",
"public_id" => ID,
"payload" => Data};
req(ack, Message, ID, NetworkID) ->
req(ack, Message, ID) ->
#{"grids" => 1,
"chain" => "gajumaru",
"network_id" => NetworkID,
"network_id" => hz:network_id(),
"type" => "ack",
"public_id" => ID,
"payload" => Message}.

View File

@ -8,7 +8,7 @@
%%% @end
-module(hz_key_master).
-vsn("0.8.3").
-vsn("0.8.2").
-export([make_key/1, encode/1, decode/1]).

View File

@ -9,7 +9,7 @@
%%% @end
-module(hz_man).
-vsn("0.8.3").
-vsn("0.8.2").
-behavior(gen_server).
-author("Craig Everett <ceverett@tsuriai.jp>").
-copyright("Craig Everett <ceverett@tsuriai.jp>").

1459
src/hz_sophia.erl Normal file

File diff suppressed because it is too large Load Diff

View File

@ -9,7 +9,7 @@
%%% @end
-module(hz_sup).
-vsn("0.8.3").
-vsn("0.8.2").
-behaviour(supervisor).
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").

View File

@ -4,7 +4,7 @@
{prefix,"hz"}.
{desc,"Gajumaru interoperation library"}.
{author,"Craig Everett"}.
{package_id,{"otpr","hakuzaru",{0,8,3}}}.
{package_id,{"otpr","hakuzaru",{0,8,2}}}.
{deps,[{"otpr","sophia",{9,0,0}},
{"otpr","gmserialization",{0,1,3}},
{"otpr","gmbytecode",{3,4,1}},