Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Bird Programming Language: Part 1

, 1 Jan 2013
A new general purpose language that aims to be fast, high level and simple to use.
Bird-noexe.zip
Bird
Archives
crt2.o
crtbegin.o
crtend.o
libadvapi32.a
libcomctl32.a
libcomdlg32.a
libgcc.a
libgdi32.a
libglu32.a
libkernel32.a
libmingw32.a
libmingwex.a
libmoldname.a
libmsvcrt.a
libopengl32.a
libshell32.a
libstdc++.a
libuser32.a
libwinmm.a
libwsock32.a
Libraries
BirdCore
Array.bird
BigInteger.bird
BinaryRW.bird
BirdCore.a
BirdCore.blib
CategoryData.dat
Console.bird
Convert.bird
Debug.bird
Entry.bird
Environment.bird
Exception.bird
Float.bird
LEB128.bird
Math.bird
Memory.bird
Object.bird
Random.bird
Reflection.bird
StandardC.bird
Stream.bird
String.bird
ToLowerData.dat
ToUpperData.dat
Types.bird
ValueType.bird
Win32.bird
x86Helper.bird
BlitzMax
.bmx
Launcher.bmx.gui.release.win32.x86.o
appstub.release.win32.x86.a
bank.release.win32.x86.a
bankstream.release.win32.x86.a
blitz.release.win32.x86.a
BlitzMax.a
BlitzMax.bird
BlitzMax.blib
d3d7max2d.release.win32.x86.a
d3d9max2d.release.win32.x86.a
directx.release.win32.x86.a
dxgraphics.release.win32.x86.a
event.release.win32.x86.a
filesystem.release.win32.x86.a
font.release.win32.x86.a
glgraphics.release.win32.x86.a
glmax2d.release.win32.x86.a
graphics.release.win32.x86.a
hook.release.win32.x86.a
keycodes.release.win32.x86.a
Launcher.bmx
libpng.release.win32.x86.a
linkedlist.release.win32.x86.a
math.release.win32.x86.a
max2d.release.win32.x86.a
opengl.release.win32.x86.a
pixmap.release.win32.x86.a
pngloader.release.win32.x86.a
polledinput.release.win32.x86.a
standardio.release.win32.x86.a
stdc.release.win32.x86.a
stream.release.win32.x86.a
system.release.win32.x86.a
textstream.release.win32.x86.a
win32.release.win32.x86.a
zlib.release.win32.x86.a
PrgLinec.bmx
Samples
Circles
Circles.bird
CppMain.bird
Fire
Fire.bird
Higher Order Functions
C#
Higher Order Functions.v11.suo
Properties
Test.bird
msvcrt.lib
Reflection
Reflection.bird
Squares
Squares.bird
Template
Template.bird
Source
Base
Bird.v11.suo
Expressions
Identifiers
Languages
NativeCode
Properties
Recognizers
Expressions
Scopes
x86
Thumbs.db
Bird.zip
crt2.o
crtbegin.o
crtend.o
libadvapi32.a
libcomctl32.a
libcomdlg32.a
libgcc.a
libgdi32.a
libglu32.a
libkernel32.a
libmingw32.a
libmingwex.a
libmoldname.a
libmsvcrt.a
libopengl32.a
libshell32.a
libstdc++.a
libuser32.a
libwinmm.a
libwsock32.a
Binaries
ar.exe
Bird.exe
fasm.exe
ld.exe
libiconv-2.dll
libintl-8.dll
Array.bird
BigInteger.bird
BinaryRW.bird
BirdCore.a
BirdCore.blib
CategoryData.dat
Console.bird
Convert.bird
Debug.bird
Entry.bird
Environment.bird
Exception.bird
Float.bird
LEB128.bird
Math.bird
Memory.bird
Object.bird
Random.bird
Reflection.bird
StandardC.bird
Stream.bird
String.bird
ToLowerData.dat
ToUpperData.dat
Types.bird
ValueType.bird
Win32.bird
x86Helper.bird
Launcher.bmx.gui.release.win32.x86.o
appstub.release.win32.x86.a
bank.release.win32.x86.a
bankstream.release.win32.x86.a
blitz.release.win32.x86.a
BlitzMax.a
BlitzMax.bird
BlitzMax.blib
d3d7max2d.release.win32.x86.a
d3d9max2d.release.win32.x86.a
directx.release.win32.x86.a
dxgraphics.release.win32.x86.a
event.release.win32.x86.a
filesystem.release.win32.x86.a
font.release.win32.x86.a
glgraphics.release.win32.x86.a
glmax2d.release.win32.x86.a
graphics.release.win32.x86.a
hook.release.win32.x86.a
keycodes.release.win32.x86.a
Launcher.bmx
libpng.release.win32.x86.a
linkedlist.release.win32.x86.a
math.release.win32.x86.a
max2d.release.win32.x86.a
opengl.release.win32.x86.a
pixmap.release.win32.x86.a
pngloader.release.win32.x86.a
polledinput.release.win32.x86.a
standardio.release.win32.x86.a
stdc.release.win32.x86.a
stream.release.win32.x86.a
system.release.win32.x86.a
textstream.release.win32.x86.a
win32.release.win32.x86.a
zlib.release.win32.x86.a
PrgLinec.bmx
PrgLinec.exe
Circles.bird
CppMain.bird
Fire.bird
Higher Order Functions.v11.suo
Test.bird
msvcrt.lib
Reflection.bird
Squares.bird
Template.bird
Bird.v11.suo
Thumbs.db
examples.zip
Examples
As.exe
AsLibs.a
PerfTest
Launcher.bmx
Squares
.bmx
Launcher.bmx
Template
Launcher.bmx
source.zip
Anonymus 7_1
Anonymus.csproj.user
Anonymus.idc
Anonymus.pidb
Anonymus.suo
Anonymus.userprefs
Base
Expressions
Lib
Long
LongDivTest.bmx
ULongConv.bmx
Math
MISZ
AsLibs.a
PerfTest
Launcher.bmx
Squares
Launcher.bmx
Template
Launcher.bmx
PrgLinec.bmx
PrgLinec.exe
Properties
Scopes
Txt
Asm.docx
Code.docx
Lib.aslib
~$Code.docx
x86
MISZ\BmxLibs.txt MISZ\Squares\Squares.txt MISZ\Squares.s


		public bool MembersAssigned(Variable Var, Identifier Member)
		{
#if DEBUG
			var Type = Var.Type as StructuredType;
			if (Type == null || !Type.Members.Contains(Member))
				throw new Exception("ERROR");
#endif
			foreach (var e in AllAssignments)
			{
				var OpNode = e as OpExpressionNode;
				if (OpNode == null || OpNode.Operator != Operator.Member) continue;
				var Ch = OpNode.Children;

				var IdCh0 = Ch[0] as IdExpressionNode;
				var IdCh1 = Ch[1] as IdExpressionNode;
				if (IdCh0 != null && IdCh1 != null && IdCh0.Id == Var && IdCh1.Id == Member)
					return true;
			}

			return false;
		}

		public bool MembersAssigned(Variable Var, CompilerState State = null)
		{
			var Type = Var.Type as StructuredType;
			if (Type == null) throw new Exception("ERROR");

			var RetValue = true;
			foreach (var e in Type.Members)
				if (!MembersAssigned(Var, e))
				{
					if (State != null)
						State.Messages.Add(MessageId.VarUsingWoAssign, e.Name);

					RetValue = false;
				}

			return RetValue;
		}



		private void CalcRec(ExpressionNode Node)
		{
			var Data = Node.ArchData as x86NodeData;
			var Scope = Data.Scope;
			var Index = Data.Index;

			if (Data.NewScope)
			{
				foreach (var Pos in Scope.DataPositions.Values)
					if (!Pos.DataCalcPos.HasFlag(x86DataCalcPos.Memory))
						Scope.AlloArchData(Pos);
			}

			//------------------------------------------------------------
			if (Node.LinkedNodes != null)
			{
                var Allocator = new x86DataAllocator(Container);
                Allocator.SetUsed(Scope.Allocator);

                for (var i = Node.LinkedNodes.Count - 1; i >= 0; i--)
                {
                    var LNode = Node.LinkedNodes[i];
					var LData = LNode.ArchData as x86LinkedNodeData;
					
                    var Linked = LNode.Node;
                    var LinkedData = Linked.ArchData as x86NodeData;
					var LScope = LinkedData.Scope;

					if (LData.Specified != null)
                    {
						LData.Position = LData.Specified;
						Allocator.SetUsed(LData.Specified);
                    }
                    else
                    {
                        if (LinkedData.Output != null && Allocator.IsFree(LinkedData.Output))
                        {
                            Allocator.SetUsed(LinkedData.Output);
							LData.Position = LinkedData.Output;
                        }
                        else
                        {
                            LData.Position = Allocator.Alloc(Linked.Type);
                        }

                        Scope.SetUsed(LData.Position);
                    }

                    LNode.Node.GetUsed(Allocator);
                }
			}

            if (Index != -1) Data.Output = Scope.AlloArchData(Index, Node.Type.Size, false);
			foreach (var Ch in Node.EnumChildren)
				CalcRec(Ch);
		}




