-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from yeslogic/brendanzab/cond-types
Add cond types
- Loading branch information
Showing
24 changed files
with
1,923 additions
and
258 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "ddl-bson" | ||
version = "0.0.0" | ||
license = "Apache-2.0" | ||
publish = false | ||
|
||
[dependencies] | ||
ddl-util = { path = "../../../ddl-util" } | ||
|
||
[build-dependencies] | ||
ddl = { path = "../../.." } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
extern crate ddl; | ||
|
||
use std::env; | ||
use std::fs::File; | ||
use std::io::prelude::*; | ||
use std::str::FromStr; | ||
|
||
use ddl::syntax::ast::Program; | ||
|
||
fn main() { | ||
let src = { | ||
let mut src_file = File::open("src/bson.ddl").unwrap(); | ||
let mut src = String::new(); | ||
src_file.read_to_string(&mut src).unwrap(); | ||
src | ||
}; | ||
|
||
let mut program = Program::from_str(&src).unwrap(); | ||
program.substitute(&ddl::syntax::ast::base_defs()); | ||
ddl::syntax::check::check_program(&program).unwrap(); | ||
let ir = ddl::ir::ast::Program::from(&program); | ||
|
||
let out_dir = env::var("OUT_DIR").unwrap(); | ||
let mut file = File::create(out_dir + "/bson.rs").unwrap(); | ||
write!(file, "{}", ddl::codegen::LowerProgram(&ir)).unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/// Binary data | ||
BinData = struct { | ||
/// The number of bytes stored | ||
len : i32be, | ||
/// Binary data subtype | ||
/// | ||
/// - `0x00`: Generic binary subtype | ||
/// - `0x01`: Function | ||
/// - `0x02`: Binary (Old) | ||
/// - `0x03`: UUID (Old) | ||
/// - `0x04`: UUID | ||
/// - `0x05`: MD5 | ||
/// - `0x80`: User defined | ||
subtype : u8, | ||
/// The binary data | ||
data: [u8; len as u64], | ||
}; | ||
|
||
ObjectId = struct { | ||
epoch_time: i32be, | ||
machine_id: u24be, | ||
process_id: u16be, | ||
counter: u24be, | ||
}; | ||
|
||
Element = struct { | ||
elem_type : u8, | ||
content: cond { | ||
/// 64-bit floating point | ||
double : elem_type == 0x01u8 => f64le, | ||
// TODO: strings | ||
// /// UTF8 string | ||
// string : elem_type == 0x02u8 => String, | ||
// FIXME: mutual recursion | ||
// /// Embedded document | ||
// document : elem_type == 0x03u8 => Document, | ||
// /// Array | ||
// array : elem_type == 0x04u8 => Array, | ||
/// Binary data | ||
bin_data : elem_type == 0x05u8 => BinData, | ||
/// Undefined (value) - deprecated | ||
undefined : elem_type == 0x06u8 => empty, | ||
/// ObjectId | ||
object_id : elem_type == 0x07u8 => ObjectId, | ||
/// Boolean | ||
/// | ||
/// - `0x00`: false | ||
/// - `0x01`: true | ||
boolean : elem_type == 0x08u8 => u8, | ||
/// UTC datetime | ||
utc_datetime : elem_type == 0x09u8 => i64le, | ||
/// Null value | ||
null : elem_type == 0x0au8 => empty, | ||
// TODO: Regular Expression | ||
// reg_ex : elem_type == 0x0bu8 => RegEx, | ||
// TODO: DBPointer — Deprecated | ||
// db_pointer : elem_type == 0x0cu8 => DbPointer, | ||
// TODO: String | ||
// javascript : elem_type == 0x0du8 => String, | ||
// TODO: Symbol. Deprecated | ||
// symbol : elem_type == 0x0eu8 => Symbol, | ||
// TODO: JavaScript code w/ scope | ||
// code_with_scope : elem_type == 0x0fu8 => CodeWithScope, | ||
/// 32-bit integer | ||
int : elem_type == 0x10u8 => i32le, | ||
/// Timestamp | ||
timestamp : elem_type == 0x11u8 => u64le, | ||
/// 64-bit integer | ||
long : elem_type == 0x12u8 => i64le, | ||
// TODO: 128-bit decimal floating point | ||
// number_decimal : elem_type == 0x13u8 => NumberDecimal, | ||
}, | ||
}; | ||
|
||
/// BSON Document | ||
/// | ||
/// <http://bsonspec.org/spec.html> | ||
Document = struct { | ||
/// Total number of bytes comprising the document. | ||
len : i32be, | ||
/// The elements that make up this document | ||
fields : [Element; 1u8], | ||
// /// Terminating byte signalling the end of the file | ||
// terminator : u8 where u8 == 0x00, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include!(concat!(env!("OUT_DIR"), "/bson.rs")); |
Oops, something went wrong.