diff --git a/highlighting/geany-reddust/filetypes.reddust.conf b/highlighting/geany-reddust/filetypes.reddust.conf new file mode 100644 index 0000000..d2370ce --- /dev/null +++ b/highlighting/geany-reddust/filetypes.reddust.conf @@ -0,0 +1,19 @@ +[styling] +default=0x000000;#FFFFFF;false;false +keyword=0x0000FF;#FFFFFF;true;false +comment=0x008000;#FFFFFF;false;true +number=0xFF0000;#FFFFFF;false;false + +[keywords] +# Palavras-chave são dígitos hex (0-9 e A-F), conforme seu tema VSCode, +# mas Geany keywords são palavras fixas, então colocaremos os dígitos + +keywords=0 1 2 3 4 5 6 7 8 9 A B C D E F + +[settings] +# Configurações para comentários +comment_single=// + +[options] +# Case insensitive keywords? Para Hex, deixamos case sensitive (false) +case_sensitive=true diff --git a/highlighting/vim-reddust/reddust.vim b/highlighting/vim-reddust/reddust.vim new file mode 100644 index 0000000..30cb189 --- /dev/null +++ b/highlighting/vim-reddust/reddust.vim @@ -0,0 +1,16 @@ +" Syntax file for RedDust +" Maintainer: Syntax Echonomics + +if exists("b:current_syntax") + finish +endif + +syntax match reddustKeyword /^\s*[0-9A-F]\ze;/ +syntax match reddustNumber /\v\<[0-9A-F]\>/ +syntax match reddustComment "//.*$" + +highlight def link reddustKeyword Keyword +highlight def link reddustNumber Number +highlight def link reddustComment Comment + +let b:current_syntax = "reddust" diff --git a/highlighting/vscode-reddust/icon.png b/highlighting/vscode-reddust/icon.png new file mode 100644 index 0000000..74ca187 Binary files /dev/null and b/highlighting/vscode-reddust/icon.png differ diff --git a/highlighting/vscode-reddust/language-configuration.json b/highlighting/vscode-reddust/language-configuration.json new file mode 100644 index 0000000..c5e4f74 --- /dev/null +++ b/highlighting/vscode-reddust/language-configuration.json @@ -0,0 +1,5 @@ +{ + "comments": { + "lineComment": "//" + } +} diff --git a/highlighting/vscode-reddust/package.json b/highlighting/vscode-reddust/package.json new file mode 100644 index 0000000..4c859b2 --- /dev/null +++ b/highlighting/vscode-reddust/package.json @@ -0,0 +1,28 @@ +{ + "name": "reddust", + "displayName": "RedDust Language", + "description": "Syntax highlighting for RedDust (.redd)", + "version": "1.0.0", + "publisher": "Syntax Echonomics", + "engines": { + "vscode": "^1.50.0" + }, + "icon": "icon.png", + "contributes": { + "languages": [ + { + "id": "reddust", + "aliases": ["RedDust", "reddust"], + "extensions": [".redd"], + "configuration": "./language-configuration.json" + } + ], + "grammars": [ + { + "language": "reddust", + "scopeName": "source.reddust", + "path": "./reddust.tmLanguage.json" + } + ] + } +} diff --git a/highlighting/vscode-reddust/reddust-1.0.0.vsix b/highlighting/vscode-reddust/reddust-1.0.0.vsix new file mode 100644 index 0000000..5f48775 Binary files /dev/null and b/highlighting/vscode-reddust/reddust-1.0.0.vsix differ diff --git a/highlighting/vscode-reddust/reddust.tmLanguage.json b/highlighting/vscode-reddust/reddust.tmLanguage.json new file mode 100644 index 0000000..a198297 --- /dev/null +++ b/highlighting/vscode-reddust/reddust.tmLanguage.json @@ -0,0 +1,19 @@ +{ + "scopeName": "source.reddust", + "patterns": [ + + { + "name": "keyword.control.reddust", + "match": "^(\\s*[0-9A-F])(?=;)" + }, + + { + "name": "constant.numeric.reddust", + "match": "\\b[0-9A-F]\\b" + }, + { + "name": "comment.line.double-slash.reddust", + "match": "//.*$" + } + ] +} diff --git a/icon/reddust.png b/icon/reddust.png new file mode 100644 index 0000000..124ab2e Binary files /dev/null and b/icon/reddust.png differ diff --git a/redd-install.sh b/redd-install.sh new file mode 100644 index 0000000..b161eab --- /dev/null +++ b/redd-install.sh @@ -0,0 +1,76 @@ +#!/bin/bash +set -e + +INSTALL_DIR="/usr/local/bin" +ICON_DIR="/usr/share/icons/reddust" +MIME_DIR="/usr/share/mime/packages" +VSCODE_EXT_DIR="$HOME/.vscode/extensions/reddust-syntax" +GITHUB_RAW="https://raw.githubusercontent.com/SynthX7/reddust/main" + +echo "[INFO] Iniciando instalação do RedDust..." + +# 1. Verifica se Python 3 está instalado +if ! command -v python3 &> /dev/null; then + echo "[INFO] Python3 não encontrado. Instalando..." + if [ -f /etc/debian_version ]; then + sudo apt-get update && sudo apt-get install -y python3 + elif [ -f /etc/arch-release ]; then + sudo pacman -Sy --noconfirm python + else + echo "[ERRO] Não foi possível detectar a distribuição. Instale Python 3 manualmente." + exit 1 + fi +else + echo "[INFO] Python3 já está instalado." +fi + +# 2. Instala interpretador +echo "[INFO] Instalando interpretador RedDust..." +sudo curl -fsSL "$GITHUB_RAW/reddust" -o "$INSTALL_DIR/reddust" +sudo chmod +x "$INSTALL_DIR/reddust" + +# 3. Ícone +echo "[INFO] Instalando ícone..." +sudo mkdir -p "$ICON_DIR" +sudo curl -fsSL "$GITHUB_RAW/icon/reddust.png" -o "$ICON_DIR/icon.png" + +# 4. Configuração MIME +echo "[INFO] Configurando MIME..." +sudo tee "$MIME_DIR/reddust.xml" > /dev/null < + + + RedDust Source Code + + + + +EOF +sudo update-mime-database /usr/share/mime +sudo update-icon-caches /usr/share/icons/* + +# 5. VSCode Syntax +echo "[INFO] Instalando suporte para VSCode..." +mkdir -p "$VSCODE_EXT_DIR" +curl -fsSL "$GITHUB_RAW/highlighting/vscode-reddust/package.json" -o "$VSCODE_EXT_DIR/package.json" +curl -fsSL "$GITHUB_RAW/highlighting/vscode-reddust/reddust.tmLanguage.json" -o "$VSCODE_EXT_DIR/reddust.tmLanguage.json" +curl -fsSL "$GITHUB_RAW/highlighting/vscode-reddust/language-configuration.json" -o "$VSCODE_EXT_DIR/language-configuration.json" +curl -fsSL "$GITHUB_RAW/highlighting/vscode-reddust/icon.png" -o "$VSCODE_EXT_DIR/icon.png" + +# 6. Geany Syntax +echo "[INFO] Instalando suporte para Geany..." +mkdir -p ~/.config/geany/filedefs +curl -fsSL "$GITHUB_RAW/highlighting/geany-reddust/filetypes.reddust.conf" -o ~/.config/geany/filedefs/filetypes.reddust.conf + +# 7. Vim Syntax +echo "[INFO] Instalando suporte para Vim..." +mkdir -p ~/.vim/syntax +curl -fsSL "$GITHUB_RAW/highlighting/vim-reddust/reddust.vim" -o ~/.vim/syntax/reddust.vim +grep -qxF 'au BufNewFile,BufRead *.redd set filetype=reddust' ~/.vimrc || echo 'au BufNewFile,BufRead *.redd set filetype=reddust' >> ~/.vimrc + +# Nano (opcional) +mkdir -p ~/.nano +grep -qxF 'include ~/.nano/reddust.nanorc' ~/.nanorc || echo '# Syntax RedDust\ninclude ~/.nano/reddust.nanorc' >> ~/.nanorc + +echo "[INFO] Instalação concluída! É recomendável reiniciar o sistema ou a sessão atual." +echo "✅ Use com: reddust arquivo.redd" diff --git a/redd-uninstall.sh b/redd-uninstall.sh new file mode 100644 index 0000000..a369f98 --- /dev/null +++ b/redd-uninstall.sh @@ -0,0 +1,28 @@ +#!/bin/bash +set -e + +echo "[INFO] Removendo RedDust..." + +# Interpretador +sudo rm -f /usr/local/bin/reddust + +# Ícone e MIME +sudo rm -rf /usr/share/icons/reddust +sudo rm -f /usr/share/mime/packages/reddust.xml +sudo update-mime-database /usr/share/mime + +# VSCode +rm -rf ~/.vscode/extensions/reddust-syntax + +# Geany +rm -f ~/.config/geany/filedefs/filetypes.reddust.conf + +# Vim +rm -f ~/.vim/syntax/reddust.vim +sed -i '/reddust/d' ~/.vimrc + +# Nano +sed -i '/reddust.nanorc/d' ~/.nanorc +rm -f ~/.nano/reddust.nanorc + +echo "[INFO] RedDust removido com sucesso!" diff --git a/reddust1 b/reddust1 new file mode 100755 index 0000000..015dbc4 --- /dev/null +++ b/reddust1 @@ -0,0 +1,216 @@ +#!/usr/bin/env python3 +import sys +import random +import time + +# Memória da máquina +memory = [0] * 256 # 256 endereços possíveis + + +def parse_line(line): + # Remove comentários após "//" + line = line.split('//')[0].strip() + if not line: + return None + + tokens = [t.strip() for t in line.split(';') if t.strip()] + + if len(tokens) != 4: + print(f"[ERRO] Linha inválida (esperado 4 valores): {line}") + return None + + try: + return [int(t, 16) for t in tokens] # HEX -> int + except ValueError: + print(f"[ERRO] Valores inválidos na linha: {line}") + return None + + +def to_hex(val): + return format(val, 'X') + + +def run_program(program, debug=False): + pc = 0 + while pc < len(program): + instr = program[pc] + cmd = format(instr[0], 'X') + + if debug: + hex_instr = [to_hex(x) for x in instr] + hex_mem = [to_hex(x) for x in memory[:16]] + print(f"[DEBUG] PC={to_hex(pc+1)}, CMD={hex_instr}, MEM[0..F]={hex_mem}") + + if cmd == "0": # HALT + print("[INFO] Programa finalizado.") + break + + elif cmd == "1": # INPUT + a, b = instr[1], instr[2] + if b != 0: + memory[a] = b + else: + print("[INFO] Waiting for input...") + try: + value = input(f"Digite valor HEX para mem[{to_hex(a)}]: ").strip() + memory[a] = int(value, 16) + except KeyboardInterrupt: + print("\n[INFO] Entrada cancelada pelo usuário (Ctrl+C).") + sys.exit(0) + except ValueError: + print("[ERRO] Valor inválido! Use HEX (ex.: A, F, 1F)") + return None + + elif cmd == "2": # OUTPUT + addr = instr[1] + print(f"[OUTPUT] {to_hex(memory[addr])}") + + elif cmd == "3": # ADD + a, b, c = instr[1], instr[2], instr[3] + memory[c] = memory[a] + memory[b] + + elif cmd == "4": # SUB + a, b, c = instr[1], instr[2], instr[3] + memory[c] = memory[a] - memory[b] + + elif cmd == "5": # DIV + a, b, c = instr[1], instr[2], instr[3] + memory[c] = memory[a] // memory[b] if memory[b] != 0 else 0 + + elif cmd == "6": # MUL + a, b, c = instr[1], instr[2], instr[3] + memory[c] = memory[a] * memory[b] + + elif cmd == "7": # COND JUMP + addr, val, target = instr[1], instr[2], instr[3] + if memory[addr] == val: + pc = target - 1 + continue + + elif cmd == "8": # JUMP + pc = instr[1] - 1 + continue + + elif cmd == "9": # CLEAR + addr = instr[1] + memory[addr] = 0 + + elif cmd == "A": # RANDOM + addr = instr[1] + memory[addr] = random.randint(0, 15) + + elif cmd == "B": # CMP GREATER + x, y, out = instr[1], instr[2], instr[3] + memory[out] = 1 if memory[x] > memory[y] else 0 + + elif cmd == "C": # CMP LESS + x, y, out = instr[1], instr[2], instr[3] + memory[out] = 1 if memory[x] < memory[y] else 0 + + elif cmd == "D": # MOVE + src, dst = instr[1], instr[2] + memory[dst] = memory[src] + + elif cmd == "E": # INC/DEC + addr, flag = instr[1], instr[2] + if flag == 1: + memory[addr] += 1 + elif flag == 0: + memory[addr] -= 1 + else: + print(f"[ERRO] Flag inválida: {to_hex(flag)}") + return None + + elif cmd == "F": # WAIT + delay = instr[1] + print(f"[INFO] Esperando {delay} segundos...") + time.sleep(delay) + + else: + print(f"[ERRO] Comando inválido: {cmd}") + return None + + pc += 1 + + +def repl(): + print("Modo REPL RedDust (digite 'exit' para sair)") + program = [] + line_num = 1 + while True: + try: + line = input(f"linha {line_num}> ").strip() + if line.lower() == "exit": + print("[INFO] Saindo do REPL e executando programa...") + break + instr = parse_line(line) + if instr: + program.append(instr) + line_num += 1 + except KeyboardInterrupt: + print("\n[INFO] Interrompido pelo usuário (Ctrl+C).") + sys.exit(0) + run_program(program) + + +def show_help(): + print(""" +RedDust Interpreter v3.1 +Uso: + reddust Executa um programa RedDust + reddust Inicia modo interativo (REPL) + reddust --debug Executa com debug (mostra memória) + reddust --version Mostra versão + reddust --help Exibe esta ajuda + +Formato do código: + Cada linha deve conter 4 valores HEX separados por ponto-e-vírgula (;) + Exemplo: + 1;A;0;0 // INPUT: pede valor para mem[A] + 2;A;0;0 // OUTPUT: mostra mem[A] + 0;0;0;0 // HALT +""") + + +def main(): + try: + if "--help" in sys.argv: + show_help() + sys.exit(0) + + if "--version" in sys.argv: + print("RedDust Interpreter v3.1 (HEX Mode)") + sys.exit(0) + + debug = "--debug" in sys.argv + + if len(sys.argv) == 1 or (len(sys.argv) == 2 and debug): + repl() + return + + filename = sys.argv[1] + if not filename.endswith(".redd"): + print("[ERRO] Arquivo deve ter extensão .redd") + sys.exit(1) + + try: + with open(filename, 'r') as f: + lines = f.readlines() + except FileNotFoundError: + print(f"[ERRO] Arquivo '{filename}' não encontrado.") + sys.exit(1) + + program = [] + for line in lines: + instr = parse_line(line) + if instr: + program.append(instr) + run_program(program, debug) + + except KeyboardInterrupt: + print("\n[INFO] Execução interrompida pelo usuário (Ctrl+C).") + sys.exit(0) + + +if __name__ == "__main__": + main()