Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gap syntaxtrees #114

Closed
wants to merge 6 commits into from
Closed

Conversation

sebasguts
Copy link

No description provided.

@fingolfin
Copy link
Owner

fingolfin commented Mar 18, 2019

@sebasguts is this up-to-date with your changes from yesterday?

I also had some more thoughts on the whole business last night we should discuss. One is that I think that we should never output "T_SEQ_STAT2", "T_SEQ_STAT3" etc., but only "T_SEQ_STAT"; then then when reassembling pieces, we should automatically use the appropriate variant. The same holds for the various 0ARGS, 1ARGS etc. calls, the loops and anything else involving these counts. Reason: While it of course makes it easier for us to produce and expect these tokens, it makes it much more complicated to manipulate these ASTs.

I've also been thinking about not produce T_SEQ_STAT at all, instead, it could just produce a list of statements. That would result in outputs that are easier to read for humans. And in a sense, T_SEQ_STAT is really an internal concept where I think it would make sense to abstract it away... I am not completely sure whether this is a good or bad idea, though... Anyway, it'd be easy to implement after applying the following patch:

@@ -99,9 +101,7 @@ static Obj SyntaxTreeCompiler(Expr expr)
 
     result = NewSyntaxTreeNode(comp.name);
 
-    comp.compile(result, expr);
-
-    return result;
+    return comp.compile(result, expr);
 }
 
 static Obj SyntaxTreeArgcompInt(UInt i)

With that, we can just throw away the record in the comp.compile function and instead return a list.

I also really want to come up with uniform terminology: As explained before, I dislike the current usage of "compile" for turning the built-in T_BODY (which also is a flattened AST) into a GAP manageable precord-of-precords-and-lists AST. If at all, I'd expect that "compile" would be the reverse direction. In this PR, you used "code" for the reverse direction, which suggest that we rename "compiler" to "decode". I could live with that, we should run it by @markuspf, too, though.

There were more things, but let's not take too many steps at once... :-)

@sebasguts
Copy link
Author

@sebasguts is this up-to-date with your changes from yesterday?

Now it is

I also had some more thoughts on the whole business last night we should discuss. One is that I think that we should never output "T_SEQ_STAT2", "T_SEQ_STAT3" etc., but only "T_SEQ_STAT"; then then when reassembling pieces, we should automatically use the appropriate variant. The same holds for the various 0ARGS, 1ARGS etc. calls, the loops and anything else involving these counts. Reason: While it of course makes it easier for us to produce and expect these tokens, it makes it much more complicated to manipulate these ASTs.

Indeed, we can do that, with a fairly easy change I think. The interesting question is on how the read in function performs compared to the "regularly" typed in function, as it might be slower.

I also really want to come up with uniform terminology: As explained before, I dislike the current usage of "compile" for turning the built-in T_BODY (which also is a flattened AST) into a GAP manageable precord-of-precords-and-lists AST. If at all, I'd expect that "compile" would be the reverse direction. In this PR, you used "code" for the reverse direction, which suggest that we rename "compiler" to "decode". I could live with that, we should run it by @markuspf, too, though.

That is fine by me.

src/syntaxtree.c Outdated Show resolved Hide resolved
src/syntaxtree.c Outdated Show resolved Hide resolved
src/syntaxtree.c Outdated Show resolved Hide resolved
src/code.c Outdated Show resolved Hide resolved
src/syntaxtree.c Outdated Show resolved Hide resolved
@sebasguts sebasguts force-pushed the gap-syntaxtrees branch 2 times, most recently from ee33756 to c4c6519 Compare March 18, 2019 15:40
@sebasguts sebasguts marked this pull request as ready for review March 18, 2019 15:40
@sebasguts
Copy link
Author

Should I make this a PR to gap-system, so we can continue discussing there? Or split this up?

