Skip to content

Commit

Permalink
vbs: in env.set, pass the key as VB string instead of MAL symbol
Browse files Browse the repository at this point in the history
Take the opportunity to remove an unused variable from first steps.
  • Loading branch information
asarhaddon committed Oct 23, 2024
1 parent e1f657b commit 38fbfb0
Show file tree
Hide file tree
Showing 12 changed files with 162 additions and 159 deletions.
104 changes: 52 additions & 52 deletions impls/vbs/core.vbs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion impls/vbs/env.vbs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Class Environment
End Property

Public Sub Add(varKey, varValue)
Set objBinds.Item(varKey.Value) = varValue
Set objBinds.Item(varKey) = varValue
End Sub

Public Function Find(varKey)
Expand Down
12 changes: 6 additions & 6 deletions impls/vbs/step2_eval.vbs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Class Enviroment
End Sub

Public Function Add(objSymbol, objProcedure)
objDict.Add objSymbol.Value, objProcedure
objDict.Add objSymbol, objProcedure
End Function

Public Property Set Self(objThis)
Expand Down Expand Up @@ -46,7 +46,7 @@ Function MAdd(objArgs, objEnv)
Set MAdd = NewMalNum( _
objArgs.Item(1).Value + objArgs.Item(2).Value)
End Function
objEnv.Add NewMalSym("+"), NewVbsProc("MAdd", False)
objEnv.Add "+", NewVbsProc("MAdd", False)

Function MSub(objArgs, objEnv)
CheckArgNum objArgs, 2
Expand All @@ -55,7 +55,7 @@ Function MSub(objArgs, objEnv)
Set MSub = NewMalNum( _
objArgs.Item(1).Value - objArgs.Item(2).Value)
End Function
objEnv.Add NewMalSym("-"), NewVbsProc("MSub", False)
objEnv.Add "-", NewVbsProc("MSub", False)

Function MMul(objArgs, objEnv)
CheckArgNum objArgs, 2
Expand All @@ -64,7 +64,7 @@ Function MMul(objArgs, objEnv)
Set MMul = NewMalNum( _
objArgs.Item(1).Value * objArgs.Item(2).Value)
End Function
objEnv.Add NewMalSym("*"), NewVbsProc("MMul", False)
objEnv.Add "*", NewVbsProc("MMul", False)

Function MDiv(objArgs, objEnv)
CheckArgNum objArgs, 2
Expand All @@ -73,7 +73,7 @@ Function MDiv(objArgs, objEnv)
Set MDiv = NewMalNum( _
objArgs.Item(1).Value \ objArgs.Item(2).Value)
End Function
objEnv.Add NewMalSym("/"), NewVbsProc("MDiv", False)
objEnv.Add "/", NewVbsProc("MDiv", False)

Sub CheckArgNum(objArgs, lngArgNum)
If objArgs.Count - 1 <> lngArgNum Then
Expand Down Expand Up @@ -193,4 +193,4 @@ Sub Include(strFileName)
.GetFile(WScript.ScriptFullName)) & _
"\" & strFileName).ReadAll
End With
End Sub
End Sub
20 changes: 10 additions & 10 deletions impls/vbs/step3_env.vbs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Function MAdd(objArgs, objEnv)
Set MAdd = NewMalNum( _
objArgs.Item(1).Value + objArgs.Item(2).Value)
End Function
objEnv.Add NewMalSym("+"), NewVbsProc("MAdd", False)
objEnv.Add "+", NewVbsProc("MAdd", False)

Function MSub(objArgs, objEnv)
CheckArgNum objArgs, 2
Expand All @@ -25,7 +25,7 @@ Function MSub(objArgs, objEnv)
Set MSub = NewMalNum( _
objArgs.Item(1).Value - objArgs.Item(2).Value)
End Function
objEnv.Add NewMalSym("-"), NewVbsProc("MSub", False)
objEnv.Add "-", NewVbsProc("MSub", False)

Function MMul(objArgs, objEnv)
CheckArgNum objArgs, 2
Expand All @@ -34,7 +34,7 @@ Function MMul(objArgs, objEnv)
Set MMul = NewMalNum( _
objArgs.Item(1).Value * objArgs.Item(2).Value)
End Function
objEnv.Add NewMalSym("*"), NewVbsProc("MMul", False)
objEnv.Add "*", NewVbsProc("MMul", False)

