-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: ffashion <[email protected]>
- Loading branch information
Showing
9 changed files
with
1,442 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Oops, something went wrong.