@fingolfin fingolfin force-pushed the mh/syntaxtree branch 3 times, most recently from fdc0022 to 332e15f Compare March 18, 2019 16:41
@sebasguts sebasguts force-pushed the gap-syntaxtrees branch 2 times, most recently from 371055c to 583ffea Compare March 18, 2019 22:50
@sebasguts
Copy link
Author

I rebased the branch and added the float coders.

@codecov
Copy link

codecov bot commented Mar 19, 2019

Codecov Report

Merging #114 into mh/syntaxtree will decrease coverage by 7.41%.
The diff coverage is 15.89%.

@@                Coverage Diff                @@
##           mh/syntaxtree     #114      +/-   ##
=================================================
- Coverage          69.12%   61.71%   -7.42%     
=================================================
  Files                633      633              
  Lines             305868   306032     +164     
=================================================
- Hits              211443   188871   -22572     
- Misses             94425   117161   +22736
Impacted Files Coverage Δ
src/code.h 86.11% <ø> (ø) ⬆️
src/syntaxtree.c 4.94% <0%> (-6.53%) ⬇️
src/code.c 90.66% <100%> (+0.04%) ⬆️
src/intrprtr.c 70.72% <100%> (+1.14%) ⬆️
lib/meatauto.gi 5.99% <0%> (-89.52%) ⬇️
lib/nilpquot.gi 11.11% <0%> (-88.89%) ⬇️
lib/grpcompl.gi 4.54% <0%> (-81.07%) ⬇️
lib/reesmat.gi 27.14% <0%> (-72.04%) ⬇️
lib/randiso2.gi 2.57% <0%> (-67.65%) ⬇️
lib/filter.gi 33.33% <0%> (-66.67%) ⬇️
... and 286 more

Copy link
Owner

@fingolfin fingolfin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments. I've not yet read through all, but I figured it's better to give these to you already so you can get started :-)

src/syntaxtree.c Outdated Show resolved Hide resolved
src/syntaxtree.c Outdated Show resolved Hide resolved
src/syntaxtree.c Outdated Show resolved Hide resolved
src/syntaxtree.c Outdated Show resolved Hide resolved
src/syntaxtree.c Outdated Show resolved Hide resolved
src/syntaxtree.c Show resolved Hide resolved
src/syntaxtree.c Outdated Show resolved Hide resolved
src/syntaxtree.c Outdated Show resolved Hide resolved
src/syntaxtree.c Outdated Show resolved Hide resolved
src/syntaxtree.c Show resolved Hide resolved
@codecov-io
Copy link

codecov-io commented Mar 19, 2019

Codecov Report

Merging #114 into master will decrease coverage by 27.45%.
The diff coverage is 10.17%.

@@             Coverage Diff             @@
##           master     #114       +/-   ##
===========================================
- Coverage   69.17%   41.72%   -27.46%     
===========================================
  Files         633       99      -534     
  Lines      305868    40161   -265707     
===========================================
- Hits       211593    16756   -194837     
+ Misses      94275    23405    -70870
Impacted Files Coverage Δ
src/code.h 86.11% <ø> (ø) ⬆️
src/code.c 90.65% <100%> (+0.03%) ⬆️
src/intrprtr.c 69.57% <100%> (-1.15%) ⬇️
src/syntaxtree.c 6.34% <2.59%> (-5.14%) ⬇️
src/system.c 44.9% <0%> (-10.19%) ⬇️
src/modules.c 49.77% <0%> (-5.48%) ⬇️
src/io.c 41.58% <0%> (-5.03%) ⬇️
src/vars.h 80% <0%> (-3.34%) ⬇️
src/objects.c 50.99% <0%> (-3.16%) ⬇️
src/gap.c 41.68% <0%> (-2.11%) ⬇️
... and 542 more

@sebasguts sebasguts force-pushed the gap-syntaxtrees branch 2 times, most recently from d50d976 to 2be1f97 Compare March 19, 2019 13:10
@fingolfin fingolfin changed the base branch from mh/syntaxtree to master March 19, 2019 14:37
Copy link
Owner

