From c2f2131fefab497b2aeba5027205c94f5b17275a Mon Sep 17 00:00:00 2001 From: Matway Burkow <2745204+MatwayBurkow@users.noreply.github.com> Date: Sun, 14 Feb 2021 21:12:40 +0300 Subject: [PATCH] Add [new] built-in Remove [copy], [isMoved], [move], and [moveIf] built-ins Make [set] built-in move writable sources --- builtinImpl.mpl | 138 ++++++++++++++---------------------------------- builtins.mpl | 5 +- defaultImpl.mpl | 4 ++ 3 files changed, 46 insertions(+), 101 deletions(-) diff --git a/builtinImpl.mpl b/builtinImpl.mpl index 0a98450..f405cd3 100644 --- a/builtinImpl.mpl +++ b/builtinImpl.mpl @@ -916,48 +916,6 @@ staticityOfBinResult: [ [TRUE @processor @block defaultMakeConstWith] "mplBuiltinConst" @declareBuiltin ucall -[ - refToVar: @processor @block pop; - processor compilable [ - refToVar getVar.temporary [ - "temporary objects cannot be copied" @processor block compilerError - ] [ - refToVar getVar.data.getTag VarImport = [ - "functions cannot be copied" @processor block compilerError - ] [ - refToVar getVar.data.getTag VarString = [ - "builtin-strings cannot be copied" @processor block compilerError - ] [ - refToVar isPlain [ - refToVar staticityOfVar Dynamic > [ - result: refToVar @processor @block copyVarToNew @processor @block createPlainIR; - TRUE @result.setMutable - result @block push - ] [ - refToVar isVirtual ~ [@refToVar @processor @block makeVarRealCaptured] when - result: refToVar @processor @block copyVarToNew; - TRUE @result.setMutable - @refToVar @result @processor @block createCopyToNew - result @block push - ] if - ] [ - refToVar isVirtual ~ [@refToVar @processor @block makeVarRealCaptured] when - result: refToVar @processor @block copyVarToNew; - result isVirtual [ - result isAutoStruct ["unable to copy virtual autostruct" @processor block compilerError] when - ] [ - TRUE @result.setMutable - @refToVar @result @processor @block createCopyToNew - ] if - - result @block push - ] if - ] if - ] if - ] if - ] when -] "mplBuiltinCopy" @declareBuiltin ucall - [ TRUE dynamic @processor.@usedFloatBuiltins set [a:; a getVar.data.getTag VarReal32 = ["@llvm.cos.f32" makeStringView]["@llvm.cos.f64" makeStringView] if @@ -1370,15 +1328,6 @@ staticityOfBinResult: [ ] when ] "mplBuiltinIsDynamic" @declareBuiltin ucall -[ - refToVar: @processor @block pop; - processor compilable [ - refToVar @block push - refToVar isAutoStruct [refToVar varIsMoved] && makeValuePair - VarCond @processor @block createVariable Static @processor @block makeStaticity @processor @block createPlainIR @block push - ] when -] "mplBuiltinIsMoved" @declareBuiltin ucall - [ refToVar: @processor @block pop; processor compilable [ @@ -1439,63 +1388,58 @@ staticityOfBinResult: [ ] "mplBuiltinMod" @declareBuiltin ucall [ - refToVar: @processor @block pop; - processor compilable [ - refToVar.mutable [ - refToVar isVirtual [ - refToVar @block push - ] [ - var: @refToVar getVar; - var.data.getTag VarStruct = [ - TRUE @refToVar.setMoved - ] when - - refToVar @block push - ] if - ] [ - "moved can be only mutable variables" @processor block compilerError - ] if - ] when -] "mplBuiltinMove" @declareBuiltin ucall + VarInt8 VarReal64 1 + [ + a:; a isAnyInt ["sub" makeStringView]["fsub" makeStringView] if + ] [ + a:; a isAnyInt ["0, " makeStringView]["0x0000000000000000, " makeStringView] if + ] [neg] [x:;] mplNumberUnaryOp +] "mplBuiltinNeg" @declareBuiltin ucall [ - refToCond: @processor @block pop; + refToVar: @processor @block pop; processor compilable [ - condVar: refToCond getVar; - condVar.data.getTag VarCond = ~ [refToCond staticityOfVar Dynamic > ~] || ["not a static Cond" @processor block compilerError] when - processor compilable [ - refToVar: @processor @block pop; - processor compilable [ - VarCond condVar.data.get.end [ - refToVar.mutable [ - refToVar isVirtual [ - refToVar @block push + refToVar getVar.temporary [ + "temporary objects cannot be copied" @processor block compilerError + ] [ + refToVar getVar.data.getTag VarImport = [ + "functions cannot be copied" @processor block compilerError + ] [ + refToVar getVar.data.getTag VarString = [ + "builtin-strings cannot be copied" @processor block compilerError + ] [ + refToVar isPlain [ + refToVar staticityOfVar Dynamic > [ + result: refToVar @processor @block copyVarToNew @processor @block createPlainIR; + TRUE @result.setMutable + result @block push + ] [ + refToVar isVirtual ~ [@refToVar @processor @block makeVarRealCaptured] when + result: refToVar @processor @block copyVarToNew; + TRUE @result.setMutable + @refToVar @result @processor @block createCopyToNew + result @block push + ] if + ] [ + refToVar isVirtual ~ [@refToVar @processor @block makeVarRealCaptured] when + result: refToVar @processor @block copyVarToNew; + result isVirtual [ + result isAutoStruct ["unable to copy virtual autostruct" @processor block compilerError] when ] [ - var: @refToVar getVar; - var.data.getTag VarStruct = [ + TRUE @result.setMutable + refToVar.mutable [refToVar isVirtual ~ [refToVar getVar .data.getTag VarStruct =] &&] && [ TRUE @refToVar.setMoved ] when - refToVar @block push + @refToVar @result @processor @block createCopyToNew ] if - ] [ - "moved can be only mutable variables" @processor block compilerError + + result @block push ] if - ] [ - refToVar @block push ] if - ] when - ] when + ] if + ] if ] when -] "mplBuiltinMoveIf" @declareBuiltin ucall - -[ - VarInt8 VarReal64 1 + [ - a:; a isAnyInt ["sub" makeStringView]["fsub" makeStringView] if - ] [ - a:; a isAnyInt ["0, " makeStringView]["0x0000000000000000, " makeStringView] if - ] [neg] [x:;] mplNumberUnaryOp -] "mplBuiltinNeg" @declareBuiltin ucall +] "mplBuiltinNew" @declareBuiltin ucall [ refToVar: @processor @block pop; diff --git a/builtins.mpl b/builtins.mpl index 7238584..f8cad29 100644 --- a/builtins.mpl +++ b/builtins.mpl @@ -40,7 +40,6 @@ builtins: ( {name: "codeRef" ; impl: @mplBuiltinCodeRef ;} {name: "compileOnce" ; impl: @mplBuiltinCompileOnce ;} {name: "const" ; impl: @mplBuiltinConst ;} - {name: "copy" ; impl: @mplBuiltinCopy ;} {name: "cos" ; impl: @mplBuiltinCos ;} {name: "def" ; impl: @mplBuiltinDef ;} {name: "dynamic" ; impl: @mplBuiltinDynamic ;} @@ -60,7 +59,6 @@ builtins: ( {name: "isCombined" ; impl: @mplBuiltinIsCombined ;} {name: "isConst" ; impl: @mplBuiltinIsConst ;} {name: "isDynamic" ; impl: @mplBuiltinIsDynamic ;} - {name: "isMoved" ; impl: @mplBuiltinIsMoved ;} {name: "isStatic" ; impl: @mplBuiltinIsStatic ;} {name: "log" ; impl: @mplBuiltinLog ;} {name: "log10" ; impl: @mplBuiltinLog10 ;} @@ -69,9 +67,8 @@ builtins: ( {name: "manuallyDestroyVariable" ; impl: @mplBuiltinManuallyDestroyVariable ;} {name: "manuallyInitVariable" ; impl: @mplBuiltinManuallyInitVariable ;} {name: "mod" ; impl: @mplBuiltinMod ;} - {name: "move" ; impl: @mplBuiltinMove ;} - {name: "moveIf" ; impl: @mplBuiltinMoveIf ;} {name: "neg" ; impl: @mplBuiltinNeg ;} + {name: "new" ; impl: @mplBuiltinNew ;} {name: "newVarOfTheSameType" ; impl: @mplBuiltinNewVarOfTheSameType ;} {name: "or" ; impl: @mplBuiltinOr ;} {name: "overload" ; impl: @mplBuiltinOverload ;} diff --git a/defaultImpl.mpl b/defaultImpl.mpl index 9ff3f61..b20d3cf 100644 --- a/defaultImpl.mpl +++ b/defaultImpl.mpl @@ -90,6 +90,10 @@ defaultSet: [ ] [ refToDst.mutable [ [refToDst staticityOfVar Weak = ~] "Destination is weak!" assert + refToSrc.mutable [refToSrc isVirtual ~ [refToSrc getVar .data.getTag VarStruct =] &&] && [ + TRUE @refToSrc.setMoved + ] when + @refToSrc @refToDst @processor @block createCopyToExists ] [ "destination is immutable" @processor block compilerError