mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-09 16:28:47 +00:00
Updated spec
This commit is contained in:
parent
6f9d0850c7
commit
94e4b16267
7 changed files with 48 additions and 18 deletions
BIN
lama-spec.pdf
BIN
lama-spec.pdf
Binary file not shown.
|
|
@ -47,6 +47,6 @@ F,enableGC;
|
|||
F,disableGC;
|
||||
F,random;
|
||||
F,time;
|
||||
F,rawTag;
|
||||
F,kindOf;
|
||||
F,compareTags;
|
||||
F,flatCompare;
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ void __post_gc_subst () {}
|
|||
# define ARRAY_TAG 0x00000003
|
||||
# define SEXP_TAG 0x00000005
|
||||
# define CLOSURE_TAG 0x00000007
|
||||
# define UNBOXED_TAG 0x00000009 // Not actually a tag; used to return from LrawTag
|
||||
# define UNBOXED_TAG 0x00000009 // Not actually a tag; used to return from LkindOf
|
||||
|
||||
# define LEN(x) ((x & 0xFFFFFFF8) >> 3)
|
||||
# define TAG(x) (x & 0x00000007)
|
||||
|
|
@ -175,7 +175,7 @@ extern void* Bsexp (int n, ...);
|
|||
void *global_sysargs;
|
||||
|
||||
// Gets a raw tag
|
||||
extern int LrawTag (void *p) {
|
||||
extern int LkindOf (void *p) {
|
||||
if (UNBOXED(p)) return UNBOXED_TAG;
|
||||
|
||||
return TAG(TO_DATA(p)->tag);
|
||||
|
|
|
|||
|
|
@ -134,7 +134,10 @@ is used.
|
|||
|
||||
Maps are immutable structures with the following interface:
|
||||
|
||||
\descr{\lstinline|fun emptyMap ()|}{Creates an empty map.}
|
||||
\descr{\lstinline|fun emptyMap (f)|}{Creates an empty map. An argument is a comparison function, which returns zero, positive or negative integer values depending on
|
||||
the order of its arguments.}
|
||||
|
||||
\descr{\lstinline|fun compareOf (m)|}{Returns a comparison function, associated with the map given as an argument.}
|
||||
|
||||
\descr{\lstinline|fun addMap (m, k, v)|}{Adds a binding of a key "\lstinline|k|" to a value "\lstinline|v|" into a map "\lstinline|m|". As a result, a new map is
|
||||
returned.}
|
||||
|
|
@ -161,7 +164,10 @@ The function takes an accumulator and a pair key-value. The bindings are enumera
|
|||
|
||||
Sets are immutable structures with the following interface:
|
||||
|
||||
\descr{\lstinline|fun emptySet ()|}{Creates an empty set.}
|
||||
\descr{\lstinline|fun emptySet (f)|}{Creates an empty set. An argument is a comparison function, which returns zero, positive or negative integer values depending on
|
||||
the order of its arguments.}
|
||||
|
||||
\descr{\lstinline|fun compareOf (m)|}{Returns a comparison function, associated with the set given as an argument.}
|
||||
|
||||
\descr{\lstinline|fun addSet (s, v)|}{Adds an element "\lstinline|v|" into a set "\lstinline|s|" and returns a new set.}
|
||||
|
||||
|
|
@ -204,7 +210,11 @@ Hash table is an immutable map which uses hashes as keys and lists of key-value
|
|||
hash function is used, the search within the same hash class is linear with physical equality "\lstinline|==|" used for
|
||||
comparison.
|
||||
|
||||
\descr{\lstinline|fun emptyHashTab ()|}{Creates an empty hash table.}
|
||||
\descr{\lstinline|fun emptyHashTab (n, h, c)|}{Creates an empty hash table. Argument are: a number of classes, hash and comparison functions.}
|
||||
|
||||
\descr{\lstinline|fun compareOf (m)|}{Returns a comparison function, associated with the hash table given as an argument.}
|
||||
|
||||
\descr{\lstinline|fun hashOf (m)|}{Returns a hash function, associated with the hash table given as an argument.}
|
||||
|
||||
\descr{\lstinline|fun addHashTab (t, k, v)|}{Adds a binding of "\lstinline|k|" to "\lstinline|v|" to the hash table "\lstinline|t|" and returns a
|
||||
new hash table.}
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
let version = "Version 1.00, c3671a0a3, Tue Aug 4 15:11:14 2020 +0300"
|
||||
let version = "Version 1.00, 6f9d0850c, Fri Aug 7 21:40:51 2020 +0300"
|
||||
|
|
|
|||
|
|
@ -323,10 +323,10 @@ public fun lookupMemo (m, v) {
|
|||
|
||||
-- Maps of hashed pointers
|
||||
public fun emptyHashTab (n, hash, compare) {
|
||||
[initArray (n, fun (_) {{}}), fun (x) {hash (x) % n}, compare]
|
||||
[initArray (n, fun (_) {{}}), compare, fun (x) {hash (x) % n}]
|
||||
}
|
||||
|
||||
public fun addHashTab (ht@[a, hash, compare], k, v) {
|
||||
public fun addHashTab (ht@[a, compare, hash], k, v) {
|
||||
local h = hash (k);
|
||||
|
||||
a [h] := [k, v] : a [h];
|
||||
|
|
@ -334,17 +334,21 @@ public fun addHashTab (ht@[a, hash, compare], k, v) {
|
|||
ht
|
||||
}
|
||||
|
||||
public fun findHashTab ([a, hash, compare], k) {
|
||||
public fun findHashTab ([a, compare, hash], k) {
|
||||
case find (fun ([k0, _]) {compare (k, k0) == 0}, a[hash(k)]) of
|
||||
Some ([_, v]) -> Some (v)
|
||||
| _ -> None
|
||||
esac
|
||||
}
|
||||
|
||||
public fun removeHashTab (ht@[a, hash, compare], k) {
|
||||
public fun removeHashTab (ht@[a, compare, hash], k) {
|
||||
local h = hash (k);
|
||||
|
||||
a [h] := remove (fun ([k0, _]) {compare (k, k0) == 0}, a [h]);
|
||||
|
||||
ht
|
||||
}
|
||||
}
|
||||
|
||||
public fun hashOf (ht) {
|
||||
ht [2]
|
||||
}
|
||||
|
|
@ -13,10 +13,19 @@ public infix =?= at < (x, y) {
|
|||
fun alreadyEq (x, y) {
|
||||
fun find (x) {
|
||||
fun walk (r) {
|
||||
case r of
|
||||
[#unboxed] -> r
|
||||
| [x] -> walk (x)
|
||||
esac
|
||||
fun walkrec (p1, p2, r) {
|
||||
case p2 of
|
||||
[_] -> p2 [0] := r
|
||||
| _ -> skip
|
||||
esac;
|
||||
|
||||
case r of
|
||||
[#unboxed] -> r
|
||||
| [x] -> walkrec (r, p1, x)
|
||||
esac
|
||||
}
|
||||
|
||||
walkrec ({}, {}, r)
|
||||
}
|
||||
|
||||
case findMap (deref (m), x) of
|
||||
|
|
@ -43,7 +52,14 @@ public infix =?= at < (x, y) {
|
|||
if rx == ry
|
||||
then true
|
||||
else
|
||||
rx [0] := ry;
|
||||
if rx[0] < ry[0]
|
||||
then
|
||||
ry [0] := ry [0] + rx [0];
|
||||
rx [0] := ry
|
||||
else
|
||||
rx [0] := rx [0] + ry [0];
|
||||
ry [0] := rx
|
||||
fi;
|
||||
false
|
||||
fi
|
||||
esac
|
||||
|
|
@ -63,7 +79,7 @@ public infix =?= at < (x, y) {
|
|||
if alreadyEq (x, y)
|
||||
then 0
|
||||
else
|
||||
local diff = x.rawTag - y.rawTag;
|
||||
local diff = x.kindOf - y.kindOf;
|
||||
|
||||
if diff != 0 then diff
|
||||
else
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue