@@ -11,11 +11,11 @@ open Naggum.Util.MaybeMonad
1111open Naggum.Compiler .Reader
1212open Naggum.Compiler .MathGenerator
1313open System
14- open System.Reflection
1514open System.Reflection .Emit
1615open System.Text .RegularExpressions
1716
18- type GeneratorFactory ( typeBldr : TypeBuilder ) =
17+ type GeneratorFactory ( typeBuilder : TypeBuilder ,
18+ methodBuilder : MethodBuilder) =
1919 member private this.makeObjectGenerator ( o : obj ) =
2020 match o with
2121 | :? System.Int32 ->
@@ -39,40 +39,44 @@ type GeneratorFactory(typeBldr:TypeBuilder) =
3939 member private this.MakeFormGenerator ( context : Context , form : SExp list ) =
4040 match form with
4141 | ( Atom ( Symbol " defun" ) :: Atom ( Symbol name) :: List args :: body) ->
42- new DefunGenerator( context, typeBldr , name, args, body, this) :> IGenerator
42+ new DefunGenerator( context, typeBuilder , name, args, body, this) :> IGenerator
4343 | Atom ( Symbol " if" ) :: condition :: if_ true :: if_ false :: [] -> //full if form
44- new FullIfGenerator( context, typeBldr , condition, if_ true, if_ false, this) :> IGenerator
44+ new FullIfGenerator( context, typeBuilder , condition, if_ true, if_ false, this) :> IGenerator
4545 | Atom ( Symbol " if" ) :: condition :: if_ true :: [] -> //reduced if form
46- new ReducedIfGenerator( context, typeBldr, condition, if_ true, this) :> IGenerator
47- | Atom ( Symbol " let" ) :: bindings :: body -> //let form
48- new LetGenerator( context, typeBldr, bindings, body, this) :> IGenerator
46+ new ReducedIfGenerator( context, typeBuilder, condition, if_ true, this) :> IGenerator
47+ | Atom ( Symbol " let" ) :: bindings :: body -> // let form
48+ new LetGenerator( context,
49+ typeBuilder,
50+ methodBuilder,
51+ bindings,
52+ body,
53+ this) :> IGenerator
4954 | Atom ( Symbol " quote" ) :: quotedExp :: [] ->
50- new QuoteGenerator( context, typeBldr , quotedExp, this) :> IGenerator
55+ new QuoteGenerator( context, typeBuilder , quotedExp, this) :> IGenerator
5156 | Atom ( Symbol " new" ) :: Atom ( Symbol typeName) :: args ->
52- new NewObjGenerator( context, typeBldr , typeName, args, this) :> IGenerator
57+ new NewObjGenerator( context, typeBuilder , typeName, args, this) :> IGenerator
5358 | Atom ( Symbol " +" ) :: args ->
54- new ArithmeticGenerator( context, typeBldr , args, OpCodes.Add, this) :> IGenerator
59+ new ArithmeticGenerator( context, typeBuilder , args, OpCodes.Add, this) :> IGenerator
5560 | Atom ( Symbol " -" ) :: args ->
56- new ArithmeticGenerator( context, typeBldr , args, OpCodes.Sub, this) :> IGenerator
61+ new ArithmeticGenerator( context, typeBuilder , args, OpCodes.Sub, this) :> IGenerator
5762 | Atom ( Symbol " *" ) :: args ->
58- new ArithmeticGenerator( context, typeBldr , args, OpCodes.Mul, this) :> IGenerator
63+ new ArithmeticGenerator( context, typeBuilder , args, OpCodes.Mul, this) :> IGenerator
5964 | Atom ( Symbol " /" ) :: args ->
60- new ArithmeticGenerator( context, typeBldr , args, OpCodes.Div, this) :> IGenerator
65+ new ArithmeticGenerator( context, typeBuilder , args, OpCodes.Div, this) :> IGenerator
6166 | Atom ( Symbol " =" ) :: arg_ a :: arg_ b :: [] ->
62- new SimpleLogicGenerator( context, typeBldr , arg_ a, arg_ b, OpCodes.Ceq, this) :> IGenerator
67+ new SimpleLogicGenerator( context, typeBuilder , arg_ a, arg_ b, OpCodes.Ceq, this) :> IGenerator
6368 | Atom ( Symbol " <" ) :: arg_ a :: arg_ b :: [] ->
64- new SimpleLogicGenerator( context, typeBldr , arg_ a, arg_ b, OpCodes.Clt, this) :> IGenerator
69+ new SimpleLogicGenerator( context, typeBuilder , arg_ a, arg_ b, OpCodes.Clt, this) :> IGenerator
6570 | Atom ( Symbol " >" ) :: arg_ a :: arg_ b :: [] ->
66- new SimpleLogicGenerator( context, typeBldr , arg_ a, arg_ b, OpCodes.Cgt, this) :> IGenerator
71+ new SimpleLogicGenerator( context, typeBuilder , arg_ a, arg_ b, OpCodes.Cgt, this) :> IGenerator
6772 | Atom ( Symbol " call" ) :: Atom ( Symbol fname) :: instance :: args ->
68- new InstanceCallGenerator( context, typeBldr , instance, fname, args, this) :> IGenerator
73+ new InstanceCallGenerator( context, typeBuilder , instance, fname, args, this) :> IGenerator
6974 | Atom ( Symbol fname) :: args -> //generic funcall pattern
7075 let tryGetType typeName =
7176 try Some ( context.types.[ new Symbol( typeName)]) with
7277 | _ ->
7378 try Some ( Type.GetType typeName) with
7479 | _ -> None
75-
7680
7781 let callRegex = new Regex( @" ([\w\.]+)\.(\w+)" , RegexOptions.Compiled)
7882 let callMatch = callRegex.Match fname
@@ -86,16 +90,19 @@ type GeneratorFactory(typeBldr:TypeBuilder) =
8690 if Option.isSome maybeClrType then
8791 let clrType = Option.get maybeClrType
8892 let methodName = callMatch.Groups.[ 2 ]. Value
89- new ClrCallGenerator( context, typeBldr , clrType, methodName, args, this) :> IGenerator
93+ new ClrCallGenerator( context, typeBuilder , clrType, methodName, args, this) :> IGenerator
9094 else
91- new FunCallGenerator( context, typeBldr , fname, args, this) :> IGenerator
95+ new FunCallGenerator( context, typeBuilder , fname, args, this) :> IGenerator
9296 | _ -> failwithf " Form %A is not supported yet" list
9397
9498 member private this.makeSequenceGenerator ( context : Context , seq : SExp list ) =
95- new SequenceGenerator( context, typeBldr , seq,( this :> IGeneratorFactory))
99+ new SequenceGenerator( context, typeBuilder , seq,( this :> IGeneratorFactory))
96100
97101 member private this.makeBodyGenerator ( context : Context , body : SExp list ) =
98- new BodyGenerator( context, typeBldr, body,( this :> IGeneratorFactory))
102+ new BodyGenerator( context,
103+ methodBuilder,
104+ body,
105+ ( this :> IGeneratorFactory))
99106
100107 interface IGeneratorFactory with
101108 member this.MakeGenerator context sexp =
@@ -107,4 +114,6 @@ type GeneratorFactory(typeBldr:TypeBuilder) =
107114
108115 member this.MakeBody context body = this.makeBodyGenerator ( context, body) :> IGenerator
109116
110- member this.MakeGeneratorFactory newTypeBuilder = ( new GeneratorFactory ( newTypeBuilder)) :> IGeneratorFactory
117+ member this.MakeGeneratorFactory newTypeBuilder newMethodBuilder =
118+ new GeneratorFactory( newTypeBuilder,
119+ newMethodBuilder) :> IGeneratorFactory
0 commit comments