Skip to content

Commit

Permalink
♻️ fix routines sortby
Browse files Browse the repository at this point in the history
  • Loading branch information
laendoor committed Dec 15, 2021
1 parent 8cc1cfe commit d12f62d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions cmp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
foones() {
TEST_INPUT="test/mamarracho/test$1.flecha"
FOONES="_cmp/foones/test$1.mam"
FOONES_OUT="_cmp/foones/test$1.output"
./bin/flecha_foones "$TEST_INPUT" > "$FOONES"
./bin/mamarracho "$FOONES" > "$FOONES_OUT"
}

diwy() {
TEST_INPUT="test/mamarracho/test$1.flecha"
DIWY="_cmp/diwy/test$1.mam"
DIWY_OUT="_cmp/diwy/test$1.output"
cabal run --verbose=silent flecha -- "$TEST_INPUT" --mam > "$DIWY"
./bin/mamarracho "$DIWY" > "$DIWY_OUT"
}

RUN_MODE=$1
Expand Down
6 changes: 5 additions & 1 deletion src/Mamarracho.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Control.Monad.State (execState, MonadState(put, get))
import Data.Char (ord)
import Data.Function (on)
import Data.List (intercalate, sortBy, (\\), union)
import Data.Text (unpack, replace, pack)

-- Compilation

Expand Down Expand Up @@ -208,7 +209,10 @@ getCode mam = [Jump "start"]
++ code mam

unfoldRoutines :: [CodeRoutine] -> [Instruction]
unfoldRoutines = unfoldRoutines' [] . sortBy (compare `on` fst)
unfoldRoutines = unfoldRoutines' [] . sortBy (compare `on` fstNum)

fstNum :: (Label, [Instruction]) -> Int
fstNum (label, _) = read $ unpack $ replace (pack "rtn") (pack "") (pack label) :: Int

unfoldRoutines' :: [Instruction] -> [CodeRoutine] -> [Instruction]
unfoldRoutines' ins [] = ins
Expand Down

0 comments on commit d12f62d

Please sign in to comment.