restructure
This commit is contained in:
0
src/lang/.gitignore → src/.gitignore
vendored
0
src/lang/.gitignore → src/.gitignore
vendored
@@ -2,5 +2,6 @@
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -13,4 +13,12 @@
|
||||
<ProjectReference Include="..\Nub.Lang\Nub.Lang.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Runtime\entry.s" />
|
||||
<EmbeddedResource Include="Runtime\nub_memcpy.s" />
|
||||
<EmbeddedResource Include="Runtime\nub_memset.s" />
|
||||
<EmbeddedResource Include="Runtime\nub_panic.s" />
|
||||
<EmbeddedResource Include="Runtime\nub_strcmp.s" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using Nub.Lang;
|
||||
using Nub.Lang.Frontend;
|
||||
using Nub.Lang.Frontend.Generation;
|
||||
@@ -105,40 +106,44 @@ foreach (var compilationUnit in compilationUnits)
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine($"Error processing {sourceTexts[compilationUnit].Path}: {ex.Message}");
|
||||
error = true;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (error)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
var assembly = Assembly.GetExecutingAssembly();
|
||||
var runtimeResources = assembly.GetManifestResourceNames().Where(name => name.EndsWith(".s", StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
const string RUNTIME_DIR = "src/runtime";
|
||||
if (Directory.Exists(RUNTIME_DIR))
|
||||
foreach (var resourceName in runtimeResources)
|
||||
{
|
||||
foreach (var runtimeFile in Directory.EnumerateFiles(RUNTIME_DIR, "*.s", SearchOption.AllDirectories))
|
||||
try
|
||||
{
|
||||
try
|
||||
await using var stream = assembly.GetManifestResourceStream(resourceName);
|
||||
if (stream == null)
|
||||
{
|
||||
var runtimeFileName = Path.GetFileNameWithoutExtension(runtimeFile);
|
||||
var objPath = Path.Combine(BIN_INT_DIR, $"runtime_{runtimeFileName}.o");
|
||||
|
||||
await InvokeAssembler(runtimeFile, objPath);
|
||||
objectFiles.Add(objPath);
|
||||
Console.Out.WriteLine($"Runtime assembled: {objPath}");
|
||||
Console.Error.WriteLine($"Warning: Could not load embedded resource {resourceName}");
|
||||
continue;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine($"Error assembling runtime file {runtimeFile}: {ex.Message}");
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (error)
|
||||
{
|
||||
return 1;
|
||||
using var reader = new StreamReader(stream);
|
||||
var assemblyCode = await reader.ReadToEndAsync();
|
||||
|
||||
var fileName = resourceName.Split('.').Reverse().Skip(1).First();
|
||||
var asmPath = Path.Combine(BIN_INT_DIR, $"runtime_{fileName}.s");
|
||||
var objPath = Path.Combine(BIN_INT_DIR, $"runtime_{fileName}.o");
|
||||
|
||||
await File.WriteAllTextAsync(asmPath, assemblyCode);
|
||||
|
||||
await InvokeAssembler(asmPath, objPath);
|
||||
objectFiles.Add(objPath);
|
||||
Console.Out.WriteLine($"Runtime assembled: {objPath}");
|
||||
|
||||
File.Delete(asmPath);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine($"Error processing runtime resource {resourceName}: {ex.Message}");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
@@ -206,7 +211,7 @@ static async Task InvokeAssembler(string asmPath, string objPath)
|
||||
|
||||
if (asProcess.ExitCode != 0)
|
||||
{
|
||||
throw new Exception($"Assembler failed for {asmPath}:\n{asErrors}");
|
||||
throw new Exception($"Assembler errors:\n{asErrors}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,6 +235,6 @@ static async Task InvokeLinker(List<string> objectFiles, string outputPath)
|
||||
|
||||
if (gccProcess.ExitCode != 0)
|
||||
{
|
||||
throw new Exception($"Linker failed:\n{gccErrors}");
|
||||
throw new Exception($"Linker errors:\n{gccErrors}");
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
.intel_syntax noprefix
|
||||
.global core_syscall
|
||||
.section .text
|
||||
|
||||
core_syscall:
|
||||
mov rax, rdi
|
||||
mov rdi, rsi
|
||||
mov rsi, rdx
|
||||
mov r10, rcx
|
||||
syscall
|
||||
ret
|
||||
@@ -1,3 +0,0 @@
|
||||
#!/bin/bash
|
||||
mkdir -p out
|
||||
npx vsce package -o out/nub-lang.vsix
|
||||
@@ -1,29 +0,0 @@
|
||||
{
|
||||
"comments": {
|
||||
"lineComment": "//",
|
||||
"blockComment": ["/*", "*/"]
|
||||
},
|
||||
"brackets": [
|
||||
["{", "}"],
|
||||
["[", "]"],
|
||||
["(", ")"]
|
||||
],
|
||||
"autoClosingPairs": [
|
||||
["{", "}"],
|
||||
["[", "]"],
|
||||
["(", ")"],
|
||||
["\"", "\""],
|
||||
["'", "'"]
|
||||
],
|
||||
"surroundingPairs": [
|
||||
["{", "}"],
|
||||
["[", "]"],
|
||||
["(", ")"],
|
||||
["\"", "\""],
|
||||
["'", "'"]
|
||||
],
|
||||
"indentationRules": {
|
||||
"increaseIndentPattern": "^((?!\\/\\*).)*(\\{[^}\"'`]*|\\([^)\"'`]*|\\[[^\\]\"'`]*)$",
|
||||
"decreaseIndentPattern": "^((?!.*?\\/\\*).*\\*/)?\\s*[\\}\\]\\)].*$"
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
{
|
||||
"name": "nub-lang",
|
||||
"displayName": "Nub Language Support",
|
||||
"description": "Syntax highlighting for Nub programming language",
|
||||
"version": "0.0.0",
|
||||
"publisher": "nub31",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://git.oliste.no/nub31/nub-lang"
|
||||
},
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"vscode": "^1.74.0"
|
||||
},
|
||||
"categories": [
|
||||
"Programming Languages"
|
||||
],
|
||||
"contributes": {
|
||||
"languages": [
|
||||
{
|
||||
"id": "nub",
|
||||
"aliases": [
|
||||
"Nub",
|
||||
"nub"
|
||||
],
|
||||
"extensions": [
|
||||
".nub"
|
||||
],
|
||||
"configuration": "./language-configuration.json"
|
||||
}
|
||||
],
|
||||
"grammars": [
|
||||
{
|
||||
"language": "nub",
|
||||
"scopeName": "source.nub",
|
||||
"path": "./syntaxes/nub.tmLanguage.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,300 +0,0 @@
|
||||
{
|
||||
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
|
||||
"name": "Nub",
|
||||
"scopeName": "source.nub",
|
||||
"patterns": [
|
||||
{
|
||||
"include": "#comments"
|
||||
},
|
||||
{
|
||||
"include": "#keywords"
|
||||
},
|
||||
{
|
||||
"include": "#modifiers"
|
||||
},
|
||||
{
|
||||
"include": "#types"
|
||||
},
|
||||
{
|
||||
"include": "#strings"
|
||||
},
|
||||
{
|
||||
"include": "#numbers"
|
||||
},
|
||||
{
|
||||
"include": "#operators"
|
||||
},
|
||||
{
|
||||
"include": "#function-definition"
|
||||
},
|
||||
{
|
||||
"include": "#struct-definition"
|
||||
},
|
||||
{
|
||||
"include": "#function-call"
|
||||
},
|
||||
{
|
||||
"include": "#identifiers"
|
||||
}
|
||||
],
|
||||
"repository": {
|
||||
"comments": {
|
||||
"patterns": [
|
||||
{
|
||||
"name": "comment.line.double-slash.nub",
|
||||
"begin": "//",
|
||||
"end": "$"
|
||||
},
|
||||
{
|
||||
"name": "comment.block.nub",
|
||||
"begin": "/\\*",
|
||||
"end": "\\*/"
|
||||
}
|
||||
]
|
||||
},
|
||||
"keywords": {
|
||||
"patterns": [
|
||||
{
|
||||
"name": "keyword.control.nub",
|
||||
"match": "\\b(if|else|while|break|continue|return|let)\\b"
|
||||
},
|
||||
{
|
||||
"name": "keyword.other.nub",
|
||||
"match": "\\b(namespace|func|struct|alloc)\\b"
|
||||
}
|
||||
]
|
||||
},
|
||||
"modifiers": {
|
||||
"patterns": [
|
||||
{
|
||||
"name": "storage.modifier.nub",
|
||||
"match": "\\b(export|extern|calls)\\b"
|
||||
}
|
||||
]
|
||||
},
|
||||
"types": {
|
||||
"patterns": [
|
||||
{
|
||||
"include": "#function-type"
|
||||
},
|
||||
{
|
||||
"name": "storage.type.primitive.nub",
|
||||
"match": "\\b(i8|i16|i32|i64|u8|u16|u32|u64|f32|f64|bool|string|void|any)\\b"
|
||||
},
|
||||
{
|
||||
"name": "storage.type.array.nub",
|
||||
"match": "\\[\\]"
|
||||
},
|
||||
{
|
||||
"name": "storage.type.pointer.nub",
|
||||
"match": "\\^"
|
||||
}
|
||||
]
|
||||
},
|
||||
"function-type": {
|
||||
"patterns": [
|
||||
{
|
||||
"begin": "\\b(func)\\s*\\(",
|
||||
"beginCaptures": {
|
||||
"1": {
|
||||
"name": "storage.type.function.nub"
|
||||
}
|
||||
},
|
||||
"end": "(?<=\\))(?:\\s*:\\s*([^\\s,;{}()]+))?",
|
||||
"endCaptures": {
|
||||
"1": {
|
||||
"name": "storage.type.nub"
|
||||
}
|
||||
},
|
||||
"patterns": [
|
||||
{
|
||||
"include": "#function-type-parameters"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"function-type-parameters": {
|
||||
"patterns": [
|
||||
{
|
||||
"match": "\\.\\.\\.",
|
||||
"name": "keyword.operator.variadic.nub"
|
||||
},
|
||||
{
|
||||
"include": "#types"
|
||||
},
|
||||
{
|
||||
"match": ",",
|
||||
"name": "punctuation.separator.nub"
|
||||
}
|
||||
]
|
||||
},
|
||||
"strings": {
|
||||
"patterns": [
|
||||
{
|
||||
"name": "string.quoted.double.nub",
|
||||
"begin": "\"",
|
||||
"end": "\"",
|
||||
"patterns": [
|
||||
{
|
||||
"name": "constant.character.escape.nub",
|
||||
"match": "\\\\(n|t|r|\\\\|\"|')"
|
||||
},
|
||||
{
|
||||
"name": "constant.character.escape.nub",
|
||||
"match": "\\\\[0-7]{1,3}"
|
||||
},
|
||||
{
|
||||
"name": "constant.character.escape.nub",
|
||||
"match": "\\\\x[0-9A-Fa-f]{1,2}"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "string.quoted.single.nub",
|
||||
"begin": "'",
|
||||
"end": "'",
|
||||
"patterns": [
|
||||
{
|
||||
"name": "constant.character.escape.nub",
|
||||
"match": "\\\\(n|t|r|\\\\|\"|')"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"numbers": {
|
||||
"patterns": [
|
||||
{
|
||||
"name": "constant.numeric.float.nub",
|
||||
"match": "\\b\\d+\\.\\d*([eE][+-]?\\d+)?[fF]?\\b"
|
||||
},
|
||||
{
|
||||
"name": "constant.numeric.integer.decimal.nub",
|
||||
"match": "\\b\\d+\\b"
|
||||
},
|
||||
{
|
||||
"name": "constant.numeric.integer.hexadecimal.nub",
|
||||
"match": "\\b0[xX][0-9A-Fa-f]+\\b"
|
||||
},
|
||||
{
|
||||
"name": "constant.numeric.integer.binary.nub",
|
||||
"match": "\\b0[bB][01]+\\b"
|
||||
}
|
||||
]
|
||||
},
|
||||
"operators": {
|
||||
"patterns": [
|
||||
{
|
||||
"name": "keyword.operator.assignment.nub",
|
||||
"match": "="
|
||||
},
|
||||
{
|
||||
"name": "keyword.operator.comparison.nub",
|
||||
"match": "(==|!=|<=|>=|<|>)"
|
||||
},
|
||||
{
|
||||
"name": "keyword.operator.arithmetic.nub",
|
||||
"match": "(\\+|\\-|\\*|/)"
|
||||
},
|
||||
{
|
||||
"name": "keyword.operator.logical.nub",
|
||||
"match": "(&&|\\|\\||!)"
|
||||
},
|
||||
{
|
||||
"name": "keyword.operator.address.nub",
|
||||
"match": "&"
|
||||
},
|
||||
{
|
||||
"name": "keyword.operator.dereference.nub",
|
||||
"match": "\\^"
|
||||
},
|
||||
{
|
||||
"name": "keyword.operator.member-access.nub",
|
||||
"match": "\\."
|
||||
}
|
||||
]
|
||||
},
|
||||
"function-definition": {
|
||||
"patterns": [
|
||||
{
|
||||
"begin": "\\b(global\\s+|extern\\s+)?(func)\\s+([a-zA-Z_][a-zA-Z0-9_]*)\\s*\\(",
|
||||
"beginCaptures": {
|
||||
"1": {
|
||||
"name": "storage.modifier.nub"
|
||||
},
|
||||
"2": {
|
||||
"name": "keyword.other.nub"
|
||||
},
|
||||
"3": {
|
||||
"name": "entity.name.function.nub"
|
||||
}
|
||||
},
|
||||
"end": "\\)",
|
||||
"patterns": [
|
||||
{
|
||||
"include": "#function-parameters"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"struct-definition": {
|
||||
"patterns": [
|
||||
{
|
||||
"match": "\\b(struct)\\s+([a-zA-Z_][a-zA-Z0-9_]*)\\b",
|
||||
"captures": {
|
||||
"1": {
|
||||
"name": "keyword.other.nub"
|
||||
},
|
||||
"2": {
|
||||
"name": "entity.name.type.struct.nub"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"function-parameters": {
|
||||
"patterns": [
|
||||
{
|
||||
"match": "\\.\\.\\.",
|
||||
"name": "keyword.operator.variadic.nub"
|
||||
},
|
||||
{
|
||||
"match": "([a-zA-Z_][a-zA-Z0-9_]*)\\s*:\\s*",
|
||||
"captures": {
|
||||
"1": {
|
||||
"name": "variable.parameter.nub"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"include": "#types"
|
||||
},
|
||||
{
|
||||
"include": "#identifiers"
|
||||
}
|
||||
]
|
||||
},
|
||||
"function-call": {
|
||||
"patterns": [
|
||||
{
|
||||
"match": "([a-zA-Z_][a-zA-Z0-9_]*)\\s*(?=\\()",
|
||||
"captures": {
|
||||
"1": {
|
||||
"name": "entity.name.function.call.nub"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"identifiers": {
|
||||
"patterns": [
|
||||
{
|
||||
"name": "variable.other.nub",
|
||||
"match": "\\b[a-zA-Z_][a-zA-Z0-9_]*\\b"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user