Browse files

All nodes have position and filename, refactored a bit

  • Loading branch information...
1 parent 986df56 commit 761bfd0ff97e4f137da08985a034e587e4dd874b @txus committed Sep 22, 2011
View
125 lib/noscript/ast.rb
@@ -49,9 +49,9 @@ def initialize(receiver, lhs, rhs)
def compile(context)
val = rhs.compile(context)
- if receiver
+ if @receiver
# rcv.a = 3 sets a slot on rcv to 3
- rcv = receiver.compile(context)
+ rcv = @receiver.compile(context)
rcv.add_slot(lhs.name, val)
elsif context.current_receiver && lhs.deref
# @foo = 'bar' sets a slot on the current receiver.foo to 'bar'
@@ -237,20 +237,34 @@ def raise_argument_error(args)
end
end
- class FunCall < Struct.new(:name, :arguments)
+ class FunctionCall < Node
+ attr_reader :name, :arguments
+
+ def initialize(name, arguments)
+ @name = name
+ @arguments = arguments
+ end
+
def compile(context)
self
end
end
- class Message < Struct.new(:receiver, :slot)
+ class Message < Node
+ attr_reader :receiver, :slot
+
+ def initialize(receiver, slot)
+ @receiver = receiver
+ @slot = slot
+ end
+
def compile(context)
ctx = Context.new(context)
ctx.current_receiver = context.current_receiver
- if receiver
+ if @receiver
# rcv.foo() looks up the message in the receiver slots
- rcv = receiver.compile(context)
+ rcv = @receiver.compile(context)
# Save a reference to the current receiver
ctx.current_receiver = rcv
@@ -283,25 +297,37 @@ def arguments
end
def call?
- slot.is_a?(FunCall)
+ slot.is_a?(FunctionCall)
end
end
- class Exception < StandardError
- end
+ class IfNode < Node
+ attr_reader :expression, :body, :else_body
+
+ def initialize(expression, body, else_body=nil)
+ @expression = expression
+ @body = body
+ @else_body = else_body
+ end
- class IfNode < Struct.new(:expression, :body, :else_body)
def compile(context)
- result = expression.compile(context)
+ result = @expression.compile(context)
if result
- body.compile(context)
+ @body.compile(context)
elsif else_body
- else_body.compile(context)
+ @else_body.compile(context)
end
end
end
- class WhileNode < Struct.new(:expression, :body)
+ class WhileNode < Node
+ attr_reader :expression, :body
+
+ def initialize(expression, body)
+ @expression = expression
+ @body = body
+ end
+
def compile(context)
while expression.compile(context)
body.compile(context)
@@ -311,37 +337,43 @@ def compile(context)
## ARITHMETIC
- class Digit < Struct.new(:val)
+ class Integer < Node
+ attr_reader :value
+
+ def initialize(value)
+ @value = value
+ end
+
def -@
- Digit.new(-to_i)
+ Integer.new(-to_i)
end
def +(num)
- Digit.new num.to_i + to_i
+ Integer.new num.to_i + to_i
end
def -(num)
- Digit.new to_i - num.to_i
+ Integer.new to_i - num.to_i
end
def *(num)
- Digit.new to_i * num.to_i
+ Integer.new to_i * num.to_i
end
def /(num)
- Digit.new to_i / num.to_i
+ Integer.new to_i / num.to_i
end
def compile(context)
self
end
def to_s
- val.to_s
+ @value.to_s
end
def to_i
- val.to_i
+ @value.to_i
end
# Boolean comparisons
@@ -371,74 +403,91 @@ def !=(num)
end
end
- class AddNode < Struct.new(:lhs, :rhs)
+ class BinaryOperation < Node
+ attr_reader :lhs, :rhs
+
+ def initialize(lhs, rhs)
+ @lhs = lhs
+ @rhs = rhs
+ end
+ end
+
+ class UnaryMinus < Node
+ attr_reader :value
+ def initialize(value)
+ @value = value
+ end
+
def compile(context)
- lhs.compile(context) + rhs.compile(context)
+ -(value.compile(context))
end
end
- class SubtractNode < Struct.new(:lhs, :rhs)
+ class AddNode < BinaryOperation
def compile(context)
- lhs.compile(context) - rhs.compile(context)
+ lhs.compile(context) + rhs.compile(context)
end
end
- class MultiplicationNode < Struct.new(:lhs, :rhs)
+ class SubtractNode < BinaryOperation
def compile(context)
- lhs.compile(context) * rhs.compile(context)
+ lhs.compile(context) - rhs.compile(context)
end
end
- class DivisionNode < Struct.new(:lhs, :rhs)
+ class MultiplicationNode < BinaryOperation
def compile(context)
- lhs.compile(context) / rhs.compile(context)
+ lhs.compile(context) * rhs.compile(context)
end
end
- class UnaryMinus < Struct.new(:val)
+ class DivisionNode < BinaryOperation
def compile(context)
- -(val.compile(context))
+ lhs.compile(context) / rhs.compile(context)
end
end
# Boolean expressions
- class EqualityExpression < Struct.new(:lhs, :rhs)
+ class EqualityExpression < BinaryOperation
def compile(context)
lhs.compile(context) == rhs.compile(context)
end
end
- class InequalityExpression < Struct.new(:lhs, :rhs)
+ class InequalityExpression < BinaryOperation
def compile(context)
!(lhs.compile(context) == rhs.compile(context))
end
end
- class GtExpression < Struct.new(:lhs, :rhs)
+ class GtExpression < BinaryOperation
def compile(context)
lhs.compile(context) > rhs.compile(context)
end
end
- class GteExpression < Struct.new(:lhs, :rhs)
+ class GteExpression < BinaryOperation
def compile(context)
lhs.compile(context) >= rhs.compile(context)
end
end
- class LtExpression < Struct.new(:lhs, :rhs)
+ class LtExpression < BinaryOperation
def compile(context)
lhs.compile(context) < rhs.compile(context)
end
end
- class LteExpression < Struct.new(:lhs, :rhs)
+ class LteExpression < BinaryOperation
def compile(context)
lhs.compile(context) <= rhs.compile(context)
end
end
+ class Exception < StandardError
+ end
+
end
end
View
44 lib/noscript/parser/noscript.racc
@@ -17,21 +17,21 @@ rule
assignment : identifier '.' identifier ASSIGN statement { result = AST::Assignment.new(val[0], val[2], val[4]); result.pos(filename, lineno) }
| identifier ASSIGN statement { result = AST::Assignment.new(nil, val[0], val[2]); result.pos(filename, lineno) }
- fun_definition : FUN parameter_list end_of_statement statements END { result = AST::Function.new(val[1], val[3]) }
+ fun_definition : FUN parameter_list end_of_statement statements END { result = AST::Function.new(val[1], val[3]); result.pos(filename, lineno) }
- message : identifier '.' identifier { result = AST::Message.new(val[0], val[2]) }
- | identifier '.' fun_call { result = AST::Message.new(val[0], val[2]) }
- | fun_call { result = AST::Message.new(nil, val[0]) }
+ message : identifier '.' identifier { result = AST::Message.new(val[0], val[2]); result.pos(filename, lineno) }
+ | identifier '.' fun_call { result = AST::Message.new(val[0], val[2]); result.pos(filename, lineno) }
+ | fun_call { result = AST::Message.new(nil, val[0]); result.pos(filename, lineno) }
- if_else : IF expression end_of_statement statements ELSE end_of_statement statements END { result = AST::IfNode.new(val[1], val[3], val[6]) }
- | IF expression end_of_statement statements END { result = AST::IfNode.new(val[1], val[3]) }
+ if_else : IF expression end_of_statement statements ELSE end_of_statement statements END { result = AST::IfNode.new(val[1], val[3], val[6]); result.pos(filename, lineno) }
+ | IF expression end_of_statement statements END { result = AST::IfNode.new(val[1], val[3]); result.pos(filename, lineno) }
- while : WHILE expression end_of_statement statements END { result = AST::WhileNode.new(val[1], val[3]) }
+ while : WHILE expression end_of_statement statements END { result = AST::WhileNode.new(val[1], val[3]); result.pos(filename, lineno) }
identifier : IDENTIFIER { result = AST::Identifier.new(val[0]); result.pos(filename, lineno) }
| DEREF { result = AST::Identifier.new(val[0], true); result.pos(filename, lineno) }
- digit : DIGIT { result = AST::Digit.new(val[0]) }
+ integer : INTEGER { result = AST::Integer.new(val[0]); result.pos(filename, lineno) }
string : STRING { result = AST::String.new(val[0]); result.pos(filename, lineno) }
tuple : '{' tuple_elements '}' { result = AST::Tuple.new(val[1]); result.pos(filename, lineno) }
array : '[' array_elements ']' { result = AST::Array.new(val[1]); result.pos(filename, lineno) }
@@ -52,7 +52,7 @@ rule
| array_element { result = [val[0]] }
| array_elements COMMA array_element { result.push(val[2]) }
- literal : digit
+ literal : integer
| string
| tuple
| array
@@ -75,12 +75,12 @@ rule
| parameter { result = [val[0]] }
| parameter_list COMMA parameter { result.push(val[2]) }
- boolean_exp : op_member EQUALS op_member { result = AST::EqualityExpression.new(val[0], val[2]) }
- | op_member NEQUALS op_member { result = AST::InequalityExpression.new(val[0], val[2]) }
- | op_member GT_OP op_member { result = AST::GtExpression.new(val[0], val[2]) }
- | op_member GTE_OP op_member { result = AST::GteExpression.new(val[0], val[2]) }
- | op_member LT_OP op_member { result = AST::LtExpression.new(val[0], val[2]) }
- | op_member LTE_OP op_member { result = AST::LteExpression.new(val[0], val[2]) }
+ boolean_exp : op_member EQUALS op_member { result = AST::EqualityExpression.new(val[0], val[2]); result.pos(filename, lineno) }
+ | op_member NEQUALS op_member { result = AST::InequalityExpression.new(val[0], val[2]); result.pos(filename, lineno) }
+ | op_member GT_OP op_member { result = AST::GtExpression.new(val[0], val[2]); result.pos(filename, lineno) }
+ | op_member GTE_OP op_member { result = AST::GteExpression.new(val[0], val[2]); result.pos(filename, lineno) }
+ | op_member LT_OP op_member { result = AST::LtExpression.new(val[0], val[2]); result.pos(filename, lineno) }
+ | op_member LTE_OP op_member { result = AST::LteExpression.new(val[0], val[2]); result.pos(filename, lineno) }
| boolean_literal
boolean_literal : TRUE { result = true }
@@ -100,18 +100,18 @@ rule
| op_member
| statement end_of_statement
- op_member : digit
+ op_member : integer
| identifier
| boolean_literal
| message
| operation
- operation : op_member '+' op_member { result = AST::AddNode.new(val[0], val[2]) }
- | op_member '-' op_member { result = AST::SubtractNode.new(val[0], val[2]) }
- | op_member '*' op_member { result = AST::MultiplicationNode.new(val[0], val[2]) }
- | op_member '/' op_member { result = AST::DivisionNode.new(val[0], val[2]) }
+ operation : op_member '+' op_member { result = AST::AddNode.new(val[0], val[2]); result.pos(filename, lineno) }
+ | op_member '-' op_member { result = AST::SubtractNode.new(val[0], val[2]); result.pos(filename, lineno) }
+ | op_member '*' op_member { result = AST::MultiplicationNode.new(val[0], val[2]); result.pos(filename, lineno) }
+ | op_member '/' op_member { result = AST::DivisionNode.new(val[0], val[2]); result.pos(filename, lineno) }
| LPAREN op_member RPAREN { result = val[1] }
- | '-' op_member =UMINUS { result = AST::UnaryMinus.new(val[1]) }
+ | '-' op_member =UMINUS { result = AST::UnaryMinus.new(val[1]); result.pos(filename, lineno) } }
statements : { result = AST::Nodes.new([]); result.pos(filename, lineno) }
| statement { result = AST::Nodes.new([val[0]]); result.pos(filename, lineno) }
@@ -121,7 +121,7 @@ rule
fun_call : identifier LPAREN argument_list RPAREN
{
- result = AST::FunCall.new(val[0], val[2])
+ result = AST::FunctionCall.new(val[0], val[2]); result.pos(filename, lineno)
}
View
2 lib/noscript/parser/noscript.rex
@@ -9,7 +9,7 @@ macro
BLANK [\ ]
rule
[\n]+[\s]* { [:NEWLINE, text] }
- \d+ { [:DIGIT, text.to_i] }
+ \d+ { [:INTEGER, text.to_i] }
== { [:EQUALS, text] }
!= { [:NEQUALS, text] }
View
2 lib/noscript/parser/noscript.rex.rb
@@ -67,7 +67,7 @@ def _next_token
action { [:NEWLINE, text] }
when (text = @ss.scan(/\d+/))
- action { [:DIGIT, text.to_i] }
+ action { [:INTEGER, text.to_i] }
when (text = @ss.scan(/==/))
action { [:EQUALS, text] }
View
24 lib/noscript/parser/noscript.tab.rb
@@ -412,7 +412,7 @@ class Parser < Racc::Parser
:WHILE => 13,
:IDENTIFIER => 14,
:DEREF => 15,
- :DIGIT => 16,
+ :INTEGER => 16,
:STRING => 17,
"{" => 18,
"}" => 19,
@@ -471,7 +471,7 @@ class Parser < Racc::Parser
"WHILE",
"IDENTIFIER",
"DEREF",
- "DIGIT",
+ "INTEGER",
"STRING",
"\"{\"",
"\"}\"",
@@ -506,7 +506,7 @@ class Parser < Racc::Parser
"if_else",
"expression",
"while",
- "digit",
+ "integer",
"string",
"tuple",
"tuple_elements",
@@ -554,49 +554,49 @@ def _reduce_4(val, _values, result)
module_eval(<<'.,.,', 'noscript.racc', 19)
def _reduce_5(val, _values, result)
- result = AST::Function.new(val[1], val[3])
+ result = AST::Function.new(val[1], val[3]); result.pos(filename, lineno)
result
end
.,.,
module_eval(<<'.,.,', 'noscript.racc', 21)
def _reduce_6(val, _values, result)
- result = AST::Message.new(val[0], val[2])
+ result = AST::Message.new(val[0], val[2]); result.pos(filename, lineno)
result
end
.,.,
module_eval(<<'.,.,', 'noscript.racc', 22)
def _reduce_7(val, _values, result)
- result = AST::Message.new(val[0], val[2])
+ result = AST::Message.new(val[0], val[2]); result.pos(filename, lineno)
result
end
.,.,
module_eval(<<'.,.,', 'noscript.racc', 23)
def _reduce_8(val, _values, result)
- result = AST::Message.new(nil, val[0])
+ result = AST::Message.new(nil, val[0]); result.pos(filename, lineno)
result
end
.,.,
module_eval(<<'.,.,', 'noscript.racc', 25)
def _reduce_9(val, _values, result)
- result = AST::IfNode.new(val[1], val[3], val[6])
+ result = AST::IfNode.new(val[1], val[3], val[6]); result.pos(filename, lineno)
result
end
.,.,
module_eval(<<'.,.,', 'noscript.racc', 26)
def _reduce_10(val, _values, result)
- result = AST::IfNode.new(val[1], val[3])
+ result = AST::IfNode.new(val[1], val[3]); result.pos(filename, lineno)
result
end
.,.,
module_eval(<<'.,.,', 'noscript.racc', 28)
def _reduce_11(val, _values, result)
- result = AST::WhileNode.new(val[1], val[3])
+ result = AST::WhileNode.new(val[1], val[3]); result.pos(filename, lineno)
result
end
.,.,
@@ -617,7 +617,7 @@ def _reduce_13(val, _values, result)
module_eval(<<'.,.,', 'noscript.racc', 33)
def _reduce_14(val, _values, result)
- result = AST::Digit.new(val[0])
+ result = AST::Integer.new(val[0]); result.pos(filename, lineno)
result
end
.,.,
@@ -964,7 +964,7 @@ def _reduce_82(val, _values, result)
module_eval(<<'.,.,', 'noscript.racc', 123)
def _reduce_85(val, _values, result)
- result = AST::FunCall.new(val[0], val[2])
+ result = AST::FunctionCall.new(val[0], val[2]); result.pos(filename, lineno)
result
end
View
14 test/ast/assignment_test.rb
@@ -10,29 +10,29 @@ def test_literal_assignment
@node = Noscript::AST::Assignment.new(
nil,
Noscript::AST::Identifier.new('a'),
- Noscript::AST::Digit.new(3)
+ Noscript::AST::Integer.new(3)
)
@node.compile(@context)
- assert_equal Noscript::AST::Digit.new(3), @context.lookup_var('a')
+ assert_equal Noscript::AST::Integer.new(3), @context.lookup_var('a')
end
def test_expression_assignment
- @context.store_var(:a, Noscript::AST::Digit.new(5))
+ @context.store_var(:a, Noscript::AST::Integer.new(5))
@node = Noscript::AST::Assignment.new(
nil,
Noscript::AST::Identifier.new('a'),
Noscript::AST::SubtractNode.new(
Noscript::AST::Identifier.new('a'),
- Noscript::AST::Digit.new('3'),
+ Noscript::AST::Integer.new('3'),
)
)
@node.compile(@context)
- assert_equal Noscript::AST::Digit.new(2), @context.lookup_var('a')
+ assert_equal Noscript::AST::Integer.new(2), @context.lookup_var('a')
end
def test_slot_assignment
@@ -42,11 +42,11 @@ def test_slot_assignment
@node = Noscript::AST::Assignment.new(
Noscript::AST::Identifier.new('foo'),
Noscript::AST::Identifier.new('a'),
- Noscript::AST::Digit.new('3'),
+ Noscript::AST::Integer.new('3'),
)
@node.compile(@context)
- assert_equal Noscript::AST::Digit.new(3), @object.slots['a']
+ assert_equal Noscript::AST::Integer.new(3), @object.slots['a']
end
end
View
10 test/ast/message_test.rb
@@ -11,11 +11,11 @@ def setup
# BODY
Noscript::AST::Nodes.new([
- Noscript::AST::Digit.new(74)
+ Noscript::AST::Integer.new(74)
])
)
@object.add_slot('bar', @function)
- @object.add_slot('baz', Digit.new(99))
+ @object.add_slot('baz', Integer.new(99))
@context.store_var('foo', @object)
end
@@ -35,14 +35,14 @@ def test_message_call_with_empty_parens_calls_the_function
# foo.bar(9)
@message = Noscript::AST::Message.new(
Noscript::AST::Identifier.new('foo'),
- Noscript::AST::FunCall.new(
+ Noscript::AST::FunctionCall.new(
Identifier.new('bar'),
- [Digit.new(9)]
+ [Integer.new(9)]
)
)
retval = @message.compile(@context)
- assert_equal Digit.new(74), retval
+ assert_equal Integer.new(74), retval
end
end
View
2 test/ast/string_interpolation_test.rb
@@ -4,7 +4,7 @@ class StringInterpolationTest < MiniTest::Unit::TestCase
def setup
@context = Noscript::Context.new
- @context.store_var('foo', Noscript::AST::Digit.new(3))
+ @context.store_var('foo', Noscript::AST::Integer.new(3))
end
def test_string_interpolation
View
2 test/integration_test.rb
@@ -109,7 +109,7 @@ def test_while
"""
].each do |code|
compiles(code) do |retval|
- assert_equal Noscript::AST::Digit.new(0), retval
+ assert_equal Noscript::AST::Integer.new(0), retval
end
end
end
View
12 test/lexer/integration_test.rb
@@ -15,12 +15,12 @@ def test_arithmetic_assignment
[:IDENTIFIER, 'foo'],
[:ASSIGN, '='],
[:LPAREN, '('],
- [:DIGIT, 3],
+ [:INTEGER, 3],
['+', '+'],
- [:DIGIT, 4],
+ [:INTEGER, 4],
[:RPAREN, ')'],
['*', '*'],
- [:DIGIT, 2],
+ [:INTEGER, 2],
]
end
@@ -29,7 +29,7 @@ def test_if
[:IF, 'if'],
[:IDENTIFIER, 'foo'],
[:EQUALS, '=='],
- [:DIGIT, 3],
+ [:INTEGER, 3],
[:NEWLINE, "\n "],
[:STRING, 'lorem'],
[:NEWLINE, "\n "],
@@ -42,7 +42,7 @@ def test_if_else
[:IF, 'if'],
[:IDENTIFIER, 'foo'],
[:EQUALS, '=='],
- [:DIGIT, 3],
+ [:INTEGER, 3],
[:NEWLINE, "\n "],
[:STRING, 'lorem'],
[:NEWLINE, "\n "],
@@ -59,7 +59,7 @@ def test_while
[:WHILE, 'while'],
[:IDENTIFIER, 'foo'],
[:GT_OP, '>'],
- [:DIGIT, 3],
+ [:INTEGER, 3],
[:NEWLINE, "\n "],
[:STRING, 'lorem'],
[:NEWLINE, "\n "],
View
4 test/lexer/lexer_test.rb
@@ -15,8 +15,8 @@ def test_ignores_whitespace
end
def test_digit
- tokenizes "3", [[:DIGIT, 3]]
- tokenizes "3234", [[:DIGIT, 3234]]
+ tokenizes "3", [[:INTEGER, 3]]
+ tokenizes "3234", [[:INTEGER, 3234]]
end
def test_assign
View
30 test/method_test.rb
@@ -16,7 +16,7 @@ def setup
[
Noscript::AST::DefaultParameter.new(
Noscript::AST::Identifier.new('bar'),
- Noscript::AST::Digit.new(23)
+ Noscript::AST::Integer.new(23)
)
],
@@ -25,15 +25,15 @@ def setup
Noscript::AST::Assignment.new(
nil,
Noscript::AST::Identifier.new('a'),
- Noscript::AST::Digit.new(3)
+ Noscript::AST::Integer.new(3)
),
- Noscript::AST::Digit.new(74)
+ Noscript::AST::Integer.new(74)
])
)
end
def test_method_returns_last_value
- assert_equal Noscript::AST::Digit.new(74), @method.call(@context)
+ assert_equal Noscript::AST::Integer.new(74), @method.call(@context)
end
def test_method_local_scope
@@ -49,10 +49,10 @@ def test_method_using_default_param
@method.body.nodes.push(
Noscript::AST::AddNode.new(
Noscript::AST::Identifier.new('bar'),
- Noscript::AST::Digit.new(2),
+ Noscript::AST::Integer.new(2),
)
)
- assert_equal Noscript::AST::Digit.new(25), @method.call(@context)
+ assert_equal Noscript::AST::Integer.new(25), @method.call(@context)
end
def test_method_overriding_default_param
@@ -63,10 +63,10 @@ def test_method_overriding_default_param
@method.body.nodes.push(
Noscript::AST::AddNode.new(
Noscript::AST::Identifier.new('bar'),
- Noscript::AST::Digit.new(2),
+ Noscript::AST::Integer.new(2),
)
)
- assert_equal Noscript::AST::Digit.new(100), @method.call(@context, Noscript::AST::Digit.new(98))
+ assert_equal Noscript::AST::Integer.new(100), @method.call(@context, Noscript::AST::Integer.new(98))
end
def test_method_using_local_var
@@ -77,10 +77,10 @@ def test_method_using_local_var
@method.body.nodes.push(
Noscript::AST::AddNode.new(
Noscript::AST::Identifier.new('a'),
- Noscript::AST::Digit.new(2),
+ Noscript::AST::Integer.new(2),
)
)
- assert_equal Noscript::AST::Digit.new(5), @method.call(@context)
+ assert_equal Noscript::AST::Integer.new(5), @method.call(@context)
end
def test_method_with_too_few_arguments
@@ -100,7 +100,7 @@ def test_method_with_too_few_arguments
def test_method_with_too_many_arguments
assert_raises RuntimeError, "This function expected 1 arguments, not 2" do
- @method.call(@context, Noscript::AST::Digit.new(10), Noscript::AST::Digit.new(9))
+ @method.call(@context, Noscript::AST::Integer.new(10), Noscript::AST::Integer.new(9))
end
end
@@ -114,11 +114,11 @@ def test_method_with_dereferencing
Noscript::AST::Identifier.new('foo', true)
)
object = Noscript::Object.new
- object.add_slot('foo', Noscript::AST::Digit.new(123))
+ object.add_slot('foo', Noscript::AST::Integer.new(123))
@context.current_receiver = object
- assert_equal Noscript::AST::Digit.new(123), @method.call(@context)
+ assert_equal Noscript::AST::Integer.new(123), @method.call(@context)
end
def test_method_with_dereferencing_on_the_call
@@ -133,11 +133,11 @@ def test_method_with_dereferencing_on_the_call
Noscript::AST::Identifier.new('bar')
)
object = Noscript::Object.new
- object.add_slot('baz', Noscript::AST::Digit.new(123))
+ object.add_slot('baz', Noscript::AST::Integer.new(123))
@context.current_receiver = object
- assert_equal Noscript::AST::Digit.new(123), @method.call(@context, Noscript::AST::Identifier.new('baz', true))
+ assert_equal Noscript::AST::Integer.new(123), @method.call(@context, Noscript::AST::Identifier.new('baz', true))
end
end
View
12 test/object_test.rb
@@ -16,35 +16,35 @@ def test_clone
def test_clone_with_tuple
tuple = Noscript::AST::Tuple.new({
- 'foo' => Noscript::AST::Digit.new(99),
+ 'foo' => Noscript::AST::Integer.new(99),
'bar' => Noscript::AST::String.new('hey'),
})
child = @object.send('clone').call(@context, tuple)
assert_equal(@object, child.parent)
assert_includes(child.slots.keys, 'clone')
- assert_equal Noscript::AST::Digit.new(99), child.send('foo')
+ assert_equal Noscript::AST::Integer.new(99), child.send('foo')
assert_equal Noscript::AST::String.new('hey'), child.send('bar')
end
def test_uses
trait = Noscript::Trait.new(Noscript::AST::Tuple.new({
- 'foo' => lambda { |*| Noscript::AST::Digit.new(3) }
+ 'foo' => lambda { |*| Noscript::AST::Integer.new(3) }
}))
@context.store_var('FooTrait', trait)
@object.send('uses').call(@context, Noscript::AST::Identifier.new('FooTrait'))
- assert_equal Noscript::AST::Digit.new(3), @object.send('foo').call(@context)
+ assert_equal Noscript::AST::Integer.new(3), @object.send('foo').call(@context)
end
def test_each
results = {}
@fun = lambda { |ctx, k, v| results[k.to_s] = v.to_i * 2 }
def @fun.compile(*); self; end
- @object.add_slot('foo', Noscript::AST::Digit.new(90))
- @object.add_slot('bar', Noscript::AST::Digit.new(20))
+ @object.add_slot('foo', Noscript::AST::Integer.new(90))
+ @object.add_slot('bar', Noscript::AST::Integer.new(20))
@object.send('each').call(@context, @fun)
View
4 test/parser/array_test.rb
@@ -18,7 +18,7 @@ def test_array_with_one_element
array = nodes.first
assert_kind_of Noscript::AST::Array, array
- assert_equal([Digit.new(1)], array.body)
+ assert_equal([Integer.new(1)], array.body)
end
end
@@ -27,7 +27,7 @@ def test_array_with_multiple_elements
array = nodes.first
assert_kind_of Noscript::AST::Array, array
- assert_equal([Digit.new(1), Digit.new(2)], array.body)
+ assert_equal([Integer.new(1), Integer.new(2)], array.body)
end
end
View
20 test/parser/assignment_test.rb
@@ -35,12 +35,12 @@ def test_operation_assignment
multiplication = assignment.rhs
assert_kind_of MultiplicationNode, multiplication
- assert_equal Digit.new(4), multiplication.rhs
+ assert_equal Integer.new(4), multiplication.rhs
parens_op = multiplication.lhs
assert_kind_of AddNode, parens_op
- assert_equal Digit.new(3), parens_op.lhs
- assert_equal Digit.new(3), parens_op.rhs
+ assert_equal Integer.new(3), parens_op.lhs
+ assert_equal Integer.new(3), parens_op.rhs
end
end
@@ -54,7 +54,7 @@ def test_double_assignment
assert_kind_of Assignment, other_assignment
assert_equal Identifier.new('b'), other_assignment.lhs
- assert_equal Digit.new(3), other_assignment.rhs
+ assert_equal Integer.new(3), other_assignment.rhs
end
end
@@ -66,7 +66,7 @@ def test_assignment_with_message
message = assignment.rhs
assert_kind_of Message, message
- assert_equal Message.new(nil, FunCall.new(Identifier.new('foo'), [])), message
+ assert_equal Message.new(nil, FunctionCall.new(Identifier.new('foo'), [])), message
end
end
@@ -81,7 +81,7 @@ def test_assignment_with_function_definition
assert_equal [Identifier.new('b'), Identifier.new('c')], function.params
body = function.body.nodes
- assert_equal [Digit.new(3)], body
+ assert_equal [Integer.new(3)], body
end
end
@@ -91,7 +91,7 @@ def test_assignment_with_semicolon
assert_kind_of Assignment, assignment
assert_equal Identifier.new('a'), assignment.lhs
- assert_equal Digit.new(3), assignment.rhs
+ assert_equal Integer.new(3), assignment.rhs
end
end
@@ -101,7 +101,7 @@ def test_assignment_with_newline
assert_kind_of Assignment, assignment
assert_equal Identifier.new('a'), assignment.lhs
- assert_equal Digit.new(3), assignment.rhs
+ assert_equal Integer.new(3), assignment.rhs
end
end
@@ -113,7 +113,7 @@ def test_assignment_with_expression
assert_equal Identifier.new('a'), assignment.lhs
assert_equal SubtractNode.new(
Identifier.new('a'),
- Digit.new(3)
+ Integer.new(3)
), assignment.rhs
end
end
@@ -125,7 +125,7 @@ def test_slot_assignment
assert_equal Identifier.new('foo'), assignment.receiver
assert_equal Identifier.new('a'), assignment.lhs
- assert_equal Digit.new(3), assignment.rhs
+ assert_equal Integer.new(3), assignment.rhs
end
end
end
View
12 test/parser/boolean_expressions_test.rb
@@ -10,7 +10,7 @@ def test_equality
assert_kind_of EqualityExpression, exp
assert_equal Identifier.new('foo'), exp.lhs
- assert_equal Digit.new(3), exp.rhs
+ assert_equal Integer.new(3), exp.rhs
end
end
@@ -20,7 +20,7 @@ def test_inequality
assert_kind_of InequalityExpression, exp
assert_equal Identifier.new('foo'), exp.lhs
- assert_equal Digit.new(3), exp.rhs
+ assert_equal Integer.new(3), exp.rhs
end
end
@@ -30,7 +30,7 @@ def test_gt
assert_kind_of GtExpression, exp
assert_equal Identifier.new('foo'), exp.lhs
- assert_equal Digit.new(3), exp.rhs
+ assert_equal Integer.new(3), exp.rhs
end
end
@@ -40,7 +40,7 @@ def test_gte
assert_kind_of GteExpression, exp
assert_equal Identifier.new('foo'), exp.lhs
- assert_equal Digit.new(3), exp.rhs
+ assert_equal Integer.new(3), exp.rhs
end
end
@@ -50,7 +50,7 @@ def test_lt
assert_kind_of LtExpression, exp
assert_equal Identifier.new('foo'), exp.lhs
- assert_equal Digit.new(3), exp.rhs
+ assert_equal Integer.new(3), exp.rhs
end
end
@@ -60,7 +60,7 @@ def test_lte
assert_kind_of LteExpression, exp
assert_equal Identifier.new('foo'), exp.lhs
- assert_equal Digit.new(3), exp.rhs
+ assert_equal Integer.new(3), exp.rhs
end
end
View
8 test/parser/function_test.rb
@@ -12,7 +12,7 @@ def test_fun_without_args
assert_equal [], fun.params
body = fun.body.nodes
- assert_equal [Digit.new(3)], body
+ assert_equal [Integer.new(3)], body
end
end
@@ -24,7 +24,7 @@ def test_fun_with_one_param
assert_equal [Identifier.new('bar')], fun.params
body = fun.body.nodes
- assert_equal [Digit.new(3)], body
+ assert_equal [Integer.new(3)], body
end
end
@@ -36,7 +36,7 @@ def test_fun_with_multiple_params
assert_equal [Identifier.new('bar'), Identifier.new('baz')], fun.params
body = fun.body.nodes
- assert_equal [Digit.new(3)], body
+ assert_equal [Integer.new(3)], body
end
end
@@ -54,7 +54,7 @@ def test_fun_with_default_param
], fun.params
body = fun.body.nodes
- assert_equal [Digit.new(3)], body
+ assert_equal [Integer.new(3)], body
end
end
end
View
10 test/parser/if_test.rb
@@ -13,9 +13,9 @@ def test_if
exp = if_node.expression
assert_kind_of EqualityExpression, exp
assert_equal Identifier.new('foo'), exp.lhs
- assert_equal Digit.new(3), exp.rhs
+ assert_equal Integer.new(3), exp.rhs
- assert_equal [Digit.new(3)], if_node.body.nodes
+ assert_equal [Integer.new(3)], if_node.body.nodes
end
end
@@ -28,10 +28,10 @@ def test_if_with_else
exp = if_node.expression
assert_kind_of InequalityExpression, exp
assert_equal Identifier.new('foo'), exp.lhs
- assert_equal Digit.new(3), exp.rhs
+ assert_equal Integer.new(3), exp.rhs
- assert_equal [Digit.new(3)], if_node.body.nodes
- assert_equal [Digit.new(4)], if_node.else_body.nodes
+ assert_equal [Integer.new(3)], if_node.body.nodes
+ assert_equal [Integer.new(4)], if_node.else_body.nodes
end
end
View
6 test/parser/message_test.rb
@@ -21,7 +21,7 @@ def test_message_without_arguments
assert_kind_of Message, message
assert_equal Identifier.new('a'), message.receiver
- assert_equal FunCall.new(Identifier.new('foo'), []), message.slot
+ assert_equal FunctionCall.new(Identifier.new('foo'), []), message.slot
assert message.call?
end
end
@@ -32,11 +32,11 @@ def test_message_with_arguments
assert_kind_of Message, message
assert_equal Identifier.new('a'), message.receiver
- assert_equal FunCall.new(
+ assert_equal FunctionCall.new(
Identifier.new('foo'),
[
String.new('hey'),
- Digit.new(34)
+ Integer.new(34)
]
), message.slot
assert message.call?
View
8 test/parser/method_call_test.rb
@@ -22,7 +22,7 @@ def test_call_message_with_args
assert_kind_of Message, message
refute message.receiver
assert_equal Identifier.new('foo'), message.name
- assert_equal [String.new('hey'), Digit.new(34)], message.arguments
+ assert_equal [String.new('hey'), Integer.new(34)], message.arguments
end
end
@@ -36,10 +36,10 @@ def test_call_message_with_arithmetic
assert_equal Identifier.new('foo'), message.name
assert_equal [
MultiplicationNode.new(
- Digit.new(3),
- Digit.new(2)
+ Integer.new(3),
+ Integer.new(2)
),
- Digit.new(9)
+ Integer.new(9)
], message.arguments
end
end
View
4 test/parser/tuple_test.rb
@@ -18,7 +18,7 @@ def test_tuple_with_one_element
tuple = nodes.first
assert_kind_of Tuple, tuple
- assert_equal({'a' => Digit.new(1)}, tuple.body)
+ assert_equal({'a' => Integer.new(1)}, tuple.body)
end
end
@@ -27,7 +27,7 @@ def test_tuple_with_multiple_elements
tuple = nodes.first
assert_kind_of Tuple, tuple
- assert_equal({'a' => Digit.new(1), 'b' => Digit.new(2)}, tuple.body)
+ assert_equal({'a' => Integer.new(1), 'b' => Integer.new(2)}, tuple.body)
end
end
View
4 test/parser/while_test.rb
@@ -13,9 +13,9 @@ def test_while
exp = while_node.expression
assert_kind_of EqualityExpression, exp
assert_equal Identifier.new('foo'), exp.lhs
- assert_equal Digit.new(3), exp.rhs
+ assert_equal Integer.new(3), exp.rhs
- assert_equal [Digit.new(3)], while_node.body.nodes
+ assert_equal [Integer.new(3)], while_node.body.nodes
end
end
View
4 test/trait_test.rb
@@ -9,7 +9,7 @@ def setup
# Body
Noscript::AST::Nodes.new([
- Noscript::AST::Digit.new(3)
+ Noscript::AST::Integer.new(3)
])
)
@@ -19,7 +19,7 @@ def setup
# Body
Noscript::AST::Nodes.new([
- Noscript::AST::Digit.new(10)
+ Noscript::AST::Integer.new(10)
])
)

0 comments on commit 761bfd0

Please sign in to comment.