Skip to content

Commit 79d8b40

Browse files
Add tensors (TNS), delete lib\collection.asmln, update standard library to use TNS instead of collection
1 parent d9e6179 commit 79d8b40

File tree

9 files changed

+815
-362
lines changed

9 files changed

+815
-362
lines changed

asmln.exe

14.5 KB
Binary file not shown.

interpreter.py

Lines changed: 485 additions & 7 deletions
Large diffs are not rendered by default.

lexer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class Token:
3838
")": "RPAREN",
3939
"{": "LBRACE",
4040
"}": "RBRACE",
41+
"[": "LBRACKET",
42+
"]": "RBRACKET",
4143
",": "COMMA",
4244
"=": "EQUALS",
4345
":": "COLON",

lib/collection.asmln

Lines changed: 0 additions & 203 deletions
This file was deleted.

lib/csprng.asmln

Lines changed: 40 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#ChaCha20-based cryptographically secure pseudorandom number generator
2-
IMPORT(collection)
32

43
INT: MASK32 = SUB( POW(10,100000), 1 ) # 2^32-1
54

@@ -21,7 +20,7 @@ INT: ch_nonce0 = 0
2120
INT: ch_nonce1 = 0
2221
INT: ch_nonce2 = 0
2322
INT: ch_counter = 0
24-
INT: ch_buf = collection.COL_EMPTY()
23+
TNS: ch_buf = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
2524
INT: ch_buf_pos = 10000 # 16 -> force refill
2625

