Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Commit

Permalink
feat: syntax highlighting everywhere!!! (and fixed wrong output types)
Browse files Browse the repository at this point in the history
  • Loading branch information
prescientmoon committed Apr 22, 2020
1 parent c669772 commit 02070b4
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 28 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"scripts": {
"prepare:purescript": "rm -rf output/bundle.js && hygen bundle prepare",
"build:purescript": "spago build",
"dev": "pnpm run prepare:purescript && parcel public/index.html --port 8080 & nodemon",
"dev": "pnpm run prepare:purescript && parcel public/index.html --port 8080",
"prebuild": "rm -rf dist",
"bundle:purescript": "cross-env NODE_ENV=production pnpm run prepare:purescript && spago bundle-app -t output/prod-bundle.js",
"build": "tsc && pnpm run bundle:purescript && parcel build public/index.html",
Expand Down
5 changes: 4 additions & 1 deletion src/Component/Editor.purs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ component =
typeMap = case solveExpression expression' of
Right map -> Map.delete Nowhere map
Left _ -> mempty
print $ expression
printString $ printTypeMap typeMap
-- printString $ printSource expression'
-- TODO: make it so this accounts for errors
Expand Down Expand Up @@ -152,7 +153,9 @@ component =
state'' = set (_atNode currentFunction id) (Just node) state'

state''' = set (_atNodeData currentFunction id) (Just def) state''
void $ put $ setId state'''

state'''' = over _functions (G.insertEdge name currentFunction) state'''
void $ put $ setId state''''
handleAction Compile
ChangeTab newTab -> do
oldTab <- gets $ view _currentTab
Expand Down
3 changes: 2 additions & 1 deletion src/Control/Monad/Dataflow/Solve/SolveExpression.purs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Data.Array as Array
import Data.Either (Either)
import Data.Map as Map
import Data.Tuple (Tuple(..))
import Lunarbox.Capability.Editor.Type (prettify)
import Lunarbox.Control.Monad.Dataflow.Infer (InferEnv(..), InferOutput(..), runInfer)
import Lunarbox.Control.Monad.Dataflow.Infer.InferExpression (infer)
import Lunarbox.Control.Monad.Dataflow.Solve (SolveContext(..), runSolve)
Expand Down Expand Up @@ -38,6 +39,6 @@ solveExpression expression = do
-- helper to print a typemap
printTypeMap :: forall l. Show l => Ord l => Map.Map l Type -> String
printTypeMap =
foldr (\(Tuple location type') result -> result <> "\n" <> show location <> " = " <> show type') ""
foldr (\(Tuple location type') result -> result <> "\n" <> show location <> " = " <> show (prettify type')) ""
<<< Array.sortBy (\(Tuple _ a) (Tuple _ b) -> compare (show a) $ show b)
<<< Map.toUnfoldable
24 changes: 10 additions & 14 deletions src/Data/Dataflow/Graph.purs
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,33 @@ module Lunarbox.Data.Dataflow.Graph
import Prelude
import Data.Lens (view)
import Data.Lens.At (at)
import Data.List (catMaybes, foldr, reverse)
import Data.List (catMaybes, foldr)
import Data.Maybe (Maybe)
import Data.Tuple (Tuple(..))
import Lunarbox.Data.Dataflow.Class.Expressible (nullExpr)
import Lunarbox.Data.Dataflow.Expression (Expression, VarName(..))
import Lunarbox.Data.Editor.ExtendedLocation (ExtendedLocation(..), letWithLocation)
import Lunarbox.Data.Dataflow.Expression (Expression(..), VarName(..), wrap)
import Lunarbox.Data.Editor.ExtendedLocation (ExtendedLocation(..))
import Lunarbox.Data.Graph (Graph, topologicalSort)

-- Takes a key and a graph and uses that to produce an Expression
compileGraphNode :: forall k v l. Ord k => (v -> Expression l) -> Graph k v -> k -> Maybe (Tuple k (Expression (ExtendedLocation k l)))
compileGraphNode toExpression graph key = Tuple key <$> map (DeepLocation key) <$> toExpression <$> view (at key) graph
compileGraphNode toExpression graph key = Tuple key <$> wrap (Location key) <$> map (DeepLocation key) <$> toExpression <$> view (at key) graph

-- Takes a graph of something and compiles it into an Expression
compileGraph :: forall k v l. Ord k => Eq l => Show k => (v -> Expression l) -> Graph k v -> Expression (ExtendedLocation k l)
compileGraph toExpression graph =
compileGraph :: forall k v l. Ord k => Eq l => Show k => Show l => (v -> Expression l) -> Graph k v -> k -> Expression (ExtendedLocation k l)
compileGraph toExpression graph main =
let
sorted =
reverse
$ topologicalSort
graph
topologicalSort
graph

emptyExpression = nullExpr Nowhere
in
foldr
( \(Tuple key value) body ->
if body == emptyExpression then
value
else
letWithLocation (Location key) (VarName $ show key) value body
Let Nowhere (VarName $ show key) value body
)
emptyExpression
(Variable Nowhere $ VarName $ show main)
$ catMaybes
$ compileGraphNode toExpression graph
<$> sorted
8 changes: 3 additions & 5 deletions src/Data/Editor/ExtendedLocation.purs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ module Lunarbox.Data.Editor.ExtendedLocation
import Prelude
import Data.Default (class Default, def)
import Data.Lens (Prism', prism')
import Data.List ((:), List(..))
import Data.Maybe (Maybe(..))
import Lunarbox.Data.Dataflow.Class.Expressible (nullExpr)
import Lunarbox.Data.Dataflow.Expression (Expression(..), VarName)
import Lunarbox.Data.Dataflow.Expression (Expression(..), VarName, wrap)

-- This represents a location which may or may not have an extra or a missing layer
data ExtendedLocation l l'
Expand Down Expand Up @@ -62,9 +61,8 @@ letWithLocation ::
letWithLocation location name value body =
Let Nowhere
name
value
$ Chain Nowhere
$ (Variable location name : body : Nil)
(wrap location value)
body

-- Normalize nested Locations
normalize :: forall l l' l''. ExtendedLocation l (ExtendedLocation l' l'') -> ExtendedLocation l (ExtendedLocation l' l'')
Expand Down
3 changes: 1 addition & 2 deletions src/Data/Editor/Node.purs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ module Lunarbox.Data.Editor.Node
) where

import Prelude
import Data.Default (def)
import Data.Lens (Prism', Traversal', is, prism')
import Data.Lens.Record (prop)
import Data.List (List, foldl, mapWithIndex)
Expand Down Expand Up @@ -52,7 +51,7 @@ compileNode nodes id child =
outputNode id case outputId of
Just outputId' -> Variable (Location outputId') $ VarName $ show outputId'
Nothing -> nothing
ComplexNode { inputs, function } -> Let def name value child
ComplexNode { inputs, function } -> Let Nowhere name value child
where
name = VarName $ show id

Expand Down
2 changes: 1 addition & 1 deletion src/Data/Editor/NodeGroup.purs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ compileNodeGroup group@(NodeGroup { nodes, output, inputs }) =
let
ordered = orderNodes group

bodyNodes = output : (ordered \\ inputs)
bodyNodes = output : (ordered \\ (output : inputs))

return =
foldl
Expand Down
3 changes: 1 addition & 2 deletions src/Data/Editor/Project.purs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import Data.Unfoldable (class Unfoldable)
import Lunarbox.Data.Dataflow.Expression (Expression)
import Lunarbox.Data.Dataflow.Graph (compileGraph)
import Lunarbox.Data.Editor.DataflowFunction (DataflowFunction(..), _VisualFunction, compileDataflowFunction)
import Lunarbox.Data.Editor.ExtendedLocation (normalize)
import Lunarbox.Data.Editor.FunctionName (FunctionName(..))
import Lunarbox.Data.Editor.Location (Location)
import Lunarbox.Data.Editor.Node (Node(..))
Expand All @@ -50,7 +49,7 @@ _ProjectMain :: Lens' Project FunctionName
_ProjectMain = newtypeIso <<< prop (SProxy :: _ "main")

compileProject :: Project -> Expression Location
compileProject = map normalize <<< compileGraph compileDataflowFunction <<< view _ProjectFunctions
compileProject (Project { functions, main }) = compileGraph compileDataflowFunction functions main

createEmptyFunction :: NodeId -> DataflowFunction
createEmptyFunction id =
Expand Down
7 changes: 6 additions & 1 deletion src/Data/Graph.purs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ module Lunarbox.Data.Graph
, keys
, vertices
, toUnfoldable
, insertEdge
, topologicalSort
, _Graph
) where

import Prelude
import Data.Bifunctor (lmap)
import Data.Bifunctor (lmap, rmap)
import Data.Foldable (class Foldable, foldMap, foldlDefault, foldrDefault)
import Data.Graph as CG
import Data.Lens (Traversal', lens, traversed, wander)
Expand Down Expand Up @@ -99,6 +100,10 @@ vertices = map fst <<< Map.values <<< unwrap
toUnfoldable :: forall u k v. Unfoldable u => Ord k => Graph k v -> u (Tuple k v)
toUnfoldable (Graph m) = Map.toUnfoldable $ fst <$> m

-- Insert an edge from the start key to the end key.
insertEdge :: forall k v. Ord k => k -> k -> Graph k v -> Graph k v
insertEdge from to (Graph g) = Graph $ Map.alter (map (rmap (Set.insert to))) from g

-- no idea how to implement this so I'm using an implementation from another lib
topologicalSort :: forall k v. Ord k => Graph k v -> List k
topologicalSort = CG.topologicalSort <<< CG.fromMap <<< unwrap
Expand Down

0 comments on commit 02070b4

Please sign in to comment.