Skip to content

Commit 540d2d8

Browse files
committed
implemented Pillar 10: Zero-Trust Security.
1 parent 4ca601d commit 540d2d8

3 files changed

Lines changed: 35 additions & 3 deletions

File tree

include/ast.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ typedef enum {
4242
EXPR_DICTIONARY, EXPR_TERNARY, EXPR_LAMBDA,
4343
EXPR_DICTIONARY, EXPR_TERNARY, EXPR_LAMBDA,
4444
EXPR_AWAIT, EXPR_THIS, EXPR_SUPER, EXPR_NEW,
45-
EXPR_SANITIZE
45+
EXPR_SANITIZE,
46+
EXPR_CRYPTO // Encrypt/Decrypt
4647
} ExprType;
4748

4849
typedef enum {
@@ -62,7 +63,8 @@ typedef enum {
6263
STMT_MODEL_DECL,
6364
STMT_MODEL_DECL,
6465
STMT_QUANTUM_BLOCK,
65-
STMT_GPU_BLOCK
66+
STMT_GPU_BLOCK,
67+
STMT_VERIFY
6668
} StmtType;
6769

6870
// --- List Structures ---
@@ -115,6 +117,7 @@ typedef struct { char *name; } VariableExpr;
115117
typedef struct { char *name; Expr *value; } AssignExpr;
116118
typedef struct { Expr *left; char *operator; Expr *right; } LogicalExpr;
117119
typedef struct { Expr *value; } SanitizeExpr;
120+
typedef struct { Expr *value; bool isEncrypt; } CryptoExpr; // isEncrypt=true (encrypt), false (decrypt)
118121
typedef struct { Expr *callee; ExprList *arguments; } CallExpr;
119122
typedef struct { Expr *object; char *name; } GetExpr;
120123
typedef struct { Expr *object; char *name; Expr *value; } SetExpr;
@@ -138,6 +141,7 @@ struct Expr {
138141
BinaryExpr binary; UnaryExpr unary; LiteralExpr literal; GroupingExpr grouping;
139142
VariableExpr variable; AssignExpr assign; LogicalExpr logical;
140143
SanitizeExpr sanitize;
144+
CryptoExpr crypto;
141145
// ... struct pointers for others due to C union size limit usually
142146
struct { Expr *callee; ExprList *arguments; } call;
143147
struct { Expr *object; char *name; } get;
@@ -170,13 +174,19 @@ typedef struct { char *name; StringList *params; TypeInfo returnType; } IntentDe
170174
typedef struct { char *name; char *targetIntent; StmtList *body; } ResolverDeclStmt;
171175
typedef struct { char *name; StringList *params; TypeInfo returnType; } IntentDeclStmt;
172176
typedef struct { char *name; char *targetIntent; StmtList *body; } ResolverDeclStmt;
177+
typedef struct { char *name; StringList *params; TypeInfo returnType; } IntentDeclStmt;
178+
typedef struct { char *name; char *targetIntent; StmtList *body; } ResolverDeclStmt;
173179
typedef struct { StmtList *body; char *strategy; int retryCount; StmtList *recoveryBody; } ResilientStmt;
174180
typedef struct { char *policyName; char *target; StmtList *rules; } PolicyDeclStmt;
175181
typedef struct { char *name; StringList *capabilities; } NodeDeclStmt;
176182
typedef struct { char *name; StmtList *fields; } DistributedDeclStmt;
183+
typedef struct { char *name; StmtList *fields; } DistributedDeclStmt;
184+
typedef struct { char *name; StringList *capabilities; } NodeDeclStmt;
185+
typedef struct { char *name; StmtList *fields; } DistributedDeclStmt;
177186
typedef struct { char *name; char *architecture; StmtList *body; } ModelDeclStmt;
178187
typedef struct { StmtList *body; } QuantumBlockStmt;
179188
typedef struct { char *kernelName; StmtList *body; } GPUBlockStmt;
189+
typedef struct { char *identityName; StmtList *body; } VerifyStmt; // verify identity <name> { ... }
180190

181191
struct Stmt {
182192
StmtType type;
@@ -201,6 +211,7 @@ struct Stmt {
201211
ModelDeclStmt model_decl;
202212
QuantumBlockStmt quantum_block;
203213
GPUBlockStmt gpu_block;
214+
VerifyStmt verify_stmt;
204215
} as;
205216
};
206217

@@ -225,6 +236,8 @@ Expr *createAwaitExpr(Expr *expression, int line, int column);
225236
Expr *createThisExpr(int line, int column);
226237
Expr *createSuperExpr(const char *method, int line, int column);
227238
Expr *createNewExpr(Expr *clazz, ExprList *args, int line, int column);
239+
Expr *createSanitizeExpr(Expr *value, int line, int column); // Added prototype
240+
Expr *createCryptoExpr(Expr *val, bool isEncrypt, int line, int column);
228241

229242
Stmt *createExpressionStmt(Expr *expression, int line, int column);
230243
Stmt *createVarDeclStmt(const char *name, Expr *init, bool is_const, bool isTemporal, int ttl, int line, int column);
@@ -254,6 +267,7 @@ Stmt *createDistributedDeclStmt(const char *name, StmtList *fields, int line, in
254267
Stmt *createModelDeclStmt(const char *name, const char *architecture, StmtList *body, int line, int column);
255268
Stmt *createQuantumBlockStmt(StmtList *body, int line, int column);
256269
Stmt *createGPUBlockStmt(const char *kernelName, StmtList *body, int line, int column);
270+
Stmt *createVerifyStmt(const char *identityName, StmtList *body, int line, int column);
257271

258272
ExprList *createExprList();
259273
void appendExpr(ExprList *list, Expr *expr);

include/scanner.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,12 @@ typedef enum {
160160
TOKEN_TENSOR,
161161
TOKEN_MATRIX,
162162
TOKEN_GPU,
163+
TOKEN_GPU,
163164
TOKEN_KERNEL,
165+
TOKEN_ENCRYPT,
166+
TOKEN_DECRYPT,
167+
TOKEN_VERIFY,
168+
TOKEN_IDENTITY,
164169

165170
TOKEN_ERROR,
166171
TOKEN_EOF

src/compiler/lexer/scanner.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ static PxTokenType identifierType(Scanner *scanner) {
232232
if (scanner->current - scanner->start > 2) {
233233
switch (scanner->start[2]) {
234234
case 'c':
235+
// decay vs decrypt (dec...)
236+
if (scanner->current - scanner->start > 3 && scanner->start[3] == 'r')
237+
return checkKeyword(scanner, 4, 3, "ypt", TOKEN_DECRYPT);
235238
return checkKeyword(scanner, 3, 2, "ay", TOKEN_DECAY); // decay
236239
case 'i': // distributed
237240
return checkKeyword(scanner, 2, 9, "stributed", TOKEN_DISTRIBUTED);
@@ -274,6 +277,7 @@ static PxTokenType identifierType(Scanner *scanner) {
274277
case 'n':
275278
if (scanner->current - scanner->start > 2) {
276279
switch (scanner->start[2]) {
280+
case 'c': return checkKeyword(scanner, 3, 4, "rypt", TOKEN_ENCRYPT); // encrypt
277281
case 'u': return checkKeyword(scanner, 3, 1, "m", TOKEN_ENUM);
278282
case 't': return checkKeyword(scanner, 3, 4, "angle", TOKEN_ENTANGLE); // entangle
279283
}
@@ -541,7 +545,16 @@ static PxTokenType identifierType(Scanner *scanner) {
541545
case 'u':
542546
return checkKeyword(scanner, 1, 2, "se", TOKEN_USE);
543547
case 'v':
544-
return checkKeyword(scanner, 1, 3, "oid", TOKEN_VOID);
548+
if (scanner->current - scanner->start > 1) {
549+
switch(scanner->start[1]) {
550+
case 'a': return checkKeyword(scanner, 2, 1, "r", TOKEN_VAR);
551+
case 'e': return checkKeyword(scanner, 2, 4, "rify", TOKEN_VERIFY); // verify
552+
case 'o': return checkKeyword(scanner, 2, 2, "id", TOKEN_VOID);
553+
}
554+
}
555+
// Fallback? Original 'void' used to be handled directly under 'v' -> check 1, 3 "oid"
556+
// But now we branch.
557+
return TOKEN_IDENTIFIER;
545558
case 'w':
546559
return checkKeyword(scanner, 1, 4, "hile", TOKEN_WHILE);
547560
}

0 commit comments

Comments
 (0)