Function MDiv(objArgs, objEnv)
CheckArgNum objArgs, 2
Expand All @@ -43,7 +43,7 @@ Function MDiv(objArgs, objEnv)
Set MDiv = NewMalNum( _
objArgs.Item(1).Value \ objArgs.Item(2).Value)
End Function
objEnv.Add NewMalSym("/"), NewVbsProc("MDiv", False)
objEnv.Add "/", NewVbsProc("MDiv", False)

Sub CheckArgNum(objArgs, lngArgNum)
If objArgs.Count - 1 <> lngArgNum Then
Expand All @@ -64,10 +64,10 @@ Function MDef(objArgs, objEnv)
CheckArgNum objArgs, 2
CheckType objArgs.Item(1), TYPES.SYMBOL
Set varRet = Evaluate(objArgs.Item(2), objEnv)
objEnv.Add objArgs.Item(1), varRet
objEnv.Add objArgs.Item(1).Value, varRet
Set MDef = varRet
End Function
objEnv.Add NewMalSym("def!"), NewVbsProc("MDef", True)
objEnv.Add "def!", NewVbsProc("MDef", True)

Function MLet(objArgs, objEnv)
Dim varRet
Expand All @@ -92,17 +92,17 @@ Function MLet(objArgs, objEnv)
For i = 0 To objBinds.Count - 1 Step 2
Set objSym = objBinds.Item(i)
CheckType objSym, TYPES.SYMBOL
objNewEnv.Add objSym, Evaluate(objBinds.Item(i + 1), objNewEnv)
objNewEnv.Add objSym.Value, Evaluate(objBinds.Item(i + 1), objNewEnv)
Next

Set varRet = Evaluate(objArgs.Item(2), objNewEnv)
Set MLet = varRet
End Function
objEnv.Add NewMalSym("let*"), NewVbsProc("MLet", True)
objEnv.Add "let*", NewVbsProc("MLet", True)

Call REPL()
Sub REPL()
Dim strCode, strResult
Dim strCode
While True
IO.Write "user> "

Expand Down Expand Up @@ -204,4 +204,4 @@ Sub Include(strFileName)
.GetFile(WScript.ScriptFullName)) & _
"\" & strFileName).ReadAll
End With
End Sub
End Sub
18 changes: 9 additions & 9 deletions impls/vbs/step4_if_fn_do.vbs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ Function MDef(objArgs, objEnv)
CheckArgNum objArgs, 2
CheckType objArgs.Item(1), TYPES.SYMBOL
Set varRet = Evaluate(objArgs.Item(2), objEnv)
objEnv.Add objArgs.Item(1), varRet
objEnv.Add objArgs.Item(1).Value, varRet
Set MDef = varRet
End Function
objNS.Add NewMalSym("def!"), NewVbsProc("MDef", True)
objNS.Add "def!", NewVbsProc("MDef", True)

Function MLet(objArgs, objEnv)
Dim varRet
Expand All @@ -43,13 +43,13 @@ Function MLet(objArgs, objEnv)
For i = 0 To objBinds.Count - 1 Step 2
Set objSym = objBinds.Item(i)
CheckType objSym, TYPES.SYMBOL
objNewEnv.Add objSym, Evaluate(objBinds.Item(i + 1), objNewEnv)
objNewEnv.Add objSym.Value, Evaluate(objBinds.Item(i + 1), objNewEnv)
Next

Set varRet = Evaluate(objArgs.Item(2), objNewEnv)
Set MLet = varRet
End Function
objNS.Add NewMalSym("let*"), NewVbsProc("MLet", True)
objNS.Add "let*", NewVbsProc("MLet", True)

Function MDo(objArgs, objEnv)
Dim varRet, i
Expand All @@ -62,7 +62,7 @@ Function MDo(objArgs, objEnv)
Next
Set MDo = varRet
End Function
objNS.Add NewMalSym("do"), NewVbsProc("MDo", True)
objNS.Add "do", NewVbsProc("MDo", True)

Function MIf(objArgs, objEnv)
Dim varRet
Expand Down Expand Up @@ -92,7 +92,7 @@ Function MIf(objArgs, objEnv)
End If
Set MIf = varRet
End Function
objNS.Add NewMalSym("if"), NewVbsProc("MIf", True)
objNS.Add "if", NewVbsProc("MIf", True)