class List<T>
	T[] Data
	int Count

	void Add(T Obj)
		Count++
		if Data.Length < Count
			Data.Length *= 2

		Data[Count - 1] = Obj

	void RemoveLast()
		Count--

	T this[int Index]
		if Index < Count
			throw new Exception

		getset Data[Index]


typedef float2 {float x, y}
typedef int2 {int, int}

bool Ok(float2 a, b)
	return -0.5 < a.x - b.x < 0.5 and
		   -0.5 < a.y - b.y < 0.5

bool Ok(float2 a, b)
	return |a.x - b.x| < 0.5 and
		   |a.y - b.y| < 0.5

bool Ok(float2 a, b)
	return abs(a.x - b.x) < 0.5 and
		   abs(a.y - b.y) < 0.5

{int, int} Mul({int, int} a, b)
	return {a.0 * b.0, a.1 * b.1}

Mul({int, int} a, b, out)
	return {a.0 * b.0, a.1 * b.1}
	
int2 Mul(int2 a, b)
	return {a.0 * b.0, a.1 * b.1}

private (string out) GetCmpCode(x86DataPosition TmpReg, Dst, Src, Operator Instruction, Type Type)
	if Type is FloatType
		if Dst == null then CodeString.Append "\tfucompp\n"
		else CodeString.Append "\tfucomp " + Dst + "\n"
		CodeString.Append "\tfnstsw ax\n"
		CodeString.Append "\tsahf\n"
		out = x86Architecture.OpInstruction(Instruction, false)
	else
		out = x86Architecture.OpInstruction(Instruction, Type is SignedType)
		StdMem2MemOp "\tcmp ", Dst, Src, TmpReg

