Skip to content

Commit

Permalink
<missing>
Browse files Browse the repository at this point in the history
--HG--
branch : com.mozilla.es4.smlnj
extra : convert_revision : 7d5b93900b3cc69516ab3c54d3cafc5a6af41f00
  • Loading branch information
[email protected] committed Aug 30, 2007
1 parent 92b364d commit 986f42a
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 29 deletions.
16 changes: 12 additions & 4 deletions tests/self/cogen-expr.es
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ package cogen
* that on Tamarin without global conventions / parallel
* with stacks, I think.
*/
let n = cgIdentExpr(ctx, lr.ident);
asm.I_findpropstrict(cgIdentExpr(ctx, lr.ident));
asm.I_getproperty(cgIdentExpr(ctx, lr.ident));
asm.I_pushnull();
Expand Down Expand Up @@ -587,9 +586,18 @@ package cogen
return emitter.multinameL(ei);
}
case (qi:QualifiedIdentifier) {
cgExpr(ctx, qi.qual);
return emitter.rtqname(qi);
}
/* switch type(qi.qual) {
case( lr:LexicalRef ) {
// Hack to deal with namespaces for now...
// later we will have to implement a namespace lookup to resolve qualified typenames
return emitter.qname({ns:new AnonymousNamespace(lr.ident.ident), id:qi.ident})
}
case( e:* ) {
*/ cgExpr(ctx, qi.qual);
return emitter.rtqname(qi);
/* }
}
*/ }
case (x:*) { throw ("Unimplemented cgIdentExpr " + e) }
}
}
Expand Down
16 changes: 12 additions & 4 deletions tests/self/cogen-stmt.es
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,10 @@ package cogen
let asm = ctx.asm;
let Lbreak = asm.newLabel();
let Lcont = asm.newLabel();
if (init != null)
if (init != null) {
cgExpr(ctx, init);
asm.I_pop();
}
let Ltop = asm.I_label();
if (cond != null) {
cgExpr(ctx, cond);
Expand Down Expand Up @@ -277,25 +279,29 @@ package cogen

function cgCatch(ctx, [code_start, code_end, Lend], {param:param, block:block} ) {
let {asm:asm, emitter:emitter, target:target} = ctx;
let catch_ctx = pushCatch(ctx);

if( param.fixtures.length != 1 )
throw "Internal Error: catch should have 1 fixture";

let [propname, fix] = param.fixtures[0];

let param_name = emitter.fixtureNameToName(propname);
let param_type = emitter.typeFromTypeExpr(fix.type);
let param_type = emitter.realTypeName(fix.type);

let catch_idx = target.addException(new ABCException(code_start, code_end, asm.length, param_type, param_name));

asm.startCatch();

let t = asm.getTemp();
asm.I_getlocal(0);
asm.I_pushscope();
//FIXME need to restore activation object/with scopes
restoreScopes(ctx);
let catch_ctx = pushCatch(ctx,t);

asm.I_newcatch(catch_idx);
asm.I_dup();
asm.I_setlocal(t); // Store catch scope in register so it can be restored later
asm.I_dup();
asm.I_pushscope();

// Store the exception object in the catch scope.
Expand All @@ -305,6 +311,8 @@ package cogen
// catch block body
cgBlock(catch_ctx, block);

asm.I_kill(t);

asm.I_popscope();
asm.I_jump(Lend);
}
Expand Down
31 changes: 27 additions & 4 deletions tests/self/cogen.es
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ package cogen

function cgBlock(ctx, b) {
// FIXME -- more here
cgHead(ctx, b.head);
let stmts = b.stmts;
for ( let i=0 ; i < stmts.length ; i++ )
cgStmt(ctx, stmts[i]);
Expand Down Expand Up @@ -229,7 +230,8 @@ package cogen
method.setDefaults(defaults);
}
let ctor_ctx = new CTX(asm, {tag:"function"}, method);
let t = asm.getTemp();
let ctor_ctx = new CTX(asm, {tag:"function", scope_reg:t}, method);
asm.I_getlocal(0);
// Should this be instanceInits.inits only?
Expand All @@ -242,6 +244,8 @@ package cogen
// Create the activation object, and initialize params
asm.I_newactivation();
asm.I_dup();
asm.I_setlocal(t);
asm.I_dup();
asm.I_pushwith();
cgHead(ctor_ctx, c.func.params);
Expand All @@ -266,6 +270,7 @@ package cogen
cgBlock(ctor_ctx, c.func.block);
asm.I_kill(t);
return method.finalize();
}
Expand Down Expand Up @@ -314,10 +319,13 @@ package cogen
*
* God only knows about the arguments object...
*/
let t = asm.getTemp();
asm.I_newactivation();
asm.I_dup();
asm.I_setlocal(t);
asm.I_pushscope();
let ctx = new CTX(asm, {tag: "function"}, method);
let ctx = new CTX(asm, {tag: "function", scope_reg:t, has_scope:true}, method);
cgHead(ctx, f.params);
Expand All @@ -328,6 +336,7 @@ package cogen
* at the end, so there's nothing to worry about here.
*/
cgBlock(ctx, f.block);
asm.I_kill(t);
return method.finalize();
}
Expand Down Expand Up @@ -404,6 +413,20 @@ package cogen
throw msg;
}

