some improvements i think

This commit is contained in:
2026-01-16 13:32:36 +02:00
parent 49adb21b81
commit c69f589439
16 changed files with 338 additions and 5 deletions

27
asmrigs/brb/brb.h Normal file
View File

@@ -0,0 +1,27 @@
#ifndef BRB_H
#define BRB_H
#include "tier2/tokenizer.h"
#include "tier3/lexer.h"
#define B_LEXEL_INTERFACE_NAME "BLexer001"
enum EBWordType
{
BWORDTYPE_CONST_WORD,
BWORDTYPE_FUNCTION,
BWORDTYPE_FUNCTION_ARGS,
BWORDTYPE_FUNCTION_ARG,
BWORDTYPE_FUNCTION_SCOPE,
BWORDTYPE_RETURN,
};
abstract_class IBLexerWord: public ILexerWord
{
public:
};
#endif

53
asmrigs/brb/lexer.cpp Normal file
View File

@@ -0,0 +1,53 @@
#include "brb.h"
abstract_class CBLexerWord: public IBLexerWord
{
public:
virtual int GetType() override;
CUtlVector<ILexerWord*> m_children;
EBWordType m_eType;
};
int CBLexerWord::GetType()
{
return m_eType;
}
uint32_t CBLexerWord::GetNumChildren()
{
return m_children.GetSize();
}
ILexerWord **CBLexerWord::GetChildren()
{
return m_children.GetData();
}
class CBLexer: public ILexer
{
public:
virtual ILexerWord *ParseTokens( CUtlVector<Token_t> tokens ) override;
CBLexerWord *ParseFunctionBody( Token_t *&pToken, const Token_t *pEnding );
bool GetExpectedToken();
CUtlString GetStringLiteral();
};
#define NEXT_TOKEN() \
pToken++; \
if (pToken == pEnding) \
goto eof \
ILexerWord *CBLexer::ParseTokens( CUtlVector<Token_t> tokens )
{
Token_t *pCurrentToken = tokens.GetData();
Token_t *pEndingToken = tokens.GetData() + tokens.GetSize();
CBLexerWord *pGlobalWord = new CBLexerWord;
return pGlobalWord;
};

19
asmrigs/brb/main.cpp Normal file
View File

@@ -0,0 +1,19 @@
#include "brb.h"
#include "tier0/commandline.h"
#include "tier2/ifilesystem.h"
int main( int argc, char **argv )
{
CommandLine()->CreateCommandLine(argc, argv);
CreateInterfaceFn filesystemFactory = Sys_GetFactory("filesystem_std");
filesystem = (IFileSystem*)filesystemFactory(FILESYSTEM_INTERFACE_VERSION, NULL);
IFileHandle *pFile = filesystem->Open(argv[1], FILEMODE_READ);
const char *szFileContents = filesystem->ReadString(pFile);
filesystem->Close(pFile);
V_free((void*)szFileContents);
}

45
asmrigs/build.cpp Normal file
View File

@@ -0,0 +1,45 @@
#include "c.h"
#include "ld.h"
#include "helper.h"
ADD_DEPENDENCY_BUILD_FILE(tier0, "../tier0/build.cpp")
ADD_DEPENDENCY_BUILD_FILE(tier1, "../tier1/build.cpp")
ADD_DEPENDENCY_BUILD_FILE(tier2, "../tier2/build.cpp")
ADD_DEPENDENCY_BUILD_FILE(fs, "../stdfilesystems/build.cpp")
DECLARE_BUILD_STAGE(brb)
{
CProject_t stProject = {};
LinkProject_t stLink = {};
CUtlString szBuiltFile = {};
stProject.m_szName = "bc";
stProject.files = {
"brb/lexer.cpp",
"brb/main.cpp",
};
stProject.includeDirectories = {
"../public"
};
stLink = ccompiler->Compile(&stProject);
stLink.libraryObjects = {
GET_PROJECT_LIBRARY(tier0, "tier0"),
GET_PROJECT_LIBRARY(tier1, "tier1"),
GET_PROJECT_LIBRARY(tier2, "tier2"),
};
szBuiltFile = linker->Link(&stLink);
ADD_OUTPUT_OBJECT("bc", szBuiltFile);
return 0;
};
DECLARE_BUILD_STAGE(brb_install)
{
CUtlString szBuildOutput = CUtlString("build/%s", Target_t::DefaultTarget().GetTriplet().GetString());
filesystem2->MakeDirectory(szBuildOutput);
filesystem2->CopyFile(szBuildOutput, GET_PROJECT_OBJECT(brb, "bc"));
filesystem2->CopyFile(szBuildOutput, GET_PROJECT_LIBRARY(tier0, "tier0"));
filesystem2->CopyFile(szBuildOutput, GET_PROJECT_LIBRARY(filesystem_std, "fs"));
return 0;
}

26
asmrigs/spec/brb.txt Normal file
View File

@@ -0,0 +1,26 @@
Brick Rigs B is a programming language made to work in the game Brick Rigs
1. The main issues of Brick Rigs
There are multiple limitations that are present in Brick Rigs:
1. Math Bricks are updated once per frame. It limits them to be one
time usage, which may cause some problems if you want to set the same
brick multiple times.
To solve this issue we've developed multiple targets:
1. Native Brick Rigs framed - allows to run code once per frame,
useful for missiles and custom built-logic.
2. Native Brick Rigs stacked - splits the code into multiple
parts, which allows stack to occur at a cost of a single frame.
3. Combat Advanced's virtual machine - it allows to run complex code by
using Combat Advanced's virtual machine
There are multiple extensions for native Brick Rigs
1. Combat Advanced's memory module
2. Combat Advanced's trigonometry functions
2. Syntaxis
It can be seen in B user's guide

42
asmrigs/spec/o.txt Normal file
View File

@@ -0,0 +1,42 @@
Brick Rigs math vehicle object file specification v 1.0.
1. Terminology
"byte" must be 1 byte long (uint8_t in C)
"word" must be 2 bytes long (uint16_t in C)
"int" must be 4 bytes long (uint16_t in C)
2. Global header
First comes global header which has following structure:
struct
{
byte magic[4];
byte architecture[2];
word symbols_number;
}
Where:
magic must equal to 0x1 'B' 'M' 'O'
architecture is defined per implementation
symbols_number is the amount of symbols
3. Symbols
First comes the header:
struct
{
byte type;
int name_offset;
byte name_lenght;
int data_offset;
byte data_lenght;
}
Where:
type is equal to 0x1 which defines function or 0x2 which defines variable
name_lenght is equal to the lenght of the name of the symbol + 1
data_lenght is equal to the data lenght of the symbol
After that comes the ASCII terminated by 0x0 set of lenght of name_lenght, which defined name of the symbol

4
asmrigs/tests/001.b Normal file
View File

@@ -0,0 +1,4 @@
main()
{
}

4
asmrigs/tests/002.b Normal file
View File

@@ -0,0 +1,4 @@
main()
{
return 0;
}

4
asmrigs/tests/003.b Normal file
View File

@@ -0,0 +1,4 @@
main()
{
return 1 + 2 * 3
}

7
asmrigs/tests/004.b Normal file
View File

@@ -0,0 +1,7 @@
main()
{
auto a, b;
a = 10;
b = a + 5;
return b;
}

9
asmrigs/tests/005.b Normal file
View File

@@ -0,0 +1,9 @@
add(a,b)
{
return a + b;
}
main()
{
return add(2,3);
}