Skip to content

Commit

Permalink
Merge pull request #44 from bryanedds/development
Browse files Browse the repository at this point in the history
Development

Former-commit-id: 567296c
  • Loading branch information
bryanedds committed Sep 6, 2015
2 parents 74cf683 + 364be0b commit 9c26c0e
Show file tree
Hide file tree
Showing 19 changed files with 930 additions and 608 deletions.
8 changes: 4 additions & 4 deletions Aml/Aml/Aml/Ast.fs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ and [<NoEquality; NoComparison>] Env =
EnvDebugInfo : DebugInfo
EnvUsingFiles : string Set
EnvInterventionBranchLists : InterveneBranch list list
EnvOptLanguageModule : ILanguageModule option
EnvOptLanguagePlugin : ILanguagePlugin option
EnvOptWorkBench : obj option
EnvPath : string
EnvRecordingCount : int
Expand All @@ -412,9 +412,9 @@ and [<NoEquality; NoComparison>] Env =
and ISpecialContent =
abstract ToValue : unit -> Expr

/// Interface for a language module.
and ILanguageModule =
/// Try to initialize the language module.
/// Interface for a language plugin.
and ILanguagePlugin =
/// Try to initialize the language plugin.
abstract TryInitialize : Env -> Env option
/// Convert a special value to a special object.
abstract SpecialValueToSpecialObject : Expr -> Env -> Expr
Expand Down
40 changes: 20 additions & 20 deletions Aml/Aml/Aml/Evaluator.fs
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ module Evaluator =

/// Apply a special builtin operation.
and applySpecialBuiltin name args argCount env =
match env.EnvOptLanguageModule with
match env.EnvOptLanguagePlugin with
| Some lm -> lm.ApplySpecialBuiltin name args argCount env
| None -> makeEvalViolation ":v/eval/invalidBuiltinOperator" "Built-in operator not found." env

Expand Down Expand Up @@ -881,9 +881,9 @@ module Evaluator =

/// Apply a special selector.
and applySpecialSelector key target env =
match env.EnvOptLanguageModule with
match env.EnvOptLanguagePlugin with
| Some lm -> lm.ApplySpecialSelector key target env
| None -> makeEvalViolation ":v/contract/missingLanguageModule" "Cannot evaluate a special selector without a language module." env
| None -> makeEvalViolation ":v/contract/missingLanguagePlugin" "Cannot evaluate a special selector without a language plugin." env

/// Apply a composite selector.
and applyCompositeSelector key selectorType members env =
Expand Down Expand Up @@ -969,22 +969,22 @@ module Evaluator =

/// Evaluate a special value.
and evalSpecialValue specialValue specialValueExpr env =
match env.EnvOptLanguageModule with
match env.EnvOptLanguagePlugin with
| Some lm when lm.Name = specialValue.SVLanguageName ->
let specialObject = lm.SpecialValueToSpecialObject specialValueExpr env
match specialObject with
| Violation _ as v -> forwardEvalViolation v env
| SpecialObject _ as s -> evalExpr s env
| _ -> failwith "Unexpected match failure in 'Aml.Evaluator.evalSpecialValue'."
| Some _ -> makeEvalViolation ":v/languageModule/mismatchedLanguageModule" "Wrong language module for special value evaluation." env
| None -> makeEvalViolation ":v/languageModule/missingLanguageModule" "Cannot evaluate a special value without a language module." env
| Some _ -> makeEvalViolation ":v/languagePlugin/mismatchedLanguagePlugin" "Wrong language plugin for special value evaluation." env
| None -> makeEvalViolation ":v/languagePlugin/missingLanguagePlugin" "Cannot evaluate a special value without a language plugin." env