function restoreScopes({stk:stk, asm:asm}) {
while (stk != null) {
if(stk.has_scope) {
asm.I_getlocal(stk.scope_reg);
asm.I_pushscope();
}
if( stk.tag != "function" ) {
stk = stk.link;
}
else {
stk = null;
}
}
}

// The following return extended contexts
function pushBreak(ctx, labels, target)
Expand All @@ -423,8 +446,8 @@ package cogen
function pushLet(ctx /*more*/) {
}

function pushCatch(ctx /*more*/)
push(ctx, {tag:"catch", has_scope:true});
function pushCatch(ctx, scope_reg )
push(ctx, {tag:"catch", has_scope:true, scope_reg:scope_reg});
// FIXME anything else?

function pushFinally(ctx /*more*/) {
Expand Down
20 changes: 20 additions & 0 deletions tests/self/emitter.es
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,26 @@ package emitter

}

// Use this only for places that need a QName, only works with basic class names
// as Tamarin doesn't support
public function realTypeName(t) {
use namespace Ast;
// not dealing with types for now
switch type (t) {
case (tn:TypeName) {
return nameFromIdentExpr(tn.ident);
}
case (st:SpecialType) {
return 0;
}
case (x:*) {
throw ("Unimplemented: realTypeName " + t + ", using *")
}
}
return 0;

}

public function fixtureNameToName(fn) {
switch type (fn) {
case (pn:PropName) {
Expand Down
2 changes: 1 addition & 1 deletion tests/self/encoder.es
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ namespace Encode;
let len = nd.strValue.length;
for (var n=0; n<len; ++n)
{
let c = nd.strValue[n];
let c = nd.strValue.charAt(n);
if (c === "\n") c = "\\n";
else if (c == '\"') c = '\\"';
else if (c == "'") c = "\\'";
Expand Down
15 changes: 8 additions & 7 deletions tests/self/encoder.es.ast
Original file line number Diff line number Diff line change
Expand Up @@ -28002,7 +28002,8 @@ var ast =
, 'name': { 'ns': { 'ast_class': 'AnonymousNamespace'
, 'name': 'Encode' }
, 'id': 'c' } }
, { 'ast_class': 'ObjectRef'
, { 'ast_class': 'CallExpr'
, 'expr': { 'ast_class': 'ObjectRef'
, 'base': { 'ast_class': 'ObjectRef'
, 'base': { 'ast_class': 'LexicalRef'
, 'ident': { 'ast_class': 'Identifier'
Expand Down Expand Up @@ -28037,11 +28038,8 @@ var ast =
, ]
, [ ]
, ] } }
, 'ident': { 'ast_class': 'ExpressionIdentifier'
, 'expr': { 'ast_class': 'ListExpr'
, 'exprs': [ { 'ast_class': 'LexicalRef'
, 'ident': { 'ast_class': 'Identifier'
, 'ident': 'n'
, 'ident': 'charAt'
, 'nss': [ [ { 'ast_class': 'PublicNamespace'
, 'name': '' }
, ]
Expand All @@ -28056,7 +28054,9 @@ var ast =
, ]
, [ ]
, ] } }
, ] }
, 'args': [ { 'ast_class': 'LexicalRef'
, 'ident': { 'ast_class': 'Identifier'
, 'ident': 'n'
, 'nss': [ [ { 'ast_class': 'PublicNamespace'
, 'name': '' }
, ]
Expand All @@ -28070,7 +28070,8 @@ var ast =
, 'name': 'Encode' }
, ]
, [ ]
, ] } } ]
, ] } }
, ] } ]
, ] }
, ] } }
, { 'ast_class': 'IfStmt'
Expand Down
12 changes: 6 additions & 6 deletions tests/self/esc2.es
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
print("start esc2");

/*
{
use namespace Decode;
var Decode_program = program;
Expand All @@ -9,13 +9,13 @@ print("start esc2");
use namespace Encode;
var Encode_program = program;
}

*/
{
print ("decoding");
var nd = Decode_program (ast);
var nd = Decode::program (ast);
print ("encoding");
var tx = "var ast = "+Encode_program (nd);
print ("writing ",tx);
writeFile (tx,"esc-tmp.ast"); // what's this in tamarin
var tx = "var ast = "+Encode::program (nd);
print ("writing ",tx); //use print in tamarin for now
//writeFile (tx,"esc-tmp.ast"); // what's this in tamarin
print (tx.length+" chars written");
}
28 changes: 26 additions & 2 deletions tests/self/esc2.es.ast
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,23 @@ var ast =
, 'block': { 'ast_class': 'Block'
, 'head': { 'fixtures': [ ]
, 'exprs': [ ] }
, 'stmts': [ { 'ast_class': 'BlockStmt'
, 'stmts': [ { 'ast_class': 'ExprStmt'
, 'expr': { 'ast_class': 'ListExpr'
, 'exprs': [ { 'ast_class': 'CallExpr'
, 'expr': { 'ast_class': 'LexicalRef'
, 'ident': { 'ast_class': 'Identifier'
, 'ident': 'print'
, 'nss': [ [ { 'ast_class': 'PublicNamespace'
, 'name': '' }
, ]
, [ ]
, ] } }
, 'args': [ { 'ast_class': 'LiteralExpr'
, 'literal': { 'ast_class': 'LiteralString'
, 'strValue': "start esc2" } }
, ] }
, ] } }
, { 'ast_class': 'BlockStmt'
, 'block': { 'ast_class': 'Block'
, 'head': { 'fixtures': [ ]
, 'exprs': [ ] }
Expand Down Expand Up @@ -142,7 +158,15 @@ var ast =
, ] } }
, 'args': [ { 'ast_class': 'LiteralExpr'
, 'literal': { 'ast_class': 'LiteralString'
, 'strValue': "writing" } }
, 'strValue': "writing " } }
, { 'ast_class': 'LexicalRef'
, 'ident': { 'ast_class': 'Identifier'
, 'ident': 'tx'
, 'nss': [ [ { 'ast_class': 'PublicNamespace'
, 'name': '' }
, ]
, [ ]
, ] } }
, ] }
, ] } }
, { 'ast_class': 'ExprStmt'
Expand Down
2 changes: 1 addition & 1 deletion tests/self/t.es
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10
print("hello world");

0 comments on commit 986f42a

Please sign in to comment.