I am implementing support for external modules. You will be able to write static libraries in C and link them to the NextBasic program, but the compiler needs to know that these functions exist so when you use them in your program they won't throw a compiler error.
The core NextBasic functions that I blogged about int the last post will be placed in a "core" module that is automatically included in all your programs. Inside NextBasic's "modules" folder, there will be a folder named "core" with the files "core.nb", "libcore.win32.a", "libcore.linux32.a" and "libcore.mac.a". An excerpt from the file "core.nb" looks as follows (with only the Array functions to not make the example too big):
$Link "core"
Extern
Function CreateArray%()
Function FreeArray(arr)
Function CountArray%(arr)
Function ArrayAddInt(arr, i)
Function ArrayAddFloat(arr, f#)
Function ArrayAddString(arr, s$)
Function ArrayAddObject(arr, obj As Struct)
Function ArraySetInt(arr, index, i)
Function ArraySetFloat(arr, index, f#)
Function ArraySetString(arr, index, s$)
Function ArraySetObject(arr, index, obj As Struct)
Function ArrayGetInt%(arr, index)
Function ArrayGetFloat#(arr, index)
Function ArrayGetString$(arr, index)
Function ArrayGetObject(arr, index) As Struct
Function ArrayRemoveAt(arr, index)
Function ArrayRemoveObject(arr, obj As Struct)
Function ArrayClear(arr)
EndExtern
The first line indicates the preprocessor that the static library "core" needs to be linked to our program. It will pick the correct name based on the platform we are compiling for (for example, on Windows it would be "libcore.win32.a"). After that,we declare an "Extern" block, which indicates that the functions we are going to declare within the block do not have a function body, because it is contained in an external library.
One thing to note is that "Struct" is a valid type for arguments and functions. It indicates that any variable which is of a user defined type will be a valid parameter, and that we can assign the return value to any of these variables (so you have to make sure that you are assigning it to the correct type). This allows NextBasic to put any kind of user defined var inside an array.
NextBasic Development
miércoles, 29 de mayo de 2013
lunes, 27 de mayo de 2013
Core library
Right today, I have finished implementinf the Core library for NextBasic. The library has been written in plain ANSI C, and it is already fully working on Windows, Mac and Linux.
Here is the list of functions in the language. They are not expressed in NextBasic syntax, but in a C-like syntax that should be very easy to understand:
Array:
int CreateArray()
void FreeArray(int arr)
int CountArray(int arr)
void ArrayAddInt(int arr, int i)
void ArrayAddFloat(int arr, float f)
void ArrayAddString(int arr, string s)
void ArrayAddObject(int arr, pointer obj)
void ArraySetInt(int arr, int index, int i)
void ArraySetFloat(int arr, int index, float f)
void ArraySetString(int arr, int index, string s)
void ArraySetObject(int arr, int index, pointer obj)
int ArrayGetInt(int arr, int index)
float ArrayGetFloat(int arr, int index)
string ArrayGetString(int arr, int index)
pointer ArrayGetObject(int arr, int index)
void ArrayRemoveAt(int arr, int index)
void ArrayRemoveObject(int arr, pointer obj)
void ArrayClear(int arr)
Console:
void Print(string str)
void Write(string str)
string Input(string prompt)
Dictionary:
int CreateDictionary()
void FreeDictionary(int dict)
int CountDictionary(int dict)
void DictionarySetInt(int dict, string key, int val)
void DictionarySetFloat(int dict, string key, float val)
void DictionarySetString(int dict, string key, string str)
void DictionarySetObject(int dict, string key, pointer obj)
int DictionaryGetInt(int dict, string key)
float DictionaryGetFloat(int dict, string key)
string DictionaryGetString(int dict, string key)
pointer DictionaryGetObject(int dict, string key)
int DictionaryHasKey(int dict, string key)
string DictionaryGetKey(int dict, int index)
void DictionaryRemoveKey(int dict, string key)
void DictionaryClear(int dict)
File:
int ReadFile(string filename)
int WriteFile(string filename, int append)
void CloseFile(int file)
int FilePos(int file)
void SeekFile(int file, int pos)
int Eof(int file)
int ReadByte(int file)
int ReadShort(int file)
int ReadInt(int file)
float ReadFloat(int file)
string ReadString(int file)
string ReadLine(int file)
int ReadBytes(int file, int buffer, int offset, int count)
void WriteByte(int file, int val)
void WriteShort(int file, int val)
void WriteInt(int file, int val)
void WriteFloat(int file, float val)
void WriteString(int file, string val)
void WriteLine(int file, string val)
int WriteBytes(int file, int buffer, int offset, int count)
File system:
int ReadDir(string path)
void CloseDir(int dir)
int MoreFiles(int dir)
string NextFile(int dir)
string CurrentDir()
void ChangeDir(string path)
void CreateDir(string path)
void DeleteDir(string path)
int FileType(string filename)
int FileSize(string filename)
void CopyFile(string filename1, string filename2)
void DeleteFile(string filename)
Math:
float Pi()
float Floor(float val)
float Ceil(float val)
float Sgn(float val)
int Abs(int val)
float FAbs(float val)
float Sqr(float val)
float Sin(float val)
float Cos(float val)
float Tan(float val)
float ASin(float val)
float ACos(float val)
float ATan(float val)
float ATan2(float y, float x)
float Exp(float val)
float Log(float val)
float Log10(float val)
int Rand(int min, int max)
float FRand(float min, float max)
void SeedRnd(int seed)
Memory:
int AllocMem(int size)
void FreeMem(int mem)
int PeekByte(int mem, int offset)
int PeekShort(int mem, int offset)
int PeekInt(int mem, int offset)
float PeekFloat(int mem, int offset)
void PokeByte(int mem, int offset, int val)
void PokeShort(int mem, int offset, int val)
void PokeInt(int mem, int offset, int val)
void PokeFloat(int mem, int offset, float val)
String:
string Str(int val)
string StrF(float val)
int Val(string str)
float ValF(string str)
string Left(string str, int n)
string Right(string str, int n)
string Mid(string str, int ofs, int n)
string Replace(string str, string find, string rep)
int Find(string str1, string str2, int ofs)
string Upper(string str)
string Lower(string str)
string LTrim(string str)
string RTrim(string str)
string Trim(string str)
string LSet(string str, int len, string c)
string RSet(string str, int len, string c)
string Chr(int asc)
int Asc(string chr)
int Len(string str)
string Hex(int val)
string StripExt(string filename)
string StripDir(string filename)
string ExtractExt(string filename)
string ExtractDir(string filename)
string LoadString(string filename)
void SaveString(string str, string filename, int append)
int SplitString(string str, string delim)
System:
string CommandLine()
string GetEnv(string var)
int System(string command)
void End(int exitCode)
Time:
int Millisecs()
void Delay(int msecs)
string CurrentDate()
string CurrentTime()
As you can see, most of the functions are identical to BlitzBasic command set. As I said on the previous post, I love the design of the classic procedural BlitzBasic languages, and their command set is very well designed, so that's why I decided to implement that core command set in NextBasic.
Here is the list of functions in the language. They are not expressed in NextBasic syntax, but in a C-like syntax that should be very easy to understand:
Array:
int CreateArray()
void FreeArray(int arr)
int CountArray(int arr)
void ArrayAddInt(int arr, int i)
void ArrayAddFloat(int arr, float f)
void ArrayAddString(int arr, string s)
void ArrayAddObject(int arr, pointer obj)
void ArraySetInt(int arr, int index, int i)
void ArraySetFloat(int arr, int index, float f)
void ArraySetString(int arr, int index, string s)
void ArraySetObject(int arr, int index, pointer obj)
int ArrayGetInt(int arr, int index)
float ArrayGetFloat(int arr, int index)
string ArrayGetString(int arr, int index)
pointer ArrayGetObject(int arr, int index)
void ArrayRemoveAt(int arr, int index)
void ArrayRemoveObject(int arr, pointer obj)
void ArrayClear(int arr)
Console:
void Print(string str)
void Write(string str)
string Input(string prompt)
Dictionary:
int CreateDictionary()
void FreeDictionary(int dict)
int CountDictionary(int dict)
void DictionarySetInt(int dict, string key, int val)
void DictionarySetFloat(int dict, string key, float val)
void DictionarySetString(int dict, string key, string str)
void DictionarySetObject(int dict, string key, pointer obj)
int DictionaryGetInt(int dict, string key)
float DictionaryGetFloat(int dict, string key)
string DictionaryGetString(int dict, string key)
pointer DictionaryGetObject(int dict, string key)
int DictionaryHasKey(int dict, string key)
string DictionaryGetKey(int dict, int index)
void DictionaryRemoveKey(int dict, string key)
void DictionaryClear(int dict)
File:
int ReadFile(string filename)
int WriteFile(string filename, int append)
void CloseFile(int file)
int FilePos(int file)
void SeekFile(int file, int pos)
int Eof(int file)
int ReadByte(int file)
int ReadShort(int file)
int ReadInt(int file)
float ReadFloat(int file)
string ReadString(int file)
string ReadLine(int file)
int ReadBytes(int file, int buffer, int offset, int count)
void WriteByte(int file, int val)
void WriteShort(int file, int val)
void WriteInt(int file, int val)
void WriteFloat(int file, float val)
void WriteString(int file, string val)
void WriteLine(int file, string val)
int WriteBytes(int file, int buffer, int offset, int count)
File system:
int ReadDir(string path)
void CloseDir(int dir)
int MoreFiles(int dir)
string NextFile(int dir)
string CurrentDir()
void ChangeDir(string path)
void CreateDir(string path)
void DeleteDir(string path)
int FileType(string filename)
int FileSize(string filename)
void CopyFile(string filename1, string filename2)
void DeleteFile(string filename)
Math:
float Pi()
float Floor(float val)
float Ceil(float val)
float Sgn(float val)
int Abs(int val)
float FAbs(float val)
float Sqr(float val)
float Sin(float val)
float Cos(float val)
float Tan(float val)
float ASin(float val)
float ACos(float val)
float ATan(float val)
float ATan2(float y, float x)
float Exp(float val)
float Log(float val)
float Log10(float val)
int Rand(int min, int max)
float FRand(float min, float max)
void SeedRnd(int seed)
Memory:
int AllocMem(int size)
void FreeMem(int mem)
int PeekByte(int mem, int offset)
int PeekShort(int mem, int offset)
int PeekInt(int mem, int offset)
float PeekFloat(int mem, int offset)
void PokeByte(int mem, int offset, int val)
void PokeShort(int mem, int offset, int val)
void PokeInt(int mem, int offset, int val)
void PokeFloat(int mem, int offset, float val)
String:
string Str(int val)
string StrF(float val)
int Val(string str)
float ValF(string str)
string Left(string str, int n)
string Right(string str, int n)
string Mid(string str, int ofs, int n)
string Replace(string str, string find, string rep)
int Find(string str1, string str2, int ofs)
string Upper(string str)
string Lower(string str)
string LTrim(string str)
string RTrim(string str)
string Trim(string str)
string LSet(string str, int len, string c)
string RSet(string str, int len, string c)
string Chr(int asc)
int Asc(string chr)
int Len(string str)
string Hex(int val)
string StripExt(string filename)
string StripDir(string filename)
string ExtractExt(string filename)
string ExtractDir(string filename)
string LoadString(string filename)
void SaveString(string str, string filename, int append)
int SplitString(string str, string delim)
System:
string CommandLine()
string GetEnv(string var)
int System(string command)
void End(int exitCode)
Time:
int Millisecs()
void Delay(int msecs)
string CurrentDate()
string CurrentTime()
As you can see, most of the functions are identical to BlitzBasic command set. As I said on the previous post, I love the design of the classic procedural BlitzBasic languages, and their command set is very well designed, so that's why I decided to implement that core command set in NextBasic.
Hello world
Hello everyone.
In this blog, I will comment all progresses on the upcoming programming language NextBasic. NextBasic will be a freeware procedural programming language for Windows, OS X and Linux. Its syntax will be inspired by BlitzBasic (although it won't compatible with it), and it will generate native x86 executables.
The current development progress is roughly as follows:
Compiler (70%)
The following features are missing:
- External library support.
- Add "#" and "$" as aliases for "As Float" and "As String".
- "Select" statement.
- Built-in static arrays (currently, dynamic array functions exist in the core library).
Libraries (40%)
The Core library is finished, but I need to create the following ones:
- An OpenGL based Graphics2D library.
- An OpenAL based Audio library.
- A procedural wrapper for Qt.
- Support for several other 3rd-party libraries (OpenGL ES 2.0, OpenAL, Lua, some 3D engines like 3Impact, Horde3D, IrrLicht or OGRE...).
IDE (90%)
The IDE has been written in C++ and Qt, and it's only missing feature is the addition of a Help tab and contextual help.
Documentation (0%)
I have to write documentation for the language, IDE, and each function in the Core, Graphics and Audio libraries.
Stay tuned for more information on NextBasic and its evolution.
In this blog, I will comment all progresses on the upcoming programming language NextBasic. NextBasic will be a freeware procedural programming language for Windows, OS X and Linux. Its syntax will be inspired by BlitzBasic (although it won't compatible with it), and it will generate native x86 executables.
The current development progress is roughly as follows:
Compiler (70%)
The following features are missing:
- External library support.
- Add "#" and "$" as aliases for "As Float" and "As String".
- "Select" statement.
- Built-in static arrays (currently, dynamic array functions exist in the core library).
Libraries (40%)
The Core library is finished, but I need to create the following ones:
- An OpenGL based Graphics2D library.
- An OpenAL based Audio library.
- A procedural wrapper for Qt.
- Support for several other 3rd-party libraries (OpenGL ES 2.0, OpenAL, Lua, some 3D engines like 3Impact, Horde3D, IrrLicht or OGRE...).
IDE (90%)
The IDE has been written in C++ and Qt, and it's only missing feature is the addition of a Help tab and contextual help.
Documentation (0%)
I have to write documentation for the language, IDE, and each function in the Core, Graphics and Audio libraries.
Stay tuned for more information on NextBasic and its evolution.
Suscribirse a:
Entradas (Atom)