From d9536b52c67a1b5a8b83591d2cbab8a33dfa1094 Mon Sep 17 00:00:00 2001 From: SpookyDervish <78246495+SpookyDervish@users.noreply.github.com> Date: Mon, 22 Dec 2025 13:21:09 +1100 Subject: [PATCH] deleted SASM --- README.md | 3 +- fib.sasm | 5 -- fib.vmbl | Bin 1536 -> 0 bytes src/asm/assembler.c | 22 ----- src/asm/assembler.h | 12 --- src/asm/instructions.c | 12 --- src/asm/instructions.h | 35 -------- src/asm/sasm.c | 29 ------- src/asm/tokenize.c | 184 ----------------------------------------- src/asm/tokenize.h | 59 ------------- sylt | Bin 0 -> 15776 bytes 11 files changed, 2 insertions(+), 359 deletions(-) delete mode 100644 fib.sasm delete mode 100644 fib.vmbl delete mode 100644 src/asm/assembler.c delete mode 100644 src/asm/assembler.h delete mode 100644 src/asm/instructions.c delete mode 100644 src/asm/instructions.h delete mode 100644 src/asm/sasm.c delete mode 100644 src/asm/tokenize.c delete mode 100644 src/asm/tokenize.h create mode 100644 sylt diff --git a/README.md b/README.md index c83c8c8..6f3970c 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,8 @@ But uhh that's the name of the VM itself, the name of the programming language I made is Sylt, named after the German island. To compile the VM for Linux: `gcc src/main.c src/vmbl.c src/exception.c src/file_utils.c -o vmbl -O3` -To compile SASM for Linux: `gcc src/asm/sasm.c src/asm/instructions.c src/file_utils.c src/asm/assembler.c -o sasm -O3` + +SASM and Sylt are written in Python for now as I'm too mentally challenged to write C code rn. ## Syntax ### Example "Hello, World!" Program diff --git a/fib.sasm b/fib.sasm deleted file mode 100644 index 93b43e2..0000000 --- a/fib.sasm +++ /dev/null @@ -1,5 +0,0 @@ -push 10 -push 9 -add -halt -add \ No newline at end of file diff --git a/fib.vmbl b/fib.vmbl deleted file mode 100644 index ba32b6d307919b4e7f4c3055c3df705fc1f11469..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1536 zcmZQzAPz9%P{s-sCs!VqKA3eJPzDoB0F8dY(sk@@J(}PscQgb>Ltr!nMniyL2mk -#include -#include - -VMBL_Instruction assembleLine(char *line) { - char *instName = strtok(line, " "); - printf("%s\n", instName); -} - -void assemble(char *sourceCode, VMBL_Instruction program[], size_t programCapacity) { - char *line = strtok(sourceCode, "\n"); - - int i = 0; - while (line != NULL) - { - program[i++] = assembleLine(line); - line = strtok(NULL, "\n"); - } - -} \ No newline at end of file diff --git a/src/asm/assembler.h b/src/asm/assembler.h deleted file mode 100644 index 9c2e2ae..0000000 --- a/src/asm/assembler.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef ASSEMBLER_H -#define ASSEMBLER_H - -#include -#include "../vmbl.h" - - -VMBL_Instruction assembleLine(char *line); -void assemble(char *sourceCode, VMBL_Instruction program[], size_t programCapacity); - - -#endif // !ASSEMBLER_H diff --git a/src/asm/instructions.c b/src/asm/instructions.c deleted file mode 100644 index 6e9f708..0000000 --- a/src/asm/instructions.c +++ /dev/null @@ -1,12 +0,0 @@ -#include "instructions.h" -#include - -InstructionType instructionNameToType(char* instName) { - for (size_t i = 0; i < sizeof(instruction_table)/sizeof(instruction_table[0]); i++) { - - if (strcmp(instName, instruction_table[i].mnemonic) == 0) { - return (InstructionType)i; - } - - } -} \ No newline at end of file diff --git a/src/asm/instructions.h b/src/asm/instructions.h deleted file mode 100644 index 4d40d3c..0000000 --- a/src/asm/instructions.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef INSTRUCTIONS_H -#define INSTRUCTIONS_H - -#include "../vmbl.h" - -#define MAX_ARGS 3 - -typedef enum -{ - ARG_TYPE_NONE, - ARG_TYPE_INT -} ArgType; - -typedef struct -{ - char *mnemonic; - uint8_t argCount; - ArgType args[MAX_ARGS]; -} InstructionInfo; - -static const InstructionInfo instruction_table[] = { - [INSTRUCTION_NOP] = { "nop", 0, { ARG_TYPE_NONE } }, - [INSTRUCTION_PUSH] = { "push", 1, { ARG_TYPE_INT } }, - [INSTRUCTION_DROP] = { "drop", 1, { ARG_TYPE_INT } }, - [INSTRUCTION_ADD] = { "add", 0, { ARG_TYPE_NONE } }, - [INSTRUCTION_SUB] = { "sub", 0, { ARG_TYPE_NONE } }, - [INSTRUCTION_MUL] = { "mul", 0, { ARG_TYPE_NONE } }, - [INSTRUCTION_DIV] = { "div", 0, { ARG_TYPE_NONE } }, - [INSTRUCTION_DUPLICATE] = { "dup", 1, { ARG_TYPE_INT } }, - [INSTRUCTION_HALT] = { "halt", 0, { ARG_TYPE_NONE } }, -}; - -InstructionType instructionNameToType(char* instName); - -#endif // !INSTRUCTIONS_H \ No newline at end of file diff --git a/src/asm/sasm.c b/src/asm/sasm.c deleted file mode 100644 index acc9d00..0000000 --- a/src/asm/sasm.c +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include -#include "../file_utils.h" -#include "assembler.h" -#include "../vmbl.h" - -int main(int argc, char *argv[]) { - if (argc < 3) { - printf("Usage: sasm \n"); - return 0; - } - - char *buffer = readStringFromFile(argv[1]); - - //printf("%s\n", buffer); - /*Tokenizer tokenizer = { - .source = buffer, - .column = 1, - .line = 1, - .pos = 0 - };*/ - - VMBL_Instruction program[VMBL_PROGRAM_SIZE]; - - assemble(buffer, program, VMBL_PROGRAM_SIZE); - free(buffer); - - return 0; -} \ No newline at end of file diff --git a/src/asm/tokenize.c b/src/asm/tokenize.c deleted file mode 100644 index aff5a13..0000000 --- a/src/asm/tokenize.c +++ /dev/null @@ -1,184 +0,0 @@ -#include "tokenize.h" -#include -#include -#include -#include - - -/* -Returns a string buffer containing the name that was parsed. -* IMPORTANT: remember to free the buffer when you're done with it! -*/ -char *parseName(Tokenizer *tokenizer) { - char *ptr = tokenizer->source; - - // loop over the string until we hit something that isn't a name - int i = 0; - while (isName(*ptr++)) - { - i++; - tokenizer->column++; - tokenizer->pos++; - - } - - char *buffer = (char*)malloc(sizeof(char) * (i + 1)); // add 1 byte for null terminator - - if (buffer == NULL) { - fprintf(stderr, "SASM: failed to allocate memory\n"); - exit(1); - } - - buffer = strncpy(buffer, tokenizer->source, i); - - tokenizer->source += i; - - return buffer; - -} - -char *parseNumber(Tokenizer *tokenizer) { - int i = 0; - char *ptr = tokenizer->source; - - while (*ptr) - { - if (*ptr == '\n') { - //tokenizer->column = 1; - tokenizer->pos++; - //tokenizer->line++; - break; - } - - if (isspace(*ptr)) - break; - - i++; - tokenizer->column++; - tokenizer->pos++; - *ptr++; - } - - char *buffer = (char*)malloc(sizeof(char) * (i + 1)); // add 1 byte for null terminator - if (buffer == NULL) { - fprintf(stderr, "SASM: failed to allocate memory\n"); - exit(1); - } - - buffer = strncpy(buffer, tokenizer->source, i); - - tokenizer->source += i; - - return buffer; -} - -void parseWhitespace(Tokenizer *tokenizer) { - tokenizer->pos++; - tokenizer->column++; - *tokenizer->source++; - return; -} - -bool isNumber(char character) { - return isdigit(character) || character == '.'; -} - -bool isName(char character) { - return isalnum(character) || character == '_'; -} - -Token getCurrentToken(Tokenizer *tokenizer) { - Token token = (Token){ - .line = tokenizer->line, - }; - - if (!*tokenizer->source) { - token.type = TOKEN_EOF; - return token; - } - - - - switch (*tokenizer->source) - { - - case ' ': - parseWhitespace(tokenizer); - return getCurrentToken(tokenizer); - break; - case '\t': - parseWhitespace(tokenizer); - return getCurrentToken(tokenizer); - break; - case '\n': - tokenizer->column = 1; - tokenizer->line++; - tokenizer->pos++; - *tokenizer->source++; - return getCurrentToken(tokenizer); - break; - case '\r': - tokenizer->pos++; - *tokenizer->source++; - return getCurrentToken(tokenizer); - break; - - default: - if (isalpha(*tokenizer->source)) { - token.columnStart = tokenizer->column; - - char *tokenValue = parseName(tokenizer); - token.value = tokenValue; - - // check if the token is in the list of instruction names - token.type = TOKEN_NAME; // by default the token is a name until we find an instruction - for (int i = 0; i < sizeof(INSTRUCTION_NAMES)/sizeof(INSTRUCTION_NAMES[0]); i++) { - - // if we found an instruction with the same name as the token - if (strcmp(INSTRUCTION_NAMES[i], tokenValue) == 0) { - token.type = TOKEN_INSTRUCTION; - break; - } - - } - } else if (isdigit(*tokenizer->source)) { - token.columnStart = token.columnStart; - char *tokenValue = parseNumber(tokenizer); - token.value = tokenValue; - - // TODO: floating point numbers - token.type = TOKEN_INT_LITERAL; - } else { - fprintf(stderr, "Invalid token `%c` on line %d, column %d\n", *tokenizer->source, tokenizer->line, tokenizer->column); - exit(1); - } - - break; - } - - return token; -} - -char* tokenTypeAsCStr(TokenType type) { - switch (type) - { - case TOKEN_INSTRUCTION: - return "INSTRUCTION"; - break; - - case TOKEN_INT_LITERAL: - return "INT_LITERAL"; - break; - - case TOKEN_EOF: - return ""; - break; - - case TOKEN_NAME: - return "NAME"; - break; - - default: - break; - } -} \ No newline at end of file diff --git a/src/asm/tokenize.h b/src/asm/tokenize.h deleted file mode 100644 index 9c7063c..0000000 --- a/src/asm/tokenize.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef TOKENIZE_H -#define TOKENIZE_H - -#include - -static char *INSTRUCTION_NAMES[] = { - "push", - "drop", - "add", - "sub", - "mul", - "div", - "eq", - "neq", - "gt", - "gte", - "lt", - "lte", - "dup", - "jc", - "halt", - "jump" -}; - -typedef enum -{ - TOKEN_EOF, // just used when looping over the tokens list - TOKEN_INSTRUCTION, - TOKEN_NAME, - TOKEN_INT_LITERAL, -} TokenType; - -typedef struct -{ - TokenType type; - char* value; - unsigned int line; - unsigned int columnStart; -} Token; - -typedef struct -{ - char *source; - unsigned int pos; - unsigned int line; - unsigned int column; -} Tokenizer; - -bool isNumber(char character); -bool isName(char character); - -Token getCurrentToken(Tokenizer *tokenizer); -char* tokenTypeAsCStr(TokenType type); - -char *parseName(Tokenizer *tokenizer); -char *parseNumber(Tokenizer *tokenizer); -void parseWhitespace(Tokenizer *tokenizer); - -#endif // !TOKENIZE_H diff --git a/sylt b/sylt new file mode 100644 index 0000000000000000000000000000000000000000..81ba3daa1c1691ba8442955a5288812daaf6cb4c GIT binary patch literal 15776 zcmeHOeQX>@6`!*c;*vCW+=jSGXim_Ol-8T`N31l|(!Ye${+kOW9`0qzxRGKvu|eCv$r#!9UdELN+c9gv-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