Skip to content

Commit

Permalink
Method: Make them work on calls and lookups
Browse files Browse the repository at this point in the history
  • Loading branch information
xFrednet committed Oct 17, 2024
1 parent 06b61aa commit 867fbfe
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 23 deletions.
6 changes: 3 additions & 3 deletions src/lang/lang.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ namespace verona::wf
inline const auto grouping = (Top <<= File) | (File <<= Body) |
(Body <<= Block) |
(Block <<=
(Freeze | Region | Assign | If | For | Func | Return | ReturnValue |
Call)++) |
(Freeze | Region | Assign | If | For | Func | Return | ReturnValue | Call |
Method)++) |
(Assign <<= (Lhs >>= lv) * (Rhs >>= rv)) |
(Lookup <<= (Lhs >>= lv) * (Rhs >>= key)) | (Region <<= Ident) |
(Lookup <<= (Op >>= operand) * (Rhs >>= key)) | (Region <<= Ident) |
(Freeze <<= Ident) | (Create <<= Ident) | (If <<= Eq * Block * Block) |
(For <<= (Key >>= Ident) * (Value >>= Ident) * (Op >>= lv) * Block) |
(Eq <<= (Lhs >>= cmp_values) * (Rhs >>= cmp_values)) |
Expand Down
4 changes: 2 additions & 2 deletions src/lang/passes/call_stmts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace verona::wf
inline const auto call_stmts = grouping |
(Block <<=
(Freeze | Region | Assign | If | For | Func | Return | ReturnValue | Call |
ClearStack | Print)++);
Method | ClearStack | Print)++);
}

PassDef call_stmts()
Expand All @@ -17,7 +17,7 @@ PassDef call_stmts()
verona::wf::call_stmts,
dir::bottomup | dir::once,
{
In(Block) * T(Call)[Call] >>
In(Block) * T(Call, Method)[Call] >>
[](auto& _) {
return Seq << _(Call) << ClearStack << create_print(_(Call));
},
Expand Down
6 changes: 3 additions & 3 deletions src/lang/passes/flatten.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ namespace verona::wf
(CreateObject <<= (KeyIter | String | Dictionary | Func)) |
(Func <<= Compile) | (Compile <<= Body) | (Create <<= Ident) |
(Assign <<= (Lhs >>= lv) * (Rhs >>= rv)) |
(Lookup <<= (Lhs >>= lv) * (Rhs >>= key)) | (Region <<= Ident) |
(Freeze <<= Ident) | (Call <<= Ident * List) | (Method <<= Lookup * List) | (List <<= rv++) |
(Params <<= Ident++) |
(Lookup <<= (Op >>= operand) * (Rhs >>= key)) | (Region <<= Ident) |
(Freeze <<= Ident) | (Call <<= Ident * List) | (Method <<= Lookup * List) |
(List <<= rv++) | (Params <<= Ident++) |
(Eq <<= (Lhs >>= cmp_values) * (Rhs >>= cmp_values)) |
(Neq <<= (Lhs >>= cmp_values) * (Rhs >>= cmp_values)) |
(Label <<= Ident)[Ident];
Expand Down
26 changes: 17 additions & 9 deletions src/lang/passes/grouping.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "../lang.h"

inline const TokenDef Rest{"rest"};

PassDef grouping()
{
PassDef p{
Expand All @@ -11,8 +13,8 @@ PassDef grouping()
T(File) << (--T(Body) * Any++[File]) >>
[](auto& _) { return File << (Body << (Block << _[File])); },

In(Group) * LV[Lhs] * (T(Lookup)[Lookup] << (T(Group) << KEY[Rhs])) >>
[](auto& _) { return Lookup << _[Lhs] << _(Rhs); },
In(Group) * OPERAND[Op] * (T(Lookup)[Lookup] << (T(Group) << KEY[Rhs])) >>
[](auto& _) { return Lookup << _(Op) << _(Rhs); },

T(Group) << ((T(Region)[Region] << End) * T(Ident)[Ident] * End) >>
[](auto& _) {
Expand All @@ -30,17 +32,25 @@ PassDef grouping()
[](auto& _) { return Assign << _(Lhs) << Null; },
// function(arg, arg)
--In(Func) *
(T(Group)[Group]
<< ((T(Ident)[Ident]) * (T(Parens)[Parens] << (~T(List)[List])) *
End)) >>
(T(Group)[Group] << (T(Ident)[Ident]) *
(T(Parens)[Parens] << (~T(List)[List])) * Any++[Rest]) >>
[](auto& _) {
auto list = _(List);
if (!list)
{
list = create_from(List, _(Parens));
}

return create_from(Call, _(Group)) << _(Ident) << list;
auto call = create_from(Call, _(Group)) << _(Ident) << list;
// If there are more nodes to process we want to keep the "Group"
if (_[Rest].size() == 0)
{
return call;
}
else
{
return Group << call << _[Rest];
}
},
--In(Method) *
(T(Group)[Group]
Expand Down Expand Up @@ -102,9 +112,7 @@ PassDef grouping()
<< ((T(Group) << End) *
(T(Group)
<< ((T(Ident)[Ident]) *
(T(Parens)[Parens] << (
// (T(Group) << T(Ident)[List]) /
~(T(List) << T(Ident)++[List]))) *
(T(Parens)[Parens] << (~(T(List) << T(Ident)++[List]))) *
End)) *
(T(Group) << T(Block)[Block]) * End) >>
[](auto& _) {
Expand Down
20 changes: 14 additions & 6 deletions tests/self.vpy
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
def object():
def str_name(self):
return "Dictionary"

def str_name(self):
return "String"
value = {}
value.name = str_name

value = "Music :3"
value.name = str_name
drop str_name
return value

name = value.name()
# Method on an object
obj = object()
obj.name()
drop obj

# Stand alone call
object().name()

# Assignment
name = object().name()

0 comments on commit 867fbfe

Please sign in to comment.