Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 0.4 #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
*.b*
*.bf*
/progs/
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Brainfuck 0.3
# Brainfuck 0.4

This is a little project that I wrote in QB64.
It contains three CLI tools:
Expand Down Expand Up @@ -69,6 +69,7 @@ The calling syntax is as follows: ```bfasm <sourceFile>```
The Brainfuck Assembler knows the following pseudo-commands:

- "**;**": comment line
- "**@**&lt;*file*&gt;": include another assembler file
- "**.mode &lt;*mode*&gt;**": config one of the display modes:
- "**ascii**" / "**byte**": input and output characters
- "**digit**" / "**number**": input and output numbers
Expand All @@ -93,7 +94,7 @@ The Brainfuck Assembler knows the following commands:
- "**dec**" / "**sub**": decrement current cell
- "**endm**" / "**endp**": end of a macro definition
- "**if**" / "**while**": begin a loop, if current cell is not 0
- "**include** &lt;*file*&gt;": include another assembler file provided as following token
- "**jmp** &lt;*address*&gt;": jump to giben adress (as a number); pre-implementation
- "**loop**" / "**loopne**" / "**loopnz**": repeat loop, if current cell is not 0
- "**macro** &lt;*name*&gt;" / "**proc** &lt;*name*&gt;": define a macro called *name*
- "**nop**": perform no operation
Expand All @@ -107,7 +108,7 @@ The Brainfuck Assembler knows the following commands:
"BF.exe" runs your compiled Brainfuck byte code.
The calling syntax is as follows: ```bf <sourceFile>```
\
**Important:** Do not provide a file extension, because the interpreter assumes files having ".bc"
**Important:** Do not provide a file extension, because the interpreter assumes files having ".bfc"
\
\
The code is running inside a BVM,
Expand Down
Binary file modified bfasm.exe
Binary file not shown.
Binary file added src/bf.exe
Binary file not shown.
16 changes: 11 additions & 5 deletions src/bfasm.bas
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@


function Main%(cmdLine as string)
dim as integer result
dim as string binaryFile, fileName, messageBuffer, sourceFile
dim as integer outFile, result
dim as string binaryFile, fileName, messageBuffer, sourceFile, tempIncludesFile

bfasmGreeting With(VERSION)

Expand All @@ -13,10 +13,16 @@ function Main%(cmdLine as string)
exit function
endif

Console.writeLine "Compiling assembly code ..."
sourceFile = BF_AssemblerFile(fileName)
Console.writeLine "Step 1: Processing includes ..."
tempIncludesFile = fileType(fileName, "temp.includes")
outFile = File.open(tempIncludesFile, FileMode.ForWriting)
result = processIncludes(outFile, fileName)
File.close outFile

Console.writeLine "Step 2: Compiling assembly code ..."
binaryFile = BF_BinaryFile(fileName)
result = compileFile(sourceFile, binaryFile)
result = compileFile(tempIncludesFile, binaryFile)
Invoke File.remove(tempIncludesFile)

if result then
Invoke File.remove(binaryFile)
Expand Down
1 change: 1 addition & 0 deletions src/bfasm.bi
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
'$include:'lib/bfasm/compileFile.bi'
'$include:'lib/bfasm/fetchToken.bi'
'$include:'lib/bfasm/mapToCode.bi'
'$include:'lib/bfasm/processIncludes.bi'

'$include:'lib/classes/Buffer.bi'
'$include:'lib/classes/Char.bi'
Expand Down
Binary file added src/bfasm.exe
Binary file not shown.
Binary file added src/bfc.exe
Binary file not shown.
6 changes: 4 additions & 2 deletions src/lib/application/core/bfArrays.bi
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
redim shared as string macroCodeList(0)
redim shared as string macroNameList(0)
redim shared as string labelNameList(0)
redim shared as unsigned long labelPtrList(0)
redim shared as string macroCodeList(0)
redim shared as string macroNameList(0)
6 changes: 3 additions & 3 deletions src/lib/application/core/versionInfo.bi
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
$versioninfo:CompanyName=Der Robert
$versioninfo:FileDescription=Brainfuck Compiler \x26 BVM
$versioninfo:FileVersion#=0,3,0,0
$versioninfo:FileVersion#=0,4,0,0
$versioninfo:InternalName=Brainfuck
$versioninfo:LegalCopyright=2023 by 'Der Robert'
$versioninfo:OriginalFileName=bf\x5Basm\x7Cc\x5D.bas
$versioninfo:Productname=Brainfuck
$versioninfo:ProductVersion#=0,3,0,0
$versioninfo:ProductVersion#=0,4,0,0

