Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions src/Sail-Jib-Interpreter-Tests/JibInterpreterTests.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,84 @@ fn zmain(zarg) {



]

{ #category : #tests }
JibInterpreterTests >> test_09a [
| program main interpreter |
program := JibParser parse:'

val zmain : () -> %unit
fn zmain() {
return = ();
end;
}

'.

main := program lookupFunction: 'zmain'.

interpreter := JibInterpreter for: main arguments: { }.

interpreter interpret.

self assert: interpreter retVal isDatatype.
self assert: interpreter retVal sort name asString = '%unit'.
self assert: interpreter retVal printString = '|()|'.


]

{ #category : #tests }
JibInterpreterTests >> test_09b [
| program main interpreter |
program := JibParser parse:'

val zmain : () -> %unit
fn zmain() {
zz1 : %unit;
zz1 = ();
return = zz1;
end;
}

'.

main := program lookupFunction: 'zmain'.

interpreter := JibInterpreter for: main arguments: { }.

interpreter interpret.

self assert: interpreter retVal isDatatype.
self assert: interpreter retVal sort name asString = '%unit'.
self assert: interpreter retVal printString = '|()|'.


]

{ #category : #tests }
JibInterpreterTests >> test_09c [
| program main interpreter |
program := JibParser parse:'

val zmain : () -> %unit
fn zmain() {
zz1 : %unit;
return = zz1;
end;
}

'.

main := program lookupFunction: 'zmain'.

interpreter := JibInterpreter for: main arguments: { }.

interpreter interpret.

self assert: interpreter retVal isDatatype.
self assert: interpreter retVal sort name asString = '%unit'.


]
6 changes: 6 additions & 0 deletions src/Sail-Jib-Interpreter/Exp_Unit.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Extension { #name : #'Exp_Unit' }

{ #category : #'*Sail-Jib-Interpreter' }
Exp_Unit >> interpretIn: interpreter [
^ interpreter interpretUnit: self
]
11 changes: 11 additions & 0 deletions src/Sail-Jib-Interpreter/JibInterpreter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,17 @@ JibInterpreter >> interpretMonomorphize: insn [
self notYetImplemented


]

{ #category : #'interpreting - insns' }
JibInterpreter >> interpretUnit: insn [
| sort unit |

sort := insn environment lookupSortForUnit.
unit := (sort constructor: 0) value.
^unit


]

{ #category : #interpreting }
Expand Down
5 changes: 5 additions & 0 deletions src/Sail-Jib/JibEnvironment.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ JibEnvironment >> initializeWithNode: aJibProgramNode [
node := aJibProgramNode.
]

{ #category : #lookup }
JibEnvironment >> lookupSortForUnit [
^self parent lookupSortForUnit
]

{ #category : #accessing }
JibEnvironment >> node [
"Return the Jib program node this environment is associated with."
Expand Down
12 changes: 11 additions & 1 deletion src/Sail-Jib/JibProgramEnvironment.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ Class {
#name : #JibProgramEnvironment,
#superclass : #JibEnvironment,
#instVars : [
'context'
'context',
'unitSort'
],
#category : #'Sail-Jib-Environment'
}
Expand All @@ -16,6 +17,15 @@ JibProgramEnvironment >> context [
JibProgramEnvironment >> initializeWithNode: aJibProgramNode [
node := aJibProgramNode.
context := Z3Context fromDefault.
unitSort := context mkEnumerationSort: '%unit'
elements: { '()' }
consts: Cell new
testers: Cell new.
]

{ #category : #lookup }
JibProgramEnvironment >> lookupSortForUnit [
^ unitSort
]

{ #category : #accessing }
Expand Down
5 changes: 5 additions & 0 deletions src/Sail-Jib/Ty_Unit.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ Ty_Unit class >> inducedParser [
==> [ :_ | self new ]
]

{ #category : #accessing }
Ty_Unit >> sort [
^ self environment lookupSortForUnit.
]

{ #category : #printing }
Ty_Unit >> unparseOn: aStream [
aStream nextPutAll:'%unit'
Expand Down