Skip to content

Commit 3c634a6

Browse files
KJ-7 Preparatory work, documenting existing semantics
1 parent 0900216 commit 3c634a6

3 files changed

Lines changed: 32 additions & 15 deletions

File tree

.idea/codeStyleSettings.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

java-semantics.iml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<exclude-output />
55
<content url="file://$MODULE_DIR$">
66
<excludeFolder url="file://$MODULE_DIR$/semantics/.k" />
7+
<excludeFolder url="file://$MODULE_DIR$/semantics/.test" />
78
<excludeFolder url="file://$MODULE_DIR$/semantics/java-kompiled" />
89
</content>
910
<orderEntry type="inheritedJdk" />

semantics/elaborate-blocks.k

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ syntax K ::= "elabInstanceInit"
5555
//@Elaborates the given statement/expression. The first step of elaboration.
5656
syntax K ::= "elab" "(" K ")"
5757

58-
//@ Intermediate state between elab and elabRes - all subterms were already elaborated. Responsible for deleting the elabRes() wrappers of subterms.
59-
syntax K ::= "elabDispose" "(" K ")"
60-
6158
//@ Wraps the elaboration result. Since elaboration may happen at both ElaborationPhase and ExecutionPhase, it cannot be KResult. Actually it is not KResult for HOLE, but is for CHOLE.
6259
syntax K ::= "elabRes" "(" K ")"
6360

@@ -290,7 +287,13 @@ when
290287
andBool isElab(HeadKs) //Forces elaboration left-to-right. Required when KL == 'ListWrap of statements.
291288
[transition-strictness]
292289
293-
//@ True if children of this label should not be automatically heated for elaboration.
290+
/*@ Terms that should use custom elaboration rules. For those terms:
291+
- They will not be automatically heated from their parents into the elab() state.
292+
- They will not be automatically passed to elabDispose() state. Instead, those terms should have custom rules
293+
for elaboration start (heating) and elaboration end (cooling).
294+
Since all the automatic elaboration-related rules are an incredible mess, we have to put all the AST terms into this
295+
cathegory one by one, and eliminate automatic elaboration heating/cooling rules altogether.
296+
*/
294297
syntax K ::= "customElabChildren" "(" KLabel ")" [function]
295298
rule customElabChildren(KL:KLabel) =>
296299
(KL ==KLabel 'Block)
@@ -305,12 +308,9 @@ rule customElabChildren(KL:KLabel) =>
305308
orBool (KL ==KLabel 'NewInstance)
306309
orBool (KL ==KLabel 'QNewInstance)
307310

308-
//@ Will not match .K - is not isElabNaked. (.K) is matched by [elabDotK].
309-
rule [unwrapElabNaked]:
310-
elab(K:K) => K
311-
when
312-
isElabNaked(K)
313-
311+
/*@ Represents terms that shoud never be wrapped by elab() or related wrappers. They are processed to their final state
312+
in elaboration phase. Those are types names, package names, id's ad literals.
313+
*/
314314
syntax K ::= "isElabNaked" "(" K ")" [function]
315315
rule isElabNaked(K:K) =>
316316
(isRawVal(K) ==K true)
@@ -324,6 +324,12 @@ rule isElabNaked(K:K) =>
324324
orBool (getKLabel(K) ==KLabel 'Id)
325325
orBool (getKLabel(K) ==KLabel 'Lit)
326326

327+
//@ Will not match .K - is not isElabNaked. (.K) is matched by [elabDotK].
328+
rule [unwrapElabNaked]:
329+
elab(K:K) => K
330+
when
331+
isElabNaked(K)
332+
327333
rule [elabCoolStatement]:
328334
(elabRes(K:K) => .) ~> elab(_:KLabel(_,, (CHOLE => elabRes(K)),, _))
329335
when
@@ -339,11 +345,14 @@ rule [elabCoolIndependent]:
339345
when
340346
isElabIndependent(ElabIndep)
341347

342-
//@ Required by the rule [elabQNewInstance-resolve-class]
343-
rule [elabDisposeCoolIndependent]:
344-
(ElabIndep:K => .) ~> elabDispose(_:KLabel(_,, (CHOLE => ElabIndep),, _))
345-
when
346-
isElabIndependent(ElabIndep)
348+
/*@ The default algorithm of transforming the term from elab to elabRes, when the children were completely elaborated.
349+
Deletes elabRes wrappers from children. This algorithm is activated when the following conditions apply:
350+
- term is not customElabChildren
351+
- term children are completely elaborated - isElab(children)
352+
- term is not naked. This case should never be true, but there is some weird case that requires it.
353+
When the default algorithm is not appropriate, the respective term should be in the cathegory customElabChildren
354+
*/
355+
syntax K ::= "elabDispose" "(" K ")"
347356

348357
rule [elabDisposeStartDefault]:
349358
elab(KL:KLabel(ElabResL:KList)) => elabDispose(KL(ElabResL))
@@ -360,6 +369,12 @@ rule [elabDisposeEnd]:
360369
when
361370
notBool isExpressionLabel(KL) andBool haveNoElabRes(Ks)
362371

372+
//@ Required by the rule [elabQNewInstance-resolve-class]
373+
rule [elabDisposeCoolIndependent]:
374+
(ElabIndep:K => .) ~> elabDispose(_:KLabel(_,, (CHOLE => ElabIndep),, _))
375+
when
376+
isElabIndependent(ElabIndep)
377+
363378
syntax K ::= "isElabIndependent" "(" K ")" [function]
364379
rule isElabIndependent(K:K) =>
365380
(isKResult(K) ==K true)

0 commit comments

Comments
 (0)