Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <sanpeqf@gmail.com>
*/

#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