diff options
| author | Drahflow <drahflow@gmx.de> | 2014-03-01 23:06:23 +0100 |
|---|---|---|
| committer | Drahflow <drahflow@gmx.de> | 2014-03-01 23:06:23 +0100 |
| commit | 80011a7059303d878d31a2eeb1c6ca9895ece2bd (patch) | |
| tree | 39bdee2b8c7711b48294ebef5f0644ca5a23264c | |
| parent | f6b526efbdcd0c4cbaf361d8ec1159a4808b9c88 (diff) | |
Dynamically-scoped variables
| -rw-r--r-- | compiler/elymasGlobalSys.ey | 1 | ||||
| -rw-r--r-- | compiler/elymasGlobalSysDyn.ey | 83 | ||||
| -rw-r--r-- | notes | 5 |
3 files changed, 89 insertions, 0 deletions
diff --git a/compiler/elymasGlobalSys.ey b/compiler/elymasGlobalSys.ey index 912d5c0..68a30c9 100644 --- a/compiler/elymasGlobalSys.ey +++ b/compiler/elymasGlobalSys.ey @@ -120,6 +120,7 @@ "elymasGlobalSysAsm.ey" include "elymasGlobalSysOpt.ey" include + "elymasGlobalSysDyn.ey" include "elymasGlobalSysTyped.ey" include leaveSubScope diff --git a/compiler/elymasGlobalSysDyn.ey b/compiler/elymasGlobalSysDyn.ey new file mode 100644 index 0000000..0f1c542 --- /dev/null +++ b/compiler/elymasGlobalSysDyn.ey @@ -0,0 +1,83 @@ +# dynamic variables with stack +< + "dyn" enterSubScope + + 5 ==DYNAMICVARIABLEMARKER + + < + # get dynamic variable value + # 0 -> dynamic variable object + # 0 <- non-zero if a value is defined, zero otherwise + # 1 <- current value (if it exists) + [[ + /rbx :popqReg + + /rdx :popqReg + DYNAMICVARIABLEMARKER /rax :movqImmReg + :STACKBOTTOMMARKER /rcx :movqImmReg + /r15 /rsi :movqRegReg + 8 /rsi :subqImm8Reg + + @scanStack + 8 /rsi :addqImm8Reg + + /rsi /rax :cmpqMemReg + /dynamicVariableMarker :jzLbl8 + /rsi /rcx :cmpqMemReg + /scanStack :jnzLbl8 + + # no value was found + /rax /rax :xorqRegReg + 63 /rax :btsqImm8Reg + /rax :pushqReg + + /rbx :pushqReg + :retn + + @dynamicVariableMarker + 8 /rsi /rdx :cmpqMemDisp8Reg + /scanStack :jnzLbl8 # wrong variable + + 16 /rsi :pushqMemDisp8 + /rax /rax :xorqRegReg + /rax :incqReg + 63 /rax :btsqImm8Reg + /rax :pushqReg + + /rbx :pushqReg + :retn + ]] /eyget defv + + # set dynamic variable and execute function + # 0 -> dynamic variable object + # 1 -> value to set + # 2 -> object to execute + [[ + 8 /r15 :subqImm8Reg + /r15 :popqMem + + 24 /r15 :subqImm8Reg + 8 /r15 :popqMemDisp8 + 16 /r15 :popqMemDisp8 + DYNAMICVARIABLEMARKER /rax :movqImmReg + /rax /r15 :movqRegMem + + |ey* /rax :movqImmReg + /rax :callqReg + + 24 /r15 :addqImm8Reg + /r15 :pushqMem + 8 /r15 :addqImm8Reg + :retn + ]] /eywith defv + > _ ==globalFunctions { defv }' ::allocateOffsetStruct + + [ + globalFunctions keys eydeff { | }' createScopeEntries + createScopeExtensionEntries + ] :execute + + leaveSubScope +> -- + +# vim: syn=elymas @@ -131,6 +131,11 @@ bottom of stack marker 0000000000000000000000000000000000000000000000000000000000000100 error data marker (only for external debugging) +0000000000000000000000000000000000000000000000000000000000000101 +dynamic variable binding marker (call stack only) +next two cells (upwards into the stack) +* reference to dynamic variable object +* reference to current value = Memory Management = |
