63 lines
1.8 KiB
C
63 lines
1.8 KiB
C
/* Calcite, src/user-apps/shell/runtime.h
|
|
* Copyright 2026 Benji Dial
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful, but
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
* for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along
|
|
* with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
void save_return_stack();
|
|
//and_call should not return.
|
|
[[noreturn]] void restore_return_stack(void (*and_call)());
|
|
|
|
void create_data_stack();
|
|
void push(int value);
|
|
int pop();
|
|
|
|
int *get_data_stack_pointer();
|
|
int *get_data_stack_top();
|
|
|
|
//null-terminated. not copied.
|
|
void set_input(const char *buffer);
|
|
|
|
//length_out is set to 0 on eof. skips all whitespace before and up to one character after.
|
|
void read_input_word(const char **start_out, int *length_out);
|
|
|
|
//errors on eof before end. skips end. end not included in length.
|
|
void read_until(char end, const char **start_out, int *length_out);
|
|
|
|
struct word {
|
|
int name_length;
|
|
const char *name;
|
|
void (*interpret)();
|
|
void (*compile)();
|
|
const struct word *previous;
|
|
};
|
|
|
|
#define INTERPRET_ERROR ((void (*)())-1)
|
|
|
|
#define COMPILE_ERROR ((void (*)())-1)
|
|
#define COMPILE_EMIT_CALL ((void (*)())-2)
|
|
|
|
//returns 0 if not found. name does not need to be null-terminated.
|
|
const struct word *look_up_word(int name_length, const char *name);
|
|
struct word *new_word();
|
|
|
|
void print_all_words();
|
|
|
|
[[noreturn]] void error(const char *message);
|
|
|
|
extern int compiling;
|
|
|
|
[[noreturn]] void main_loop();
|