-
Notifications
You must be signed in to change notification settings - Fork 0
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
Gap syntaxtrees #114
Conversation
16dda94
to
3022308
Compare
@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 I've also been thinking about not produce @@ -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 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... :-) |
Now it is
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.
That is fine by me. |
0112689
to
9dce3f6
Compare
92a1bd0
to
2f61be1
Compare
ee33756
to
c4c6519
Compare
Should I make this a PR to gap-system, so we can continue discussing there? Or split this up? |
fdc0022
to
332e15f
Compare
371055c
to
583ffea
Compare
I rebased the branch and added the float coders. |
583ffea
to
e476029
Compare
Codecov Report
@@ 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
|
332e15f
to
62d24a6
Compare
There was a problem hiding this 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 :-)
Codecov Report
@@ 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
|
d50d976
to
2be1f97
Compare
2be1f97
to
4fec202
Compare
There was a problem hiding this 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; |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
static Expr SyntaxTreeCodeImmediateInteger(Obj node) | ||
{ | ||
Obj value = ELM_REC(node, RNamName("value")); | ||
return INTEXPR_INT(Int_ObjInt(value)); |
There was a problem hiding this comment.
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/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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
4fec202
to
56a4321
Compare
tst/testinstall/syntaxtree.tst
Outdated
@@ -1730,7 +1737,7 @@ rec( | |||
true | |||
|
|||
# T_INFO | |||
gap> testit(function(x) Info(1, "test"); end); | |||
gap> testit(function(x) Info( 1, "test"); end); |
There was a problem hiding this comment.
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 ), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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;
}
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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
to indicate that the statement stack is complete and does not need any more additions.
81ef7ee
to
2f82bf0
Compare
2f82bf0
to
9fa7002
Compare
No description provided.