Skip to content

Commit 94efa44

Browse files
committed
feat kmcvm: init commit
Signed-off-by: ffashion <[email protected]>
1 parent c5af4c3 commit 94efa44

File tree

9 files changed

+1442
-0
lines changed

9 files changed

+1442
-0
lines changed

usr/command/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# SPDX-License-Identifier: GPL-2.0-or-later
22
obj-y += arch/
3+
obj-y += kmcvm/
34
obj-$(CONFIG_KCMD_ASCII85) += ascii85.o
45
obj-$(CONFIG_KCMD_BASE32) += base32.o
56
obj-$(CONFIG_KCMD_BASE64) += base64.o

usr/command/kmcvm/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# SPDX-License-Identifier: GPL-2.0-or-later
2+
obj-y += kmcvm.o
3+
obj-y += parser.o
4+
obj-y += token.o
5+
obj-y += mpool.o

usr/command/kmcvm/kmcvm.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/* SPDX-License-Identifier: GPL-2.0-or-later */
2+
/*
3+
* Copyright(c) 2022 John Sanpe <[email protected]>
4+
*/
5+
6+
#include <kshell.h>
7+
#include <initcall.h>
8+
#include "parser.h"
9+
#include "token.h"
10+
11+
static state kmcvm_main(struct kshell_context *ctx, int argc, char *argv[])
12+
{
13+
Token *head;
14+
Node *node;
15+
mpool_t *pool;
16+
const char *token;
17+
18+
token = kshell_getenv(ctx, "COMPUTE");
19+
20+
pool = mpool_create(MPOOL_DEFAULT_SIZE, NULL);
21+
if (pool == NULL) {
22+
return -ENOMEM;
23+
}
24+
25+
head = tokenize(token, pool);
26+
if (head == NULL) {
27+
mpool_destroy(pool);
28+
return -EINVAL;
29+
}
30+
31+
//skip head
32+
node = parser(list_next_entry(head, list), pool);
33+
34+
if (node == NULL) {
35+
mpool_destroy(pool);
36+
return -EINVAL;
37+
}
38+
39+
kshell_printf(ctx, "%d\n", compute(node));
40+
41+
mpool_destroy(pool);
42+
43+
return -ENOERR;
44+
}
45+
46+
static struct kshell_command kmcvm_cmd = {
47+
.name = "kmcvm",
48+
.desc = "kernal memory c lang compiler",
49+
.exec = kmcvm_main,
50+
};
51+
52+
static state kmcvm_init(void)
53+
{
54+
return kshell_register(&kmcvm_cmd);
55+
}
56+
kshell_initcall(kmcvm_init);

0 commit comments

Comments
 (0)