corth-lang / Corth

A self-hosted stack based language like Forth
MIT License
7 stars 1 forks source link

Structs #20

Open HuseyinSimsek7904 opened 9 months ago

HuseyinSimsek7904 commented 9 months ago

We need structs in the language. Structs in Corth will be stored in the stack and when we have a better way to create variables, we will add struct pointers etc. This should probably not be priority until types are improved.

// Defining a struct
struct Employee
  int id
  int salary
end

// Constructing a struct
3 3800 make Employee

//  Get the value of a field in the struct
3 3800 make Employee let emp in
  emp get id putu
  // ...or...
  emp get Employee id putu
end

// Set the value of a field in the struct
3 3800 make Employee let emp in
  4 emp set id
  // ...or...
  4 emp set Employee id
end