The Dio Programming Language

New Syntax Not Found In Other Languages

Before I explain string interpolation and type aliasing I'd like to say the next version will have alternative syntax. I hear backticks are difficult to type and I don't think people will get use to reading @@ even after being use to the rest of the syntax. The constructor and destructor may change as well.

There's a few things going on in this example. Below is the source of the sqlite demo. It shows some unique syntax that allows you to create a wrapper for a C library and use string interpolation. There's also type aliasing (class name = different_class) that allow you to create a class from an opaque type

main() int {
cn``= $SQLite(":memory:")
a``=9
rows ``= cn.Query("select $a")
r2 ``= rows.Step() //Enter first row
puts(itoa(rows.get_int(0))) //Get first column
//The SQLite and SQLiteStatement class tells the compiler how to cleans up
return 0
}

_Extern sqlite3, sqlite3_stmt

_C_Decl {
sqlite3_open(u8*sz; sqlite3@@db) s32
sqlite3_close(sqlite3@ db) s32
sqlite3_close_v2(sqlite3@ db) s32

sqlite3_step(sqlite3_stmt*stmt) s32
sqlite3_finalize(sqlite3_stmt@stmt) s32
sqlite3_column_int(sqlite3_stmt*stmt; s32 col) s32

sqlite3_prepare_v2(sqlite3 db`; u8*sql; s32 bytes; sqlite3_stmt ppStmt@@; u8?@@pzTail) s32
sqlite3_bind_int64(sqlite3_stmt stmt`; s32 index; s64 v) s32
}

class SQLiteStatement = sqlite3_stmt {
SQLITE_ROW = 100
SQLITE_DONE = 101
Step() int { return sqlite3_step(this) }
this { sqlite3_finalize(this@) }
get_int(int col) int { return sqlite3_column_int(this, col); }
}

class SQLite = sqlite3 {
this(string filename) { r = sqlite3_open(filename, cn@@); return cn}
this { sqlite3_close(this@) } //Destructor is this without params
_SI SQLiteQuery = sqlite3_stmt { //Syntax is likely to change
this { r = sqlite3_prepare_v2(context`, val, -1, stmt@@, null); return stmt }
s64 { r = sqlite3_bind_int64(this`, i, val) }
//TODO u8[], strings and other types.
}
Query(SQLiteQuery@query) SQLiteStatement { return query }
}