Skip to content

Commit

Permalink
Updates for new Pony match semantics (#45)
Browse files Browse the repository at this point in the history
This PR contains updates for the new Pony match semantics, which
necessitated a bunch of json changes. It also updates to the latest
Kiuatan, which is much more performant than before.

Closes #40
Closes #38
  • Loading branch information
chalcolith authored Feb 20, 2025
1 parent 50e6133 commit de8031c
Show file tree
Hide file tree
Showing 84 changed files with 414 additions and 398 deletions.
2 changes: 1 addition & 1 deletion corral.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"deps": [
{
"locator": "github.com/chalcolith/kiuatan.git",
"version": "1.6.0"
"version": "1.6.1"
},
{
"locator": "github.com/ponylang/appdirs.git",
Expand Down
6 changes: 3 additions & 3 deletions eohippus/analyzer/eohippus_analyzer.pony
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ actor EohippusAnalyzer is Analyzer
| let file: File =>
let json_str = recover val file.read_string(file.size()) end
match json.Parse(json_str)
| let obj: json.Object =>
| let obj: json.Object val =>
match ast.ParseNode(src_file.canonical_path.path, obj)
| let node: ast.Node =>
_log(Fine) and _log.log(
Expand All @@ -1114,7 +1114,7 @@ actor EohippusAnalyzer is Analyzer
src_file.task_id.string() + ": error loading " +
syntax_path.path + ": " + err)
end
| let item: json.Item =>
| let item: json.Item val =>
_log(Error) and _log.log(
src_file.task_id.string() + ": error loading " + syntax_path.path +
": a syntax tree must be an object")
Expand Down Expand Up @@ -1184,7 +1184,7 @@ actor EohippusAnalyzer is Analyzer
match OpenFile(scope_path)
| let file: File =>
let json_str = recover val file.read_string(file.size()) end
match recover val json.Parse(json_str) end
match json.Parse(json_str)
| let obj: json.Object val =>
match recover val ParseScopeJson(_context.file_auth, obj, None) end
| let scope: Scope val =>
Expand Down
66 changes: 35 additions & 31 deletions eohippus/analyzer/scope.pony
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use "collections"
use "files"
use "itertools"

use ast = "../ast"
use json = "../json"
Expand Down Expand Up @@ -102,7 +103,6 @@ class val Scope

fun get_json(): json.Object =>
let props = [ as (String, json.Item): ("index", I128.from[USize](index)) ]

let kind_string =
match kind
| PackageScope =>
Expand All @@ -124,57 +124,61 @@ class val Scope
props.push(("canonical_path", canonical_path.path))
end
props.push(
( "range",
json.Sequence(
( "range"
, json.Sequence(
[ as I128:
I128.from[USize](range._1)
I128.from[USize](range._2)
I128.from[USize](range._3)
I128.from[USize](range._4)
])) )
]) ))
if imports.size() > 0 then
let import_items = Array[json.Item]
for (node_index, identifier, path) in imports.values() do
import_items.push(json.Object(
[ as (String, json.Item):
("node", I128.from[USize](node_index))
("identifier", identifier)
("path", path)
]))
import_items.push(
recover val
json.Object(
[ as (String, json.Item):
("node", I128.from[USize](node_index))
("identifier", identifier)
("path", path)
])
end)
end
props.push(("imports", json.Sequence(import_items)))
end
if definitions.size() > 0 then
let def_items = Array[json.Item]
for def_array in definitions.values() do
for (node_index, identifier, doc_string) in def_array.values() do
def_items.push(json.Object(
[ as (String, json.Item):
("node", I128.from[USize](node_index))
("identifier", identifier)
("doc_string", doc_string) ]))
def_items.push(
json.Object(
[ as (String, json.Item):
("node", I128.from[USize](node_index))
("identifier", identifier)
("doc_string", doc_string) ]))
end
end
props.push(("definitions", json.Sequence(def_items)))
end
if children.size() > 0 then
let children_items = Array[json.Item]
for child in children.values() do
children_items.push(child.get_json())
end
props.push(("children", json.Sequence(children_items)))
let child_items =
Iter[Scope box](children.values())
.map[json.Item]({(child) => child.get_json() })
.collect(Array[json.Item](children.size()))
props.push(("children", json.Sequence(child_items)))
end
json.Object(consume props)
json.Object(props)

primitive ParseScopeJson
fun apply(
auth: FileAuth,
scope_item: json.Item,
scope_item: json.Item val,
parent: (Scope ref | None))
: (Scope ref | String)
=>
match scope_item
| let scope_obj: json.Object =>
| let scope_obj: json.Object val =>
let kind =
match try scope_obj("kind")? end
| "PackageScope" =>
Expand All @@ -194,14 +198,14 @@ primitive ParseScopeJson
end
let name =
match try scope_obj("name")? end
| let str: String box =>
| let str: String val =>
str
else
return "scope.name must be a string"
end
let canonical_path =
match try scope_obj("canonical_path")? end
| let str: String box =>
| let str: String val =>
FilePath(auth, str.clone())
else
match parent
Expand All @@ -213,7 +217,7 @@ primitive ParseScopeJson
end
let range =
match try scope_obj("range")? end
| let seq: json.Sequence box =>
| let seq: json.Sequence val =>
match try (seq(0)?, seq(1)?, seq(2)?, seq(3)?) end
| (let l: I128, let c: I128, let nl: I128, let nc: I128) =>
( USize.from[I128](l),
Expand All @@ -239,10 +243,10 @@ primitive ParseScopeJson
kind, name.clone(), canonical_path, range, index, parent)

match try scope_obj("imports")? end
| let seq: json.Sequence =>
| let seq: json.Sequence val =>
for item in seq.values() do
match item
| let obj: json.Object =>
| let obj: json.Object val =>
try
let node_index = USize.from[I128](obj("node")? as I128)
let identifier = obj("identifier")? as String box
Expand All @@ -255,10 +259,10 @@ primitive ParseScopeJson
end
end
match try scope_obj("definitions")? end
| let seq: json.Sequence =>
| let seq: json.Sequence val =>
for item in seq.values() do
match item
| let obj: json.Object =>
| let obj: json.Object val =>
try
let node_index = USize.from[I128](obj("node")? as I128)
let identifier = obj("identifier")? as String box
Expand All @@ -272,7 +276,7 @@ primitive ParseScopeJson
end
end
match try scope_obj("children")? end
| let seq: json.Sequence =>
| let seq: json.Sequence val =>
for item in seq.values() do
match ParseScopeJson(auth, item, scope)
| let child: Scope ref =>
Expand Down
2 changes: 1 addition & 1 deletion eohippus/ast/annotation.pony
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class val Annotation is NodeData
props.push(("identifiers", node.child_refs(identifiers)))

primitive ParseAnnotation
fun apply(obj: json.Object, children: NodeSeq): (Annotation | String) =>
fun apply(obj: json.Object val, children: NodeSeq): (Annotation | String) =>
let identifiers =
match ParseNode._get_seq_with[Identifier](
obj,
Expand Down
2 changes: 1 addition & 1 deletion eohippus/ast/call_args.pony
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class val CallArgs is NodeData
end

primitive ParseCallArgs
fun apply(obj: json.Object, children: NodeSeq): (CallArgs | String) =>
fun apply(obj: json.Object val, children: NodeSeq): (CallArgs | String) =>
let positional =
match ParseNode._get_seq_with[Expression](
obj,
Expand Down
2 changes: 1 addition & 1 deletion eohippus/ast/doc_string.pony
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class val DocString is NodeData
props.push(("string", node.child_ref(string)))

primitive ParseDocString
fun apply(obj: json.Object, children: NodeSeq): (DocString | String) =>
fun apply(obj: json.Object val, children: NodeSeq): (DocString | String) =>
let string =
match ParseNode._get_child_with[LiteralString](
obj,
Expand Down
2 changes: 1 addition & 1 deletion eohippus/ast/error_section.pony
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class val ErrorSection is NodeData
props.push(("message", message))

primitive ParseErrorSection
fun apply(obj: json.Object, children: NodeSeq): (ErrorSection | String) =>
fun apply(obj: json.Object val, children: NodeSeq): (ErrorSection | String) =>
let message =
match try obj("message")? end
| let message': String box =>
Expand Down
2 changes: 1 addition & 1 deletion eohippus/ast/exp_array.pony
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class val ExpArray is NodeData
end

primitive ParseExpArray
fun apply(obj: json.Object, children: NodeSeq): (ExpArray | String) =>
fun apply(obj: json.Object val, children: NodeSeq): (ExpArray | String) =>
let array_type =
match ParseNode._get_child_with[TypeType](
obj,
Expand Down
2 changes: 1 addition & 1 deletion eohippus/ast/exp_atom.pony
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class val ExpAtom is NodeData
props.push(("body", node.child_ref(body)))

primitive ParseExpAtom
fun apply(obj: json.Object, children: NodeSeq): (ExpAtom | String) =>
fun apply(obj: json.Object val, children: NodeSeq): (ExpAtom | String) =>
let body =
match ParseNode._get_child(
obj,
Expand Down
2 changes: 1 addition & 1 deletion eohippus/ast/exp_call.pony
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class val ExpCall is NodeData
end

primitive ParseExpCall
fun apply(obj: json.Object, children: NodeSeq): (ExpCall | String) =>
fun apply(obj: json.Object val, children: NodeSeq): (ExpCall | String) =>
let lhs =
match ParseNode._get_child_with[Expression](
obj,
Expand Down
2 changes: 1 addition & 1 deletion eohippus/ast/exp_consume.pony
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class val ExpConsume is NodeData
props.push(("body", node.child_ref(body)))

primitive ParseExpConsume
fun apply(obj: json.Object, children: NodeSeq): (ExpConsume | String) =>
fun apply(obj: json.Object val, children: NodeSeq): (ExpConsume | String) =>
let cap =
match ParseNode._get_child_with[Keyword](
obj,
Expand Down
2 changes: 1 addition & 1 deletion eohippus/ast/exp_decl.pony
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class val ExpDecl is NodeData
end

primitive ParseExpDecl
fun apply(obj: json.Object, children: NodeSeq): (ExpDecl | String) =>
fun apply(obj: json.Object val, children: NodeSeq): (ExpDecl | String) =>
let kind =
match ParseNode._get_child_with[Keyword](
obj, children, "kind", "ExpDecl.kind must be a Keyword")
Expand Down
2 changes: 1 addition & 1 deletion eohippus/ast/exp_ffi.pony
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class val ExpFfi is NodeData
primitive ParseExpFfi
fun help_id(): String => "ExpFfi.identifier must be an Identifier or Literal"

fun apply(obj: json.Object, children: NodeSeq): (ExpFfi | String) =>
fun apply(obj: json.Object val, children: NodeSeq): (ExpFfi | String) =>
let identifier =
match ParseNode._get_child(obj, children, "identifier", help_id())
| let node: Node =>
Expand Down
2 changes: 1 addition & 1 deletion eohippus/ast/exp_for.pony
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class val ExpFor is NodeData
end

primitive ParseExpFor
fun apply(obj: json.Object, children: NodeSeq): (ExpFor | String) =>
fun apply(obj: json.Object val, children: NodeSeq): (ExpFor | String) =>
let pattern =
match ParseNode._get_child_with[TuplePattern](
obj,
Expand Down
2 changes: 1 addition & 1 deletion eohippus/ast/exp_generic.pony
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class val ExpGeneric is NodeData
props.push(("type_args", node.child_ref(type_args)))

primitive ParseExpGeneric
fun apply(obj: json.Object, children: NodeSeq): (ExpGeneric | String) =>
fun apply(obj: json.Object val, children: NodeSeq): (ExpGeneric | String) =>
let lhs =
match ParseNode._get_child_with[Expression](
obj,
Expand Down
2 changes: 1 addition & 1 deletion eohippus/ast/exp_hash.pony
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class val ExpHash is NodeData
props.push(("rhs", node.child_ref(rhs)))

primitive ParseExpHash
fun apply(obj: json.Object, children: NodeSeq): (ExpHash | String) =>
fun apply(obj: json.Object val, children: NodeSeq): (ExpHash | String) =>
let rhs =
match ParseNode._get_child_with[Expression](
obj,
Expand Down
4 changes: 2 additions & 2 deletions eohippus/ast/exp_if.pony
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class val ExpIf is NodeData
end

primitive ParseExpIf
fun apply(obj: json.Object, children: NodeSeq): (ExpIf | String) =>
fun apply(obj: json.Object val, children: NodeSeq): (ExpIf | String) =>
let kind =
match try obj("kind")? end
| let str: String box =>
Expand Down Expand Up @@ -117,7 +117,7 @@ class val IfCondition is NodeData
props.push(("then_block", node.child_ref(then_block)))

primitive ParseIfCondition
fun apply(obj: json.Object, children: NodeSeq): (IfCondition | String) =>
fun apply(obj: json.Object val, children: NodeSeq): (IfCondition | String) =>
let if_true =
match ParseNode._get_child_with[Expression](
obj,
Expand Down
2 changes: 1 addition & 1 deletion eohippus/ast/exp_jump.pony
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class val ExpJump is NodeData
end

primitive ParseExpJump
fun apply(obj: json.Object, children: NodeSeq): (ExpJump | String) =>
fun apply(obj: json.Object val, children: NodeSeq): (ExpJump | String) =>
let keyword =
match ParseNode._get_child_with[Keyword](
obj,
Expand Down
2 changes: 1 addition & 1 deletion eohippus/ast/exp_lambda.pony
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class val ExpLambda is NodeData
end

primitive ParseExpLambda
fun apply(obj: json.Object, children: NodeSeq): (ExpLambda | String) =>
fun apply(obj: json.Object val, children: NodeSeq): (ExpLambda | String) =>
let bare =
match try obj("bare")? end
| let bool: Bool =>
Expand Down
6 changes: 3 additions & 3 deletions eohippus/ast/exp_match.pony
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class val ExpMatch is NodeData
end

primitive ParseExpMatch
fun apply(obj: json.Object, children: NodeSeq): (ExpMatch | String) =>
fun apply(obj: json.Object val, children: NodeSeq): (ExpMatch | String) =>
let expression =
match ParseNode._get_child_with[Expression](
obj,
Expand Down Expand Up @@ -99,7 +99,7 @@ class val MatchPattern is NodeData
end

primitive ParseMatchPattern
fun apply(obj: json.Object, children: NodeSeq): (MatchPattern | String) =>
fun apply(obj: json.Object val, children: NodeSeq): (MatchPattern | String) =>
let pattern =
match ParseNode._get_child_with[Expression](
obj,
Expand Down Expand Up @@ -152,7 +152,7 @@ class val MatchCase is NodeData
props.push(("body", node.child_ref(body)))

primitive ParseMatchCase
fun apply(obj: json.Object, children: NodeSeq): (MatchCase | String) =>
fun apply(obj: json.Object val, children: NodeSeq): (MatchCase | String) =>
let patterns =
match ParseNode._get_seq_with[MatchPattern](
obj,
Expand Down
2 changes: 1 addition & 1 deletion eohippus/ast/exp_object.pony
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class val ExpObject is NodeData
props.push(("members", node.child_ref(members)))

primitive ParseExpObject
fun apply(obj: json.Object, children: NodeSeq): (ExpObject | String) =>
fun apply(obj: json.Object val, children: NodeSeq): (ExpObject | String) =>
let cap =
match ParseNode._get_child_with[Keyword](
obj,
Expand Down
2 changes: 1 addition & 1 deletion eohippus/ast/exp_operation.pony
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class val ExpOperation is NodeData
end

primitive ParseExpOperation
fun apply(obj: json.Object, children: NodeSeq): (ExpOperation | String) =>
fun apply(obj: json.Object val, children: NodeSeq): (ExpOperation | String) =>
let lhs =
match ParseNode._get_child(
obj,
Expand Down
Loading

0 comments on commit de8031c

Please sign in to comment.