/// Evaluate a special object.
and evalSpecialObject specialObject specialObjectExpr env =
match env.EnvOptLanguageModule with
match env.EnvOptLanguagePlugin with
| Some lm when lm.Guid = specialObject.SOLanguageGuid -> lm.EvalSpecialObject specialObjectExpr env
| Some _ -> makeEvalViolation ":v/languageModule/mismatchedLanguageModule" "Wrong language module for special object evaluation." env
| None -> makeEvalViolation ":v/languageModule/missingLanguageModule" "Cannot evaluate a special object without a language module." env
| Some _ -> makeEvalViolation ":v/languagePlugin/mismatchedLanguagePlugin" "Wrong language plugin for special object evaluation." env
| None -> makeEvalViolation ":v/languagePlugin/missingLanguagePlugin" "Cannot evaluate a special object without a language plugin." env

/// Evaluate a violation.
and evalViolation violation vioExpr env =
Expand All @@ -997,9 +997,9 @@ module Evaluator =

/// Evaluate a prefixed expressions.
and evalPrefixed (_ : PrefixedRecord) pfxExpr env =
match env.EnvOptLanguageModule with
match env.EnvOptLanguagePlugin with
| Some lm -> lm.EvalPrefixed pfxExpr env
| _ -> makeEvalViolation ":v/languageModule/missingLanguageModule" "Cannot evaluate prefixed expressions without a language module." env
| _ -> makeEvalViolation ":v/languagePlugin/missingLanguagePlugin" "Cannot evaluate prefixed expressions without a language plugin." env

/// Evaluate an operation.
and evalOperation (exprs : Expr list) exprCount env =
Expand Down Expand Up @@ -1370,27 +1370,27 @@ module Evaluator =

/// Evaluate an Aml language.
and evalUsingLanguage usingLanguage env =
match env.EnvOptLanguageModule with
// TODO: consider making a violation if a different LM than a current one is loaded
match env.EnvOptLanguagePlugin with
// TODO: consider making a violation if a different LP than a current one is loaded
| Some _ -> makeEvalUnit env
| None ->
try let assembly = Reflection.Assembly.LoadFrom usingLanguage.ULPath
let instance = assembly.CreateInstance usingLanguage.ULType
if instance = null then makeEvalViolation ":v/languageModule/creationFailure" ("Could not make language module '" + usingLanguage.ULType + "'.") env
if instance = null then makeEvalViolation ":v/languagePlugin/creationFailure" ("Could not make language plugin '" + usingLanguage.ULType + "'.") env
else
let languageModule = instance :?> ILanguageModule
let envLm = { env with EnvOptLanguageModule = Some languageModule }
let optEnvLm = languageModule.TryInitialize envLm
let languagePlugin = instance :?> ILanguagePlugin
let envLm = { env with EnvOptLanguagePlugin = Some languagePlugin }
let optEnvLm = languagePlugin.TryInitialize envLm
match optEnvLm with
| Some envLm -> makeEvalUnit envLm
| None -> makeEvalViolation ":v/languageModule/creationFailure" ("Could not make language module '" + usingLanguage.ULType + "' due to duplicate declaration names.") env
| None -> makeEvalViolation ":v/languagePlugin/creationFailure" ("Could not make language plugin '" + usingLanguage.ULType + "' due to duplicate declaration names.") env
with exn -> makeEvalExceptionViolation exn env

/// Evaluate a special series.
and evalSpecialSeries specialSeries env =
match env.EnvOptLanguageModule with
match env.EnvOptLanguagePlugin with
| Some lm -> lm.EvalSpecialSeries specialSeries env
| _ -> makeEvalViolation ":v/languageModule/missingLanguageModule" "Cannot evaluate special series without a language module." env
| _ -> makeEvalViolation ":v/languagePlugin/missingLanguagePlugin" "Cannot evaluate special series without a language plugin." env

