-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prelude split into multiple files (#133)
Now the Prelude is split into several files. The two most notable files are `Base/Types` with some standard types and `Base/Operators` with some standard operators. Each of other files contains only methods that should be visible without importing anything. There is no `Base/List` file with standard methods on list. The user must import `List` module by himself. Other minor changes are the following: - Added LICENSE header in each library file - Added comparison operators for Bool type - Added unary minus to `Int` type - Removed `makeString` method (function?), as it seemed broken.
- Loading branch information
Showing
10 changed files
with
168 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
(* This file is part of DBL, released under MIT license. | ||
* See LICENSE for details. | ||
*) | ||
|
||
import open Types | ||
|
||
pub method toString = if self then "True" else "False" | ||
|
||
pub method neg = | ||
if self then False else True | ||
|
||
pub method equal (oth : Bool) = | ||
if self then oth else oth.neg | ||
|
||
pub method neq (oth : Bool) = | ||
if self then oth.neg else oth | ||
|
||
pub method gt (oth : Bool) = | ||
self && oth.neg | ||
|
||
pub method lt {self : Bool} oth = | ||
self.neg && oth | ||
|
||
pub method ge (oth : Bool) = | ||
self || oth.neg | ||
|
||
pub method le {self : Bool} oth = | ||
self.neg || oth |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
(* This file is part of DBL, released under MIT license. | ||
* See LICENSE for details. | ||
*) | ||
|
||
import open /Base/Types | ||
|
||
pub method code = (extern dbl_chrCode : Char -> Int) self | ||
|
||
pub method equal = (extern dbl_eqInt : Char -> Char -> Bool) self | ||
pub method neq = (extern dbl_neqInt : Char -> Char -> Bool) self | ||
pub method gt = (extern dbl_gtInt : Char -> Char -> Bool) self | ||
pub method lt = (extern dbl_ltInt : Char -> Char -> Bool) self | ||
pub method ge = (extern dbl_geInt : Char -> Char -> Bool) self | ||
pub method le = (extern dbl_leInt : Char -> Char -> Bool) self | ||
|
||
pub method toString = (extern dbl_chrToString : Char -> String) self |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
(* This file is part of DBL, released under MIT license. | ||
* See LICENSE for details. | ||
*) | ||
|
||
import open Types | ||
import open Operators | ||
|
||
pub method toString = (extern dbl_intToString : Int -> String) self | ||
|
||
pub method equal = (extern dbl_eqInt : Int -> Int -> Bool) self | ||
pub method neq = (extern dbl_neqInt : Int -> Int -> Bool) self | ||
pub method gt = (extern dbl_gtInt : Int -> Int -> Bool) self | ||
pub method lt = (extern dbl_ltInt : Int -> Int -> Bool) self | ||
pub method ge = (extern dbl_geInt : Int -> Int -> Bool) self | ||
pub method le = (extern dbl_leInt : Int -> Int -> Bool) self | ||
|
||
pub method add = (extern dbl_addInt : Int -> Int -> Int) self | ||
pub method sub = (extern dbl_subInt : Int -> Int -> Int) self | ||
pub method mul = (extern dbl_mulInt : Int -> Int -> Int) self | ||
|
||
pub method div {`re : {type X} -> Unit ->[|_] X} (n : Int) = | ||
if n.equal 0 then `re () | ||
else (extern dbl_divInt : Int -> Int -> Int) self n | ||
|
||
pub method mod {`re : {type X} -> Unit ->[|_] X} (n : Int) = | ||
if n.equal 0 then `re () | ||
else (extern dbl_modInt : Int -> Int -> Int) self n | ||
|
||
pub method neg {self : Int} = 0 - self | ||
|
||
pub method land = (extern dbl_andInt : Int -> Int -> Int) self | ||
pub method lor = (extern dbl_orInt : Int -> Int -> Int) self | ||
pub method lxor = (extern dbl_xorInt : Int -> Int -> Int) self | ||
|
||
pub method shiftl = (extern dbl_lslInt : Int -> Int -> Int) self | ||
pub method shiftr = (extern dbl_lsrInt : Int -> Int -> Int) self | ||
pub method ashiftr = (extern dbl_asrInt : Int -> Int -> Int) self |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
(* This file is part of DBL, released under MIT license. | ||
* See LICENSE for details. | ||
*) | ||
|
||
pub method fn (- .) = neg | ||
|
||
pub method fn (+) = add | ||
pub method fn (-) = sub | ||
pub method fn (%) = mod | ||
pub method fn (/) = div | ||
pub method fn ( * ) = mul | ||
|
||
pub method fn (==) = equal | ||
pub method fn (!=) = neq | ||
pub method fn (>) = gt | ||
pub method fn (>=) = ge | ||
pub method fn (<) = lt | ||
pub method fn (<=) = le | ||
|
||
pub method fn (&&&) = land | ||
pub method fn (^^^) = lxor | ||
pub method fn (|||) = lor | ||
pub method fn (<<) = shiftl | ||
pub method fn (>>) = shiftr | ||
pub method fn (>>>) = ashiftr | ||
|
||
pub method fn (:=) = set |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
(* This file is part of DBL, released under MIT license. | ||
* See LICENSE for details. | ||
*) | ||
|
||
import open /Base/Types | ||
import open /Base/Operators | ||
import /Base/Int | ||
|
||
pub method add = (extern dbl_strCat : String -> String -> String) self | ||
|
||
pub method equal = (extern dbl_eqStr : String -> String -> Bool) self | ||
pub method neq = (extern dbl_neqStr : String -> String -> Bool) self | ||
pub method gt = (extern dbl_gtStr : String -> String -> Bool) self | ||
pub method lt = (extern dbl_ltStr : String -> String -> Bool) self | ||
pub method ge = (extern dbl_geStr : String -> String -> Bool) self | ||
pub method le = (extern dbl_leStr : String -> String -> Bool) self | ||
|
||
pub method length = (extern dbl_strLen : String -> Int) self | ||
pub method get {`re : {type X} -> Unit ->[|_] X, self : String} (n : Int) = | ||
if n >= 0 && n < self.length then | ||
(extern dbl_strGet : String -> Int -> Char) self n | ||
else `re () | ||
|
||
pub method toList {self : String} = | ||
let getChar = extern dbl_strGet : String -> Int -> Char in | ||
let rec iter (n : Int) acc = | ||
if n == 0 then | ||
acc | ||
else | ||
iter (n - 1) (getChar self (n - 1) :: acc) | ||
in iter self.length [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
(* This file is part of DBL, released under MIT license. | ||
* See LICENSE for details. | ||
*) | ||
|
||
pub data Bool = False | True | ||
|
||
pub data Option A = None | Some of A | ||
|
||
pub data rec List A = [] | (::) of A, List A | ||
|
||
pub data Pair X Y = (,) of X, Y | ||
|
||
pub data Either X Y = Left of X | Right of Y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters