Multiple changes:

- Add the book and a few first pages
- Add the code generator
This commit is contained in:
2022-04-17 19:48:45 +02:00
parent 0469c6dbdf
commit 199758d97d
47 changed files with 5143 additions and 41 deletions

View File

@@ -0,0 +1,11 @@
Extension { #name : #ByteString }
{ #category : #'*Carp' }
ByteString >> asCarpModule [
^ CarpModule named: self
]
{ #category : #'*Carp' }
ByteString >> asCarpSymbol [
^ CarpSymbol named: self
]

View File

@@ -0,0 +1,23 @@
Class {
#name : #CarpBinding,
#superclass : #CarpExpression,
#instVars : [
'name'
],
#category : #'Carp-IDE'
}
{ #category : #accessing }
CarpBinding >> bindingName [
^ self subclassResponsibility
]
{ #category : #accessing }
CarpBinding >> name [
^ name
]
{ #category : #accessing }
CarpBinding >> name: aString [
name := aString
]

View File

@@ -0,0 +1,43 @@
Class {
#name : #CarpCall,
#superclass : #CarpExpression,
#instVars : [
'function',
'arguments'
],
#category : #'Carp-IDE'
}
{ #category : #'instance creation' }
CarpCall class >> function: aSymbol arguments: aCollection [
^ self new name: aSymbol; arguments: aCollection
]
{ #category : #accessing }
CarpCall >> addArgument: anArgument [
arguments add: anArgument
]
{ #category : #accessing }
CarpCall >> arguments: aCollection [
arguments := aCollection
]
{ #category : #initialization }
CarpCall >> initialize [
arguments := OrderedCollection new
]
{ #category : #accessing }
CarpCall >> name: aSymbol [
function := aSymbol
]
{ #category : #accessing }
CarpCall >> toCarp [
^ String streamContents: [ :aStream |
aStream << '(' << function toCarp.
arguments do: [ :anArgument | aStream << ' ' << anArgument toCarp ].
aStream << ')' ]
]

View File

@@ -0,0 +1,5 @@
Class {
#name : #CarpDouble,
#superclass : #CarpNumber,
#category : #'Carp-IDE'
}

View File

@@ -0,0 +1,10 @@
Class {
#name : #CarpDynamicFunction,
#superclass : #CarpNamedFunction,
#category : #'Carp-IDE'
}
{ #category : #accessing }
CarpDynamicFunction >> bindingName [
^ 'defndynamic'
]

View File

@@ -0,0 +1,10 @@
Class {
#name : #CarpDynamicVariable,
#superclass : #CarpVariable,
#category : #'Carp-IDE'
}
{ #category : #accessing }
CarpDynamicVariable >> bindingName [
^ 'defdynamic'
]

View File

@@ -0,0 +1,10 @@
Class {
#name : #CarpExpression,
#superclass : #Object,
#category : #'Carp-IDE'
}
{ #category : #converting }
CarpExpression >> toCarp [
^ self subclassResponsibility
]

View File

@@ -0,0 +1,36 @@
Class {
#name : #CarpFile,
#superclass : #Object,
#instVars : [
'fileName',
'contents'
],
#category : #'Carp-IDE'
}
{ #category : #'instance creation' }
CarpFile class >> for: aFileName [
^ self new for: aFileName
]
{ #category : #accessing }
CarpFile >> contents [
^ contents
]
{ #category : #accessing }
CarpFile >> contents: aString [
contents := aString
]
{ #category : #accessing }
CarpFile >> fileName: aFileName [
fileName := aFileName
]
{ #category : #accessing }
CarpFile >> for: aFileName [
self fileName: aFileName.
self contents: (CarpParser parse: aFileName asFileReference contents).
]

View File

@@ -0,0 +1,10 @@
Class {
#name : #CarpFloat,
#superclass : #CarpNumber,
#category : #'Carp-IDE'
}
{ #category : #accessing }
CarpFloat >> suffix [
^ 'f'
]

View File

@@ -0,0 +1,10 @@
Class {
#name : #CarpInteger,
#superclass : #CarpNumber,
#category : #'Carp-IDE'
}
{ #category : #accessing }
CarpInteger >> suffix [
^ ''
]

View File

@@ -0,0 +1,5 @@
Class {
#name : #CarpLiteral,
#superclass : #CarpExpression,
#category : #'Carp-IDE'
}

View File

@@ -0,0 +1,10 @@
Class {
#name : #CarpLong,
#superclass : #CarpNumber,
#category : #'Carp-IDE'
}
{ #category : #accessing }
CarpLong >> suffix [
^ 'l'
]

View File

@@ -0,0 +1,10 @@
Class {
#name : #CarpMacro,
#superclass : #CarpNamedFunction,
#category : #'Carp-IDE'
}
{ #category : #accessing }
CarpMacro >> bindingName [
^ 'defmacro'
]

View File

@@ -0,0 +1,55 @@
Class {
#name : #CarpModule,
#superclass : #CarpExpression,
#instVars : [
'uses',
'expressions',
'name'
],
#category : #'Carp-IDE'
}
{ #category : #'instance creation' }
CarpModule class >> named: aString [
^ self new name: aString
]
{ #category : #accessing }
CarpModule >> addExpression: anExpression [
expressions add: anExpression
]
{ #category : #accessing }
CarpModule >> addUse: aString [
uses add: aString
]
{ #category : #initialization }
CarpModule >> initialize [
uses := Set new.
expressions := OrderedCollection new.
]
{ #category : #converting }
CarpModule >> name [
^ name
]
{ #category : #accessing }
CarpModule >> name: aString [
name := aString
]
{ #category : #converting }
CarpModule >> toCarp [
^ String streamContents: [ :aStream |
aStream << '(defmodule ' << self name << ' '
<< (uses ifEmpty: [ '' ] ifNotEmpty: [
Character lf , Character tab , '(use-all '
, (' ' join: uses) , ')' ]).
expressions do: [ :expression |
aStream << Character lf << Character tab
<< expression toCarp ].
aStream << ')' ]
]

View File

@@ -0,0 +1,53 @@
Class {
#name : #CarpNamedFunction,
#superclass : #CarpBinding,
#instVars : [
'arguments',
'body'
],
#category : #'Carp-IDE'
}
{ #category : #'instance creation' }
CarpNamedFunction class >> named: aString withArguments: aCollection andBody: anExpression [
^ self new
name: aString;
arguments: aCollection;
body: anExpression
]
{ #category : #accessing }
CarpNamedFunction >> addArgument: anArgument [
arguments add: anArgument
]
{ #category : #accessing }
CarpNamedFunction >> arguments: aCollection [
arguments := aCollection
]
{ #category : #accessing }
CarpNamedFunction >> body [
^ body
]
{ #category : #accessing }
CarpNamedFunction >> body: anExpression [
body := anExpression
]
{ #category : #initialization }
CarpNamedFunction >> initialize [
arguments := OrderedCollection new
]
{ #category : #converting }
CarpNamedFunction >> toCarp [
^ String streamContents: [ :aStream |
aStream << '(' << self bindingName << ' ' << self name toCarp
<< ' ['.
arguments do: [ :anArgument | aStream << anArgument toCarp << ' ' ].
aStream << '] ' << self body toCarp << ')' ]
]

View File

@@ -0,0 +1,28 @@
Class {
#name : #CarpNumber,
#superclass : #CarpLiteral,
#instVars : [
'number'
],
#category : #'Carp-IDE'
}
{ #category : #'instance creation' }
CarpNumber class >> number: aNumber [
^ self new number: aNumber
]
{ #category : #acccessing }
CarpNumber >> number: aNumber [
number := aNumber
]
{ #category : #accessing }
CarpNumber >> suffix [
^ self subclassResponsibility
]
{ #category : #converting }
CarpNumber >> toCarp [
^ number asString, self suffix
]

View File

@@ -0,0 +1,10 @@
Class {
#name : #CarpStaticFunction,
#superclass : #CarpNamedFunction,
#category : #'Carp-IDE'
}
{ #category : #accessing }
CarpStaticFunction >> bindingName [
^ 'defn'
]

View File

@@ -0,0 +1,10 @@
Class {
#name : #CarpStaticVariable,
#superclass : #CarpVariable,
#category : #'Carp-IDE'
}
{ #category : #accessing }
CarpStaticVariable >> bindingName [
^ 'def'
]

View File

@@ -0,0 +1,23 @@
Class {
#name : #CarpStringExpression,
#superclass : #CarpExpression,
#instVars : [
'contents'
],
#category : #'Carp-IDE'
}
{ #category : #'instance creation' }
CarpStringExpression class >> contents: aString [
^ self new contents: aString
]
{ #category : #'instance creation' }
CarpStringExpression >> contents: aString [
contents := aString
]
{ #category : #accessing }
CarpStringExpression >> toCarp [
^ contents asString
]

View File

@@ -0,0 +1,23 @@
Class {
#name : #CarpSymbol,
#superclass : #CarpLiteral,
#instVars : [
'name'
],
#category : #'Carp-IDE'
}
{ #category : #'instance creation' }
CarpSymbol class >> named: aString [
^ self new name: aString
]
{ #category : #accessing }
CarpSymbol >> name: aString [
name := aString
]
{ #category : #accessing }
CarpSymbol >> toCarp [
^ name
]

View File

@@ -0,0 +1,34 @@
Class {
#name : #CarpVariable,
#superclass : #CarpBinding,
#instVars : [
'binding'
],
#category : #'Carp-IDE'
}
{ #category : #'instance creation' }
CarpVariable class >> named: aString binding: anExpression [
^ self new
name: aString;
binding: anExpression
]
{ #category : #accessing }
CarpVariable >> binding [
^ binding
]
{ #category : #accessing }
CarpVariable >> binding: anExpression [
binding := anExpression
]
{ #category : #converting }
CarpVariable >> toCarp [
^ String streamContents: [ :aStream |
aStream << '(' << self bindingName << ' ' << self name toCarp
<< ' ' << self binding toCarp << ')' ]
]

View File

@@ -0,0 +1,11 @@
Extension { #name : #Float }
{ #category : #'*Carp' }
Float >> asCarpDouble [
^ CarpDouble number: self
]
{ #category : #'*Carp' }
Float >> asCarpFloat [
^ CarpFloat number: self
]

View File

@@ -0,0 +1,11 @@
Extension { #name : #Integer }
{ #category : #'*Carp' }
Integer >> asCarpInteger [
^ CarpInteger number: self
]
{ #category : #'*Carp' }
Integer >> asCarpLong [
^ CarpLong number: self
]