Skip to content

Instantly share code, notes, and snippets.

@okram
Last active November 13, 2019 20:49
Show Gist options
  • Save okram/156672609c818584fb13b9f3b6bbf072 to your computer and use it in GitHub Desktop.
Save okram/156672609c818584fb13b9f3b6bbf072 to your computer and use it in GitHub Desktop.
// type checking/inference
// The result is the compiled bytecode which shows the types for nested sequences
mmadt> obj{0} <= [start,int][plus,5][mult,5][is,[gt,5]][plus,100][is,[mult,45][minus,10][gt,0]]
==>int{?} <= [start,int][plus,5][mult,5][is,bool <= [gt,5]][plus,100][is,bool{?} <= [mult,45][minus,10][gt,0]]
// instance execution
// take the resultant instruction above and plug in 10 for int at the [start]
mmadt> int{?} <= [start,10][plus,5][mult,5][is,bool <= [gt,5]][plus,100][is,bool{?} <= [mult,45][minus,10][gt,0]]
==>175
mmadt> int{?} <= [start,-10][plus,5][mult,5][is,bool <= [gt,5]][plus,100][is,bool{?} <= [mult,45][minus,10][gt,0]]
mmadt>
// Thus, the type was right, int{?}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment