Skip to content

Commit

Permalink
Initial dump of codegen work. Requires manual running of various pyth…
Browse files Browse the repository at this point in the history
…on scripts to build servo.
  • Loading branch information
jdm committed Mar 13, 2013
1 parent 3067640 commit ebd1ce8
Show file tree
Hide file tree
Showing 19 changed files with 5,921 additions and 5 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
*.dSYM
*.dll
*.dummy
*.pkl
*.pyc
servo-test
Makefile
Servo.app
build
config.mk
config.stamp
config.stamp
parser.out
22 changes: 20 additions & 2 deletions src/servo/dom/bindings/codegen/BindingGen.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.

import sys
sys.path.append("./parser/")
sys.path.append("./ply/")
import os
import cPickle
import WebIDL
from Configuration import *
from Codegen import CGBindingRoot, replaceFileIfChanged
from CodegenRust import CGBindingRoot, replaceFileIfChanged
# import Codegen in general, so we can set a variable on it
import Codegen

Expand All @@ -32,6 +35,19 @@ def generate_binding_cpp(config, outputprefix, webidlfile):
if replaceFileIfChanged(filename, root.define()):
print "Generating binding implementation: %s" % (filename)

def generate_binding_rs(config, outputprefix, webidlfile):
"""
|config| Is the configuration object.
|outputprefix| is a prefix to use for the header guards and filename.
"""

filename = outputprefix + ".rs"
root = CGBindingRoot(config, outputprefix, webidlfile)
#root2 = CGBindingRoot(config, outputprefix, webidlfile)
#if replaceFileIfChanged(filename, root.declare() + root2.define()):
if replaceFileIfChanged(filename, root.define()):
print "Generating binding implementation: %s" % (filename)

def main():

# Parse arguments.
Expand All @@ -42,7 +58,7 @@ def main():
help="When an error happens, display the Python traceback.")
(options, args) = o.parse_args()

if len(args) != 4 or (args[0] != "header" and args[0] != "cpp"):
if len(args) != 4 or (args[0] != "header" and args[0] != "cpp" and args[0] != "rs"):
o.error(usagestring)
buildTarget = args[0]
configFile = os.path.normpath(args[1])
Expand All @@ -62,6 +78,8 @@ def main():
generate_binding_header(config, outputPrefix, webIDLFile);
elif buildTarget == "cpp":
generate_binding_cpp(config, outputPrefix, webIDLFile);
elif buildTarget == "rs":
generate_binding_rs(config, outputPrefix, webIDLFile);
else:
assert False # not reached

Expand Down
7 changes: 6 additions & 1 deletion src/servo/dom/bindings/codegen/Bindings.conf
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ DOMInterfaces = {
}
}],

'ClientRect': [
{
'nativeType': 'ClientRect',
}],

'ClientRectList': [
{
'nativeType': 'nsClientRectList',
Expand Down Expand Up @@ -509,7 +514,7 @@ addExternalHTMLElement('HTMLOptGroupElement')
addExternalHTMLElement('HTMLVideoElement')
addExternalIface('CanvasGradient', headerFile='nsIDOMCanvasRenderingContext2D.h')
addExternalIface('CanvasPattern', headerFile='nsIDOMCanvasRenderingContext2D.h')
addExternalIface('ClientRect')
#addExternalIface('ClientRect')
addExternalIface('CSSRule')
addExternalIface('CSSValue')
addExternalIface('DOMStringList', nativeType='nsDOMStringList',
Expand Down
14 changes: 14 additions & 0 deletions src/servo/dom/bindings/codegen/ClientRect.webidl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/

interface ClientRect {
readonly attribute float top;
readonly attribute float right;
readonly attribute float bottom;
readonly attribute float left;
readonly attribute float width;
readonly attribute float height;
};
85 changes: 85 additions & 0 deletions src/servo/dom/bindings/codegen/ClientRectList.webidl
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/

interface ClientRect;

interface ClientRectList {
readonly attribute unsigned long length;
getter ClientRect? item(unsigned long index);
};

/* Helpers

unsafe fn unwrap<T>(obj: *JSObject) -> *rust_box<T> {
let val = JS_GetReservedSlot(obj, 0);
cast::reinterpret_cast(&RUST_JSVAL_TO_PRIVATE(val))
}

trait ToJsval {
fn to_jsval(cx: *JSContext) -> jsval;
}

impl Option : ToJsval {
fn to_jsval(cx: *JSContext) -> jsval {
match self {
Some(v) => v.to_jsval(),
None => JSVAL_NULL
}
}
}

*/

/*

trait ClientRectList {
fn getLength() -> u32;
fn getItem(u32 index) -> Option<@ClientRect>;
}

mod ClientRectList {
mod bindings {

fn getLength(cx: *JSContext, argc: c_uint, argv: *jsval) -> JSBool unsafe {
let obj = JS_THIS_OBJECT(cx, unsafe::reinterpret_cast(&vp));
if obj.is_null() {
return 0;
}

let conrete = unwrap<ClientRectList>(obj);
let rval = (*concrete).getLength();

JS_SET_RVAL(argv, rval);
return 1;
}

fn getItem(cx: *JSContext, argc: c_uint, vp: *jsval) -> JSBool unsafe {
let obj = JS_THIS_OBJECT(cx, unsafe::reinterpret_cast(&vp));
if obj.is_null() {
return 0;
}

let raw_arg1 = if argc < 1 {
//XXX convert null
} else {
JS_ARGV(vp, 0);
};

let arg1 = if !RUST_JSVAL_IS_INT(raw_arg1) {
//XXX convert to int
} else {
RUST_JSVAL_TO_INT(raw_arg1);
} as u32;

let conrete = unwrap<ClientRectList>(obj);
let rval = (*concrete).getItem(arg1);

JS_SET_RVAL(vp, rval.to_jsval())
return 1;
}
}

*/
Loading

0 comments on commit ebd1ce8

Please sign in to comment.