-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemforth.c
More file actions
46 lines (37 loc) · 847 Bytes
/
emforth.c
File metadata and controls
46 lines (37 loc) · 847 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* @file emforth.c
* @author Tavish Naruka (tavishnaruka@gmail.com)
* @brief Forth outer interpreter
*
* @copyright Copyright (c) 2025
*
*/
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "builtins.h"
#include "emforth.h"
#include "interpreter.h"
int emforth_init(struct forth_ctx *ctx)
{
if (ctx == NULL || ctx->plat.puts == NULL ||
ctx->plat.getchar == NULL) {
return -1;
}
/* initialize dictionary */
memset(ctx->dict.mem, 0, sizeof(ctx->dict.mem));
ctx->dict.here = &ctx->dict.mem[0];
ctx->dict.latest = DICT_NULL;
/* intiialize stacks */
ctx->sp = 0;
ctx->rsp = 0;
/* Initialize threading registers */
ctx->ip = NULL;
ctx->w = NULL;
builtins_init(ctx);
/* Initialize interpreter */
interpreter_init(ctx);
ctx->plat.puts("emForth initialized\n");
return 0;
}