-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathobjectdb.lll
80 lines (69 loc) · 1.88 KB
/
objectdb.lll
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
{
;; Modes
(def 'PRIVATE_MODE 0)
(def 'PUBLIC_MODE 1)
(def 'DEFAULT_MODE PUBLIC_MODE)
;; Init
(def 'NAME 'ObjectDB) (regname NAME)
(def 'PARENT 0) [[PARENT]] (caller)
(def 'PUBLIC 1) [[PUBLIC]] DEFAULT_MODE
;; Byte lengths
(def 'ID_SIZE 20)
(def 'KEY_SIZE (- 32 ID_SIZE))
;; Numeric value limits
(def 'MIN_ID 0)
(def 'MIN_KEY 1)
(def 'MAX_ID (- (exp 256 ID_SIZE) 1))
(def 'MAX_KEY (- (exp 256 KEY_SIZE) 1))
;; Namereg
(def 'NAMEREG 0x50441127ea5b9dfd835a9aba4e1dc9c1257b58ca)
(def 'unregister () {
[0] "unregister"
(call (- (gas) 100) NAMEREG 0 0 32 0 0)
})
;; Reserved keys
(def 'OWNER 0)
;; Code
(returnlll {
(def 'command $0)
(def 'id $32)
(def 'key $64)
(def 'value $96)
(def 'index (id key) (+ key (* id (exp 256 KEY_SIZE))))
(def 'pos (index id key))
(def 'owner (index id OWNER))
(when (= command 'add) {
(unless (or @@PUBLIC (eq (caller) @@PARENT)) (return 0))
(unless (eq @@owner 0) (return 1))
(when (slt id MIN_ID) (return 2))
(when (sgt id MAX_ID) (return 3))
[[ owner ]] (caller)
(stop)
})
(when (= command 'get) {
(def 'currentValue @@pos)
(return currentValue)
})
(when (= command 'set) {
(unless (or @@PUBLIC (eq (caller) @@PARENT)) (return 0))
(unless (eq (caller) @@owner) (return 1))
(when (slt key MIN_KEY) (return 2))
(when (sgt key MAX_KEY) (return 3))
[[ pos ]] value
(stop)
})
(when (= command 'config) {
(def 'config_key $32)
(def 'config_value $64)
(unless (eq (caller) @@PARENT) (return 1))
(when (eq config_key "public") [[PUBLIC]] config_value)
(when (eq config_key "parent") [[PARENT]] config_value)
(stop)
})
(when (= command 'kill) {
(unless (eq (caller) @@PARENT) (stop))
(unregister)
(suicide @@PARENT)
})
})
}