Skip to content

Commit

Permalink
delete variable or property, closes #155 (ms 2.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmgl committed Nov 7, 2022
1 parent f3aa661 commit 986269d
Show file tree
Hide file tree
Showing 13 changed files with 1,657 additions and 1,546 deletions.
21 changes: 21 additions & 0 deletions static/js/languages/microscript/v2/compiler.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class Compiler
return @compileDo(statement)
else if statement instanceof Program.Sleep
return @compileSleep(statement)
else if statement instanceof Program.Delete
return @compileDelete(statement)
else if true
console.info statement
throw "Not implemented"
Expand Down Expand Up @@ -655,6 +657,25 @@ class Compiler
@routine.MUL sleep
@routine.SLEEP sleep

compileDelete:(del)->
if del.field instanceof Program.Variable
@routine.LOAD_THIS del
@routine.LOAD_VALUE del.field.identifier,del
@routine.DELETE del
return
else
@compile del.field.expression

chain = del.field.chain

for i in [0..chain.length-1] by 1
@compile chain[i]
if i < chain.length-1
@routine.LOAD_PROPERTY del

@routine.DELETE del
return

exec:(context)->
@processor = new Processor()
@processor.load @routine
Expand Down
1,419 changes: 736 additions & 683 deletions static/js/languages/microscript/v2/compiler.js

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions static/js/languages/microscript/v2/parser.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ class @Parser
when Token.TYPE_EVERY then @parseEvery token
when Token.TYPE_DO then @parseDo token
when Token.TYPE_SLEEP then @parseSleep token
when Token.TYPE_DELETE then @parseDelete token

else
@tokenizer.pushBack token
Expand Down Expand Up @@ -659,3 +660,11 @@ class @Parser
@tokenizer.pushBack token

return new Program.Sleep sleep,delay,multiplier

parseDelete:(del)->
v = @parseExpression()

if not v? or (v not instanceof Program.Variable and v not instanceof Program.Field)
@error "expecting variable name or property access after keyword `delete`"
else
return new Program.Delete del,v
Loading

0 comments on commit 986269d

Please sign in to comment.