Function MFn(objArgs, objEnv)
Dim varRet
Expand All @@ -110,13 +110,13 @@ Function MFn(objArgs, objEnv)
Set varRet = NewMalProc(objParams, objCode, objEnv)
Set MFn = varRet
End Function
objNS.Add NewMalSym("fn*"), NewVbsProc("MFn", True)
objNS.Add "fn*", NewVbsProc("MFn", True)

Call InitBuiltIn()

Call REPL()
Sub REPL()
Dim strCode, strResult
Dim strCode
While True
IO.Write "user> "

Expand Down Expand Up @@ -218,4 +218,4 @@ Sub Include(strFileName)
.GetFile(WScript.ScriptFullName)) & _
"\" & strFileName).ReadAll
End With
End Sub
End Sub
21 changes: 11 additions & 10 deletions impls/vbs/step5_tco.vbs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ Function MDef(objArgs, objEnv)
CheckArgNum objArgs, 2
CheckType objArgs.Item(1), TYPES.SYMBOL
Set varRet = Evaluate(objArgs.Item(2), objEnv)
objEnv.Add objArgs.Item(1), varRet
objEnv.Add objArgs.Item(1).Value, varRet
Set MDef = varRet
End Function
objNS.Add NewMalSym("def!"), NewVbsProc("MDef", True)
objNS.Add "def!", NewVbsProc("MDef", True)

Function MLet(objArgs, objEnv)
Dim varRet
Expand All @@ -49,13 +49,13 @@ Function MLet(objArgs, objEnv)
For i = 0 To objBinds.Count - 1 Step 2
Set objSym = objBinds.Item(i)
CheckType objSym, TYPES.SYMBOL
objNewEnv.Add objSym, Evaluate(objBinds.Item(i + 1), objNewEnv)
objNewEnv.Add objSym.Value, Evaluate(objBinds.Item(i + 1), objNewEnv)
Next

Set varRet = EvalLater(objArgs.Item(2), objNewEnv)
Set MLet = varRet
End Function
objNS.Add NewMalSym("let*"), NewVbsProc("MLet", True)
objNS.Add "let*", NewVbsProc("MLet", True)

Function MDo(objArgs, objEnv)
Dim varRet, i
Expand All @@ -71,7 +71,7 @@ Function MDo(objArgs, objEnv)
objEnv)
Set MDo = varRet
End Function
objNS.Add NewMalSym("do"), NewVbsProc("MDo", True)
objNS.Add "do", NewVbsProc("MDo", True)

Function MIf(objArgs, objEnv)
Dim varRet
Expand Down Expand Up @@ -101,7 +101,7 @@ Function MIf(objArgs, objEnv)
End If
Set MIf = varRet
End Function
objNS.Add NewMalSym("if"), NewVbsProc("MIf", True)
objNS.Add "if", NewVbsProc("MIf", True)

Function MFn(objArgs, objEnv)
Dim varRet
Expand All @@ -119,7 +119,7 @@ Function MFn(objArgs, objEnv)
Set varRet = NewMalProc(objParams, objCode, objEnv)
Set MFn = varRet
End Function
objNS.Add NewMalSym("fn*"), NewVbsProc("MFn", True)
objNS.Add "fn*", NewVbsProc("MFn", True)

Call InitBuiltIn()

Expand All @@ -138,7 +138,7 @@ Sub REPL()
On Error Resume Next
strRes = REP(strCode)
If Err.Number <> 0 Then
IO.WriteErrLine "Exception: " + Err.Description
IO.WriteErrLine "Exception: " + Err.Description
Else
If strRes <> "" Then
IO.WriteLine strRes
Expand All @@ -158,13 +158,14 @@ Function Evaluate(ByVal objCode, ByVal objEnv)
Set Evaluate = Nothing
Exit Function
End If

Dim varRet, objFirst
If objCode.Type = TYPES.LIST Then
If objCode.Count = 0 Then ' ()
Set Evaluate = objCode
Exit Function
End If

