Skip to content

Commit d10914c

Browse files
authored
build(git): merged pull request #31 from plume-lang/feat/cf-statements
Added support for while statements
2 parents 9568fbe + 253cdbd commit d10914c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+1777
-320
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,10 @@ jobs:
2525
with:
2626
submodules: true
2727

28-
- name: Install CLang on Windows and Ubuntu
29-
uses: KyleMayes/install-llvm-action@v2
30-
if: startsWith(matrix.os, 'windows') || startsWith(matrix.os, 'ubuntu')
31-
with:
32-
version: "17.0"
33-
34-
- uses: xmake-io/github-action-setup-xmake@v1
35-
with:
36-
xmake-version: latest
37-
actions-cache-folder: '.xmake-cache'
38-
actions-cache-key: '${{matrix.os}}'
39-
4028
- name: Checking for dependencies
4129
run: |
4230
python3 --version
43-
xmake --version --root
44-
45-
- name: Update xmake repository
46-
run: xmake repo --update --root
31+
node --version
4732
4833
- name: Set up GHC ${{ matrix.ghc-version }}
4934
uses: haskell-actions/setup@v2
@@ -82,7 +67,7 @@ jobs:
8267
key: ${{ steps.cache.outputs.cache-primary-key }}
8368

8469
- name: Build compiler and VM
85-
run: python3 scripts/build_native.py --root
70+
run: python3 scripts/build_project.py
8671

8772
- name: Create ZIP archive on UNIX
8873
if: startsWith(matrix.os, 'ubuntu') || startsWith(matrix.os, 'macos')

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,6 @@ CMakeFiles
4848

4949
node_modules
5050

51-
example/**/*.js
51+
example/**/*.js
52+
53+
.idea

app/Main.hs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Main where
55

66
import Control.Monad.Exception
77
import Control.Monad.Parser
8-
import Data.Text.IO hiding (putStr)
8+
import Data.Text.IO hiding (putStr, writeFile)
99
import Plume.Compiler.ClosureConversion.Conversion
1010
import Plume.Compiler.Desugaring.Desugar
1111
import Plume.Compiler.TypeErasure.EraseType
@@ -55,6 +55,13 @@ main = setEncoding $ do
5555
MkOptions file_input ext_type file_output remove_prelude <- parseOptions
5656
let output = fromMaybe file_input file_output
5757

58+
case ext_type of
59+
"native" -> pure ()
60+
"js" -> pure ()
61+
_ -> do
62+
ppFailure $ "Invalid backend, received: " <> fromString ext_type
63+
exitFailure
64+
5865
env <- lookupEnv "PLUME_PATH"
5966
mod' <- lookupEnv "PPM_PATH"
6067

@@ -73,7 +80,9 @@ main = setEncoding $ do
7380

7481
paths <- fromEither [] <$> parse getPaths file content
7582
let paths' = case env of
76-
Just _ | not remove_prelude -> ("std:prelude", Nothing) : paths
83+
Just _ | not remove_prelude -> do
84+
let preludeName = if ext_type == "js" then "prelude-js.plm" else "prelude.plm"
85+
("std:" <> preludeName, Nothing) : paths
7786
_ -> paths
7887

7988
ppBuilding "Parsing file and dependencies..."
@@ -82,7 +91,7 @@ main = setEncoding $ do
8291
void $ checkModule (env, mod') file
8392

8493
runConcreteToAbstract env dir paths' file `with` \ast -> do
85-
let ast' = concatMap (removeUselessBlocks (False, False)) ast
94+
let ast' = concatMap (removeUselessBlocks (False, True)) ast
8695
ppBuilding "Typechecking..."
8796
runSynthesize ast' `with` \tlir -> do
8897
ppBuilding "Compiling and optimizing..."
@@ -97,9 +106,9 @@ main = setEncoding $ do
97106

98107
let outputPath = output -<.> "js"
99108
writeFileText outputPath code
100-
ppSuccess ("Javacsript code written to " <> fromString outputPath)
109+
ppSuccess ("Javascript code written to " <> fromString outputPath)
101110

102-
_ -> do
111+
"native" -> do
103112
(bytecode, natives', constants) <- runLLIRAssembler desugared
104113
let nativeFuns = getNativeFunctions natives'
105114

@@ -112,11 +121,20 @@ main = setEncoding $ do
112121
writeFileLBS newPath sbc
113122
ppSuccess ("Bytecode written to " <> fromString newPath)
114123

124+
_ -> ppFailure "Invalid backend"
125+
115126
printBytecode :: [Instruction] -> IO ()
116127
printBytecode bytecode =
117128
mapM_
118129
( \(i, instr) -> do
119130
putStr (show i <> ": ")
120131
print instr
121132
)
122-
(zip [0 :: Int ..] bytecode)
133+
(zip [0 :: Int ..] bytecode)
134+
135+
showBytecode :: [Instruction] -> Text
136+
showBytecode bytecode =
137+
unlines
138+
[ show i <> ": " <> show instr
139+
| (i, instr) <- zip [0 :: Int ..] bytecode
140+
]

example/basic/fibonacci.plm

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
require "helper"
22

3-
fn fib_with_tco(n: int, a: int, b: int): int {
4-
if n == 0 {
5-
return a
6-
} else {
7-
return fib_with_tco(n - 1, b, a + b)
3+
fn fib(n: int) =>
4+
switch n {
5+
case 0 => 0
6+
case 1 => 1
7+
case ? => fib(n - 1) + fib(n - 2)
88
}
9-
}
10-
11-
fn fib(n: int) => fib_with_tco(n, 0, 1)
129

1310
xs = range(0, 31).map(fn (n) => (n, fib(n)))
1411

0 commit comments

Comments
 (0)