Skip to content

Commit

Permalink
Add [new] built-in
Browse files Browse the repository at this point in the history
Remove [copy], [isMoved], [move], and [moveIf] built-ins
Make [set] built-in move writable sources
  • Loading branch information
MatwayBurkow committed Feb 14, 2021
1 parent 57c2514 commit c2f2131
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 101 deletions.
138 changes: 41 additions & 97 deletions builtinImpl.mpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 [
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 1 addition & 4 deletions builtins.mpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;}
Expand All @@ -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 ;}
Expand All @@ -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 ;}
Expand Down
4 changes: 4 additions & 0 deletions defaultImpl.mpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c2f2131

Please sign in to comment.