aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-12-15 15:31:04 +0000
committerMichael Williamson <mike@zwobble.org>2023-12-15 15:31:04 +0000
commit549ec911f67484c875a09d4b5b8a9a4fc0ecc806 (patch)
tree1940d5adcdb5db95712d8edcbd924cd436b21fb3
parenta2d7af1fdcc64f117d5db91761cb2610854e9e60 (diff)
Store Patio ints as pointers
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:positionalAndNamedParamsAreDefined(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected58
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenIfTests]/[method:canGenerateCodeForIfWithMultipleResults(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected44
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenIfTests]/[method:canGenerateCodeForIfWithNoResults(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected22
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenIfTests]/[method:canGenerateCodeForIfWithSingleResult(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected118
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenIntAddTests]/[method:canGenerateCodeForIntAdd(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected37
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenIntEqualsTests]/[method:canGenerateCodeForIntEquals(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected28
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenIntNotEqualTests]/[method:canGenerateCodeForIntNotEqual(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected28
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenIntSubTests]/[method:canGenerateCodeForIntSub(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected37
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenLoopTests]/[method:canGenerateCodeForLoop(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected11
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenPushIntTests]/[method:pushIntInstructionGeneratesIntGetInstruction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected11
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenStringAddTests]/[method:canGenerateCodeForStringAdd(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected6
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenSwitchTests]/[method:canGenerateCodeForSwitchWithSingleResult(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected118
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenTryTests]/[method:canGenerateCodeForTry(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected11
-rw-r--r--src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java4
-rw-r--r--src/main/java/org/shedlang/compiler/patio/PatioCodeGenInts.java188
-rw-r--r--src/main/java/org/shedlang/compiler/patio/PatioCodeGenLocalSpace.java8
16 files changed, 663 insertions, 66 deletions
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:positionalAndNamedParamsAreDefined(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:positionalAndNamedParamsAreDefined(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index 408f2917..0388fdf5 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:positionalAndNamedParamsAreDefined(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:positionalAndNamedParamsAreDefined(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -4,7 +4,7 @@ Compilation unit elements:
function
"shed__function__f__0"
visibility=private
- locals=((param "closurePointer__0" data-ptr) (param "local__param1" int) (param "local__param2" int) (param "local__paramA" int) (param "local__paramB" int) (param "local__paramC" int) (val "local__a" int) (val "local__b" int) (val "tmp__0" int) (val "tmp__1" int))
+ locals=((param "closurePointer__0" data-ptr) (param "local__param1" int) (param "local__param2" int) (param "local__paramA" int) (param "local__paramB" int) (param "local__paramC" int) (val "local__a" int) (val "local__b" int) (val "binaryOpResult__0" int) (val "intPointer__0" data-ptr) (val "intBinaryOpLeftValue__0" int) (val "intPointer__1" data-ptr) (val "intBinaryOpLeftValue__1" int) (val "intBinaryOpResultValue__0" int) (val "intPointer__2" data-ptr) (val "binaryOpResult__1" int) (val "intPointer__3" data-ptr) (val "intBinaryOpLeftValue__2" int) (val "intPointer__4" data-ptr) (val "intBinaryOpLeftValue__3" int) (val "intBinaryOpResultValue__1" int) (val "intPointer__5" data-ptr))
return-type=int
body=(
(
@@ -21,9 +21,59 @@ Compilation unit elements:
layout=(struct (function-ptr (struct (int int))))
offset=(1 1)
)
- (int-add (local "tmp__0") (local "local__a") (local "local__param1"))
- (int-add (local "tmp__1") (local "tmp__0") (local "local__paramA"))
- (return (local "tmp__1"))
+ (int-to-data-ptr (local "intPointer__0") (local "local__a"))
+ (
+ memory-load
+ (local "intBinaryOpLeftValue__0")
+ pointer=(local "intPointer__0")
+ layout=(struct (int))
+ offset=(0)
+ )
+ (int-to-data-ptr (local "intPointer__1") (local "local__param1"))
+ (
+ memory-load
+ (local "intBinaryOpLeftValue__1")
+ pointer=(local "intPointer__1")
+ layout=(struct (int))
+ offset=(0)
+ )
+ (int-add (local "intBinaryOpResultValue__0") (local "intBinaryOpLeftValue__0") (local "intBinaryOpLeftValue__1"))
+ (alloc-heap (local "intPointer__2") (struct (int)))
+ (
+ memory-store
+ pointer=(local "intPointer__2")
+ layout=(struct (int))
+ offset=(0)
+ value=(local "intBinaryOpResultValue__0")
+ )
+ (data-ptr-to-int (local "binaryOpResult__0") (local "intPointer__2"))
+ (int-to-data-ptr (local "intPointer__3") (local "binaryOpResult__0"))
+ (
+ memory-load
+ (local "intBinaryOpLeftValue__2")
+ pointer=(local "intPointer__3")
+ layout=(struct (int))
+ offset=(0)
+ )
+ (int-to-data-ptr (local "intPointer__4") (local "local__paramA"))
+ (
+ memory-load
+ (local "intBinaryOpLeftValue__3")
+ pointer=(local "intPointer__4")
+ layout=(struct (int))
+ offset=(0)
+ )
+ (int-add (local "intBinaryOpResultValue__1") (local "intBinaryOpLeftValue__2") (local "intBinaryOpLeftValue__3"))
+ (alloc-heap (local "intPointer__5") (struct (int)))
+ (
+ memory-store
+ pointer=(local "intPointer__5")
+ layout=(struct (int))
+ offset=(0)
+ value=(local "intBinaryOpResultValue__1")
+ )
+ (data-ptr-to-int (local "binaryOpResult__1") (local "intPointer__5"))
+ (return (local "binaryOpResult__1"))
)
)
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenIfTests]/[method:canGenerateCodeForIfWithMultipleResults(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenIfTests]/[method:canGenerateCodeForIfWithMultipleResults(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index 1fef2829..1dce9179 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenIfTests]/[method:canGenerateCodeForIfWithMultipleResults(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenIfTests]/[method:canGenerateCodeForIfWithMultipleResults(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -7,9 +7,13 @@ Locals:
* (val "tmp__0" int)
* (val "tmp__1" int)
* (val "int__0" int)
+ * (val "intPointer__0" data-ptr)
* (val "int__1" int)
+ * (val "intPointer__1" data-ptr)
* (val "int__2" int)
+ * (val "intPointer__2" data-ptr)
* (val "int__3" int)
+ * (val "intPointer__3" data-ptr)
Instructions:
@@ -23,16 +27,48 @@ Instructions:
(
block
(
- (local-store (local "int__0") (int 1))
- (local-store (local "int__1") (int 2))
+ (alloc-heap (local "intPointer__0") (struct (int)))
+ (
+ memory-store
+ pointer=(local "intPointer__0")
+ layout=(struct (int))
+ offset=(0)
+ value=(int 1)
+ )
+ (data-ptr-to-int (local "int__0") (local "intPointer__0"))
+ (alloc-heap (local "intPointer__1") (struct (int)))
+ (
+ memory-store
+ pointer=(local "intPointer__1")
+ layout=(struct (int))
+ offset=(0)
+ value=(int 2)
+ )
+ (data-ptr-to-int (local "int__1") (local "intPointer__1"))
)
results=((local "int__0") (local "int__1"))
)
(
block
(
- (local-store (local "int__2") (int 101))
- (local-store (local "int__3") (int 102))
+ (alloc-heap (local "intPointer__2") (struct (int)))
+ (
+ memory-store
+ pointer=(local "intPointer__2")
+ layout=(struct (int))
+ offset=(0)
+ value=(int 101)
+ )
+ (data-ptr-to-int (local "int__2") (local "intPointer__2"))
+ (alloc-heap (local "intPointer__3") (struct (int)))
+ (
+ memory-store
+ pointer=(local "intPointer__3")
+ layout=(struct (int))
+ offset=(0)
+ value=(int 102)
+ )
+ (data-ptr-to-int (local "int__3") (local "intPointer__3"))
)
results=((local "int__2") (local "int__3"))
)
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenIfTests]/[method:canGenerateCodeForIfWithNoResults(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenIfTests]/[method:canGenerateCodeForIfWithNoResults(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index 325129b3..3aeb727c 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenIfTests]/[method:canGenerateCodeForIfWithNoResults(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenIfTests]/[method:canGenerateCodeForIfWithNoResults(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -5,7 +5,9 @@ Locals:
* (val "tmp__conditionInt__0" int)
* (val "tmp__conditionBool__0" bool)
* (val "int__0" int)
+ * (val "intPointer__0" data-ptr)
* (val "int__1" int)
+ * (val "intPointer__1" data-ptr)
Instructions:
@@ -19,14 +21,30 @@ Instructions:
(
block
(
- (local-store (local "int__0") (int 1))
+ (alloc-heap (local "intPointer__0") (struct (int)))
+ (
+ memory-store
+ pointer=(local "intPointer__0")
+ layout=(struct (int))
+ offset=(0)
+ value=(int 1)
+ )
+ (data-ptr-to-int (local "int__0") (local "intPointer__0"))
)
results=()
)
(
block
(
- (local-store (local "int__1") (int 101))
+ (alloc-heap (local "intPointer__1") (struct (int)))
+ (
+ memory-store
+ pointer=(local "intPointer__1")
+ layout=(struct (int))
+ offset=(0)
+ value=(int 101)
+ )
+ (data-ptr-to-int (local "int__1") (local "intPointer__1"))
)
results=()
)
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenIfTests]/[method:canGenerateCodeForIfWithSingleResult(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenIfTests]/[method:canGenerateCodeForIfWithSingleResult(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index 715d5258..1e61b1a6 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenIfTests]/[method:canGenerateCodeForIfWithSingleResult(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenIfTests]/[method:canGenerateCodeForIfWithSingleResult(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -6,11 +6,27 @@ Locals:
* (val "tmp__conditionBool__0" bool)
* (val "tmp__0" int)
* (val "int__0" int)
+ * (val "intPointer__0" data-ptr)
* (val "int__1" int)
- * (val "tmp__1" int)
+ * (val "intPointer__1" data-ptr)
+ * (val "binaryOpResult__0" int)
+ * (val "intPointer__2" data-ptr)
+ * (val "intBinaryOpLeftValue__0" int)
+ * (val "intPointer__3" data-ptr)
+ * (val "intBinaryOpLeftValue__1" int)
+ * (val "intBinaryOpResultValue__0" int)
+ * (val "intPointer__4" data-ptr)
* (val "int__2" int)
+ * (val "intPointer__5" data-ptr)
* (val "int__3" int)
- * (val "tmp__2" int)
+ * (val "intPointer__6" data-ptr)
+ * (val "binaryOpResult__1" int)
+ * (val "intPointer__7" data-ptr)
+ * (val "intBinaryOpLeftValue__2" int)
+ * (val "intPointer__8" data-ptr)
+ * (val "intBinaryOpLeftValue__3" int)
+ * (val "intBinaryOpResultValue__1" int)
+ * (val "intPointer__9" data-ptr)
Instructions:
@@ -24,20 +40,102 @@ Instructions:
(
block
(
- (local-store (local "int__0") (int 1))
- (local-store (local "int__1") (int 2))
- (int-add (local "tmp__1") (local "int__0") (local "int__1"))
+ (alloc-heap (local "intPointer__0") (struct (int)))
+ (
+ memory-store
+ pointer=(local "intPointer__0")
+ layout=(struct (int))
+ offset=(0)
+ value=(int 1)
+ )
+ (data-ptr-to-int (local "int__0") (local "intPointer__0"))
+ (alloc-heap (local "intPointer__1") (struct (int)))
+ (
+ memory-store
+ pointer=(local "intPointer__1")
+ layout=(struct (int))
+ offset=(0)
+ value=(int 2)
+ )
+ (data-ptr-to-int (local "int__1") (local "intPointer__1"))
+ (int-to-data-ptr (local "intPointer__2") (local "int__0"))
+ (
+ memory-load
+ (local "intBinaryOpLeftValue__0")
+ pointer=(local "intPointer__2")
+ layout=(struct (int))
+ offset=(0)
+ )
+ (int-to-data-ptr (local "intPointer__3") (local "int__1"))
+ (
+ memory-load
+ (local "intBinaryOpLeftValue__1")
+ pointer=(local "intPointer__3")
+ layout=(struct (int))
+ offset=(0)
+ )
+ (int-add (local "intBinaryOpResultValue__0") (local "intBinaryOpLeftValue__0") (local "intBinaryOpLeftValue__1"))
+ (alloc-heap (local "intPointer__4") (struct (int)))
+ (
+ memory-store
+ pointer=(local "intPointer__4")
+ layout=(struct (int))
+ offset=(0)
+ value=(local "intBinaryOpResultValue__0")
+ )
+ (data-ptr-to-int (local "binaryOpResult__0") (local "intPointer__4"))
)
- results=((local "tmp__1"))
+ results=((local "binaryOpResult__0"))
)
(
block
(
- (local-store (local "int__2") (int 101))
- (local-store (local "int__3") (int 102))
- (int-add (local "tmp__2") (local "int__2") (local "int__3"))
+ (alloc-heap (local "intPointer__5") (struct (int)))
+ (
+ memory-store
+ pointer=(local "intPointer__5")
+ layout=(struct (int))
+ offset=(0)
+ value=(int 101)
+ )
+ (data-ptr-to-int (local "int__2") (local "intPointer__5"))
+ (alloc-heap (local "intPointer__6") (struct (int)))
+ (
+ memory-store
+ pointer=(local "intPointer__6")
+ layout=(struct (int))
+ offset=(0)
+ value=(int 102)
+ )
+ (data-ptr-to-int (local "int__3") (local "intPointer__6"))
+ (int-to-data-ptr (local "intPointer__7") (local "int__2"))
+ (
+ memory-load
+ (local "intBinaryOpLeftValue__2")
+ pointer=(local "intPointer__7")
+ layout=(struct (int))
+ offset=(0)
+ )
+ (int-to-data-ptr (local "intPointer__8") (local "int__3"))
+ (
+ memory-load
+ (local "intBinaryOpLeftValue__3")
+ pointer=(local "intPointer__8")
+ layout=(struct (int))
+ offset=(0)
+ )
+ (int-add (local "intBinaryOpResultValue__1") (local "intBinaryOpLeftValue__2") (local "intBinaryOpLeftValue__3"))
+ (alloc-heap (local "intPointer__9") (struct (int)))
+ (
+ memory-store
+ pointer=(local "intPointer__9")
+ layout=(struct (int))
+ offset=(0)
+ value=(local "intBinaryOpResultValue__1")
+ )
+ (data-ptr-to-int (local "binaryOpResult__1") (local "intPointer__9"))
)
- results=((local "tmp__2"))
+ results=((local "binaryOpResult__1"))
)
)
)
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenIntAddTests]/[method:canGenerateCodeForIntAdd(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenIntAddTests]/[method:canGenerateCodeForIntAdd(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index 405e751e..74c72b1b 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenIntAddTests]/[method:canGenerateCodeForIntAdd(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenIntAddTests]/[method:canGenerateCodeForIntAdd(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -2,14 +2,45 @@ Compilation unit elements:
Locals:
- * (val "tmp__0" int)
+ * (val "binaryOpResult__0" int)
+ * (val "intPointer__0" data-ptr)
+ * (val "intBinaryOpLeftValue__0" int)
+ * (val "intPointer__1" data-ptr)
+ * (val "intBinaryOpLeftValue__1" int)
+ * (val "intBinaryOpResultValue__0" int)
+ * (val "intPointer__2" data-ptr)
Instructions:
(
- (int-add (local "tmp__0") (local "b") (local "c"))
+ (int-to-data-ptr (local "intPointer__0") (local "b"))
+ (
+ memory-load
+ (local "intBinaryOpLeftValue__0")
+ pointer=(local "intPointer__0")
+ layout=(struct (int))
+ offset=(0)
+ )
+ (int-to-data-ptr (local "intPointer__1") (local "c"))
+ (
+ memory-load
+ (local "intBinaryOpLeftValue__1")
+ pointer=(local "intPointer__1")
+ layout=(struct (int))
+ offset=(0)
+ )
+ (int-add (local "intBinaryOpResultValue__0") (local "intBinaryOpLeftValue__0") (local "intBinaryOpLeftValue__1"))
+ (alloc-heap (local "intPointer__2") (struct (int)))
+ (
+ memory-store
+ pointer=(local "intPointer__2")
+ layout=(struct (int))
+ offset=(0)
+ value=(local "intBinaryOpResultValue__0")
+ )
+ (data-ptr-to-int (local "binaryOpResult__0") (local "intPointer__2"))
)
Temporary stack:
- * PatioLocalRef[name=tmp__0]
+ * PatioLocalRef[name=binaryOpResult__0]
* PatioLocalRef[name=a]
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenIntEqualsTests]/[method:canGenerateCodeForIntEquals(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenIntEqualsTests]/[method:canGenerateCodeForIntEquals(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index 41ffd0ca..964c884b 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenIntEqualsTests]/[method:canGenerateCodeForIntEquals(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenIntEqualsTests]/[method:canGenerateCodeForIntEquals(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -2,16 +2,36 @@ Compilation unit elements:
Locals:
+ * (val "binaryOpResult__0" int)
* (val "tmp__0" int)
- * (val "tmp__1" int)
+ * (val "intPointer__0" data-ptr)
+ * (val "intBinaryOpLeftValue__0" int)
+ * (val "intPointer__1" data-ptr)
+ * (val "intBinaryOpLeftValue__1" int)
Instructions:
(
- (int-eq (local "tmp__1") (local "b") (local "c"))
- (bool-to-int (local "tmp__0") (local "tmp__1"))
+ (int-to-data-ptr (local "intPointer__0") (local "b"))
+ (
+ memory-load
+ (local "intBinaryOpLeftValue__0")
+ pointer=(local "intPointer__0")
+ layout=(struct (int))
+ offset=(0)
+ )
+ (int-to-data-ptr (local "intPointer__1") (local "c"))
+ (
+ memory-load
+ (local "intBinaryOpLeftValue__1")
+ pointer=(local "intPointer__1")
+ layout=(struct (int))
+ offset=(0)
+ )
+ (int-eq (local "tmp__0") (local "intBinaryOpLeftValue__0") (local "intBinaryOpLeftValue__1"))
+ (bool-to-int (local "binaryOpResult__0") (local "tmp__0"))
)
Temporary stack:
- * PatioLocalRef[name=tmp__0]
+ * PatioLocalRef[name=binaryOpResult__0]
* PatioLocalRef[name=a]
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenIntNotEqualTests]/[method:canGenerateCodeForIntNotEqual(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenIntNotEqualTests]/[method:canGenerateCodeForIntNotEqual(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index c25a9d55..c935f1c2 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenIntNotEqualTests]/[method:canGenerateCodeForIntNotEqual(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenIntNotEqualTests]/[method:canGenerateCodeForIntNotEqual(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -2,16 +2,36 @@ Compilation unit elements:
Locals:
+ * (val "binaryOpResult__0" int)
* (val "tmp__0" int)
- * (val "tmp__1" int)
+ * (val "intPointer__0" data-ptr)
+ * (val "intBinaryOpLeftValue__0" int)
+ * (val "intPointer__1" data-ptr)
+ * (val "intBinaryOpLeftValue__1" int)
Instructions:
(
- (int-ne (local "tmp__1") (local "b") (local "c"))
- (bool-to-int (local "tmp__0") (local "tmp__1"))
+ (int-to-data-ptr (local "intPointer__0") (local "b"))
+ (
+ memory-load
+ (local "intBinaryOpLeftValue__0")
+ pointer=(local "intPointer__0")
+ layout=(struct (int))
+ offset=(0)
+ )
+ (int-to-data-ptr (local "intPointer__1") (local "c"))
+ (
+ memory-load
+ (local "intBinaryOpLeftValue__1")
+ pointer=(local "intPointer__1")
+ layout=(struct (int))
+ offset=(0)
+ )
+ (int-ne (local "tmp__0") (local "intBinaryOpLeftValue__0") (local "intBinaryOpLeftValue__1"))
+ (bool-to-int (local "binaryOpResult__0") (local "tmp__0"))
)
Temporary stack:
- * PatioLocalRef[name=tmp__0]
+ * PatioLocalRef[name=binaryOpResult__0]
* PatioLocalRef[name=a]
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenIntSubTests]/[method:canGenerateCodeForIntSub(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenIntSubTests]/[method:canGenerateCodeForIntSub(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index ff8a8b01..dcaff51f 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenIntSubTests]/[method:canGenerateCodeForIntSub(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenIntSubTests]/[method:canGenerateCodeForIntSub(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -2,14 +2,45 @@ Compilation unit elements:
Locals:
- * (val "tmp__0" int)
+ * (val "binaryOpResult__0" int)
+ * (val "intPointer__0" data-ptr)
+ * (val "intBinaryOpLeftValue__0" int)
+ * (val "intPointer__1" data-ptr)
+ * (val "intBinaryOpLeftValue__1" int)
+ * (val "intBinaryOpResultValue__0" int)
+ * (val "intPointer__2" data-ptr)
Instructions:
(
- (int-sub (local "tmp__0") (local "b") (local "c"))
+ (int-to-data-ptr (local "intPointer__0") (local "b"))
+ (
+ memory-load
+ (local "intBinaryOpLeftValue__0")
+ pointer=(local "intPointer__0")
+ layout=(struct (int))
+ offset=(0)
+ )
+ (int-to-data-ptr (local "intPointer__1") (local "c"))
+ (
+ memory-load
+ (local "intBinaryOpLeftValue__1")
+ pointer=(local "intPointer__1")
+ layout=(struct (int))
+ offset=(0)
+ )
+ (int-sub (local "intBinaryOpResultValue__0") (local "intBinaryOpLeftValue__0") (local "intBinaryOpLeftValue__1"))
+ (alloc-heap (local "intPointer__2") (struct (int)))
+ (
+ memory-store
+ pointer=(local "intPointer__2")
+ layout=(struct (int))
+ offset=(0)
+ value=(local "intBinaryOpResultValue__0")
+ )
+ (data-ptr-to-int (local "binaryOpResult__0") (local "intPointer__2"))
)
Temporary stack:
- * PatioLocalRef[name=tmp__0]
+ * PatioLocalRef[name=binaryOpResult__0]
* PatioLocalRef[name=a]
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenLoopTests]/[method:canGenerateCodeForLoop(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenLoopTests]/[method:canGenerateCodeForLoop(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index 5e62b229..476d643a 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenLoopTests]/[method:canGenerateCodeForLoop(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenLoopTests]/[method:canGenerateCodeForLoop(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -3,6 +3,7 @@ Compilation unit elements:
Locals:
* (val "int__0" int)
+ * (val "intPointer__0" data-ptr)
Instructions:
@@ -10,7 +11,15 @@ Instructions:
(
loop
(
- (local-store (local "int__0") (int 1))
+ (alloc-heap (local "intPointer__0") (struct (int)))
+ (
+ memory-store
+ pointer=(local "intPointer__0")
+ layout=(struct (int))
+ offset=(0)
+ value=(int 1)
+ )
+ (data-ptr-to-int (local "int__0") (local "intPointer__0"))
)
)
)
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenPushIntTests]/[method:pushIntInstructionGeneratesIntGetInstruction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenPushIntTests]/[method:pushIntInstructionGeneratesIntGetInstruction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index 3d1ab6f1..524c5179 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenPushIntTests]/[method:pushIntInstructionGeneratesIntGetInstruction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenPushIntTests]/[method:pushIntInstructionGeneratesIntGetInstruction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -3,11 +3,20 @@ Compilation unit elements:
Locals:
* (val "int__0" int)
+ * (val "intPointer__0" data-ptr)
Instructions:
(
- (local-store (local "int__0") (int 42))
+ (alloc-heap (local "intPointer__0") (struct (int)))
+ (
+ memory-store
+ pointer=(local "intPointer__0")
+ layout=(struct (int))
+ offset=(0)
+ value=(int 42)
+ )
+ (data-ptr-to-int (local "int__0") (local "intPointer__0"))
)
Temporary stack:
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenStringAddTests]/[method:canGenerateCodeForStringAdd(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenStringAddTests]/[method:canGenerateCodeForStringAdd(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index 89d4d9c3..d5f76603 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenStringAddTests]/[method:canGenerateCodeForStringAdd(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenStringAddTests]/[method:canGenerateCodeForStringAdd(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -8,14 +8,14 @@ Compilation unit elements:
)
Locals:
- * (val "tmp__0" int)
+ * (val "binaryOpResult__0" int)
Instructions:
(
- (call (local "tmp__0") "shed__runtime__string_add" ((local "b") (local "c")))
+ (call (local "binaryOpResult__0") "shed__runtime__string_add" ((local "b") (local "c")))
)
Temporary stack:
- * PatioLocalRef[name=tmp__0]
+ * PatioLocalRef[name=binaryOpResult__0]
* PatioLocalRef[name=a]
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenSwitchTests]/[method:canGenerateCodeForSwitchWithSingleResult(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenSwitchTests]/[method:canGenerateCodeForSwitchWithSingleResult(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index 0ca0fb87..031ddf07 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenSwitchTests]/[method:canGenerateCodeForSwitchWithSingleResult(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenSwitchTests]/[method:canGenerateCodeForSwitchWithSingleResult(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -6,11 +6,27 @@ Locals:
* (val "switchTag__0" int)
* (val "structValuePointer__0" data-ptr)
* (val "int__0" int)
+ * (val "intPointer__0" data-ptr)
* (val "int__1" int)
- * (val "tmp__1" int)
+ * (val "intPointer__1" data-ptr)
+ * (val "binaryOpResult__0" int)
+ * (val "intPointer__2" data-ptr)
+ * (val "intBinaryOpLeftValue__0" int)
+ * (val "intPointer__3" data-ptr)
+ * (val "intBinaryOpLeftValue__1" int)
+ * (val "intBinaryOpResultValue__0" int)
+ * (val "intPointer__4" data-ptr)
* (val "int__2" int)
+ * (val "intPointer__5" data-ptr)
* (val "int__3" int)
- * (val "tmp__2" int)
+ * (val "intPointer__6" data-ptr)
+ * (val "binaryOpResult__1" int)
+ * (val "intPointer__7" data-ptr)
+ * (val "intBinaryOpLeftValue__2" int)
+ * (val "intPointer__8" data-ptr)
+ * (val "intBinaryOpLeftValue__3" int)
+ * (val "intBinaryOpResultValue__1" int)
+ * (val "intPointer__9" data-ptr)
Instructions:
@@ -34,11 +50,52 @@ Instructions:
(
block
(
- (local-store (local "int__0") (int 1))
- (local-store (local "int__1") (int 2))
- (int-add (local "tmp__1") (local "int__0") (local "int__1"))
+ (alloc-heap (local "intPointer__0") (struct (int)))
+ (
+ memory-store
+ pointer=(local "intPointer__0")
+ layout=(struct (int))
+ offset=(0)
+ value=(int 1)
+ )
+ (data-ptr-to-int (local "int__0") (local "intPointer__0"))
+ (alloc-heap (local "intPointer__1") (struct (int)))
+ (
+ memory-store
+ pointer=(local "intPointer__1")
+ layout=(struct (int))
+ offset=(0)
+ value=(int 2)
+ )
+ (data-ptr-to-int (local "int__1") (local "intPointer__1"))
+ (int-to-data-ptr (local "intPointer__2") (local "int__0"))
+ (
+ memory-load
+ (local "intBinaryOpLeftValue__0")
+ pointer=(local "intPointer__2")
+ layout=(struct (int))
+ offset=(0)
+ )
+ (int-to-data-ptr (local "intPointer__3") (local "int__1"))
+ (
+ memory-load
+ (local "intBinaryOpLeftValue__1")
+ pointer=(local "intPointer__3")
+ layout=(struct (int))
+ offset=(0)
+ )
+ (int-add (local "intBinaryOpResultValue__0") (local "intBinaryOpLeftValue__0") (local "intBinaryOpLeftValue__1"))
+ (alloc-heap (local "intPointer__4") (struct (int)))
+ (
+ memory-store
+ pointer=(local "intPointer__4")
+ layout=(struct (int))
+ offset=(0)
+ value=(local "intBinaryOpResultValue__0")
+ )
+ (data-ptr-to-int (local "binaryOpResult__0") (local "intPointer__4"))
)
- results=((local "tmp__1"))
+ results=((local "binaryOpResult__0"))
)
)
(
@@ -47,11 +104,52 @@ Instructions:
(
block
(
- (local-store (local "int__2") (int 101))
- (local-store (local "int__3") (int 102))
- (int-add (local "tmp__2") (local "int__2") (local "int__3"))
+ (alloc-heap (local "intPointer__5") (struct (int)))
+ (
+ memory-store
+ pointer=(local "intPointer__5")
+ layout=(struct (int))
+ offset=(0)
+ value=(int 101)
+ )
+ (data-ptr-to-int (local "int__2") (local "intPointer__5"))
+ (alloc-heap (local "intPointer__6") (struct (int)))
+ (
+ memory-store
+ pointer=(local "intPointer__6")
+ layout=(struct (int))
+ offset=(0)
+ value=(int 102)
+ )
+ (data-ptr-to-int (local "int__3") (local "intPointer__6"))
+ (int-to-data-ptr (local "intPointer__7") (local "int__2"))
+ (
+ memory-load
+ (local "intBinaryOpLeftValue__2")
+ pointer=(local "intPointer__7")
+ layout=(struct (int))
+ offset=(0)
+ )
+ (int-to-data-ptr (local "intPointer__8") (local "int__3"))
+ (
+ memory-load
+ (local "intBinaryOpLeftValue__3")
+ pointer=(local "intPointer__8")
+ layout=(struct (int))
+ offset=(0)
+ )
+ (int-add (local "intBinaryOpResultValue__1") (local "intBinaryOpLeftValue__2") (local "intBinaryOpLeftValue__3"))
+ (alloc-heap (local "intPointer__9") (struct (int)))
+ (
+ memory-store
+ pointer=(local "intPointer__9")
+ layout=(struct (int))
+ offset=(0)
+ value=(local "intBinaryOpResultValue__1")
+ )
+ (data-ptr-to-int (local "binaryOpResult__1") (local "intPointer__9"))
)
- results=((local "tmp__2"))
+ results=((local "binaryOpResult__1"))
)
)
)
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenTryTests]/[method:canGenerateCodeForTry(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenTryTests]/[method:canGenerateCodeForTry(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index 40131cb3..d41b1648 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenTryTests]/[method:canGenerateCodeForTry(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenTryTests]/[method:canGenerateCodeForTry(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -23,6 +23,7 @@ Locals:
* (val "tmp__0" int)
* (val "effectHandler__0" data-ptr)
* (val "int__0" int)
+ * (val "intPointer__0" data-ptr)
* (val "tmp__1" int)
Instructions:
@@ -51,7 +52,15 @@ Instructions:
(
block
(
- (local-store (local "int__0") (int 42))
+ (alloc-heap (local "intPointer__0") (struct (int)))
+ (
+ memory-store
+ pointer=(local "intPointer__0")
+ layout=(struct (int))
+ offset=(0)
+ value=(int 42)
+ )
+ (data-ptr-to-int (local "int__0") (local "intPointer__0"))
(call _ "shed__runtime__effects_pop_handler" ())
)
results=((local "int__0"))
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java
index 3e3a2aa7..0345a529 100644
--- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java
+++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java
@@ -554,7 +554,7 @@ public class PatioCodeGen {
var target = targetResult.value();
context = targetResult.context();
- context = PatioCodeGenInts.store(
+ context = PatioCodeGenInts.storeConst(
target,
pushInt.value(),
pushInt.source(),
@@ -860,7 +860,7 @@ public class PatioCodeGen {
context = leftResult.context();
var targetResult = context.allocateVal(
- PatioCodeGenLocalSpace.TEMPORARY,
+ PatioCodeGenLocalSpace.BINARY_OP_RESULT,
PatioCodeGenTypes.VALUE_TYPE
);
var target = targetResult.value();
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenInts.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenInts.java
index 037bd64b..0178033f 100644
--- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenInts.java
+++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenInts.java
@@ -4,28 +4,38 @@ import org.shedlang.compiler.patio.ast.instructions.*;
import org.shedlang.compiler.patio.ast.operands.PatioInt;
import org.shedlang.compiler.patio.ast.operands.PatioLocalRef;
import org.shedlang.compiler.patio.ast.operands.PatioOperand;
+import org.shedlang.compiler.patio.ast.types.PatioDataLayout;
+import org.shedlang.compiler.patio.ast.types.PatioDataLayouts;
import org.shedlang.compiler.patio.ast.types.PatioType;
+import org.shedlang.compiler.patio.ast.types.PatioTypes;
import org.shedlang.compiler.sources.Source;
import java.math.BigInteger;
+import java.util.List;
public class PatioCodeGenInts {
public static final PatioType INT_TYPE = PatioCodeGenTypes.VALUE_TYPE;
+ public static final PatioDataLayout INT_DATA_LAYOUT =
+ PatioDataLayouts.struct(List.of(PatioDataLayouts.INT));
+
+ public static final List<Integer> VALUE_OFFSET = List.of(0);
+
private PatioCodeGenInts() {
}
- public static PatioCodeGenContext store(
+ public static PatioCodeGenContext storeConst(
PatioLocalRef target,
BigInteger value,
Source source,
PatioCodeGenContext context
) {
- return context.addInstruction(new PatioLocalStore(
+ return store(
target,
new PatioInt(value.intValueExact()),
- source
- ));
+ source,
+ context
+ );
}
public static PatioCodeGenContext add(
@@ -35,12 +45,14 @@ public class PatioCodeGenInts {
Source source,
PatioCodeGenContext context
) {
- return context.addInstruction(new PatioIntAdd(
+ return binaryOpToInt(
+ PatioIntAdd::new,
target,
left,
right,
- source
- ));
+ source,
+ context
+ );
}
public static PatioCodeGenContext sub(
@@ -50,12 +62,14 @@ public class PatioCodeGenInts {
Source source,
PatioCodeGenContext context
) {
- return context.addInstruction(new PatioIntSub(
+ return binaryOpToInt(
+ PatioIntSub::new,
target,
left,
right,
- source
- ));
+ source,
+ context
+ );
}
public static PatioCodeGenContext equals(
@@ -65,12 +79,14 @@ public class PatioCodeGenInts {
Source source,
PatioCodeGenContext context
) {
- return context.addInstruction(new PatioIntEquals(
+ return binaryOpToBool(
+ PatioIntEquals::new,
target,
left,
right,
- source
- ));
+ source,
+ context
+ );
}
public static PatioCodeGenContext notEqual(
@@ -80,11 +96,155 @@ public class PatioCodeGenInts {
Source source,
PatioCodeGenContext context
) {
- return context.addInstruction(new PatioIntNotEqual(
+ return binaryOpToBool(
+ PatioIntNotEqual::new,
target,
left,
right,
+ source,
+ context
+ );
+ }
+
+ private interface BinaryInstruction {
+ PatioInstruction create(
+ PatioLocalRef target,
+ PatioOperand left,
+ PatioOperand right,
+ Source source
+ );
+ }
+
+ private static PatioCodeGenContext binaryOpToBool(
+ BinaryInstruction instruction,
+ PatioLocalRef target,
+ PatioOperand left,
+ PatioOperand right,
+ Source source,
+ PatioCodeGenContext context
+ ) {
+ var leftValueResult = loadIntValue(left, source, context);
+ var leftValue = leftValueResult.value();
+ context = leftValueResult.context();
+
+ var rightValueResult = loadIntValue(right, source, context);
+ var rightValue = rightValueResult.value();
+ context = rightValueResult.context();
+
+ context = context.addInstruction(instruction.create(
+ target,
+ leftValue,
+ rightValue,
source
));
+
+ return context;
+ }
+
+ private static PatioCodeGenContext binaryOpToInt(
+ BinaryInstruction instruction,
+ PatioLocalRef target,
+ PatioOperand left,
+ PatioOperand right,
+ Source source,
+ PatioCodeGenContext context
+ ) {
+ var leftValueResult = loadIntValue(left, source, context);
+ var leftValue = leftValueResult.value();
+ context = leftValueResult.context();
+
+ var rightValueResult = loadIntValue(right, source, context);
+ var rightValue = rightValueResult.value();
+ context = rightValueResult.context();
+
+ var targetValueResult = context.allocateVal(
+ PatioCodeGenLocalSpace.INT_BINARY_OP_RESULT_VALUE,
+ PatioTypes.INT
+ );
+ var targetValue = targetValueResult.value();
+ context = targetValueResult.context();
+
+ context = context.addInstruction(instruction.create(
+ targetValue,
+ leftValue,
+ rightValue,
+ source
+ ));
+
+ context = store(target, targetValue, source, context);
+
+ return context;
+ }
+
+ private static PatioCodeGenResult<PatioOperand> loadIntValue(
+ PatioOperand genericValue,
+ Source source,
+ PatioCodeGenContext context
+ ) {
+ var pointerResult = context.allocateVal(
+ PatioCodeGenLocalSpace.INT_POINTER,
+ PatioTypes.DATA_POINTER
+ );
+ var pointer = pointerResult.value();
+ context = pointerResult.context();
+
+ context = context.addInstruction(new PatioIntToDataPtr(
+ pointer,
+ genericValue,
+ source
+ ));
+
+ var valueResult = context.allocateVal(
+ PatioCodeGenLocalSpace.INT_BINARY_OP_LEFT_VALUE,
+ PatioTypes.INT
+ );
+ var value = valueResult.value();
+ context = valueResult.context();
+
+ context = context.addInstruction(new PatioMemoryLoad(
+ value,
+ pointer,
+ INT_DATA_LAYOUT,
+ VALUE_OFFSET,
+ source
+ ));
+
+ return context.toResult(value);
+ }
+
+ private static PatioCodeGenContext store(
+ PatioLocalRef target,
+ PatioOperand value,
+ Source source,
+ PatioCodeGenContext context
+ ) {
+ var targetPointerResult = context.allocateVal(
+ PatioCodeGenLocalSpace.INT_POINTER,
+ PatioTypes.DATA_POINTER
+ );
+ var targetPointer = targetPointerResult.value();
+ context = targetPointerResult.context();
+
+ context = context.addInstruction(new PatioAllocHeap(
+ targetPointer,
+ INT_DATA_LAYOUT,
+ source
+ ));
+
+ context = context.addInstruction(new PatioMemoryStore(
+ targetPointer,
+ INT_DATA_LAYOUT,
+ VALUE_OFFSET,
+ value,
+ source
+ ));
+
+ context = context.addInstruction(new PatioDataPtrToInt(
+ target,
+ targetPointer,
+ source
+ ));
+
+ return context;
}
}
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenLocalSpace.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenLocalSpace.java
index 89a47708..7f042ffc 100644
--- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenLocalSpace.java
+++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenLocalSpace.java
@@ -1,6 +1,7 @@
package org.shedlang.compiler.patio;
public enum PatioCodeGenLocalSpace {
+ BINARY_OP_RESULT("binaryOpResult"),
CALL_ARG_POSITIONAL("callArgPositional"),
CALL_ARG_NAMED("callArgNamed"),
CALL_FUNCTION_POINTER("callFunctionPointer"),
@@ -12,6 +13,13 @@ public enum PatioCodeGenLocalSpace {
EFFECT_HANDLER_METHOD("effectHandlerMethod"),
EFFECT_HANDLER_METHOD_POINTER("effectHandlerMethodPointer"),
INT("int"),
+ INT_POINTER("intPointer"),
+ INT_BINARY_OP_LEFT_POINTER("intBinaryOpLeftPointer"),
+ INT_BINARY_OP_LEFT_VALUE("intBinaryOpLeftValue"),
+ INT_BINARY_OP_RIGHT_POINTER("intBinaryOpRightPointer"),
+ INT_BINARY_OP_RIGHT_VALUE("intBinaryOpRightValue"),
+ INT_BINARY_OP_RESULT_POINTER("intBinaryOpResultPointer"),
+ INT_BINARY_OP_RESULT_VALUE("intBinaryOpResultValue"),
MAIN("main"),
NAMESPACE_IS_INITED_POINTER("namespaceIsInitedPointer"),
NAMESPACE_POINTER("namespacePointer"),