Skip to content

Commit

Permalink
yeah its over
Browse files Browse the repository at this point in the history
  • Loading branch information
bristermitten committed Nov 7, 2023
1 parent 62e788b commit 19054e9
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 43 deletions.
11 changes: 7 additions & 4 deletions build/Elara.Prim.core.elr
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ module Elara.Prim
{ Elara.Prim.cons : forall (a_1 : Type). a_1 -> [] a_1 -> [] a_1
= Elara.Prim.elaraPrimitive @(a_1 -> [] a_1 -> [] a_1) "cons"
;
Elara.Prim.empty : forall (a_2 : Type). [] a_2
= Elara.Prim.elaraPrimitive @([] a_2) "empty"
;
Elara.Prim.println : String -> IO ()
= Elara.Prim.elaraPrimitive @(String -> IO ()) "println"
;
Elara.Prim.toString : forall (a_2 : Type). a_2 -> String
= Elara.Prim.elaraPrimitive @(a_2 -> String) "toString"
Elara.Prim.toString : forall (a_3 : Type). a_3 -> String
= Elara.Prim.elaraPrimitive @(a_3 -> String) "toString"
;
Elara.Prim.* : Int -> Int -> Int
= Elara.Prim.elaraPrimitive @(Int -> Int -> Int) "*"
;
Elara.Prim.- : Int -> Int -> Int
= Elara.Prim.elaraPrimitive @(Int -> Int -> Int) "-"
;
Elara.Prim.== : forall (a_3 : Type). a_3 -> a_3 -> Bool
= Elara.Prim.elaraPrimitive @(a_3 -> a_3 -> Bool) "==" }
Elara.Prim.== : forall (a_4 : Type). a_4 -> a_4 -> Bool
= Elara.Prim.elaraPrimitive @(a_4 -> a_4 -> Bool) "==" }
39 changes: 24 additions & 15 deletions build/Elara.Prim.typed.elr
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ let Elara.Prim.cons =
List
a_1

def Elara.Prim.empty : forall (a_2 : Type) . List a_2
let Elara.Prim.empty =
((Elara.Prim.elaraPrimitive : forall (a_0 : Type) . Text -> a_0 @List
a_2) : forall (a_2 : Type) .
List
a_2 "empty" : Text) : forall (a_2 : Type) .
List
a_2

def Elara.Prim.println : Text -> IO Unit
let Elara.Prim.println =
((Elara.Prim.elaraPrimitive : forall (a_0 : Type) . Text -> a_0 @Text ->
Expand All @@ -29,13 +38,13 @@ let Elara.Prim.println =
IO Unit


def Elara.Prim.toString : forall (a_2 : Type) . a_2 -> Text
def Elara.Prim.toString : forall (a_3 : Type) . a_3 -> Text
let Elara.Prim.toString =
((Elara.Prim.elaraPrimitive : forall (a_0 : Type) . Text -> a_0 @a_2 ->
Text) : forall (a_2 : Type) .
a_2 ->
Text "toString" : Text) : forall (a_2 : Type) .
a_2 ->
((Elara.Prim.elaraPrimitive : forall (a_0 : Type) . Text -> a_0 @a_3 ->
Text) : forall (a_3 : Type) .
a_3 ->
Text "toString" : Text) : forall (a_3 : Type) .
a_3 ->
Text

def Elara.Prim.(*) : Integer -> Integer -> Integer
Expand All @@ -58,14 +67,14 @@ let Elara.Prim.(-) =
Integer ->
Integer

def Elara.Prim.(==) : forall (a_3 : Type) . a_3 -> a_3 -> Bool
def Elara.Prim.(==) : forall (a_4 : Type) . a_4 -> a_4 -> Bool
let Elara.Prim.(==) =
((Elara.Prim.elaraPrimitive : forall (a_0 : Type) . Text -> a_0 @a_3 ->
a_3 ->
Bool) : forall (a_3 : Type) .
a_3 ->
a_3 ->
Bool "==" : Text) : forall (a_3 : Type) .
a_3 ->
a_3 ->
((Elara.Prim.elaraPrimitive : forall (a_0 : Type) . Text -> a_0 @a_4 ->
a_4 ->
Bool) : forall (a_4 : Type) .
a_4 ->
a_4 ->
Bool "==" : Text) : forall (a_4 : Type) .
a_4 ->
a_4 ->
Bool
Binary file modified build/Elara/Prim.class
Binary file not shown.
Binary file modified build/Main.class
Binary file not shown.
5 changes: 2 additions & 3 deletions build/Main.core.elr
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module Main
{ Main.fact : Int -> Int
= \ (n_4 : Int) -> case (Elara.Prim.== @Int n_4 0) { Elara.Prim.True -> 1; Elara.Prim.False -> Elara.Prim.* n_4 (Main.fact (Elara.Prim.- n_4 1))}
= \ (n_5 : Int) -> case (Elara.Prim.== @Int n_5 0) { Elara.Prim.True -> 1; Elara.Prim.False -> Elara.Prim.* n_5 (Main.fact (Elara.Prim.- n_5 1))}
;
Main.main : IO ()
= let x_5 : Int
= Main.fact 5 in Elara.Prim.println (Elara.Prim.toString @Int x_5) }
= Elara.Prim.println (Elara.Prim.toString @([] Int) (Prelude.++ (Elara.Prim.cons 1 Elara.Prim.empty) (Elara.Prim.cons 2 Elara.Prim.empty))) }
36 changes: 23 additions & 13 deletions build/Main.typed.elr
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,38 @@ import Elara.Prim exposing (..)

def Main.fact : Integer -> Integer
let Main.fact =
(\ n_4 -> ((if (((Elara.Prim.(==) : forall (a_3 : Type) .
a_3 ->
a_3 ->
(\ n_5 -> ((if (((Elara.Prim.(==) : forall (a_4 : Type) .
a_4 ->
a_4 ->
Bool @Integer) : Integer ->
Bool n_4 : Integer) : Integer ->
Bool n_5 : Integer) : Integer ->
Bool 0 : Integer) : Bool then 1 : Integer else ((Elara.Prim.(*) : Integer ->
Integer ->
Integer n_4 : Integer) : Integer ->
Integer n_5 : Integer) : Integer ->
Integer (Main.fact : Integer ->
Integer ((Elara.Prim.(-) : Integer ->
Integer ->
Integer n_4 : Integer) : Integer ->
Integer n_5 : Integer) : Integer ->
Integer 1 : Integer) : Integer) : Integer) : Integer) : Integer)) : Integer ->
Integer

def Main.main : IO Unit
let Main.main =
let x_5 = (Main.fact : Integer ->
Integer 5 : Integer) : Integer in (Elara.Prim.println : Text ->
IO Unit
((Elara.Prim.toString : forall (a_2 : Type) .
a_2 ->
Text @Integer) : Text x_5 : Integer) : Text) : IO Unit
: IO Unit
(Elara.Prim.println : Text ->
IO Unit
((Elara.Prim.toString : forall (a_3 : Type) .
a_3 -> Text @List
Integer) : Text ((Prelude.(++) : forall (a_10 : Type) .
List
a_10 ->
List
a_10 ->
List
a_10 [ 1 : Integer ] : List
Integer) : List
Integer ->
List
Integer [ 2 : Integer ] : List
Integer) : List
Integer) : Text) : IO Unit

Binary file modified build/Prelude.class
Binary file not shown.
4 changes: 2 additions & 2 deletions build/Prelude.core.elr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Prelude
{ Prelude.++ : forall (a_10 : Type). [] a_10 -> [] a_10 -> [] a_10
= \ (a_11 : [] a_10) (b_12 : [] a_10) -> case a_11 of (a_59 : forall (a_10 : Type). [] a_10) { Elara.Prim.[] -> b_12; Elara.Prim.:: -> Elara.Prim.cons @a_10 x_13 (Prelude.++ xs_14 b_12)}
= \ (a_11 : [] a_10) (b_12 : [] a_10) -> case a_11 of (a_64 : forall (a_10 : Type). [] a_10) { Elara.Prim.empty -> b_12; Elara.Prim.cons -> Elara.Prim.cons @a_10 x_13 (Prelude.++ xs_14 b_12)}
;
Prelude.reverse : forall (a_6 : Type). [] a_6 -> [] a_6
= \ (x_7 : [] a_6) -> case x_7 of (x_60 : forall (a_6 : Type). [] a_6) { Elara.Prim.[] -> Elara.Prim.[]; Elara.Prim.:: -> Prelude.++ (Prelude.reverse xs_9) (Elara.Prim.:: x_8 Elara.Prim.[])} }
= \ (x_7 : [] a_6) -> case x_7 of (x_65 : forall (a_6 : Type). [] a_6) { Elara.Prim.empty -> Elara.Prim.empty; Elara.Prim.cons -> Prelude.++ (Prelude.reverse xs_9) (Elara.Prim.cons x_8 Elara.Prim.empty)} }
Binary file added jvm-stdlib/elara/EList.class
Binary file not shown.
5 changes: 4 additions & 1 deletion prim.elr
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ def toString : a -> String
let toString = elaraPrimitive "toString"

def cons : a -> [a] -> [a]
let cons = elaraPrimitive "cons"
let cons = elaraPrimitive "cons"

def empty : [a]
let empty = elaraPrimitive "empty"
2 changes: 0 additions & 2 deletions source.elr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@ let fact n =
if n == 0 then 1 else n * fact (n - 1)

let main =
let x = fact 5
println (toString x)
println (toString ([1] ++ [2]))
4 changes: 3 additions & 1 deletion src/Elara/Emit.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Elara.Emit.Operator (translateOperatorName)
import Elara.Emit.State (MethodCreationState, initialMethodCreationState)
import Elara.Emit.Utils
import Elara.Emit.Var (JVMExpr, transformTopLevelLambdas)
import Elara.Prim.Core (intCon, ioCon, stringCon)
import Elara.Prim.Core (intCon, ioCon, stringCon, listCon)
import JVM.Data.Abstract.Builder
import JVM.Data.Abstract.Builder.Code (CodeBuilder, CodeBuilderT (..), emit, runCodeBuilderT', unCodeBuilderT)
import JVM.Data.Abstract.ClassFile
Expand Down Expand Up @@ -175,7 +175,9 @@ generateMainMethod m =
That is, a type that can be compiled to a field rather than a method.
-}
typeIsValue :: Type -> Bool
typeIsValue (ForAllTy _ x) = typeIsValue x
typeIsValue (AppTy con _) | con == ioCon = True
typeIsValue (AppTy con _) | con == listCon = True
typeIsValue c | c == stringCon = True
typeIsValue c | c == intCon = True
typeIsValue _ = False
4 changes: 4 additions & 0 deletions src/Elara/Emit/Expr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,8 @@ generatePrimInstructions "cons" = pure
ALoad 1,
InvokeStatic (ClassInfoType "elara.EList") "cons" (MethodDescriptor [ObjectFieldType "java.lang.Object", ObjectFieldType "elara.EList"] (TypeReturn (ObjectFieldType "elara.EList")))
]
generatePrimInstructions "empty" = pure
[
InvokeStatic (ClassInfoType "elara.EList") "empty" (MethodDescriptor [] (TypeReturn (ObjectFieldType "elara.EList")))
]
generatePrimInstructions other = error $ "Unknown elara primitive: " <> showPretty other
4 changes: 2 additions & 2 deletions src/Elara/Prim/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ falseCtorName :: Qualified Text
falseCtorName = Qualified "False" (ModuleName ("Elara" :| ["Prim"]))

emptyListCtorName :: Qualified Text
emptyListCtorName = Qualified "[]" (ModuleName ("Elara" :| ["Prim"]))
emptyListCtorName = Qualified "empty" (ModuleName ("Elara" :| ["Prim"]))

consCtorName :: Qualified Text
consCtorName = Qualified "::" (ModuleName ("Elara" :| ["Prim"]))
consCtorName = Qualified "cons" (ModuleName ("Elara" :| ["Prim"]))

consType :: Member UniqueGen r => Sem r Type
consType = do
Expand Down

0 comments on commit 19054e9

Please sign in to comment.