-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gene Gleyzer
committed
Nov 12, 2024
1 parent
5a84542
commit 1c0274b
Showing
11 changed files
with
132 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* JSON Object. | ||
*/ | ||
@AutoFreezable | ||
class JsonObject | ||
implements Freezable | ||
delegates Map<String, Doc>(jsonObject) { | ||
|
||
construct(Map<String, Doc> map = []) { | ||
jsonObject = new ListMap(); | ||
if (!map.empty) { | ||
jsonObject.putAll(map); | ||
} | ||
} | ||
|
||
private Map<String, Doc> jsonObject; | ||
|
||
@Override | ||
immutable Freezable freeze(Boolean inPlace = False) = makeImmutable(); | ||
|
||
@Override | ||
@Op("[]") Value? getOrNull(Key key) = super(key); | ||
|
||
@Override | ||
@Op("[]=") void putInPlace(Key key, Value value) = super(key, value); | ||
|
||
// this doesn't work atm, but it should; will make put ops more usable | ||
// @Op("[]=") void putInPlace(Key key, Int value) = putInPlace(key, value.toIntLiteral()); | ||
// | ||
// @Op("[]=") void putInPlace(Key key, FPNumber value) = putInPlace(key, value.toIntLiteral()); | ||
|
||
@Auto | ||
Doc toDoc() = jsonObject; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,31 @@ | ||
module TestSimple { | ||
|
||
import ecstasy.collections.NaturalHasher; | ||
package json import json.xtclang.org; | ||
|
||
@Inject Console console; | ||
|
||
import json.*; | ||
|
||
void run() { | ||
Char a = 'a'; | ||
Char b = 'b'; | ||
console.print(a.hashCode()); | ||
console.print(new NaturalHasher<Char>().hashOf(a)); | ||
|
||
console.print(a==b); | ||
console.print(new NaturalHasher<Char>().areEqual(a, b)); | ||
|
||
console.print(a<=>b); | ||
|
||
try { | ||
Hashable h = obfuscate(a); | ||
console.print(h.hashCode()); | ||
} | ||
catch (Exception e) { | ||
console.print(e); | ||
} | ||
|
||
try { | ||
Const c = obfuscate(a); | ||
console.print(c.hashCode()); | ||
} | ||
catch (Exception e) { | ||
console.print(e); | ||
} | ||
Test t = new Test(); | ||
console.print(t.getObject()); | ||
console.print(t.getDoc()); | ||
|
||
try { | ||
Orderable c1 = obfuscate(a); | ||
Orderable c2 = obfuscate(b); | ||
console.print(c1 <=> c2); | ||
} | ||
catch (Exception e) { | ||
console.print(e); | ||
} | ||
} | ||
|
||
service Test { | ||
|
||
try { | ||
Const c1 = obfuscate(a); | ||
Const c2 = obfuscate(b); | ||
console.print(c1 == c2); | ||
} | ||
catch (Exception e) { | ||
console.print(e); | ||
JsonObject getObject(Int i = 1) { | ||
JsonObject o = json.newObject(); | ||
o["a"] = i /*this will not be needed*/.toIntLiteral(); | ||
return o; // no need to freeze | ||
} | ||
|
||
try { | ||
Const c1 = obfuscate(a); | ||
Const c2 = obfuscate(b); | ||
console.print(c1 <=> c2); | ||
} | ||
catch (Exception e) { | ||
console.print(e); | ||
Doc getDoc(Dec d = 1) { | ||
JsonObject o = json.newObject(); | ||
o["a"] = d/*this will not be needed*/.toFPLiteral(); | ||
return o; | ||
} | ||
} | ||
|
||
<T> T obfuscate(Object o) = o.as(T); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.