parent
68ddeb3e17
commit
cf1a0cd99b
@ -1,3 +1,3 @@ |
|||||||
#!/bin/bash |
#!/bin/bash |
||||||
|
|
||||||
cc *.c -o forth |
cc -I include src/*.c -o forth |
||||||
|
@ -1,48 +0,0 @@ |
|||||||
/**
|
|
||||||
* TODO file description |
|
||||||
* |
|
||||||
* Created on 2021/11/13. |
|
||||||
*/ |
|
||||||
|
|
||||||
#ifndef FORTH_H |
|
||||||
#define FORTH_H |
|
||||||
|
|
||||||
#include <stdint.h> |
|
||||||
#include <stdbool.h> |
|
||||||
|
|
||||||
/* for printing */ |
|
||||||
#include <stdlib.h> |
|
||||||
#include <stdio.h> |
|
||||||
|
|
||||||
#include "fh_config.h" |
|
||||||
#include "fh_error.h" |
|
||||||
|
|
||||||
struct fh_thread_s; |
|
||||||
struct fh_word_s; |
|
||||||
struct fh_instruction_s; |
|
||||||
|
|
||||||
/** Word handler typedef */ |
|
||||||
typedef enum fh_error (*word_exec_t)(struct fh_thread_s *fh); |
|
||||||
|
|
||||||
/** Forth runtime global state */ |
|
||||||
struct fh_global_s { |
|
||||||
/** Verbose logging enabled */ |
|
||||||
bool verbose; |
|
||||||
/** Interactive mode (i.e. not started with a file argument) */ |
|
||||||
bool interactive; |
|
||||||
}; |
|
||||||
|
|
||||||
extern struct fh_global_s fh_globals; |
|
||||||
|
|
||||||
/* logging */ |
|
||||||
#define LOG(format, ...) do { if(fh_globals.verbose) { fprintf(stderr, format "\n", ##__VA_ARGS__); } } while (0) |
|
||||||
#define LOGI(format, ...) fprintf(stderr, "\x1b[32m" format "\x1b[m\n", ##__VA_ARGS__) |
|
||||||
#define LOGE(format, ...) fprintf(stderr, "\x1b[31;1m" format "\x1b[m\n", ##__VA_ARGS__) |
|
||||||
/* Forth standard output. XXX should be stdout, but then colors get mangled if logging is used */ |
|
||||||
#define FHPRINT(format, ...) fprintf(stderr, "\x1b[33;1m" format "\x1b[m", ##__VA_ARGS__) |
|
||||||
#define FHPRINT_SVC(format, ...) fprintf(stderr, "" format "", ##__VA_ARGS__) |
|
||||||
|
|
||||||
enum fh_error fh_init_thread(struct fh_thread_s *fh); |
|
||||||
enum fh_error fh_process_line(struct fh_thread_s *fh, char *linebuf); |
|
||||||
|
|
||||||
#endif //FORTH_H
|
|
@ -0,0 +1,20 @@ |
|||||||
|
/**
|
||||||
|
* Global state |
||||||
|
* |
||||||
|
* Created on 2021/11/13. |
||||||
|
*/ |
||||||
|
|
||||||
|
#ifndef FORTH_FH_GLOBALS_H |
||||||
|
#define FORTH_FH_GLOBALS_H |
||||||
|
|
||||||
|
/** Forth runtime global state */ |
||||||
|
struct fh_global_s { |
||||||
|
/** Verbose logging enabled */ |
||||||
|
bool verbose; |
||||||
|
/** Interactive mode (i.e. not started with a file argument) */ |
||||||
|
bool interactive; |
||||||
|
}; |
||||||
|
|
||||||
|
extern struct fh_global_s fh_globals; |
||||||
|
|
||||||
|
#endif //FORTH_FH_GLOBALS_H
|
@ -0,0 +1,24 @@ |
|||||||
|
/**
|
||||||
|
* Forth printing |
||||||
|
* |
||||||
|
* Created on 2021/11/13. |
||||||
|
*/ |
||||||
|
|
||||||
|
#ifndef FORTH_FH_PRINT_H |
||||||
|
#define FORTH_FH_PRINT_H |
||||||
|
|
||||||
|
/* for printing */ |
||||||
|
#include <stdlib.h> |
||||||
|
#include <stdio.h> |
||||||
|
#include "fh_globals.h" |
||||||
|
|
||||||
|
/* logging */ |
||||||
|
#define LOG(format, ...) do { if(fh_globals.verbose) { fprintf(stderr, format "\n", ##__VA_ARGS__); } } while (0) |
||||||
|
#define LOGI(format, ...) fprintf(stderr, "\x1b[32m" format "\x1b[m\n", ##__VA_ARGS__) |
||||||
|
#define LOGE(format, ...) fprintf(stderr, "\x1b[31;1m" format "\x1b[m\n", ##__VA_ARGS__) |
||||||
|
|
||||||
|
/* Forth standard output. XXX should be stdout, but then colors get mangled if logging is used */ |
||||||
|
#define FHPRINT(format, ...) fprintf(stderr, "\x1b[33;1m" format "\x1b[m", ##__VA_ARGS__) |
||||||
|
#define FHPRINT_SVC(format, ...) fprintf(stderr, "" format "", ##__VA_ARGS__) |
||||||
|
|
||||||
|
#endif //FORTH_FH_PRINT_H
|
@ -1,5 +1,5 @@ |
|||||||
/**
|
/**
|
||||||
* Forth internal stack operations |
* Forth stack operations |
||||||
* |
* |
||||||
* Created on 2021/11/13. |
* Created on 2021/11/13. |
||||||
*/ |
*/ |
@ -0,0 +1,21 @@ |
|||||||
|
/**
|
||||||
|
* Forth main entry-point |
||||||
|
* |
||||||
|
* Created on 2021/11/13. |
||||||
|
*/ |
||||||
|
|
||||||
|
#ifndef FORTH_H |
||||||
|
#define FORTH_H |
||||||
|
|
||||||
|
#include <stdint.h> |
||||||
|
#include <stdbool.h> |
||||||
|
|
||||||
|
#include "fh_config.h" |
||||||
|
#include "fh_error.h" |
||||||
|
|
||||||
|
struct fh_thread_s; |
||||||
|
|
||||||
|
enum fh_error fh_init(struct fh_thread_s *fh); |
||||||
|
enum fh_error fh_process_line(struct fh_thread_s *fh, const char *linebuf); |
||||||
|
|
||||||
|
#endif //FORTH_H
|
@ -1,6 +1,9 @@ |
|||||||
#include <string.h> |
#include <string.h> |
||||||
#include "forth.h" |
#include <stdbool.h> |
||||||
#include "fh_runtime.h" |
#include "fh_runtime.h" |
||||||
|
#include "fh_config.h" |
||||||
|
#include "fh_error.h" |
||||||
|
#include "fh_print.h" |
||||||
#include "fh_builtins.h" |
#include "fh_builtins.h" |
||||||
#include "fh_stack.h" |
#include "fh_stack.h" |
||||||
#include "fh_mem.h" |
#include "fh_mem.h" |
@ -1,6 +1,8 @@ |
|||||||
#include "forth.h" |
#include "fh_error.h" |
||||||
|
#include "fh_config.h" |
||||||
#include "fh_runtime.h" |
#include "fh_runtime.h" |
||||||
#include "fh_stack.h" |
#include "fh_stack.h" |
||||||
|
#include "fh_print.h" |
||||||
|
|
||||||
/** Pop from data stack */ |
/** Pop from data stack */ |
||||||
enum fh_error ds_pop(struct fh_thread_s *fh, uint32_t *out) |
enum fh_error ds_pop(struct fh_thread_s *fh, uint32_t *out) |
@ -1,20 +1,18 @@ |
|||||||
#include <stdio.h> |
#include <stdio.h> |
||||||
#include <stdint.h> |
|
||||||
#include <stdbool.h> |
#include <stdbool.h> |
||||||
#include <stdlib.h> |
|
||||||
#include <string.h> |
#include <string.h> |
||||||
#include <errno.h> |
|
||||||
#include <unistd.h> |
#include <unistd.h> |
||||||
#include <ctype.h> |
#include <ctype.h> |
||||||
|
|
||||||
#include "forth.h" |
#include "forth.h" |
||||||
#include "fh_runtime.h" |
#include "fh_runtime.h" |
||||||
|
#include "fh_print.h" |
||||||
|
|
||||||
int main(int argc, char *argv[]) |
int main(int argc, char *argv[]) |
||||||
{ |
{ |
||||||
enum fh_error rv; |
enum fh_error rv; |
||||||
struct fh_thread_s fh; |
struct fh_thread_s fh; |
||||||
rv = fh_init_thread(&fh); |
rv = fh_init(&fh); |
||||||
if (rv != FH_OK) { |
if (rv != FH_OK) { |
||||||
LOGE("Error in forth init: %s", fherr_name(rv)); |
LOGE("Error in forth init: %s", fherr_name(rv)); |
||||||
return 1; |
return 1; |
Loading…
Reference in new issue