Closed liyili2 closed 10 years ago
This is a small example:
module TEST
configuration
<T multiplicity="?">
<k color="green" multiplicity="?">
loadMergeObj(
unwrapObj($OBJ1:Bag),
unwrapObj($OBJ2:Bag))
~> ($PGM:K)
</k>
<options> $OPTIONS:Set </options>
</T>
<global>
<tu>
<env>.Map</env>
</tu>
</global>
syntax Bag ::= unwrapObj(Bag) [function]
rule unwrapObj(<generatedTop>...
<global> G:Bag </global>
...</generatedTop>)
=> <global> G </global>
rule unwrapObj(.Bag) => .Bag
syntax KItem ::= loadMergeObj(Bag , Bag) [function]
syntax KItem ::= loadObj(Bag)
rule loadMergeObj(A:Bag , .Bag) => loadObj(A)
rule loadMergeObj(.Bag , A:Bag) => loadObj(A)
rule <k> loadObj(<global> G:Bag </global>) => .K ...</k>
<global> (_:Bag => G) </global>
requires (G =/=Bag .Bag)
[structural]
rule loadObj(.Bag) => .K
[structural]
syntax KItem ::= "start" | "end"
syntax CId ::= Identifier(String)
syntax Map ::= "builtins" [function]
rule builtins =>
"atan" |-> 1
"atan2" |-> 1
syntax KItem ::= addBuiltins(Map) | addBuiltin(CId,Int)
rule addBuiltins(.Map) => .K
rule <k> (.K => addBuiltin(Identifier(C),I)) ~> addBuiltins((C:String |-> I:Int => .Map) S:Map)
...</k>
rule <k> addBuiltin(C:CId,I:Int) => .K ...</k>
<env>... (.Map => C |-> I) ...</env>
rule <T><k> true </k><options>S:Set</options> </T> => . [structural]
rule start => addBuiltins(builtins) ~> end
rule <k> end => (Identifier("atan") in keys(M)) ...</k><env>M:Map</env>
endmodule
This is the expected output:
<global>
<tu>
<env>
Identifier ( "atan2" ) |-> 1 Identifier ( "atan" ) |-> 1
</env>
</tu>
</global>
This is the actually output:
<T>
<k>
false
</k>
<options>
SetItem ( 1 )
</options>
</T>
<global>
<tu>
<env>
Identifier ( "atan2" ) |-> 1 Identifier ( "atan" ) |-> 1
</env>
</tu>
</global>
Update some info:
I use the Java debugger to run the program. I find the main problem is from the "BuiltinSetOperations.in" function.
Evaluating the boolean expression "Identifier( "atan" ) in Identifier ( "atan2" ) Identifier ( "atan" )" will return false.
I set up a break point in the Java program of the builtin function and find that the hash code for the term of "Identifier( "atan" )" in the LHS is different from the hash code for the same term in the RHS set. They have the same klabel but they don't have the same klist, even if their klist terms look the same as "String(#""atan"")".
When I go deep in comparing the structure of their klist terms. I find that their structures are the same: "KList ---- StringToken ---- Value". However, the values are different, the LHS term has value atan, while the RHS has value "atan".
@yilongli , Hi, Would you mind to tell me what is the status of the bug fixing?
I haven't got a chance to look into this issue.
@dwightguth @andreistefanescu I am not sure how to fix this. The problem is that when you convert a Java-backend StringToken
back to generic KIL in BackendJavaKILtoKILTransformer#transform(Token)
, the sort of the StringToken
is String
rather than #String
, which makes org.kframework.kil.Token.kAppOf
to return a GenericToken
insteadof StringBuiltin
. Therefore, when that GenericToken
is converted to Java backend again, it becomes an UninterpretedToken
. Any suggestion? Thanks.
The #String sort should be eliminated. So the StringToken should be created from something that has sort String instead. I tried to do that at one point, but I got so many errors from the backend that I gave up.
How can I proceed here. I need the problem to be solved in order to move forward for my C semantics.
On Sun, Aug 10, 2014 at 5:13 PM, Radu Mereuta notifications@github.com wrote:
The #String sort should be eliminated. So the StringToken should be created from something that has sort String instead. I tried to do that at one point, but I got so many errors from the backend that I gave up.
— Reply to this email directly or view it on GitHub https://github.com/kframework/k/issues/789#issuecomment-51729103.
I think we should get rid of #String and the likes. I'm not sure who is best to do it...
On Sun, Aug 10, 2014 at 10:29 PM, Liyi Li notifications@github.com wrote:
How can I proceed here. I need the problem to be solved in order to move forward for my C semantics.
On Sun, Aug 10, 2014 at 5:13 PM, Radu Mereuta notifications@github.com wrote:
The #String sort should be eliminated. So the StringToken should be created from something that has sort String instead. I tried to do that at one point, but I got so many errors from the backend that I gave up.
— Reply to this email directly or view it on GitHub https://github.com/kframework/k/issues/789#issuecomment-51729103.
— Reply to this email directly or view it on GitHub https://github.com/kframework/k/issues/789#issuecomment-51739027.
@radumereuta Since I have changed the sort representation from String to class, I guess the backend errors should be much easier to fix now.
There were also problems in the maude backend. Those are the ones that I couldn't fix.
what should i do to avoid the problem
@radumereuta yeah, I am aware of that this morning when I tried to fix this issue. What about this? First, you change the front-end to eliminate #String
(just this one for now). Then I continue on your branch to fix any issues in the Java backend. This should temporarily unblock the progress on C semantics.
Try to use https://github.com/kframework/k/pull/837 as a temporary solution if all tests pass.
I spent two days to understand this problem really. If I have this set of rules:
and I run the program "start" by the following command:
I will get a correct result as:
because K will evaluate the final boolean expression "(Identifier("atan") in keys(M))" to "true". To show the error, I will need to run the binary version of the command above as:
Then, I will run another command as:
This command will input the final configuration above as a binary file "ctype.o" and run the program "end", which is in b.test. However, the Java bacend will incorrectly evaluate the final boolean expression "(Identifier("atan") in keys(M))" to "false". The final configuration of running the program "end" is:
I expect the final configuration of running program "end" by inputing ctype.o the same as the final configuration as the final configuration by running program "start" through the command: