-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
240 additions
and
28 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
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,15 @@ | ||
(function(sc) { | ||
"use strict"; | ||
|
||
require("./codegen"); | ||
|
||
var CodeGen = sc.lang.compiler.CodeGen; | ||
|
||
CodeGen.addGenerateMethod("BlockExpression", function(node) { | ||
var body = this.withFunction([], function() { | ||
return this.generateStatements(node.body); | ||
}); | ||
|
||
return [ "(", body, ")()" ]; | ||
}); | ||
})(sc); |
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,46 @@ | ||
(function() { | ||
"use strict"; | ||
|
||
require("./"); | ||
|
||
var Syntax = sc.lang.compiler.Syntax; | ||
var Token = sc.lang.compiler.Token; | ||
|
||
describe("sc.lang.compiler.CodeGen", function() { | ||
describe("BlockExpression", function() { | ||
sc.test.codegen().each([ | ||
{ | ||
code: "(var a = 10; a)", | ||
expected: "(function() { var $a; $a = $.Integer(10); return $a; })()", | ||
ast: { | ||
type: Syntax.BlockExpression, | ||
body: [ | ||
{ | ||
type: Syntax.VariableDeclaration, | ||
kind: "var", | ||
declarations: [ | ||
{ | ||
type: Syntax.VariableDeclarator, | ||
id: { | ||
type: Syntax.Identifier, | ||
name: "a" | ||
}, | ||
init: { | ||
type: Syntax.Literal, | ||
value: "10", | ||
valueType: Token.IntegerLiteral | ||
} | ||
} | ||
] | ||
}, | ||
{ | ||
type: Syntax.Identifier, | ||
name: "a" | ||
} | ||
] | ||
} | ||
}, | ||
]); | ||
}); | ||
}); | ||
})(); |
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
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
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,24 @@ | ||
(function(sc) { | ||
"use strict"; | ||
|
||
require("./parser"); | ||
|
||
var Node = sc.lang.compiler.Node; | ||
var Parser = sc.lang.compiler.Parser; | ||
|
||
Parser.addParseMethod("BlockExpression", function() { | ||
var marker = this.createMarker(); | ||
|
||
this.expect("("); | ||
|
||
var expr = this.withScope(function() { | ||
return Node.createBlockExpression( | ||
this.parseFunctionBody() | ||
); | ||
}); | ||
|
||
this.expect(")"); | ||
|
||
return marker.update().apply(expr); | ||
}); | ||
})(sc); |
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,69 @@ | ||
(function() { | ||
"use strict"; | ||
|
||
require("./"); | ||
|
||
var Syntax = sc.lang.compiler.Syntax; | ||
var Token = sc.lang.compiler.Token; | ||
var Message = sc.lang.compiler.Message; | ||
var strlib = sc.libs.strlib; | ||
|
||
describe("sc.lang.compiler.Parser", function() { | ||
describe("parseBlockExpression", function() { | ||
sc.test.compile(this.title).each({ | ||
"(var a = 10;)": sc.test.OK, | ||
"var a = 10;": strlib.format(Message.UnexpectedKeyword, "var"), | ||
}); | ||
sc.test.parse(this.title).each({ | ||
"(var a = 10;)": { | ||
type: Syntax.BlockExpression, | ||
body: [ | ||
{ | ||
type: Syntax.VariableDeclaration, | ||
kind: "var", | ||
declarations: [ | ||
{ | ||
type: Syntax.VariableDeclarator, | ||
id: { | ||
type: Syntax.Identifier, | ||
name: "a", | ||
range: [ 5, 6 ], | ||
loc: { | ||
start: { line: 1, column: 5 }, | ||
end: { line: 1, column: 6 } | ||
} | ||
}, | ||
init: { | ||
type: Syntax.Literal, | ||
value: "10", | ||
valueType: Token.IntegerLiteral, | ||
range: [ 9, 11 ], | ||
loc: { | ||
start: { line: 1, column: 9 }, | ||
end: { line: 1, column: 11 } | ||
} | ||
}, | ||
range: [ 5, 11 ], | ||
loc: { | ||
start: { line: 1, column: 5 }, | ||
end: { line: 1, column: 11 } | ||
} | ||
} | ||
], | ||
range: [ 1, 11 ], | ||
loc: { | ||
start: { line: 1, column: 1 }, | ||
end: { line: 1, column: 11 } | ||
}, | ||
} | ||
], | ||
range: [ 0, 13 ], | ||
loc: { | ||
start: { line: 1, column: 0 }, | ||
end: { line: 1, column: 13 } | ||
} | ||
} | ||
}); | ||
}); | ||
}); | ||
})(); |
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
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