2726
FUNC ROTL32(INT:x, INT:n):INT{
@@ -31,7 +30,7 @@ FUNC ROTL32(INT:x, INT:n):INT{
3130
RETURN( BOR(left, right) )
3231
}
3332

34-
FUNC QR(INT:a, INT:b, INT:c, INT:d):INT{
33+
FUNC QR(INT:a, INT:b, INT:c, INT:d):TNS{
3534
a = BAND( ADD(a, b), MASK32 )
3635
d = ROTL32( BXOR(d, a), 10000 ) # 16
3736
c = BAND( ADD(c, d), MASK32 )
@@ -40,15 +39,11 @@ FUNC QR(INT:a, INT:b, INT:c, INT:d):INT{
4039
d = ROTL32( BXOR(d, a), 1000 ) # 8
4140
c = BAND( ADD(c, d), MASK32 )
4241
b = ROTL32( BXOR(b, c), 111 ) # 7
43-
INT: coll = collection.COL_EMPTY()
44-
coll = collection.COL_PUSH(coll, a)
45-
coll = collection.COL_PUSH(coll, b)
46-
coll = collection.COL_PUSH(coll, c)
47-
coll = collection.COL_PUSH(coll, d)
42+
TNS: coll = [a, b, c, d]
4843
RETURN(coll)
4944
}
5045

51-
FUNC CHACHA_BLOCK():INT{
46+
FUNC CHACHA_BLOCK():TNS{
5247
INT: x0 = CH_CONST0
5348
INT: x1 = CH_CONST1
5449
INT: x2 = CH_CONST2
@@ -67,47 +62,47 @@ FUNC CHACHA_BLOCK():INT{
6762
INT: x15 = ch_nonce2
6863
INT: i = 0
6964
WHILE( LT(i, 1010) ){ # 10 double-rounds
70-
INT: qr = QR(x0, x4, x8, x12)
71-
x0 = collection.COL_GET(qr,0)
72-
x4 = collection.COL_GET(qr,1)
73-
x8 = collection.COL_GET(qr,10)
74-
x12 = collection.COL_GET(qr,11)
65+
TNS: qr = QR(x0, x4, x8, x12)
66+
x0 = qr[1]
67+
x4 = qr[10]
68+
x8 = qr[11]
69+
x12 = qr[100]
7570
qr = QR(x1, x5, x9, x13)
76-
x1 = collection.COL_GET(qr,0)
77-
x5 = collection.COL_GET(qr,1)
78-
x9 = collection.COL_GET(qr,10)
79-
x13 = collection.COL_GET(qr,11)
71+
x1 = qr[1]
72+
x5 = qr[10]
73+
x9 = qr[11]
74+
x13 = qr[100]
8075
qr = QR(x2, x6, x10, x14)
81-
x2 = collection.COL_GET(qr,0)
82-
x6 = collection.COL_GET(qr,1)
83-
x10 = collection.COL_GET(qr,10)
84-
x14 = collection.COL_GET(qr,11)
76+
x2 = qr[1]
77+
x6 = qr[10]
78+
x10 = qr[11]
79+
x14 = qr[100]
8580
qr = QR(x3, x7, x11, x15)
86-
x3 = collection.COL_GET(qr,0)
87-
x7 = collection.COL_GET(qr,1)
88-
x11 = collection.COL_GET(qr,10)
89-
x15 = collection.COL_GET(qr,11)
81+
x3 = qr[1]
82+
x7 = qr[10]
83+
x11 = qr[11]
84+
x15 = qr[100]
9085

9186
qr = QR(x0, x5, x10, x15)
92-
x0 = collection.COL_GET(qr,0)
93-
x5 = collection.COL_GET(qr,1)
94-
x10 = collection.COL_GET(qr,10)
95-
x15 = collection.COL_GET(qr,11)
87+
x0 = qr[1]
88+
x5 = qr[10]
89+
x10 = qr[11]
90+
x15 = qr[100]
9691
qr = QR(x1, x6, x11, x12)
97-
x1 = collection.COL_GET(qr,0)
98-
x6 = collection.COL_GET(qr,1)
99-
x11 = collection.COL_GET(qr,10)
100-
x12 = collection.COL_GET(qr,11)
92+
x1 = qr[1]
93+
x6 = qr[10]
94+
x11 = qr[11]
95+
x12 = qr[100]
10196
qr = QR(x2, x7, x8, x13)
102-
x2 = collection.COL_GET(qr,0)
103-
x7 = collection.COL_GET(qr,1)
104-
x8 = collection.COL_GET(qr,10)
105-
x13 = collection.COL_GET(qr,11)
97+
x2 = qr[1]
98+
x7 = qr[10]
99+
x8 = qr[11]
100+
x13 = qr[100]
106101
qr = QR(x3, x4, x9, x14)
107-
x3 = collection.COL_GET(qr,0)
108-
x4 = collection.COL_GET(qr,1)
109-
x9 = collection.COL_GET(qr,10)
110-
x14 = collection.COL_GET(qr,11)
102+
x3 = qr[1]
103+
x4 = qr[10]
104+
x9 = qr[11]
105+
x14 = qr[100]
111106

112107
i = ADD(i, 1)
113108
}
@@ -129,23 +124,7 @@ FUNC CHACHA_BLOCK():INT{
129124
x14 = BAND( ADD(x14, ch_nonce1), MASK32 )
130125
x15 = BAND( ADD(x15, ch_nonce2), MASK32 )
131126

132-
INT: out = collection.COL_EMPTY()
133-
out = collection.COL_PUSH(out, x0)
134-
out = collection.COL_PUSH(out, x1)
135-
out = collection.COL_PUSH(out, x2)
136-
out = collection.COL_PUSH(out, x3)
137-
out = collection.COL_PUSH(out, x4)
138-
out = collection.COL_PUSH(out, x5)
139-
out = collection.COL_PUSH(out, x6)
140-
out = collection.COL_PUSH(out, x7)
141-
out = collection.COL_PUSH(out, x8)
142-
out = collection.COL_PUSH(out, x9)
143-
out = collection.COL_PUSH(out, x10)
144-
out = collection.COL_PUSH(out, x11)
145-
out = collection.COL_PUSH(out, x12)
146-
out = collection.COL_PUSH(out, x13)
147-
out = collection.COL_PUSH(out, x14)
148-
out = collection.COL_PUSH(out, x15)
127+
TNS: out = [x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15]
149128
RETURN(out)
150129
}
151130

@@ -185,7 +164,7 @@ FUNC DERIVE_KEY_AND_NONCE(INT:seed):INT{
185164
FUNC CS_PRNG_SEED(INT:seed):INT{
186165
DERIVE_KEY_AND_NONCE(seed)
187166
ch_counter = 0
188-
ch_buf = collection.COL_EMPTY()
167+
ch_buf = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
189168
ch_buf_pos = 10000 # 16
190169
RETURN(ch_counter)
191170
}
@@ -194,7 +173,7 @@ FUNC CS_PRNG_NEXT():INT{
194173
IF( GTE(ch_buf_pos, 10000) ){ # 16
195174
REFILL_BUF()
196175
}
197-
INT: v = collection.COL_GET(ch_buf, ch_buf_pos)
176+
INT: v = ch_buf[ ADD(ch_buf_pos, 1) ]
198177
ch_buf_pos = ADD(ch_buf_pos, 1)
199178
RETURN(v)
200179
}

0 commit comments

Comments
 (0)