2017-07-02 15:41:36 +03:00
|
|
|
Object subclass: MALObject [
|
|
|
|
| type value meta |
|
|
|
|
|
|
|
|
type [ ^type ]
|
|
|
|
value [ ^value ]
|
|
|
|
meta [ ^meta ]
|
|
|
|
|
2017-07-07 19:36:48 +03:00
|
|
|
value: aValue [
|
2017-07-02 15:41:36 +03:00
|
|
|
value := aValue.
|
|
|
|
]
|
|
|
|
|
2017-07-07 19:36:48 +03:00
|
|
|
meta: aMeta [
|
2017-07-02 15:41:36 +03:00
|
|
|
meta := aMeta.
|
|
|
|
]
|
|
|
|
|
|
|
|
MALObject class >> new: type value: value meta: meta [
|
|
|
|
| object |
|
|
|
|
object := super new.
|
|
|
|
object init: type value: value meta: meta.
|
|
|
|
^object
|
|
|
|
]
|
|
|
|
|
|
|
|
init: aType value: aValue meta: aMeta [
|
|
|
|
type := aType.
|
|
|
|
value := aValue.
|
|
|
|
meta := aMeta.
|
|
|
|
]
|
|
|
|
|
|
|
|
withMeta: meta [
|
|
|
|
| object |
|
|
|
|
object := self deepCopy.
|
2017-07-07 19:36:48 +03:00
|
|
|
object meta: meta.
|
2017-07-02 15:41:36 +03:00
|
|
|
^object
|
|
|
|
]
|
|
|
|
|
|
|
|
printOn: stream [
|
|
|
|
stream nextPutAll: '<';
|
|
|
|
nextPutAll: self class printString;
|
|
|
|
nextPutAll: ': ';
|
|
|
|
nextPutAll: value printString.
|
|
|
|
meta notNil ifTrue: [
|
|
|
|
stream nextPutAll: ' | '
|
|
|
|
nextPutAll: meta printString.
|
|
|
|
].
|
|
|
|
stream nextPutAll: '>'.
|
|
|
|
]
|
2017-07-05 10:15:41 +03:00
|
|
|
|
|
|
|
= x [
|
|
|
|
self type ~= x type ifTrue: [ ^false ].
|
|
|
|
^self value = x value
|
|
|
|
]
|
|
|
|
|
|
|
|
hash [
|
|
|
|
^self value hash
|
|
|
|
]
|
2017-07-02 15:41:36 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
MALObject subclass: MALTrue [
|
|
|
|
MALTrue class >> new [
|
|
|
|
^super new: #true value: true meta: nil.
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
MALObject subclass: MALFalse [
|
|
|
|
MALFalse class >> new [
|
|
|
|
^super new: #false value: false meta: nil.
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
MALObject subclass: MALNil [
|
|
|
|
MALNil class >> new [
|
|
|
|
^super new: #nil value: nil meta: nil.
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
MALObject class extend [
|
|
|
|
True := MALTrue new.
|
|
|
|
False := MALFalse new.
|
|
|
|
Nil := MALNil new.
|
|
|
|
|
|
|
|
True [ ^True ]
|
|
|
|
False [ ^False ]
|
|
|
|
Nil [ ^Nil ]
|
|
|
|
]
|
|
|
|
|
|
|
|
MALObject subclass: MALNumber [
|
|
|
|
MALNumber class >> new: value [
|
|
|
|
^super new: #number value: value meta: nil.
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
MALObject subclass: MALString [
|
|
|
|
MALString class >> new: value [
|
|
|
|
^super new: #string value: value meta: nil.
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
MALObject subclass: MALSymbol [
|
|
|
|
MALSymbol class >> new: value [
|
|
|
|
^super new: #symbol value: value meta: nil.
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
MALObject subclass: MALKeyword [
|
|
|
|
MALKeyword class >> new: value [
|
|
|
|
^super new: #keyword value: value meta: nil.
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
MALObject subclass: MALList [
|
|
|
|
MALList class >> new: value [
|
|
|
|
^super new: #list value: value meta: nil.
|
|
|
|
]
|
2017-07-05 10:15:41 +03:00
|
|
|
|
|
|
|
= x [
|
|
|
|
(x type ~= #list and: [ x type ~= #vector ]) ifTrue: [ ^false ].
|
|
|
|
^self value = x value
|
|
|
|
]
|
2017-07-02 15:41:36 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
MALObject subclass: MALVector [
|
|
|
|
MALVector class >> new: value [
|
|
|
|
^super new: #vector value: value meta: nil.
|
|
|
|
]
|
2017-07-05 10:15:41 +03:00
|
|
|
|
|
|
|
= x [
|
|
|
|
(x type ~= #vector and: [ x type ~= #list ]) ifTrue: [ ^false ].
|
|
|
|
^self value = x value
|
|
|
|
]
|
2017-07-02 15:41:36 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
MALObject subclass: MALMap [
|
|
|
|
MALMap class >> new: value [
|
|
|
|
^super new: #map value: value meta: nil.
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
MALObject subclass: MALAtom [
|
|
|
|
MALAtom class >> new: value [
|
|
|
|
^super new: #atom value: value meta: nil.
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
2017-07-09 21:05:59 +03:00
|
|
|
MALObject subclass: Fn [
|
|
|
|
| fn |
|
|
|
|
|
|
|
|
fn [ ^fn ]
|
|
|
|
|
|
|
|
Fn class >> new: fn [
|
|
|
|
| f |
|
|
|
|
f := super new: #fn value: fn meta: nil.
|
|
|
|
f init: fn.
|
|
|
|
^f
|
|
|
|
]
|
|
|
|
|
|
|
|
init: f [
|
|
|
|
fn := f.
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
2017-07-02 15:41:36 +03:00
|
|
|
Error subclass: MALError [
|
|
|
|
description [ ^'A MAL-related error' ]
|
|
|
|
isResumable [ ^true ]
|
2017-07-09 11:51:56 +03:00
|
|
|
|
|
|
|
data [ ^self messageText ]
|
2017-07-02 15:41:36 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
MALError subclass: MALUnterminatedSequence [
|
|
|
|
MALUnterminatedSequence class >> new [ ^super new ]
|
|
|
|
|
|
|
|
messageText [ ^'expected ''', self basicMessageText, ''', got EOF' ]
|
|
|
|
]
|
|
|
|
|
|
|
|
MALError subclass: MALUnexpectedToken [
|
|
|
|
MALUnexpectedToken class >> new [ ^super new ]
|
|
|
|
|
|
|
|
messageText [ ^'unexpected token: ''', self basicMessageText, '''']
|
|
|
|
]
|
|
|
|
|
|
|
|
MALError subclass: MALEmptyInput [
|
|
|
|
MALEmptyInput class >> new [ ^super new ]
|
|
|
|
|
|
|
|
messageText [ ^'Empty input' ]
|
|
|
|
]
|
2017-07-02 23:13:53 +03:00
|
|
|
|
|
|
|
MALError subclass: MALUnknownSymbol [
|
|
|
|
MALUnknownSymbol class >> new [ ^super new ]
|
|
|
|
|
|
|
|
messageText [ ^'''', self basicMessageText, ''' not found']
|
|
|
|
]
|
2017-07-08 20:49:09 +03:00
|
|
|
|
|
|
|
MALError subclass: MALOutOfBounds [
|
|
|
|
MALOutOfBounds class >> new [ ^super new ]
|
|
|
|
|
|
|
|
messageText [ ^'Out of bounds' ]
|
|
|
|
]
|
2017-07-09 11:51:56 +03:00
|
|
|
|
|
|
|
MALError subclass: MALCustomError [
|
|
|
|
MALCustomError class >> new [ ^super new ]
|
|
|
|
|
|
|
|
messageText [ ^Printer prStr: self basicMessageText printReadably: true ]
|
|
|
|
data [ ^self basicMessageText ]
|
|
|
|
]
|