@fingolfin fingolfin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some quick comments, I'll now read the full PR again.

src/syntaxtree.c Outdated
}
WRITE_EXPR(fl, 0, ix);
WRITE_EXPR(fl, 1, PushValue(value));
return fl;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is 90% identical to CodeLazyFloatExpr. I wonder if we should just call that, and then use PopExpr. Or alternatively, extract the common code into a helper. I'd prefer that over exporting the super low-level getNextFloatExprNumber, which is a (problematic) implementation detail that I hope will go away at some point...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either popping the expr, or just adding a parameter like for CodeFuncExprEnd and returning the expression. What would you prefer?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the additional parameter.

src/syntaxtree.c Outdated Show resolved Hide resolved
src/syntaxtree.c Outdated
static Expr SyntaxTreeCodeImmediateInteger(Obj node)
{
Obj value = ELM_REC(node, RNamName("value"));
return INTEXPR_INT(Int_ObjInt(value));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So yeah, this is indeed unsafe because the resulting Int might be too big. So I'd switch back from Int_ObjInt to INT_INTOBJ, and instead insert an IS_INTOBJ check before (resp. use RequireSmallInt).

In an ideal world, though, I'd unify handling of T_INTEXPR and T_INT_EXPR: use only of them in the generated prec "tree"; then when coding back into a function, look at the value, and depending on whether it is immediate or not, output a T_INTEXPR or T_INT_EXPR... That would make it nicer to use. But doesn't have to happen in this PR!

src/syntaxtree.c Show resolved Hide resolved
src/intrprtr.c Outdated Show resolved Hide resolved
src/intrprtr.c Outdated Show resolved Hide resolved
src/code.c Outdated
/* get the body of the function */
/* push an additional return-void-statement if necessary */
/* the function interpreters depend on each function ``returning'' */
if (nr == 0) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The above formatting changes should be reverted.

src/code.c Outdated
{
PushStat(stat1);
if (TNUM_STAT(stat1) != T_RETURN_VOID &&
TNUM_STAT(stat1) != T_RETURN_OBJ) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The above formatting changes should be reverted.

src/code.c Outdated
/* if the body is a long sequence, pack the other statements */
if (7 < nr) {
stat1 = PopSeqStat(nr - 6);
PushStat(stat1);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The above formatting changes should be reverted.

src/syntaxtree.c Outdated Show resolved Hide resolved
src/syntaxtree.c Outdated Show resolved Hide resolved
@@ -1730,7 +1737,7 @@ rec(
true

# T_INFO
gap> testit(function(x) Info(1, "test"); end);
gap> testit(function(x) Info( 1, "test"); end);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drop this?

@@ -2854,6 +2861,7 @@ rec(
stats := rec(
statements := [ rec(
obj := rec(
string := "1.0",
type := "T_FLOAT_EXPR_EAGER",
value := 1 ),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, how come the value is 1 here? I think that's wrong -- we probably are returning the index into the values array, instead of the value stored in it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is definitely the value, the code looks like this:

static Obj SyntaxTreeFloatEager(Obj result, Expr expr)
{
    Obj value = GET_VALUE_FROM_CURRENT_BODY(READ_EXPR(expr, 0));
    Obj string = GET_VALUE_FROM_CURRENT_BODY(READ_EXPR(expr, 1));
    AssPRec(result, RNamName("value"), value);
    AssPRec(result, RNamName("string"), string);
    return result;
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, so it is the value, but again: how is that possible??? I still suspect something is wrong here...

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, so the problem is the print method for floats:

gap> Print(1.);
1

src/syntaxtree.c Outdated Show resolved Hide resolved
to indicate that the statement stack is complete
and does not need any more additions.
@sebasguts sebasguts force-pushed the gap-syntaxtrees branch 2 times, most recently from 81ef7ee to 2f82bf0 Compare March 19, 2019 15:51
@sebasguts sebasguts mentioned this pull request Mar 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants