Skip to content

Commit

Permalink
esc: add type exprs to ast decoder; improve performance by removing s…
Browse files Browse the repository at this point in the history
…ome recursion and array manip

--HG--
branch : com.mozilla.es4.smlnj
extra : convert_revision : 6233cb739e2b4df3047bdb15c0bbdaa9a960085d
  • Loading branch information
jeffdyer committed Aug 16, 2007
1 parent e977c4b commit c64b0d4
Show file tree
Hide file tree
Showing 8 changed files with 1,589 additions and 174 deletions.
26 changes: 14 additions & 12 deletions tests/self/ast.es
Original file line number Diff line number Diff line change
Expand Up @@ -455,10 +455,10 @@ namespace Ast
}

class CallExpr {
const func : EXPR;
const args : [EXPR];
function CallExpr (func,args)
: func = func
const expr : EXPR;
const args : EXPRS;
function CallExpr (expr,args)
: expr = expr
, args = args {}
}

Expand All @@ -479,10 +479,10 @@ namespace Ast
}

class NewExpr {
const func : EXPR;
const args : [EXPR];
function NewExpr (func,args)
: func = func
const expr : EXPR;
const args : EXPRS;
function NewExpr (expr,args)
: expr = expr
, args = args {}
}

Expand Down Expand Up @@ -739,6 +739,7 @@ namespace Ast
, init : EXPR }

type FIELD_TYPE = FieldType;
type FIELD_TYPES = [FIELD_TYPE];

class LiteralFunction {
const func : FUNC;
Expand Down Expand Up @@ -977,6 +978,7 @@ namespace Ast

// TYPES

type TYPE_EXPRS = [TYPE_EXPR];
type TYPE_EXPR = (
SpecialType,
UnionType,
Expand Down Expand Up @@ -1020,7 +1022,7 @@ namespace Ast
}

class ArrayType {
const types : [TYPE_EXPR];
const types : TYPE_EXPRS;
function ArrayType (types)
: types = types { }
}
Expand Down Expand Up @@ -1061,10 +1063,10 @@ namespace Ast
}

class FieldType {
const name: IDENT;
const ident: IDENT;
const type: TYPE_EXPR;
function FieldType (name,ty)
: name = name
function FieldType (ident,ty)
: ident = ident
, type = ty {}
}

Expand Down
71 changes: 69 additions & 2 deletions tests/self/ast_decoder.es
Original file line number Diff line number Diff line change
Expand Up @@ -507,12 +507,12 @@ namespace Decode;
var ndx = new ListExpr (nd1);
break;
case 'CallExpr':
var nd1 = expr (ob.func);
var nd1 = expr (ob.expr);
var nd2 = exprs (ob.args);
var ndx = new CallExpr (nd1,nd2);
break;
case 'NewExpr':
var nd1 = expr (ob.func);
var nd1 = expr (ob.expr);
var nd2 = exprs (ob.args);
var ndx = new NewExpr (nd1,nd2);
break;
Expand Down Expand Up @@ -811,7 +811,20 @@ namespace Decode;
return ndx;
}

function typeExprs (ob)
: TYPE_EXPRS
{
enter ("Decode::typeExprs ", ob.length);

var nd1 = [];
for (var i = 0; i < ob.length; ++i) {
var nd = typeExpr (ob[i]);
nd1.push (nd);
}

exit ("Decode::typeExprs");
return nd1;
}

function typeExpr (ob)
: TYPE_EXPR
Expand All @@ -823,6 +836,32 @@ namespace Decode;
var nd1 = specialTypeKind (ob.kind);
var ndx = new SpecialType (nd1);
break;
case 'UnionType':
var nd1 = typeExprs (ob.types);
var ndx = new UnionType (nd1);
break;
case 'ArrayType':
var nd1 = typeExprs (ob.types);
var ndx = new UnionType (nd1);
break;
case 'ObjectType':
var nd1 = fieldTypes (ob.fields);
var ndx = new ObjectType (nd1);
break;
case 'AppType':
var nd1 = typeExpr (ob.type);
var nd2 = typeExprs (ob.args);
var ndx = new AppType (nd1,nd2);
break;
case 'NullableType':
var nd1 = typeExpr (ob.type);
var nd2 = ob.isNullable;
var ndx = new NullableType (nd1,nd2);
break;
case 'TypeName':
var nd1 = identExpr (ob.ident);
var ndx = new TypeName (nd1);
break;
default:
throw "error Decode::typeExpr " + ob.ast_class;
}
Expand All @@ -831,6 +870,34 @@ namespace Decode;
return ndx;
}

function fieldTypes (ob)
: FIELD_TYPES
{
enter ("Decode::fieldTypes ", ob.length);

var nd1 = [];
for (var i = 0; i < ob.length; ++i) {
var nd = fieldType (ob[i]);
nd1.push (nd);
}

exit ("Decode::fieldTypes");
return nd1;
}

function fieldType (ob)
: FIELD_TYPE
{
enter ("Decode::fieldType ", ob.ast_class);

let nd1 = ob.ident;
let nd2 = typeExpr (ob.type);
var ndx = new FieldType (nd1,nd2);

exit ("Decode::fieldType");
return ndx;
}

function specialTypeKind (ob)
: SPECIAL_TYPE_KIND
{
Expand Down
Loading

0 comments on commit c64b0d4

Please sign in to comment.