Set objFirst = Evaluate(objCode.Item(0), objEnv)
Set varRet = objFirst.Apply(objCode, objEnv)
Else
Expand Down Expand Up @@ -239,4 +240,4 @@ Sub Include(strFileName)
.GetFile(WScript.ScriptFullName)) & _
"\" & strFileName).ReadAll
End With
End Sub
End Sub
23 changes: 12 additions & 11 deletions impls/vbs/step6_file.vbs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ Function MDef(objArgs, objEnv)
CheckArgNum objArgs, 2
CheckType objArgs.Item(1), TYPES.SYMBOL
Set varRet = Evaluate(objArgs.Item(2), objEnv)
objEnv.Add objArgs.Item(1), varRet
objEnv.Add objArgs.Item(1).Value, varRet
Set MDef = varRet
End Function
objNS.Add NewMalSym("def!"), NewVbsProc("MDef", True)
objNS.Add "def!", NewVbsProc("MDef", True)

Function MLet(objArgs, objEnv)
Dim varRet
Expand All @@ -49,13 +49,13 @@ Function MLet(objArgs, objEnv)
For i = 0 To objBinds.Count - 1 Step 2
Set objSym = objBinds.Item(i)
CheckType objSym, TYPES.SYMBOL
objNewEnv.Add objSym, Evaluate(objBinds.Item(i + 1), objNewEnv)
objNewEnv.Add objSym.Value, Evaluate(objBinds.Item(i + 1), objNewEnv)
Next

Set varRet = EvalLater(objArgs.Item(2), objNewEnv)
Set MLet = varRet
End Function
objNS.Add NewMalSym("let*"), NewVbsProc("MLet", True)
objNS.Add "let*", NewVbsProc("MLet", True)

Function MDo(objArgs, objEnv)
Dim varRet, i
Expand All @@ -71,7 +71,7 @@ Function MDo(objArgs, objEnv)
objEnv)
Set MDo = varRet
End Function
objNS.Add NewMalSym("do"), NewVbsProc("MDo", True)
objNS.Add "do", NewVbsProc("MDo", True)

Function MIf(objArgs, objEnv)
Dim varRet
Expand Down Expand Up @@ -101,7 +101,7 @@ Function MIf(objArgs, objEnv)
End If
Set MIf = varRet
End Function
objNS.Add NewMalSym("if"), NewVbsProc("MIf", True)
objNS.Add "if", NewVbsProc("MIf", True)

Function MFn(objArgs, objEnv)
Dim varRet
Expand All @@ -119,7 +119,7 @@ Function MFn(objArgs, objEnv)
Set varRet = NewMalProc(objParams, objCode, objEnv)
Set MFn = varRet
End Function
objNS.Add NewMalSym("fn*"), NewVbsProc("MFn", True)
objNS.Add "fn*", NewVbsProc("MFn", True)

Function MEval(objArgs, objEnv)
Dim varRes
Expand All @@ -129,7 +129,7 @@ Function MEval(objArgs, objEnv)
Set varRes = EvalLater(varRes, objNS)
Set MEval = varRes
End Function
objNS.Add NewMalSym("eval"), NewVbsProc("MEval", True)
objNS.Add "eval", NewVbsProc("MEval", True)

Call InitBuiltIn()

Expand All @@ -143,7 +143,7 @@ Sub InitArgs()
objArgs.Add NewMalStr(WScript.Arguments.Item(i))
Next

objNS.Add NewMalSym("*ARGV*"), objArgs
objNS.Add "*ARGV*", objArgs

If WScript.Arguments.Count > 0 Then
REP "(load-file """ + WScript.Arguments.Item(0) + """)"
Expand Down Expand Up @@ -186,13 +186,14 @@ Function Evaluate(ByVal objCode, ByVal objEnv)
Set Evaluate = Nothing
Exit Function
End If

Dim varRet, objFirst
If objCode.Type = TYPES.LIST Then
If objCode.Count = 0 Then ' ()
Set Evaluate = objCode
Exit Function
End If

Set objFirst = Evaluate(objCode.Item(0), objEnv)
Set varRet = objFirst.Apply(objCode, objEnv)
Else
Expand Down Expand Up @@ -267,4 +268,4 @@ Sub Include(strFileName)
.GetFile(WScript.ScriptFullName)) & _
"\" & strFileName).ReadAll
End With
End Sub
End Sub
Loading

0 comments on commit 38fbfb0

Please sign in to comment.