const VERSION = "0.3"
const VERSION = "0.4"
4 changes: 2 additions & 2 deletions src/lib/application/hexCode.bi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function dec2hex$(decimalNumber as integer, count as integer)
function dec2hex$(decimalNumber as unsigned long, count as integer)
dim as string result, zeros
if count < 1 then
dec2hex = hex$(decimalNumber)
Expand All @@ -11,6 +11,6 @@ function dec2hex$(decimalNumber as integer, count as integer)
endif
end function

function hex2dec%(hexNumber as string)
function hex2dec&&(hexNumber as string)
hex2Dec = val(String.concat("&H0", String.trim(hexNumber)))
end function
13 changes: 11 additions & 2 deletions src/lib/application/hexTokens.bi
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
'0111 7 input current cell (depending on config)
'1000 8 begin loop if current cell is not zero
'1001 9 repeat loop if current cell is not zero
'1010 A --- (reserved for "short jump/call")
'1010 B --- (reserved for "long jump/call")
'1010 A --- (reserved for "jump to label")
'1010 B --- (reserved for "call subroutine")
'1100 C switch to ascii mode (default; text mode only!)
'1101 D switch to number mode (text mode only!)
'1110 E switch to text mode (default)
Expand Down Expand Up @@ -68,6 +68,15 @@ function HexToken_EndLoop$()
end function


function HexToken_JumpToLabel$()
HexToken_JumpToLabel = "A"
end function

function HexToken_CallSubRoutine$()
HexToken_CallSubRoutine = "B"
end function


function HexToken_SwitchToAsciiMode$()
HexToken_SwitchToAsciiMode = "C"
end function
Expand Down
5 changes: 5 additions & 0 deletions src/lib/application/labels.bi
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'$include:'labels/addLabelName.bi'
'$include:'labels/addLabelPtr.bi'
'$include:'labels/getLabelIndexOf.bi'
'$include:'labels/getLabelPtr.bi'
'$include:'labels/getLastLabelIndex.bi'
29 changes: 29 additions & 0 deletions src/lib/application/labels/addLabelName.bi
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
function addLabelName%(labelName as string)
dim as integer index, labelCount
dim as string currentLabel, normalizedName

normalizedName = String.trim(labelName)
if String.isEmpty(normalizedName) then
addLabelName = -1
exit function
endif

labelCount = ubound(labelNameList)
for index = 0 to labelCount
currentLabel = labelNameList(index)
if Strings.areEqual(currentLabel, normalizedName) then
addLabelName = index
exit function
elseif String.isEmpty(currentLabel) then
labelNameList(index) = normalizedName
addLabelName = index
exit function
endif
next

labelCount = labelCount + 1
redim preserve labelNameList(labelCount)
labelNameList(labelCount) = normalizedName

addLabelName = labelCount
end function
8 changes: 8 additions & 0 deletions src/lib/application/labels/addLabelPtr.bi
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
sub addLabelPtr(index as integer, labelPtr as unsigned long)
dim as integer labelCount

labelCount = ubound(labelPtrList)
if index > labelCount then redim preserve labelPtrList(index)

labelPtrList(index) = labelPtr
end sub
21 changes: 21 additions & 0 deletions src/lib/application/labels/getLabelIndexOf.bi
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function getLabelIndexOf%(labelName as string)
dim as integer index, labelCount
dim as string currentLabel, normalizedName

normalizedName = String.trim(labelName)
if String.isEmpty(normalizedName) then
getLabelIndexOf = -1
exit function
endif

labelCount = ubound(labelNameList)
for index = 0 to labelCount
currentLabel = labelNameList(index)
if Strings.areEqual(currentLabel, normalizedName) then
getLabelIndexOf = index
exit function
endif
next

getLabelIndexOf = -1
end function
16 changes: 16 additions & 0 deletions src/lib/application/labels/getLabelPtr.bi
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function getLabelPtr&&(index as integer)
dim as integer labelCount

if index < 0 then
getLabelPtr = -1
exit function
endif

labelCount = ubound(labelPtrList)
if index > labelCount then
getLabelPtr = -1
exit function
endif

getLabelPtr = labelPtrList(index)
end function
13 changes: 13 additions & 0 deletions src/lib/application/labels/getLastLabelIndex.bi
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function getLastLabelIndex%()
dim as integer labelCount
dim as string currentLabel

labelCount = ubound(labelPtrList)
currentLabel = labelPtrList(labelCount)

if String.isNotEmpty(currentLabel) then
labelCount = labelCount + 1
endif

getLastLabelIndex = labelCount
end function
Loading