For example, a language that I was looking at recently- Terra. You can address the question in the context of any language, I'm just most comfortable with Lua so I'm starting from there.
The Terra Language can be metaprogrammed with Lua and is backwards compatible with C. C code can be used inside of it and its code can be used inside of C. I'll give some code examples from the main page.
terra hello(argc : int, argv : &rawstring)
-- Here we call a C function from Terra
C.printf("Hello, Terra!\n")
return 0
end
-- You can call Terra functions directly from Lua, they are JIT compiled
-- using LLVM to create machine code
hello(0,nil)
hello:disas()
--[[ output:
assembly for function at address 0x60e6010
0x60e6010(+0): push rax
0x60e6011(+1): movabs rdi, 102129664
0x60e601b(+11): movabs rax, 140735712154681
0x60e6025(+21): call rax
0x60e6027(+23): xor eax, eax
0x60e6029(+25): pop rdx
0x60e602a(+26): ret
]]
Save Terra code to an external representation such as an object file, or executable. filetype can be one of "object" (an object file *.o), "asm" (an assembly file *.s), "bitcode" (LLVM bitcode *.bc), "llvmir" (LLVM textual IR *.ll), or "executable" (no extension).
Now, what I want to know (in relation to Terra and/or in general):
- Does this mean that I can write an operating system in Lua? (Is this the level of criteria I should be looking for when examing frameworks and languages?)
- If so, can I also implement Lua libraries such as Torch? (All languages have libraries, so I'm curious about what defines how much they can make use of them through OS development).
- Is there an objectively better way or language to do this? (As in, when does a language fully meet the critera yet not hold viability when it comes to operating system development?)