Skip to content

Commit

Permalink
Parse Newspeak Numerals
Browse files Browse the repository at this point in the history
- make implementation more spec-complient
- use a separate parser, that’s driven by the lexer
- support also BigInteger literals
- the NumeralParser also contains the logic to convert numerals into numbers
- use isDigit as defined in Newspeak spec, instead of as defined by Java

- replace Integer and Double symbol with Numeral
- updated DynamicMetrics test data after change in Kernel.som
- updated CHANGELOG

Remaining Issues:
 - can’t parse 1-0 or similar strings into numeral, send, numeral, because we don’t have the necessary context in the lexer to not consume the minus

Signed-off-by: Stefan Marr <git@stefan-marr.de>

Updated dym test data

Signed-off-by: Stefan Marr <git@stefan-marr.de>

Fix changelog

Signed-off-by: Stefan Marr <git@stefan-marr.de>
  • Loading branch information
smarr committed Jul 16, 2017
1 parent 668a664 commit a674a6a
Show file tree
Hide file tree
Showing 11 changed files with 521 additions and 108 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,8 @@
## [Unreleased] \(0.5.0\) [v5]

- Implement Newspeak setter send syntax and remove old assignment syntax
- Added support for Newspeak's full numeral syntax. This includes notation for
a radix and the exponent notation. Examples: 16rFFFF, 2r10.11, 3.7e3 [PR #172](https://github.com/smarr/SOMns/pull/172)

## [0.4.0] - [Concurrency-Agnostic Debugger][v4]

Expand Down
2 changes: 1 addition & 1 deletion core-lib/Benchmarks/Validation.som
Expand Up @@ -600,7 +600,7 @@ class Validation usingPlatform: platform andHarness: harness = Value (
actors after: 1 do: [ :r |
counter <-: B.
lim > 0 ifTrue: [
doB: counter lim: (lim-1)
doB: counter lim: lim - 1
]
]
)
Expand Down
2 changes: 1 addition & 1 deletion core-lib/Kernel.som
Expand Up @@ -198,7 +198,7 @@ class Kernel vmMirror: vmMirror = Object <: Value (
public <= argument = ( ^ (self < argument) or: [ self = argument ] )
public negative = ( ^ self < 0 )
public between: a and: b = ( ^ (self > a) and: [ self < b ] )
public compareTo: other = ( ^ self < other ifTrue: [ - 1 ] ifFalse: [ self = other ifTrue: [ 0 ] ifFalse: [ 1 ] ] )
public compareTo: other = ( ^ self < other ifTrue: [ -1 ] ifFalse: [ self = other ifTrue: [ 0 ] ifFalse: [ 1 ] ] )

(* Converting *)
public asString = ( ^ vmMirror intAsString: self )
Expand Down
26 changes: 17 additions & 9 deletions core-lib/TestSuite/DoubleTests.som
Expand Up @@ -28,51 +28,59 @@ class DoubleTests usingPlatform: platform testFramework: minitest = (
public testIntegerDivision = (
self assert: 1 equals: (4/3) + (4/5)
)

public testDoubleDivision = (
self assert: 32 // 15 equals: (4//3) + (4//5)
)

public testAsString = (
self assert: '0.5' equals: (1//2) asString.
self assert: '0.5' equals: 0.5 asString.
)

public testEquals = (
self assert: (1.0 = 1).
)

public testRound = (
self assert: 1 equals: (5//10) round.
self assert: 1 equals: (14//10) round.
self assert: 445 equals: (44534//100) round.
)

public testInfinity = (
self assert: Double PositiveInfinity > 1.
self assert: Double PositiveInfinity equals: Double PositiveInfinity + 1.
self assert: Double PositiveInfinity equals: Double PositiveInfinity - 1.
)

public testSin = (
assert: 0.0 sin equals: 0.0.
assert: 1.5707963267948966 sin equals: 1.0.
assert: 3.2 sin < 0
)

public testAbs = (
assert: 1.5 abs equals: 1.5.
assert: -1.5 abs equals: 1.5.
)

public testLog = (
assert: 1.0 log equals: 0.0.
assert: 2.718281828459045 log equals: 1.0.
)

public testExp = (
assert: 1.0 exp equals: 2.718281828459045.
assert: 0.0 exp equals: 1.0.
)

public testAdvancedLiterals = (
assert: 1e-1 equals: 0.1.
assert: 1e-10 equals: 0.0000000001.
assert: 2r0.1 equals: 0.5.
assert: 36r0.I equals: 0.5.
assert: 36r0.I00 equals: 0.5.
)
) : ( TEST_CONTEXT = () )
)
92 changes: 51 additions & 41 deletions core-lib/TestSuite/IntegerTests.som
Expand Up @@ -39,92 +39,92 @@ class IntegerTests usingPlatform: platform testFramework: minitest = (
| a b |
a:: 42.
b:: 42.

self assert: a = b. (* Integers are equal based on their value *)

(* Sometimes it can be hard to implement efficiently, but it SHOULD really
be true for all values of integers. *)
a:: 1 << 30. b:: 1 << 30.
self assert: a equals: b.

a:: 1 << 32. b:: 1 << 32.
self assert: a equals: b.

a:: 1 << 60. b:: 1 << 60.
self assert: a equals: b.

a:: 1 << 70. b:: 1 << 70.
self assert: a equals: b.

a:: 1 << 100. b:: 1 << 100.
self assert: a equals: b.
)

public testClassAndValueRanges = (
| i |
self assert: #Integer equals: (ObjectMirror reflecting: -42) className.
self assert: #Integer equals: (ObjectMirror reflecting: 0) className.
self assert: #Integer equals: (ObjectMirror reflecting: 23) className.
self assert: #Integer equals: (ObjectMirror reflecting: 1073741823) className.
self assert: #Integer equals: (ObjectMirror reflecting: 1073741824) className.

(* Let's test for size behavior and corresponding class *)
i:: 1 << 30.
self assert: #Integer equals: (ObjectMirror reflecting: i) className.
self assert: i > 0 description: 'should not overflow'.
self assert: '1073741824' equals: i asString.
i:: 1 << 32.
self assert: #Integer equals: (ObjectMirror reflecting: i) className.
self assert: i > 0 description: 'should not overflow'.
self assert: '4294967296' equals: i asString.
i:: 1 << 60.
self assert: #Integer equals: (ObjectMirror reflecting: i) className.
self assert: i > 0 description: 'should not overflow'.
self assert: '1152921504606846976' equals: i asString.
i:: 1 << 70.
self assert: #Integer equals: (ObjectMirror reflecting: i) className.
self assert: i > 0 description: 'should not overflow'.
self assert: '1180591620717411303424' equals: i asString.
i:: -1 << 30.
self assert: #Integer equals: (ObjectMirror reflecting: i) className.
self assert: i < 0 description: 'should not underflow'.
self assert: '-1073741824' equals: i asString.
i:: -1 << 32.
self assert: #Integer equals: (ObjectMirror reflecting: i) className.
self assert: i < 0 description: 'should not underflow'.
self assert: '-4294967296' equals: i asString.
i:: -1 << 60.
self assert: #Integer equals: (ObjectMirror reflecting: i) className.
self assert: i < 0 description: 'should not underflow'.
self assert: '-1152921504606846976' equals: i asString.
i:: -1 << 70.
self assert: #Integer equals: (ObjectMirror reflecting: i) className.
self assert: i < 0 description: 'should not underflow'.
self assert: '-1180591620717411303424' equals: i asString.
)
public testStringConversion = (
self assert: '0' equals: ( 0 asString).
self assert: '1' equals: ( 1 asString).
self assert: '2' equals: ( 2 asString).
self assert: '-1' equals: (-1 asString).
self assert: '-2' equals: (-2 asString).
self assert: 1 equals: (Integer fromString: '1').
self assert: -1 equals: (Integer fromString: '-1').
self assert: 42 equals: (Integer fromString: '42').
self assert: 42 equals: '42' asInteger.
self assert: -2 equals: '-2' asInteger.
)
public testRangeBorders = (
self assert: '536870911' equals: 536870911 asString.
self assert: '536870912' equals: 536870912 asString.
Expand All @@ -142,7 +142,7 @@ class IntegerTests usingPlatform: platform testFramework: minitest = (
self assert: '-2147483647' equals: -2147483647 asString.
self assert: '-2147483648' equals: -2147483648 asString.
)
public testComparisons = (
self assert: ( 9 = 9).
self deny: ( 1 = 2).
Expand All @@ -165,24 +165,24 @@ class IntegerTests usingPlatform: platform testFramework: minitest = (
)
public testAddition = (
self assert: 0 equals: ( 0+0).
self assert: 1 equals: ( 1+0).
self assert: 1 equals: ( 0+1).
self assert: 2 equals: ( 1+1).
self assert: 0 equals: (-1+1).
self assert: 1 equals: (-1+2).
self assert: 0 equals: 0 + 0.
self assert: 1 equals: 1 + 0.
self assert: 1 equals: 0 + 1.
self assert: 2 equals: 1 + 1.
self assert: 0 equals: -1 + 1.
self assert: 1 equals: -1 + 2.
)
public testSubtraction = (
self assert: 1 equals: (1-0).
self assert: -1 equals: (0-1).
self assert: 1 equals: (2-1).
self assert: 1 equals: 1 - 0.
self assert: -1 equals: 0 - 1.
self assert: 1 equals: 2 - 1.
)
public testMultiplication = (
self assert: 0 equals: ( 1* 0).
self assert: -1 equals: (-1* 1).
self assert: -25 equals: ( 5* -5).
self assert: 0 equals: ( 1* 0).
self assert: -1 equals: (-1* 1).
self assert: -25 equals: ( 5* -5).
self assert: 12 equals: (-3* -4).
)
Expand All @@ -203,13 +203,13 @@ class IntegerTests usingPlatform: platform testFramework: minitest = (
self assert: -4 equals: ( 20// -5).
self assert: 1 equals: ( -5// -5).
)
public testModulo = (
self assert: 1 equals: ( 10 % 3).
self assert: -2 equals: ( 10 % -3).
self assert: 2 equals: (-10 % 3).
self assert: -1 equals: (-10 % -3).
self assert: 1 equals: ( 10 rem: 3).
self assert: 1 equals: ( 10 rem: -3).
self assert: -1 equals: (-10 rem: 3).
Expand All @@ -235,12 +235,12 @@ class IntegerTests usingPlatform: platform testFramework: minitest = (
self assert: 0 equals: (2 & 1).
self assert: 2 equals: (2 & 2).
)
public testBitXor = (
self assert: 0 equals: (1 bitXor: 1).
self assert: 3 equals: (2 bitXor: 1).
)
public testAs32BitUnsignedValue = (
self assert: 1 << 1 equals: (1 << 1) as32BitUnsignedValue.
self assert: 1 << 10 equals: (1 << 10) as32BitUnsignedValue.
Expand All @@ -255,30 +255,30 @@ class IntegerTests usingPlatform: platform testFramework: minitest = (
self assert: -2147483648 equals: (1 << 31) as32BitSignedValue.
self assert: 0 equals: (1 << 32) as32BitSignedValue.
)
public testUnsignedRightShift = (
self assert: 0 equals: 1 >>> 1.
self assert: 512 equals: 1024 >>> 1.
self assert: 127 equals: 1023 >>> 3.
(* not sure whether we should really insist on this *)
self assert: 9223372036854775807 equals: -1 >>> 1.
self assert: 9223372036854775296 equals: -1024 >>> 1.
)
public testMinMax = (
assert: (0 min: 1) equals: 0.
assert: (1 min: 0) equals: 0.
assert: (1 max: 0) equals: 1.
assert: (0 max: 1) equals: 1.
)
public testToByDo = (
| v |
v:: Vector new.
0 to: 10 by: 2 do: [:i |
v append: i ].
assert: v size equals: 6.
assert: (v at: 1) equals: 0.
assert: (v at: 2) equals: 2.
Expand All @@ -287,7 +287,7 @@ class IntegerTests usingPlatform: platform testFramework: minitest = (
assert: (v at: 5) equals: 8.
assert: (v at: 6) equals: 10.
)
public testDownToByDo = (
| v |
v:: Vector new.
Expand All @@ -302,5 +302,15 @@ class IntegerTests usingPlatform: platform testFramework: minitest = (
assert: (v at: 5) equals: 2.
assert: (v at: 6) equals: 0.
)
public testAdvancedLiterals = (
assert: 1e1 equals: 10.0.
assert: 16rA equals: 10.
assert: 2r11 equals: 3.
assert: 2r1111 equals: 15.
assert: 10r1111 equals: 1111.
assert: 36rZ equals: 35.
assert: 60rZ0 equals: 2100.
)
) : ( TEST_CONTEXT = () )
)

0 comments on commit a674a6a

Please sign in to comment.