Skip to content

Commit

Permalink
Pass context to compileProgram
Browse files Browse the repository at this point in the history
  • Loading branch information
cruessler committed Feb 18, 2024
1 parent eaa4ca7 commit acb9386
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions app/elm/Compiler/Ast.elm
Original file line number Diff line number Diff line change
Expand Up @@ -837,14 +837,14 @@ compile context node =
[ Instruction.Raise error ]


compileProgram : Program -> CompiledProgram
compileProgram { functions, body } =
compileProgram : Context -> Program -> CompiledProgram
compileProgram context { functions, body } =
let
compiledFunctions =
List.map compileFunction functions

instructions =
List.concatMap (compileInContext Statement) body
List.concatMap (compileInContext context) body
in
{ instructions = instructions
, compiledFunctions = compiledFunctions
Expand Down
4 changes: 2 additions & 2 deletions app/elm/Logo.elm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Logo exposing
, step
)

import Compiler.Ast as Ast
import Compiler.Ast as Ast exposing (Context(..))
import Compiler.Linker as Linker
import Compiler.Parser as Parser
import Dict
Expand Down Expand Up @@ -73,7 +73,7 @@ compile program logo =
program
|> Parser.run parser
|> Result.mapError ParseError
|> Result.map Ast.compileProgram
|> Result.map (Ast.compileProgram Statement)

result =
compiledProgram
Expand Down
4 changes: 2 additions & 2 deletions app/elm/StandardLibrary.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module StandardLibrary exposing (compiledFunctions)

import Compiler.Ast as Ast exposing (CompiledFunction)
import Compiler.Ast as Ast exposing (CompiledFunction, Context(..))
import Compiler.Parser as Parser
import Dict
import Parser.Advanced as Parser
Expand Down Expand Up @@ -45,7 +45,7 @@ compiledFunctions =
compiledProgram =
functions
|> Parser.run parser
|> Result.map Ast.compileProgram
|> Result.map (Ast.compileProgram Statement)
in
compiledProgram
|> Result.map .compiledFunctions
Expand Down
4 changes: 2 additions & 2 deletions app/elm/Vm/Vm.elm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ machine as well as functions for running it.
-}

import Array exposing (Array)
import Compiler.Ast as Ast exposing (CompiledFunction, CompiledProgram, Program)
import Compiler.Ast as Ast exposing (CompiledFunction, CompiledProgram, Context(..), Program)
import Compiler.Linker as Linker exposing (LinkedProgram)
import Compiler.Parser as Parser exposing (Parser)
import Dict exposing (Dict)
Expand Down Expand Up @@ -489,7 +489,7 @@ parseAndCompileProgram : Parser Program -> String -> Result Error CompiledProgra
parseAndCompileProgram parser =
Parser.run parser
>> Result.mapError (always <| Internal ParsingFailed)
>> Result.map Ast.compileProgram
>> Result.map (Ast.compileProgram Statement)


parseAndEvalInstructions : Vm -> List Type.Value -> Result Error Vm
Expand Down

0 comments on commit acb9386

Please sign in to comment.