Skip to content

Commit

Permalink
feat kmcvm: init commit
Browse files Browse the repository at this point in the history
Signed-off-by: ffashion <[email protected]>
  • Loading branch information
ffashion committed Apr 27, 2023
1 parent c5af4c3 commit 787f37a
Show file tree
Hide file tree
Showing 9 changed files with 1,442 additions and 0 deletions.
1 change: 1 addition & 0 deletions usr/command/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# SPDX-License-Identifier: GPL-2.0-or-later
obj-y += arch/
obj-y += kmcvm/
obj-$(CONFIG_KCMD_ASCII85) += ascii85.o
obj-$(CONFIG_KCMD_BASE32) += base32.o
obj-$(CONFIG_KCMD_BASE64) += base64.o
Expand Down
5 changes: 5 additions & 0 deletions usr/command/kmcvm/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# SPDX-License-Identifier: GPL-2.0-or-later
obj-y += kmcvm.o
obj-y += parser.o
obj-y += token.o
obj-y += mpool.o
56 changes: 56 additions & 0 deletions usr/command/kmcvm/kmcvm.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright(c) 2022 John Sanpe <[email protected]>
*/

#include <kshell.h>
#include <initcall.h>
#include "parser.h"
#include "token.h"

static state kmcvm_main(struct kshell_context *ctx, int argc, char *argv[])
{
Token *head;
Node *node;
mpool_t *pool;
const char *token;

token = kshell_getenv(ctx, "COMPUTE");

pool = mpool_create(MPOOL_DEFAULT_SIZE, NULL);
if (pool == NULL) {
return -ENOMEM;
}

head = tokenize(token, pool);
if (head == NULL) {
mpool_destroy(pool);
return -EINVAL;
}

//skip head
node = parser(list_next_entry(head, list), pool);

if (node == NULL) {
mpool_destroy(pool);
return -EINVAL;
}

kshell_printf(ctx, "%d\n", compute(node));

mpool_destroy(pool);

return -ENOERR;
}

static struct kshell_command kmcvm_cmd = {
.name = "kmcvm",
.desc = "kernal memory c lang compiler",
.exec = kmcvm_main,
};

static state kmcvm_init(void)
{
return kshell_register(&kmcvm_cmd);
}
kshell_initcall(kmcvm_init);
Loading

0 comments on commit 787f37a

Please sign in to comment.