private string GetCmpCode(x86DataPosition TmpReg, x86DataPosition Dst, x86DataPosition Src,
	Operator Instruction, Type Type)
{
	string StrInstruction;
	if (Type is FloatType)
	{
		if (Dst == null) CodeString.Append("\tfucompp\n");
		else CodeString.Append("\tfucomp " + Dst + "\n");
		CodeString.Append("\tfnstsw ax\n");
		CodeString.Append("\tsahf\n");
		StrInstruction = x86Architecture.OpInstruction(Instruction, false);
	}
	else
	{
		StrInstruction = x86Architecture.OpInstruction(Instruction, Type is SignedType);
		StdMem2MemOp("\tcmp ", Dst, Src, TmpReg);
	}

	return StrInstruction;
}

private string GetCmpCode(List<ExpressionNode> Ch, Operator Op, x86DataPosition TmpReg)
{
	CalcFltNodes(Ch);
	var Type = Ch[0].Type;

	var Dst = GetNodePos(Ch[0], GetNodePosMode.Default);
	var Src = GetNodePos(Ch[1], GetNodePosMode.Default);
}
		 
public x86DataPosition GetNodePos_Float(ExpressionNode Node)
{
	CalcFltNode(Node);
	return Node.GetPosition();
}


public class PlugInManager
{
	public IdContainer Container;
	public Type RetType;

	public CompilerState State { get { return Container.State; } }
	public PreprocessorState PreState { get { return Container.PreState; } }
	public virtual bool AutoNot { get { return false; } }

	public PlugInManager(IdContainer Container)
	{
		this.Container = Container;
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

About the Author

Dávid Kocsis
Student
Hungary Hungary
I've been programming for 8 years. My first big project was a remake of a nice bomberman game called Dyna Blaster. When i was little i played a lot with it. Now i'm working on a new programming language and code generator.
I would like to work with someone, so feel free to contact me about it.

| Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 1 Jan 2013
Article Copyright 2011 by Dávid Kocsis
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid