Uses 1059K of libraries. Click here for Pure Java version (625L/4K).
1 | !7 |
2 | |
3 | // Makes the Concept.Ref object unnecessary by directly |
4 | // storing the reference in a field. |
5 | // We can probably get rid of the refs field in the same go. |
6 | // Of course, backRefs are still needed. |
7 | |
8 | // TODO: We need backRefs to be able to store concepts also |
9 | // (by changing its type to L). |
10 | // Or we add another field directBackRefs. |
11 | |
12 | sbool isConceptRefValid(Concept src, Concept dest) { |
13 | ret src != null && dest != null && src._concepts != null && src._concepts == dest._concepts; |
14 | } |
15 | |
16 | svoid indexConceptRef(Concept src, Concept dest) { |
17 | if (isConceptRefValid(src, dest)) { |
18 | // dest._addBackRef(src); |
19 | change(); |
20 | } |
21 | } |
22 | |
23 | svoid unindexConceptRef(Concept src, Concept dest) {} |
24 | |
25 | sO conceptRefMutex(Concept c) { |
26 | ret or(c._concepts, dummyMutex()); |
27 | } |
28 | |
29 | concept Thing { |
30 | Thing ref_ptr; |
31 | |
32 | // setter |
33 | selfType ref(Thing dest) { |
34 | synchronized(conceptRefMutex(this)) { |
35 | if (ref_ptr != dest) { |
36 | unindexConceptRef(this, ref_ptr); |
37 | ref_ptr = dest; |
38 | indexConceptRef(this, dest); |
39 | } |
40 | } |
41 | this; |
42 | } |
43 | |
44 | // getter. we could get rid of this by making the field |
45 | // publicly accessible, but then we run the slight chance |
46 | // of setting it without the setter inadvertently. |
47 | Thing ref() { ret ref_ptr; } |
48 | } |
49 | |
50 | cprint {} |
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt
No comments. add comment
Snippet ID: | #1031144 |
Snippet name: | Weightless Concept Refs Spike [dev.] |
Eternal ID of this version: | #1031144/5 |
Text MD5: | b6ad928836ac2767cab8eae8ba53f2b1 |
Transpilation MD5: | 8970b7adedc1065d5ce1a5695e984995 |
Author: | stefan |
Category: | javax / concepts |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-05-12 23:26:19 |
Source code size: | 1299 bytes / 50 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 171 / 272 |
Version history: | 4 change(s) |
Referenced in: | [show references] |