diff options
author | SoniEx2 <endermoneymod@gmail.com> | 2024-05-29 23:00:53 -0300 |
---|---|---|
committer | SoniEx2 <endermoneymod@gmail.com> | 2024-05-29 23:00:53 -0300 |
commit | 5eecbd6ef771a54b455d96f4033212062d7c3f8f (patch) | |
tree | 9fef3d210df849e82baa763b8b2b885c4806ca96 /src/cratera/compiler.lua | |
parent | bbb9f04eecc66a9e8e208cc4abc0466697807765 (diff) |
Implement cratera bootstrap
Diffstat (limited to 'src/cratera/compiler.lua')
-rw-r--r-- | src/cratera/compiler.lua | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/cratera/compiler.lua b/src/cratera/compiler.lua index 2f4a998..cb0681f 100644 --- a/src/cratera/compiler.lua +++ b/src/cratera/compiler.lua @@ -1,6 +1,6 @@ --[[ This file is part of Cratera Compiler - Copyright (C) 2019 Soni L. + Copyright (C) 2019, 2024 Soni L. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by @@ -42,7 +42,9 @@ local END_OF_STMT = {} local END_OF_CRATERA = {} -- implementation of myobj:[mytrait].myfunction(...) -local CRATERA_FUNCTION = "function(myobj, mytrait, myfunction, ...) return myobj[mytrait][myfunction](myobj, ...) end" +-- TODO benchmark under luajit? +local CRATERA_FUNCTION = "_CRATERA_INVOKE_TRAIT" +local CRATERA_INIT = "local function "..CRATERA_FUNCTION.."(myobj, mytrait, myfunction, ...) return myobj[mytrait][myfunction](myobj, ...) end " local EXTRA_DATA = {[TK.NAME] = true, [TK.INT] = true, [TK.FLT] = true, [TK.STRING] = true, [END_OF_STMT] = true} @@ -134,7 +136,7 @@ defs[parser.EOZ] = function(state, token) return FINISH end defs[parser.FALLBACK] = function(state, token) - local results = state.results or (function() state.results = {} return state.results end)() + local results = state.results or (function() state.results = {CRATERA_INIT, n=1} return state.results end)() do -- handle newlines. this allows error messages to correctly map between lua and cratera local oldline = state.oldline or 1 |