Added more definitions.
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
#ifndef __SAGITTARIUS_ASSEMBLER_H_
|
||||
#define __SAGITTARIUS_ASSEMBLER_H_
|
||||
#include "../Sagittarius.h"
|
||||
#include <stdbool.h>
|
||||
/**
|
||||
*
|
||||
* The file format of assembly code for Sagittarius is as follows:
|
||||
*
|
||||
* Label:
|
||||
* <label_name>:
|
||||
* Special Labels:
|
||||
*
|
||||
* These labels are section indicators, and they indicate the beginning of a section. The content of the section will be determined by the label, and the assembler will handle the content accordingly:
|
||||
*
|
||||
* .code:
|
||||
* Code section, where instructions are placed. The program counter starts from the beginning of this section.
|
||||
* .data:
|
||||
* Data section, where data is placed. The data in this section can be accessed by instructions, and the offset of the data is determined by the order of the data in this section.
|
||||
* .const:
|
||||
* Constant section, when the program is being assembled, the assembler will replace the label in the code with the value from constant section. Constant data won't be included in the final program.
|
||||
*
|
||||
* To use a label, simply use the label name in the code. The assembler will replace the label with the offset of the label in the final program. For example:
|
||||
* `set 0 data_0`
|
||||
*
|
||||
* Note: special labels cannot be used as normal labels, and normal labels cannot have the same name as special labels.
|
||||
*
|
||||
*
|
||||
*
|
||||
* Format of instruction:
|
||||
* <inst_name> <arg1> <arg2> ... <argn>
|
||||
*
|
||||
* Format of data:
|
||||
* <data_name> <type> <data_value>
|
||||
* Data types:
|
||||
* - string
|
||||
* - base64
|
||||
* - file
|
||||
*
|
||||
* Instruction alias:
|
||||
*
|
||||
* set.<type> <reg> <value> is an alias for set instruction, which sets the register to the value of the specified type. The assembler will convert the value to the corresponding type and then generate the set instruction. For example:
|
||||
*
|
||||
* Comments:
|
||||
*
|
||||
* Any text after a semicolon (;) and hash (#) is considered a comment and will be ignored by the assembler.
|
||||
*
|
||||
* Example:
|
||||
* .code:
|
||||
* start:
|
||||
* set.uint64 syscal_printf_arg0 data_0
|
||||
* set.int32 16 0x123
|
||||
* .data:
|
||||
* data_0 string "Hello, World!"
|
||||
* .code:
|
||||
* set.float 24 3.14
|
||||
* add int32 8 16 32
|
||||
* syscall syscall_printf_namespace syscall_printf_func
|
||||
* .const:
|
||||
* syscall_printf_namespace 0
|
||||
* syscall_printf_func 0
|
||||
* syscal_printf_arg0 40
|
||||
*/
|
||||
typedef struct Sag_Str{
|
||||
char* head;
|
||||
uint64_t start;
|
||||
uint64_t length;
|
||||
} Sag_Str;
|
||||
typedef struct Sag_IntermediateInst{
|
||||
SagittariusInst inst;
|
||||
Sag_Str* label;
|
||||
Sag_Str* args;
|
||||
uint64_t arg_count;
|
||||
} Sag_IntermediateInst;
|
||||
typedef struct Sag_IntermediateProgram{
|
||||
Sag_IntermediateInst* insts;
|
||||
uint64_t inst_count;
|
||||
Sag_Str* data;
|
||||
uint64_t data_count;
|
||||
Sag_Str* Consts;
|
||||
uint64_t Consts_count;
|
||||
} Sag_IntermediateProgram;
|
||||
bool Sag_NextWord(FILE* f, Sag_Str* out);
|
||||
bool Sag_Scan(FILE* f, Sag_IntermediateProgram* out);
|
||||
bool Sag_Combine(Sag_IntermediateProgram* L, Sag_IntermediateProgram* R, Sag_IntermediateProgram* out);
|
||||
bool Sag_Finalize(Sag_IntermediateProgram* intermediate, SagittariusProgram* out);
|
||||
bool Sag_WriteProgram(FILE* f, SagittariusProgram* program);
|
||||
#endif
|
||||
+14
-2
@@ -7,7 +7,7 @@
|
||||
#include "SagittariusBase.h"
|
||||
typedef struct SagittariusRegister
|
||||
{
|
||||
// 256 Usable + Overflow preventing 256 extra bytes.
|
||||
// 256 Usable + Overflow preventing purpose 256 extra bytes.
|
||||
uint8_t head[512];
|
||||
} SagittariusRegister;
|
||||
typedef struct SagittariusMemory
|
||||
@@ -19,9 +19,11 @@ typedef struct SagittariusCore
|
||||
{
|
||||
SagittariusRegister reg;
|
||||
SagittariusMemory *memory;
|
||||
struct SagittariusVM *vm;
|
||||
uint64_t pc;
|
||||
} SagittariusCore;
|
||||
typedef int32_t (*SagittariusSyscall)(SagittariusCore *core, uint64_t arg_start);
|
||||
typedef int32_t (*SagittariusSyscall)(SagittariusCore *core);
|
||||
typedef int32_t (*SagittariusPanicHandler)(SagittariusCore *core, uint64_t panic_id, const char *msg);
|
||||
typedef struct SagittariusSyscallEntry
|
||||
{
|
||||
uint64_t id;
|
||||
@@ -32,8 +34,16 @@ typedef struct SagittariusVM
|
||||
SagittariusSyscallEntry *SagittariusSyscallEntries;
|
||||
uint64_t SagittariusSyscallCount;
|
||||
uint64_t SagittariusSyscallCapacity;
|
||||
SagittariusCore core;
|
||||
SagittariusMemory Memory;
|
||||
SagittariusPanicHandler panic_handler;
|
||||
} SagittariusVM;
|
||||
/**
|
||||
* The layout of program in byte form (without the head):
|
||||
* |0..31|32..95|96..159|160..|...
|
||||
* |format version|inst count|data size|instructions...|data...|
|
||||
* |uint32|uint64|uint64|inst1|inst2|...|data...|
|
||||
*/
|
||||
typedef struct SagittariusProgram
|
||||
{
|
||||
SagittariusInst *instructions;
|
||||
@@ -42,9 +52,11 @@ typedef struct SagittariusProgram
|
||||
uint64_t data_size;
|
||||
} SagittariusProgram;
|
||||
SAGITTARIUS_API SagittariusVM *sagittarius_vm_new(uint64_t memory_size);
|
||||
SAGITTARIUS_API void sagittarius_register_syscall(SagittariusVM *vm, uint64_t id, SagittariusSyscall syscall);
|
||||
SAGITTARIUS_API void sagittarius_vm_free(SagittariusVM *vm);
|
||||
SAGITTARIUS_API void sagittarius_step(SagittariusVM *vm);
|
||||
SAGITTARIUS_API void sagittarius_mem_resize(SagittariusVM *vm, uint64_t new_size);
|
||||
SAGITTARIUS_API uint64_t sagittarius_mem_getsize(SagittariusVM *vm);
|
||||
SAGITTARIUS_API void sagittarius_load_program_to_mem(SagittariusVM *vm, SagittariusProgram *program, uint64_t offset);
|
||||
SAGITTARIUS_API SagittariusProgram *sagittarius_load_program_from_byte_array(uint8_t *data, uint64_t size);
|
||||
#endif
|
||||
@@ -9,4 +9,7 @@
|
||||
#define internal __attribute__((visibility("hidden")))
|
||||
#endif
|
||||
|
||||
#define SAGITTARUIS_PROGRAM_HEAD "SAGPROG"
|
||||
#define SAGITTARIUS_PROGRAM_FORMAT_VERSION 0x00000001
|
||||
|
||||
#endif
|
||||
@@ -34,7 +34,7 @@ typedef enum SagittariusInstDef
|
||||
* |0|1|2..7|8..15(another instruction struct)|
|
||||
* |set|length(1-8 bytes)|padding|payload|
|
||||
*/
|
||||
set,
|
||||
set,
|
||||
/**
|
||||
* Move data from one register to another.
|
||||
* Layout:
|
||||
@@ -128,10 +128,13 @@ typedef enum SagittariusInstDef
|
||||
*/
|
||||
syscall,
|
||||
/**
|
||||
* Test System Call
|
||||
* Test System Call, for its existence.
|
||||
*
|
||||
* Layout:
|
||||
* |0|1|2|3|
|
||||
* |tsyscall|namespace reg| function id reg| result reg|
|
||||
*
|
||||
* 0 - failed, 1 - success, other values are reserved for future use.
|
||||
*/
|
||||
tsyscall,
|
||||
} SagittariusInstDef;
|
||||
@@ -157,6 +160,7 @@ typedef enum math1op
|
||||
sag_math1_acos,
|
||||
sag_math1_atan,
|
||||
sag_math1_abs,
|
||||
sag_math1_exp,
|
||||
} math1op;
|
||||
typedef enum sagittarius_type
|
||||
{
|
||||
|
||||
@@ -5,5 +5,29 @@ internal bool SagMath2Sub(SagittariusCore *core, sagittarius_type t, uint8_t L,
|
||||
internal bool SagMath2Mul(SagittariusCore *core, sagittarius_type t, uint8_t L, uint8_t R, uint8_t T);
|
||||
internal bool SagMath2Div(SagittariusCore *core, sagittarius_type t, uint8_t L, uint8_t R, uint8_t T);
|
||||
internal bool SagMath2Mod(SagittariusCore *core, sagittarius_type t, uint8_t L, uint8_t R, uint8_t T);
|
||||
internal bool SagMath1Sin(SagittariusCore *core, sagittarius_type t, uint8_t L, uint8_t T);
|
||||
internal bool SagMath1Cos(SagittariusCore *core, sagittarius_type t, uint8_t L, uint8_t T);
|
||||
internal bool SagMath1Tan(SagittariusCore *core, sagittarius_type t, uint8_t L, uint8_t T);
|
||||
internal bool SagMath1Sinh(SagittariusCore *core, sagittarius_type t, uint8_t L, uint8_t T);
|
||||
internal bool SagMath1Cosh(SagittariusCore *core, sagittarius_type t, uint8_t L, uint8_t T);
|
||||
internal bool SagMath1Tanh(SagittariusCore *core, sagittarius_type t, uint8_t L, uint8_t T);
|
||||
internal bool SagMath1Asin(SagittariusCore *core, sagittarius_type t, uint8_t L, uint8_t T);
|
||||
internal bool SagMath1Acos(SagittariusCore *core, sagittarius_type t, uint8_t L, uint8_t T);
|
||||
internal bool SagMath1Atan(SagittariusCore *core, sagittarius_type t, uint8_t L, uint8_t T);
|
||||
internal bool SagMath1Abs(SagittariusCore *core, sagittarius_type t, uint8_t L, uint8_t T);
|
||||
internal bool SagMath1Exp(SagittariusCore *core, sagittarius_type t, uint8_t L, uint8_t T);
|
||||
|
||||
internal bool Math2Op(SagittariusCore *core, SagittariusInst inst);
|
||||
internal bool Math1Op(SagittariusCore *core, SagittariusInst inst);
|
||||
|
||||
internal bool SagCvt(SagittariusCore *core, SagittariusInst inst);
|
||||
internal bool SagSet(SagittariusCore *core, SagittariusInst inst);
|
||||
internal bool SagMv(SagittariusCore *core, SagittariusInst inst);
|
||||
internal bool SagCp(SagittariusCore *core, SagittariusInst inst);
|
||||
internal bool SagSave(SagittariusCore *core, SagittariusInst inst);
|
||||
internal bool SagLoad(SagittariusCore *core, SagittariusInst inst);
|
||||
internal bool SagCmp(SagittariusCore *core, SagittariusInst inst);
|
||||
internal bool SagMathV(SagittariusCore *core, SagittariusInst inst);
|
||||
internal bool SagHalt(SagittariusCore *core, SagittariusInst inst);
|
||||
internal bool SagSyscall(SagittariusCore *core, SagittariusInst inst);
|
||||
internal bool SagTSyscall(SagittariusCore *core, SagittariusInst inst);
|
||||
@@ -0,0 +1,6 @@
|
||||
#include "../../Headers/Assembler/SagittariusAssembler.h"
|
||||
|
||||
int main(int ac,char** av){
|
||||
printf("Copyright (C) 2026 Creeper Lv.\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "../../Headers/Sagittarius.h"
|
||||
int main(int ac,char** av){
|
||||
|
||||
printf("Copyright (C) 2026 Creeper Lv.\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -13,12 +13,20 @@ then
|
||||
echo "Build Commit: $git_str"
|
||||
else
|
||||
echo "Project is not tracked by git!"
|
||||
git_str=""
|
||||
git_str="null"
|
||||
fi
|
||||
|
||||
if [ -z "$SKIP_STANDALONE"];
|
||||
then
|
||||
EXEC="$CC Source/Standalone/*.c Source/VM/*.c -DVER=\"$git_str\" -o Binaries/Sagittarius"
|
||||
EXEC="$CC Source/Standalone/*.c Source/VM/*.c -DSAGITTARIUS_COMMIT=\"$git_str\" -o Binaries/Sagittarius"
|
||||
echo "[$INDEX] $EXEC"
|
||||
INDEX=$((INDEX+1))
|
||||
$EXEC
|
||||
fi
|
||||
|
||||
if [ -z "$SKIP_ASSEMBLER"];
|
||||
then
|
||||
EXEC="$CC Source/Assembler/*.c Source/VM/*.c -DSAGITTARIUS_COMMIT=\"$git_str\" -o Binaries/SagittariusAssembler"
|
||||
echo "[$INDEX] $EXEC"
|
||||
INDEX=$((INDEX+1))
|
||||
$EXEC
|
||||
|
||||
Reference in New Issue
Block a user