Skip to content

Commit

Permalink
Juvix.Core.Main.Language
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszcz committed Dec 12, 2024
1 parent 710b4fe commit 33737f0
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Juvix.lean
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-- This module serves as the root of the `Juvix` library.
-- Import modules here that should be built as part of the library.
import Juvix.Basic
import Juvix.Core.Main
1 change: 0 additions & 1 deletion Juvix/Basic.lean

This file was deleted.

3 changes: 3 additions & 0 deletions Juvix/Core/Main.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

import Juvix.Core.Main.Language
import Juvix.Core.Main.Semantics
3 changes: 3 additions & 0 deletions Juvix/Core/Main/Language.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

import Juvix.Core.Main.Language.Base
import Juvix.Core.Main.Language.Value
40 changes: 40 additions & 0 deletions Juvix/Core/Main/Language/Base.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

namespace Juvix.Core.Main

abbrev Name : Type := String

inductive Constant : Type where
| int : Int → Constant
| string : String → Constant
deriving Inhabited, DecidableEq

inductive BuiltinOp : Type where
| add_int : BuiltinOp
| sub_int : BuiltinOp
| mul_int : BuiltinOp
| div_int : BuiltinOp
deriving Inhabited, DecidableEq

mutual
inductive Expr : Type where
| var : Nat → Expr
| ident : Name → Expr
| const : Constant → Expr
| app : Expr → Expr → Expr
| builtin_app : (oper : BuiltinOp) → (args : List Expr) → Expr
| constr_app : (constr : Name) → (args : List Expr) → Expr
| lambda : (body : Expr) → Expr
| let : (value : Expr) → (body : Expr) → Expr
| case : (value : Expr) → (branches : List CaseBranch) → Expr
| unit : Expr
deriving Inhabited

structure CaseBranch where
constr : Name
body : Expr
end

structure Program where
defs : List Expr

end Juvix.Core.Main
15 changes: 15 additions & 0 deletions Juvix/Core/Main/Language/Value.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

import Juvix.Core.Main.Language.Base

namespace Juvix.Core.Main

inductive Value : Type where
| const : Constant → Value
| constr_app : (constr : Name) → (args : List Value) → Value
| closure : (ctx : List Value) → (value : Expr) → Value
| unit : Value
deriving Inhabited

abbrev Context : Type := List Value

end Juvix.Core.Main
11 changes: 11 additions & 0 deletions Juvix/Core/Main/Semantics.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

import Juvix.Core.Main.Language

namespace Juvix.Core.Main

def f : Expr -> Expr := λ e =>
match e with
| Expr.lambda (body := e) => e
| _ => Expr.lambda (body := e)

end Juvix.Core.Main
Empty file added Juvix/Core/Stored/Language.lean
Empty file.
Empty file.
Empty file.
Empty file.

0 comments on commit 33737f0

Please sign in to comment.