/// Evaluate an Aml expression structure.
and evalExpr expr env =
Expand Down
6 changes: 3 additions & 3 deletions Aml/Aml/Aml/EvaluatorPrimitives.fs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ module EvaluatorPrimitives =
match expr with
| Symbol symbol ->
if not ^ InitialBuiltinNames.Contains symbol.SymName then
match env.EnvOptLanguageModule with
match env.EnvOptLanguagePlugin with
| Some lm -> lm.IsSpecialBuiltin symbol.SymName env
| None -> false
else true
Expand All @@ -191,9 +191,9 @@ module EvaluatorPrimitives =
let getType value env =
match value with
| SpecialObject _ | Prefixed _ ->
match env.EnvOptLanguageModule with
match env.EnvOptLanguagePlugin with
| Some lm -> lm.GetSpecialType value env
| None -> makeViolationWithPositions ":v/languageModule/missingLanguageModule" "Cannot get type of special value without a language module." env
| None -> makeViolationWithPositions ":v/languagePlugin/missingLanguagePlugin" "Cannot get type of special value without a language plugin." env
| _ ->
let optType = tryFindTypeByValue value
match optType with
Expand Down
2 changes: 1 addition & 1 deletion Aml/Aml/Aml/Initial.fs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ module Initial =
(DoubleTypeStr, DoubleType, makeDoc "A 64-bit, floating point, fractional number (may be 80-bit on certain platforms).")
(KeywordTypeStr, KeywordType, makeDoc "A purely symbolic value.")
(PackageTypeStr, PackageType, makeDoc "Couples an optional parameter with a value.")
(SpecialValueTypeStr, SpecialValueType, makeDoc "A value that describes a corresponding value in a language module.")
(SpecialValueTypeStr, SpecialValueType, makeDoc "A value that describes a corresponding value in a language plugin.")
(LambdaTypeStr, LambdaType, makeDoc "A lamda in terms of the lambda calculus.")
(UnitTypeStr, UnitType, makeDoc "A unit type (a type with no values).")
(RefTypeStr, RefType, makeDoc "A reference type for mutable values.")
Expand Down
4 changes: 2 additions & 2 deletions Aml/Aml/Aml/Primitives.fs
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ module Primitives =
debugInfo
usingFiles
interventionBranchLists
optLanguageModule
optLanguagePlugin
optWorkBench
path
recordingCount
Expand All @@ -512,7 +512,7 @@ module Primitives =
EnvDebugInfo = debugInfo
EnvUsingFiles = usingFiles
EnvInterventionBranchLists = interventionBranchLists
EnvOptLanguageModule = optLanguageModule
EnvOptLanguagePlugin = optLanguagePlugin
EnvOptWorkBench = optWorkBench
EnvPath = path
EnvRecordingCount = recordingCount
Expand Down
8 changes: 4 additions & 4 deletions Aml/Aml/Aml/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -487,15 +487,15 @@ module Tests =

let [<Fact>] interveneTest () = test {
Expected = "0"
Actual = "(intervene {} (:v/languageModule 0))" }
Actual = "(intervene {} (:v/languagePlugin 0))" }

let [<Fact>] intervene2Test () = test {
Expected = "0"
Actual = "(let (f () {}) (intervene (f) (:v/languageModule 0)))" }
Actual = "(let (f () {}) (intervene (f) (:v/languagePlugin 0)))" }

let [<Fact>] intervene3Test () = test {
Expected = "(violation :v/languageModule/missingLanguageModule)"
Actual = "(intervene {} (:v/languageModule {}))" }
Expected = "(violation :v/languagePlugin/missingLanguagePlugin)"
Actual = "(intervene {} (:v/languagePlugin {}))" }

let [<Fact>] interveneHideTest () = test {
Expected = "0"
Expand Down
2 changes: 1 addition & 1 deletion Aml/Aml/Aml/Writer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ module Writer =
let firstFileLineTrimmed = if trimStartOfFirstLine then firstFileLine.Trim () else firstFileLine
let start = positions.ParStart
let startFile = if start.StreamName.Length <> 0 then start.StreamName else "[N/A]"
let startStr = "[Ln: " + acstring start.Line + ", Col: " + string start.Column + ", In: " + startFile + "]"
let startStr = "[Ln: " + acstring start.Line + ", Col: " + acstring start.Column + ", In: " + startFile + "]"
let result = firstFileLineTrimmed + "\n " + startStr
Some result
else None
Expand Down
Loading

0 comments on commit 9c26c0e

Please sign in to comment.